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

Go to the SVN repository for this file.

1 /* $Id: featuretbl_frame.cpp 43605 2019-08-07 19:40:03Z filippov $
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: Andrea Asztalos
27  */
28 
29 
30 #include <ncbi_pch.hpp>
31 
34 
35 #include <gui/objutils/utils.hpp>
37 
45 
46 #include <wx/sizer.h>
47 #include <wx/checkbox.h>
48 #include <wx/button.h>
49 #include <wx/filedlg.h>
50 
53 
54 /*!
55  * CFeatureTblFr type definition
56  */
57 
59 
60 
61 /*!
62  * CFeatureTblFr event table definition
63  */
64 
65 BEGIN_EVENT_TABLE( CFeatureTblFr, wxFrame )
66 
68  EVT_BUTTON(ID_FTBL_REFRESHBTN, CFeatureTblFr::OnRefreshClick)
69 
71 
72 
73 /*!
74  * CFeatureTblFr constructors
75  */
76 
78  : m_Workbench(0)
79 {
80  Init();
81 }
82 
83 CFeatureTblFr::CFeatureTblFr(wxWindow* parent, IWorkbench* workbench, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style)
84  : m_Workbench(workbench)
85 {
86  Init();
87  Create( parent, id, caption, pos, size, style );
89 }
90 
91 
92 /*!
93  * CFeatureTblFr creator
94  */
95 
96 bool CFeatureTblFr::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
97 {
98 ////@begin CFeatureTblFr creation
99  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
100  wxFrame::Create(parent, id, caption, pos, size, style);
101  wxVisualAttributes attr = wxPanel::GetClassDefaultAttributes();
102  if (attr.colBg != wxNullColour)
103  SetOwnBackgroundColour(attr.colBg);
104 
105  CreateControls();
106  Centre();
107 ////@end CFeatureTblFr creation
108  return true;
109 }
110 
111 
112 /*!
113  * CFeatureTblFr destructor
114  */
115 
117 {
118  wxWindow::TransferDataFromWindow();
119  SaveSettings();
120  // job is canceled if main window is destroyed
121  if (m_JobAdapter) {
122  m_JobAdapter->Cancel();
123  }
124 }
125 
126 
127 /*!
128  * Member initialisation
129  */
130 
132 {
133 ////@begin CFeatureTblFr member initialisation
134  m_ProteinId = NULL;
135  m_Source = NULL;
138  m_FindMode = 1;
139  SetRegistryPath("5ColFeatureTable");
140  LoadSettings();
141 ////@end CFeatureTblFr member initialisation
142 }
143 
144 
145 /*!
146  * Control creation for CFeatureTblFr
147  */
148 
150 {
151 ////@begin CFeatureTblFr content construction
152  CFeatureTblFr* itemFrame1 = this;
153 
154  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
155  itemFrame1->SetSizer(itemBoxSizer2);
156 
157  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
158  itemBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
159 
160  wxStaticText* itemStaticText4 = new wxStaticText( itemFrame1, wxID_STATIC, _("Show"), wxDefaultPosition, wxDefaultSize, 0 );
161  itemBoxSizer3->Add(itemStaticText4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
162 
163  m_ProteinId = new wxCheckBox( itemFrame1, ID_FTBL_CHCKBX1, _("Protein/Transcript Id"), wxDefaultPosition, wxDefaultSize, 0 );
164  itemBoxSizer3->Add(m_ProteinId, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
165 
166  m_Source = new wxCheckBox( itemFrame1, ID_FTBL_CHCKBX2, _("Source Descriptor/Feature"), wxDefaultPosition, wxDefaultSize, 0 );
167  itemBoxSizer3->Add(m_Source, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
168 
169  m_ProteinFeats = new wxCheckBox(itemFrame1, ID_FTBL_CHCKBX2, _("Protein Features"), wxDefaultPosition, wxDefaultSize, 0);
170  itemBoxSizer3->Add(m_ProteinFeats, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
171 
172  wxButton* itemButton1 = new wxButton( itemFrame1, ID_FTBL_REFRESHBTN, _("Refresh"), wxDefaultPosition, wxDefaultSize, 0 );
173  itemBoxSizer3->Add(itemButton1, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
174 
175  m_GenericPanel = new CGenericPanel( itemFrame1, m_Workbench, ID_FTBL_GENPANEL, wxDefaultPosition, wxSize(100, 100), 0 );
176  itemBoxSizer2->Add(m_GenericPanel, 1, wxGROW|wxALL, 5);
178  m_GenericPanel->SetHelpUrl(_("https://www.ncbi.nlm.nih.gov/tools/gbench/manual8/#show-feature-table"));
179 
180  m_ProteinId->SetValidator(wxGenericValidator( &m_ShowTranscriptId ));
181  m_Source->SetValidator(wxGenericValidator( &m_ShowSources ));
182  m_ProteinFeats->SetValidator(wxGenericValidator(&m_ShowProteinFeats));
183 
184  wxWindow::InitDialog();
185  x_RefreshTable();
186 ////@end CFeatureTblFr content construction
187 }
188 
189 void CFeatureTblFr::SetWorkDir(const wxString& workDir)
190 {
191  if (m_GenericPanel)
192  m_GenericPanel->SetWorkDir(workDir);
193 }
194 
195 /*!
196  * Should we show tooltips?
197  */
198 
200 {
201  return true;
202 }
203 
204 /*!
205  * Get bitmap resources
206  */
207 
208 wxBitmap CFeatureTblFr::GetBitmapResource( const wxString& name )
209 {
210  // Bitmap retrieval
211 ////@begin CFeatureTblFr bitmap retrieval
212  wxUnusedVar(name);
213  return wxNullBitmap;
214 ////@end CFeatureTblFr bitmap retrieval
215 }
216 
217 /*!
218  * Get icon resources
219  */
220 
221 wxIcon CFeatureTblFr::GetIconResource( const wxString& name )
222 {
223  // Icon retrieval
224 ////@begin CFeatureTblFr icon retrieval
225  wxUnusedVar(name);
226  return wxNullIcon;
227 ////@end CFeatureTblFr icon retrieval
228 }
229 
230 static const char* kShowSources = "Show Sources";
231 static const char* kShowTranscriptID = "Show Transcript ID";
232 static const char* kShowProteinFeats = "Show Protein Features";
233 static const char* kCaseSensitive = "Search mode";
234 
235 void CFeatureTblFr::SetRegistryPath(const string& path)
236 {
237  m_RegPath = path;
238 }
239 
241 {
242  if (!m_RegPath.empty()) {
244  CRegistryWriteView view = gui_reg.GetWriteView(m_RegPath);
245 
249  if (m_GenericPanel)
251  }
252 }
253 
254 
256 {
257  if (!m_RegPath.empty()) {
259 
260  CRegistryReadView view = gui_reg.GetReadView(m_RegPath);
264  m_FindMode = view.GetInt(kCaseSensitive, 1);
265 
266  }
267 }
268 
269 void CFeatureTblFr::OnRefreshClick(wxCommandEvent& event)
270 {
271  x_RefreshTable();
272 }
273 
274 void CFeatureTblFr::OnCloseWindow(wxCloseEvent& event)
275 {
276  Destroy();
277 }
278 
279 
280 namespace {
281  struct SFeatTableParams {
283  string filename;
284 
285  bool showProteinId;
286  bool showSrcFeature;
287  bool showProteinFeats;
288 
289  SFeatTableParams(bool protein_id, bool src_feat, bool show_prot_feats)
290  : filename(kEmptyStr),
291  showProteinId(protein_id),
292  showSrcFeature(src_feat),
293  showProteinFeats(show_prot_feats) {}
294  };
295 }
296 
297 
298 static bool s_Create5ColFeatTable(SFeatTableParams& input, string& output, string& error, ICanceled& canceled)
299 {
300  CBioseq_Handle bsh;
301  TConstScopedObjects& objects = input.objects;
302 
303  _ASSERT(!objects.empty());
305  CRef<CScope> scope = objects.front().scope;
306 
307  if (canceled.IsCanceled())
308  return false;
309 
310  // check whether multiple features have been selected
311  vector<CSeq_feat_Handle> handles;
312  for (TConstScopedObjects::const_iterator it = objects.begin(); it != objects.end(); ++it) {
313  const CSeq_feat* feat = dynamic_cast<const CSeq_feat*>(it->object.GetPointer());
314  if (feat) {
315  CSeq_feat_Handle fh = scope->GetSeq_featHandle(*feat);
316  handles.push_back(fh);
317  }
318  }
319 
320  bool only_na = FocusedOnNucleotides(objects, seh);
321  bool all = FocusedOnAll(objects, seh);
322  if (handles.empty() && !only_na && !all) {
324  if (canceled.IsCanceled())
325  return false;
326 
327  const CSeq_loc* loc = dynamic_cast<const CSeq_loc*>(it->object.GetPointer());
328  if (loc) {
329  bsh = scope->GetBioseqHandle(*loc);
330  if (bsh) {
331  break;
332  }
333  }
334  }
335  }
336 
337  if (canceled.IsCanceled())
338  return false;
339 
340  LOG_POST(Info << "Generate feature table... ");
341  try {
342  CFlatFileConfig ff_config;
343  ff_config.SetFormatFTable();
344 
346  ff_config.SetShowPeptides();
347  ff_config.SetShowFtablePeptides(input.showProteinFeats);
348  if (only_na) {
349  ff_config.SetViewNuc();
350  } else {
351  ff_config.SetViewAll();
352  }
353 
354  if (!input.showProteinId) {
355  ff_config.SetHideProteinID();
356  }
357  if (!input.showSrcFeature) {
358  ff_config.SetHideSourceFeatures();
359  }
360 
361  // default: show protein ids, transcript_ids, no source features
362  CFlatFileGenerator ff(ff_config);
364 
365 
366  if (!handles.empty()) {
367  for (vector<CSeq_feat_Handle>::const_iterator it = handles.begin(); it != handles.end(); ++it) {
368  CMappedFeat mapped_feat(*it);
369  output.append(ff.GetSeqFeatText(mapped_feat, *scope, ff_config));
370  }
371 
372  } else {
373  CNcbiOstrstream ostr;
374  if (bsh) {
375  ff.Generate(bsh, ostr);
376  }
377  else {
378  ff.Generate(seh, ostr);
379  }
381  }
382 
383 
384  if (!input.filename.empty()) {
385  CNcbiOfstream ofstr(input.filename.c_str());
386  if (ofstr.good()) {
387  ofstr << output;
388  }
389  else {
390  LOG_POST("Unable to open file for writing: " << input.filename);
391  }
392  }
393  }
394  catch (const CException& e) {
395  error = e.GetMsg();
396  LOG_POST(Error << e.GetMsg());
397  return false;
398  }
399  catch (const std::exception& e) {
400  error = e.what();
401  LOG_POST(Error << e.what());
402  return false;
403  }
404 
405  return true;
406 }
407 
408 
410 {
411  CJobAdapterResult<string>* jobResult = dynamic_cast<CJobAdapterResult<string>*>(result);
412  if (jobResult) {
413  const string& data = jobResult->GetData();
415  LOG_POST(Info << "Finished generating feature table.");
416  }
417 }
418 
419 void CFeatureTblFr::OnJobFailed(const string& errMsg, CJobAdapter&)
420 {
421  string err_msg = "Failed: ";
422  if (!errMsg.empty()) {
423  err_msg += errMsg;
424  }
425  else {
426  err_msg += "Unknown fatal error";
427  }
428 
429  NcbiErrorBox(err_msg);
430 }
431 
432 void CFeatureTblFr::x_RefreshTable(const string& path)
433 {
434  if (!m_Workbench) return;
435 
436  m_GenericPanel->SetText(ToWxString("Loading..."));
439  if (sel_srv){
440  sel_srv->GetActiveObjects(objects);
441  }
442  if (objects.empty()) {
444  }
445 
446 
447  if (objects.empty()) {
448  NcbiWarningBox("No objects selected!");
449  return;
450  }
451 
453 
454 
455  SFeatTableParams input(m_ProteinId->IsChecked(), m_Source->IsChecked(), m_ProteinFeats->IsChecked());
456  input.objects = objects;
457  input.filename = path;
458 
459  m_JobAdapter.Reset(LaunchAdapterJob<SFeatTableParams, string>
460  (this, input, s_Create5ColFeatTable, "C5ColFeatTableJob", "Generate 5 Column tab delimited feature table"));
461 }
462 
463 
CBioseq_Handle –.
CFeatureTblFr()
Constructors.
virtual void OnJobResult(CObject *result, CJobAdapter &adapter)
CGenericPanel * m_GenericPanel
static bool ShowToolTips()
Should we show tooltips?
virtual void LoadSettings()
virtual void OnJobFailed(const string &, CJobAdapter &adapter)
virtual void SetRegistryPath(const string &reg_path)
void OnCloseWindow(wxCloseEvent &event)
void SetWorkDir(const wxString &workDir)
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
wxCheckBox * m_ProteinId
~CFeatureTblFr()
Destructor.
void x_RefreshTable(const string &path=kEmptyStr)
IWorkbench * m_Workbench
void Init()
Initialises member variables.
wxCheckBox * m_ProteinFeats
void OnRefreshClick(wxCommandEvent &event)
void CreateControls()
Creates the controls and sizers.
virtual void SaveSettings() const
CRef< CJobAdapter > m_JobAdapter
wxCheckBox * m_Source
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
bool Create(wxWindow *parent, wxWindowID id=ID_CFEATURETBLFR, const wxString &caption=_("Feature Table"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(700, 600), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX)
CFlatFileConfig & SetShowPeptides(bool val=true)
CFlatFileConfig & SetHideSourceFeatures(bool val=true)
CFlatFileConfig & SetHideProteinID(bool val=true)
CFlatFileConfig & SetShowContigFeatures(bool val=true)
CFlatFileConfig & SetShowContigSources(bool val=true)
CFlatFileConfig & SetShowFtablePeptides(bool val=true)
void SetFormatFTable(void)
void Generate(const CSeq_entry_Handle &entry, CFlatItemOStream &item_os, const multiout &={})
SAnnotSelector & SetAnnotSelector(void)
static string GetSeqFeatText(const CMappedFeat &feat, CScope &scope, const CFlatFileConfig &cfg, CRef< feature::CFeatTree > ftree=null)
void SetHelpUrl(const wxString &url)
void SetText(const wxString &text)
void SetWorkDir(const wxString &workDir)
void SetFindMode(int mode)
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
CMappedFeat –.
Definition: mapped_feat.hpp:59
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
Definition: ncbistre.hpp:802
CObject –.
Definition: ncbiobj.hpp:180
class CRegistryReadView provides a nested hierarchical view at a particular key.
Definition: reg_view.hpp:58
int GetInt(const string &key, int default_val=0) const
access a named key at this level, with no recursion
Definition: reg_view.cpp:230
bool GetBool(const string &key, bool default_val=false) const
Definition: reg_view.cpp:241
void Set(const string &key, int val)
access a named key at this level, with no recursion
Definition: reg_view.cpp:533
CSeq_entry_Handle –.
CSeq_feat_Handle –.
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
Interface for testing cancellation request in a long lasting operation.
Definition: icanceled.hpp:51
IWorkbench is the central interface in the application framework.
Definition: workbench.hpp:113
#define _(proto)
Definition: ct_nlmzip_i.h:78
IMPLEMENT_CLASS(CFloatingFrame, CFloatingFrameBaseClass) const static long kFloatFrameStyle
CFloatingFrame.
USING_SCOPE(objects)
static const char * kCaseSensitive
static const char * kShowProteinFeats
static bool s_Create5ColFeatTable(SFeatTableParams &input, string &output, string &error, ICanceled &canceled)
static const char * kShowTranscriptID
static const char * kShowSources
static void Init(void)
Definition: cursor6.c:76
static SQLCHAR output[256]
Definition: print.c:5
char data[12]
Definition: iconv.c:80
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
#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
void Info(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1185
CIRef< T > GetServiceByType()
retrieves a typed reference to a service, the name of C++ type is used as the name of the service.
Definition: service.hpp:91
static objects::SAnnotSelector GetAnnotSelector(TAnnotFlags flags=0)
request an annotation selector for a given type
Definition: utils.cpp:167
objects::CSeq_entry_Handle GetTopSeqEntryFromScopedObject(SConstScopedObject &obj)
Definition: utils.cpp:2542
void NcbiWarningBox(const string &message, const string &title="Warning")
specialized Message Box function for reporting non-critical errors
void NcbiErrorBox(const string &message, const string &title="Error")
specialized Message Box function for reporting critical errors
void Cancel()
Definition: job_adapter.cpp:48
const T & GetData()
Definition: job_adapter.hpp:84
vector< SConstScopedObject > TConstScopedObjects
Definition: objects.hpp:65
CBioseq_Handle GetBioseqHandle(const CSeq_id &id)
Get bioseq handle by seq-id.
Definition: scope.cpp:95
CSeq_feat_Handle GetSeq_featHandle(const CSeq_feat &feat, EMissing action=eMissing_Default)
Definition: scope.cpp:200
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#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
IO_PREFIX::ofstream CNcbiOfstream
Portable alias for ofstream.
Definition: ncbistre.hpp:500
#define kEmptyStr
Definition: ncbistr.hpp:123
where boath are integers</td > n< td ></td > n</tr > n< tr > n< td > tse</td > n< td > optional</td > n< td > String</td > n< td class=\"description\"> TSE option controls what blob is smart and slim</td> n<td> orig</td> n</tr> n<tr> n<td> last_modified</td> n<td> optional</td> n<td> Integer</td> n<td class=\"description\"> The blob last modification If provided then the exact match will be requested with n the Cassandra storage corresponding field value</td> n<td> Positive integer Not provided means that the most recent match will be selected</td> n<td></td> n</tr> n<tr> n<td> use_cache</td> n<td> optional</td> n<td> String</td> n<td class=\"description\"> The option controls if the Cassandra LMDB cache and or database should be used It n affects the seq id resolution step and the blob properties lookup step The following n options are BIOSEQ_INFO and BLOB_PROP at all
END_EVENT_TABLE()
static int input()
bool FocusedOnNucleotides(TConstScopedObjects &objects, const objects::CSeq_entry_Handle &tse)
void GetViewObjects(IWorkbench *workbench, TConstScopedObjects &objects)
bool FocusedOnAll(TConstScopedObjects &objects, const objects::CSeq_entry_Handle &tse)
void ReportUsage(const wxString &dialog_name)
Report opening & accepting events in the editing package.
const struct ncbi::grid::netcache::search::fields::SIZE size
#define _ASSERT
else result
Definition: token2.c:20
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
Modified on Sun Apr 14 05:25:17 2024 by modify_doxy.py rev. 669887