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

Go to the SVN repository for this file.

1 /* $Id: bam_coverage_graph_panel.cpp 45702 2020-10-27 15:13:28Z shkeda $
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: Liangshou Wu
27  */
28 
29 
30 // Generated by DialogBlocks (unregistered), 02/03/2011 09:12:09
31 
32 #include <ncbi_pch.hpp>
35 #include <gui/utils/job_future.hpp>
36 
37 #include <corelib/ncbifile.hpp>
38 #include <wx/dirdlg.h>
39 #include <wx/filename.h>
40 #include <wx/checkbox.h>
41 #include <wx/radiobut.h>
42 #include <wx/sizer.h>
43 #include <wx/stattext.h>
44 #include <wx/statbox.h>
45 #include <wx/button.h>
46 #include <wx/msgdlg.h>
47 #include <wx/textctrl.h>
48 #include <wx/filedlg.h>
49 
51 
53 
54 ////@begin XPM images
55 ////@end XPM images
56 
59 
60 /*!
61  * CBamCoverageGraphPanel type definition
62  */
63 
64 IMPLEMENT_DYNAMIC_CLASS( CBamCoverageGraphPanel, wxPanel )
65 
66 
67 /*!
68  * CBamCoverageGraphPanel event table definition
69  */
70 
71 BEGIN_EVENT_TABLE( CBamCoverageGraphPanel, wxPanel )
72 
73 ////@begin CBamCoverageGraphPanel event table entries
75 ////@end CBamCoverageGraphPanel event table entries
76 
78 
79 
80 /*!
81  * CBamCoverageGraphPanel constructors
82  */
83 
85 {
86  Init();
87 }
88 
89 CBamCoverageGraphPanel::CBamCoverageGraphPanel( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
90 {
91  Init();
92  Create(parent, id, caption, pos, size, style);
93 }
94 
95 
96 /*!
97  * CBamCoverageGraphPanel creator
98  */
99 
100 bool CBamCoverageGraphPanel::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
101 {
102 ////@begin CBamCoverageGraphPanel creation
103  SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY);
104  wxPanel::Create( parent, id, pos, size, style );
105 
106  CreateControls();
107  if (GetSizer())
108  {
109  GetSizer()->SetSizeHints(this);
110  }
111  Centre();
112 ////@end CBamCoverageGraphPanel creation
113 
114  return true;
115 }
116 
117 
118 /*!
119  * CBamCoverageGraphPanel destructor
120  */
121 
123 {
124 ////@begin CBamCoverageGraphPanel destruction
125 ////@end CBamCoverageGraphPanel destruction
126 }
127 
128 
129 /*!
130  * Member initialisation
131  */
132 
134 {
135 ////@begin CBamCoverageGraphPanel member initialisation
138 ////@end CBamCoverageGraphPanel member initialisation
139 }
140 
141 
142 /*!
143  * Control creation for CBamCoverageGraphPanel
144  */
145 
146 // Fix Solaris/DialogBlocks issue
147 #ifndef _T
148  #define _T wxT
149 #endif
150 
152 {
153 ////@begin CBamCoverageGraphPanel content construction
154  CBamCoverageGraphPanel* itemPanel1 = this;
155 
156  wxStaticBox* itemStaticBoxSizer1Static = new wxStaticBox(itemPanel1, wxID_ANY, _("Assembly Options"));
157  wxStaticBoxSizer* itemStaticBoxSizer1 = new wxStaticBoxSizer(itemStaticBoxSizer1Static, wxVERTICAL);
158  itemPanel1->SetSizer(itemStaticBoxSizer1);
159 
160  wxStaticBox* itemStaticBoxSizer2Static = new wxStaticBox(itemStaticBoxSizer1->GetStaticBox(), wxID_ANY, _("BAM File Assembly Identifier"));
161  wxStaticBoxSizer* itemStaticBoxSizer2 = new wxStaticBoxSizer(itemStaticBoxSizer2Static, wxHORIZONTAL);
162  itemStaticBoxSizer1->Add(itemStaticBoxSizer2, 0, wxGROW|wxALL, 5);
163 
164  m_BamAssembly = new wxStaticText( itemStaticBoxSizer2->GetStaticBox(), wxID_STATIC, _("N/A"), wxDefaultPosition, wxSize(213, -1), wxALIGN_LEFT|wxSTATIC_BORDER );
165  itemStaticBoxSizer2->Add(m_BamAssembly, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
166 
167  wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
168  itemStaticBoxSizer1->Add(itemBoxSizer4, 0, wxGROW|wxLEFT|wxRIGHT, 5);
169 
170  m_AssemblyPanel = new CAssemblySelPanel( itemStaticBoxSizer1->GetStaticBox(), ID_PANEL9, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
171  itemBoxSizer4->Add(m_AssemblyPanel, 1, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM, 5);
172 
173 ////@end CBamCoverageGraphPanel content construction
174 }
175 
176 
177 void CBamCoverageGraphPanel::SetBamFiles(const vector<pair<string, string>>& bam_files)
178 {
179  if (bam_files.empty()) return;
180 
181  m_BamFiles = bam_files;
182  m_BamAssemblyFuture = job_async([bam_files](ICanceled& canceled) {
183  string bamAssembly;
184  try {
185  for (const auto& iter : bam_files) {
186  if (canceled.IsCanceled())
187  break;
188  CBamRawDb db(iter.first);
189  //string header = db.GetHeaderText();
190  const string& header = db.GetHeader().GetText();
191  if (header.empty())
192  continue;
193  if (canceled.IsCanceled())
194  break;
195  list<string> lines;
196  NStr::Split(header, "\n\r", lines, NStr::fSplit_Tokenize);
197  for (const auto& line : lines) {
198  if (line.size() > 3 && line.substr(0, 3) == "@SQ") {
199  list<string> fields;
200  NStr::Split(line, "\t", fields, NStr::fSplit_Tokenize);
201  for (const auto& field : fields) {
202  if (field.size() > 3 && field.substr(0, 3) == "AS:") {
203  bamAssembly = field.substr(3);
204  break;
205  }
206  }
207  if (!bamAssembly.empty())
208  break;
209  }
210  }
211  if (!bamAssembly.empty())
212  break;
213  }
214  } catch (const exception& e) {
215  ERR_POST(Error << e.what());
216  }
217  return bamAssembly;
218  }, "Retrieving BAM Assembly");
219 
220  m_BamAssembly->SetLabel(wxT("Pending..."));
221  m_BamAssembly->SetToolTip(wxT("BAM Assembly tag is being retrieved..."));
222 }
223 
224 
226 {
228 }
229 
230 
231 
232 /*!
233  * Should we show tooltips?
234  */
235 
237 {
238  return true;
239 }
240 
241 /*!
242  * Get bitmap resources
243  */
244 
245 wxBitmap CBamCoverageGraphPanel::GetBitmapResource( const wxString& name )
246 {
247  // Bitmap retrieval
248 ////@begin CBamCoverageGraphPanel bitmap retrieval
249  wxUnusedVar(name);
250  return wxNullBitmap;
251 ////@end CBamCoverageGraphPanel bitmap retrieval
252 }
253 
254 /*!
255  * Get icon resources
256  */
257 
258 wxIcon CBamCoverageGraphPanel::GetIconResource( const wxString& name )
259 {
260  // Icon retrieval
261 ////@begin CBamCoverageGraphPanel icon retrieval
262  wxUnusedVar(name);
263  return wxNullIcon;
264 ////@end CBamCoverageGraphPanel icon retrieval
265 }
266 
267 
268 /*!
269  * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BROWSEBUTTON
270  */
271 
272 
273 static const char* kMappingAssembly = ".MapAssembly";
274 
276 {
277  if( ! m_RegPath.empty()) {
280 
282  }
283 }
284 
286 {
287  if ( !m_RegPath.empty() ) {
290 
292  }
293 }
294 
295 
296 /*!
297  * wxEVT_IDLE event handler for ID_CBAMCOVERAGEGRAPHPANEL
298  */
299 
300 void CBamCoverageGraphPanel::OnIdle(wxIdleEvent& event)
301 {
303  try {
304  string bam_assembly = m_BamAssemblyFuture();
305  if (!bam_assembly.empty()) {
306  wxString str = ToWxString(bam_assembly);
307  m_BamAssembly->SetLabel(str);
308  m_BamAssembly->SetToolTip(str);
309  } else {
310  m_BamAssembly->SetLabel(wxT("N/A"));
311  m_BamAssembly->SetToolTip(wxEmptyString);
312  }
313 
314 
315  } catch (const std::exception&) {
316  }
317  m_BamAssemblyFuture.reset(); // not neccessary but recommended to release resources
318  } else
319  event.Skip();
320 }
321 
322 
324 
325 
326 
327 
USING_SCOPE(objects)
static const char * kMappingAssembly
CMapAssemblyParams & GetData()
Data access.
virtual bool TransferDataFromWindow()
static bool ShowToolTips()
Should we show tooltips?
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
void SetBamFiles(const vector< pair< string, string >> &bam_files)
void Init()
Initialises member variables.
vector< pair< string, string > > m_BamFiles
void OnIdle(wxIdleEvent &event)
wxEVT_IDLE event handler for ID_CBAMCOVERAGEGRAPHPANEL
bool Create(wxWindow *parent, wxWindowID id=ID_CBAMCOVERAGEGRAPHPANEL, const wxString &caption=_("Assembly Options"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
Creation.
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
job_future< string > m_BamAssemblyFuture
void CreateControls()
Creates the controls and sizers.
const string & GetText() const
Definition: bamindex.hpp:67
const CBamHeader & GetHeader() const
Definition: bamindex.hpp:1010
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
class CRegistryReadView provides a nested hierarchical view at a particular key.
Definition: reg_view.hpp:58
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 ERR_POST(message)
Error posting with file, line number information but without error codes.
Definition: ncbidiag.hpp:186
void Error(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1197
#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
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
Definition: ncbistr.cpp:3461
@ fSplit_Tokenize
All delimiters are merged and trimmed, to get non-empty tokens only.
Definition: ncbistr.hpp:2508
job_function_traits< _Fty >::future job_async(const _Fty &_Fnarg, const string &descr)
Definition: job_future.hpp:428
END_EVENT_TABLE()
for(len=0;yy_str[len];++len)
if(yy_accept[yy_current_state])
#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
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
Modified on Sun Apr 14 05:29:15 2024 by modify_doxy.py rev. 669887