NCBI C++ ToolKit
vcf_assembly_sel_panel.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: vcf_assembly_sel_panel.cpp 45881 2021-01-05 03:10:02Z rudnev $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Vladislav Evgeniev
27  */
28 
29 #include <ncbi_pch.hpp>
33 #include <gui/utils/job_future.hpp>
34 
35 #include <corelib/ncbifile.hpp>
36 #include <wx/dirdlg.h>
37 #include <wx/filename.h>
38 #include <wx/sizer.h>
39 #include <wx/stattext.h>
40 #include <wx/statbox.h>
41 
45 
46 
49 
50 /*!
51  * CVcfAssemblySelectionPanel type definition
52  */
53 
54 IMPLEMENT_DYNAMIC_CLASS( CVcfAssemblySelectionPanel, wxPanel )
55 
56 
57 /*!
58  * CVcfAssemblySelectionPanel event table definition
59  */
60 
61 BEGIN_EVENT_TABLE( CVcfAssemblySelectionPanel, wxPanel )
62 
63 ////@begin CVcfAssemblySelectionPanel event table entries
65 ////@end CVcfAssemblySelectionPanel event table entries
66 
68 
69 
70 /*!
71  * CVcfAssemblySelectionPanel constructors
72  */
73 
75 {
76  Init();
77 }
78 
80  const wxString &input_vcf, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
81  : m_VCFReader(vcf_reader), m_InputVcf(input_vcf)
82 {
83  Init();
84  Create(parent, id, pos, size, style);
85 }
86 
87 
88 /*!
89  * CVcfAssemblySelectionPanel creator
90  */
91 
92 bool CVcfAssemblySelectionPanel::Create( wxWindow* parent,
93  wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
94 {
95 ////@begin CVcfAssemblySelectionPanel creation
96  SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY);
97  wxPanel::Create( parent, id, pos, size, style );
98 
100  if (GetSizer())
101  {
102  GetSizer()->SetSizeHints(this);
103  }
104  Centre();
105 ////@end CVcfAssemblySelectionPanel creation
106  return true;
107 }
108 
109 
110 /*!
111  * CVcfAssemblySelectionPanel destructor
112  */
113 
115 {
116 ////@begin CVcfAssemblySelectionPanel destruction
117 ////@end CVcfAssemblySelectionPanel destruction
118 }
119 
120 
121 /*!
122  * Member initialisation
123  */
124 
126 {
127 ////@begin CVcfAssemblySelectionPanel member initialisation
130 ////@end CVcfAssemblySelectionPanel member initialisation
131 }
132 
133 
134 /*!
135  * Control creation for CVcfAssemblySelectionPanel
136  */
137 
139 {
140 ////@begin CVcfAssemblySelectionPanel content construction
141  // Generated by DialogBlocks, 25/09/2020 13:45:56 (unregistered)
142 
143  CVcfAssemblySelectionPanel* itemPanel1 = this;
144 
145  wxStaticBox* itemStaticBoxSizer2Static = new wxStaticBox(itemPanel1, wxID_ANY, _("Assembly Options"));
146  wxStaticBoxSizer* itemStaticBoxSizer2 = new wxStaticBoxSizer(itemStaticBoxSizer2Static, wxVERTICAL);
147  itemPanel1->SetSizer(itemStaticBoxSizer2);
148 
149  wxStaticBox* itemStaticBoxSizer3Static = new wxStaticBox(itemStaticBoxSizer2->GetStaticBox(), wxID_ANY, _("VCF File Assembly Identifier"));
150  wxStaticBoxSizer* itemStaticBoxSizer3 = new wxStaticBoxSizer(itemStaticBoxSizer3Static, wxHORIZONTAL);
151  itemStaticBoxSizer2->Add(itemStaticBoxSizer3, 0, wxGROW|wxALL, 5);
152 
153  m_VcfAssembly = new wxStaticText( itemStaticBoxSizer3->GetStaticBox(), wxID_STATIC, _("N/A"), wxDefaultPosition, wxSize(213, -1), wxALIGN_LEFT|wxSTATIC_BORDER );
154  itemStaticBoxSizer3->Add(m_VcfAssembly, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
155  x_ReadAssembly();
156 
157  wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxHORIZONTAL);
158  itemStaticBoxSizer2->Add(itemBoxSizer5, 0, wxGROW|wxLEFT|wxRIGHT, 5);
159 
160  m_AssemblyPanel = new CAssemblySelPanel( itemStaticBoxSizer2->GetStaticBox(), ID_PANEL9, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
161  itemBoxSizer5->Add(m_AssemblyPanel, 1, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM, 5);
162 
163 ////@end CVcfAssemblySelectionPanel content construction
166 }
167 
168 static string s_ReadVCFAssembly(CColumnarVCFReader* reader, const wxString& input_vcf, ICanceled& canceled)
169 {
170  string vcf_assm;
171  if (!reader || canceled.IsCanceled())
172  return vcf_assm;
173 
174  try {
175  CCompressedFile file(input_vcf);
176  reader->ReadHeader(file.GetIstream(false), &canceled);
177  vcf_assm = reader->GetAssembly();
178  }
179  catch (const CException& e) {
180  LOG_POST(Error << "s_ReadVCFAssembly failed: " << e.GetMsg());
181  }
182  catch (const exception& e) {
183  LOG_POST(Error << "s_ReadVCFAssembly failed: " << e.what());
184  }
185  return vcf_assm;
186 }
187 
189 {
190  if (!m_VCFReader)
191  return;
193  "Retrieve Assembly name/accession present in VCF file");
194 
195  m_VcfAssembly->SetLabel(wxT("Pending..."));
196  m_VcfAssembly->SetToolTip(wxT("VCF Assembly tag is being retrieved..."));
197 }
198 
200 {
202 }
203 
204 void CVcfAssemblySelectionPanel::SetNewFile(const wxString &input_vcf)
205 {
206  m_InputVcf = input_vcf;
207  x_ReadAssembly();
208 }
209 /*!
210  * Should we show tooltips?
211  */
212 
214 {
215  return true;
216 }
217 
218 /*!
219  * Get bitmap resources
220  */
221 
222 wxBitmap CVcfAssemblySelectionPanel::GetBitmapResource(const wxString& name)
223 {
224  // Bitmap retrieval
225 ////@begin CVcfAssemblySelectionPanel bitmap retrieval
226  wxUnusedVar(name);
227  return wxNullBitmap;
228  ////@end CVcfAssemblySelectionPanel bitmap retrieval
229 }
230 
231 /*!
232  * Get icon resources
233  */
234 
236 {
237  // Icon retrieval
238 ////@begin CVcfAssemblySelectionPanel icon retrieval
239  wxUnusedVar(name);
240  return wxNullIcon;
241  ////@end CVcfAssemblySelectionPanel icon retrieval
242 }
243 
244 
245 /*!
246  * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BROWSEBUTTON
247  */
248 
249 
250 static const char* kMappingAssembly = ".MapAssembly";
251 
253 {
254  if (!m_RegPath.empty()) {
257 
259  }
260 }
261 
263 {
264  if (!m_RegPath.empty()) {
267 
269  }
270 }
271 
272 
273 /*!
274  * wxEVT_IDLE event handler for ID_CVcfAssemblySelectionPanel
275  */
276 
277 void CVcfAssemblySelectionPanel::OnIdle(wxIdleEvent& event)
278 {
280  try {
281  CMapAssemblyParams params;
282  params.SetUseMapping(true);
283 
284  string vcf_assembly = m_VcfAssemblyFuture();
285  if (!vcf_assembly.empty()) {
286  wxString str = ToWxString(vcf_assembly);
287  m_VcfAssembly->SetLabel(str);
288  m_VcfAssembly->SetToolTip(str);
289 
290  params.SetSearchTerm(vcf_assembly);
291  }
292  else {
293  m_VcfAssembly->SetLabel(wxT("N/A"));
294  m_VcfAssembly->SetToolTip(wxEmptyString);
295  }
296  m_AssemblyPanel->SetData(params);
298  }
299  catch (const exception&) {
300  }
301  m_VcfAssemblyFuture.reset(); // not neccessary but recommended to release resources
302  }
303  else {
304  event.Skip();
305  }
306 }
307 
308 
310 
311 
312 
313 
CMapAssemblyParams & GetData()
Data access.
void SetData(const CMapAssemblyParams &data)
void SetUseMapping(bool mapping=true)
virtual bool TransferDataFromWindow()
virtual bool TransferDataToWindow()
void EnableUseMapping(bool enable=true)
Class responsible to read VCF files.
const string & GetAssembly() const
bool ReadHeader(CNcbiIstream &in, ICanceled *canceled=nullptr, objects::ILineErrorListener *listener=nullptr)
Reads only the header section of the file.
CRegistryWriteView GetWriteView(const string &section)
get a read-write view at a particular level.
Definition: registry.cpp:462
static CGuiRegistry & GetInstance()
access the application-wide singleton
Definition: registry.cpp:400
CRegistryReadView GetReadView(const string &section) const
get a read-only view at a particular level.
Definition: registry.cpp:428
void LoadSettings(CRegistryReadView &view)
void SaveSettings(CRegistryWriteView &view) const
void SetSearchTerm(string value)
void SetUseMapping(bool value)
class CRegistryReadView provides a nested hierarchical view at a particular key.
Definition: reg_view.hpp:58
bool Create(wxWindow *parent, wxWindowID id=ID_VCFASSEMBLYSELPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
Creation.
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void Init()
Initialises member variables.
void CreateControls()
Creates the controls and sizers.
void OnIdle(wxIdleEvent &event)
wxEVT_IDLE event handler for ID_VCFASSEMBLYSELPANEL
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
void SetNewFile(const wxString &input_vcf)
job_future< string > m_VcfAssemblyFuture
static bool ShowToolTips()
Should we show tooltips?
Interface for testing cancellation request in a long lasting operation.
Definition: icanceled.hpp:51
bool IsComplete() const
Definition: job_future.hpp:205
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
static const char * str(char *buf, int n)
Definition: stats.c:84
#define NULL
Definition: ncbistd.hpp:225
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
Definition: ncbidiag.hpp:226
void Error(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1197
const string & GetMsg(void) const
Get message string.
Definition: ncbiexpt.cpp:461
virtual const char * what(void) const noexcept
Standard report (includes full backlog).
Definition: ncbiexpt.cpp:342
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
virtual bool IsCanceled(void) const =0
job_function_traits< _Fty >::future job_async(const _Fty &_Fnarg, const string &descr)
Definition: job_future.hpp:428
END_EVENT_TABLE()
FILE * file
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
static static static wxID_ANY
USING_SCOPE(objects)
static const char * kMappingAssembly
static string s_ReadVCFAssembly(CColumnarVCFReader *reader, const wxString &input_vcf, ICanceled &canceled)
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
Modified on Fri Sep 20 14:57:42 2024 by modify_doxy.py rev. 669887