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

Go to the SVN repository for this file.

1 /* $Id: annot_compare.cpp 39666 2017-10-25 16:01:13Z katargir $
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: Mike DiCuccio
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
34 
35 #include <ncbi_pch.hpp>
37 #include <gui/objutils/utils.hpp>
38 #include <gui/utils/view_event.hpp>
39 #include <serial/iterator.hpp>
41 
43 #include <objmgr/util/sequence.hpp>
44 
45 // #include "annot_filter_dlg.hpp"
46 
49 
50 /////////////////////////////////////////////////////////////////////////////
51 // CAnnotCompareModel
52 /*
53 
54 !!! TODO: EVRYTHING FROM HERE GOES TO annot_compare_ds, this is now a model
55 
56 class CAnnotCompareModel : public CwxAbstractTableModel
57 {
58 public:
59  /// our data is stored as a vector of vectors
60  typedef vector<string> TRowData;
61  typedef vector<TRowData> TModelData;
62 
63  CAnnotCompareModel();
64 
65  virtual int GetNumRows() const;
66  virtual int GetNumColumns() const;
67  virtual wxVariant GetValueAt( int row, int col ) const;
68 
69  virtual wxString GetColumnType(int col_idx) const;
70 
71  virtual wxString GetColumnName(int col_idx) const;
72 
73  /// setters - to be called to push data in from the outside
74  void SetDataSource(CAnnotCompareDS& ds);
75  void Update();
76 
77 private:
78  CRef<CAnnotCompareDS> m_DS;
79 
80  /// saved column names
81  mutable vector<string> m_ColNames;
82 };
83 
84 
85 CAnnotCompareModel::CAnnotCompareModel()
86 {
87 }
88 
89 
90 int CAnnotCompareModel::GetNumRows() const
91 {
92  return (m_DS ? m_DS->GetRows() : 0);
93 }
94 
95 
96 int CAnnotCompareModel::GetNumColumns() const
97 {
98  return CAnnotCompareWidget::eMaxCol;
99 }
100 
101 
102 const CAnyType CAnnotCompareModel::GetValueAt( int r, int c ) const
103 {
104  const CAnnotCompareDS::SRow& row = m_DS->GetRow(r);
105 
106  switch (c) {
107  case CAnnotCompareWidget::eFeat1Label:
108  if (row.feat1_label.empty() && row.feat1) {
109  CLabel::GetLabel(*row.feat1, &row.feat1_label,
110  CLabel::eDefault, &m_DS->GetScope());
111  }
112  return row.feat1_label;
113 
114  case CAnnotCompareWidget::eFeat1Location:
115  if (row.feat1_loc_label.empty() && row.feat1_loc) {
116  CLabel::GetLabel(*row.feat1_loc, &row.feat1_loc_label,
117  CLabel::eDefault, &m_DS->GetScope());
118  }
119  return row.feat1_loc_label;
120 
121  case CAnnotCompareWidget::eFeat1Sequence:
122  if (row.feat1_seq_label.empty() && row.feat1_seq) {
123  CLabel::GetLabel(*row.feat1_seq.GetSeqId(), &row.feat1_seq_label,
124  CLabel::eDefault, &m_DS->GetScope());
125  }
126  return row.feat1_seq_label;
127 
128  case CAnnotCompareWidget::eFeat2Label:
129  if (row.feat2_label.empty() && row.feat2) {
130  CLabel::GetLabel(*row.feat2, &row.feat2_label,
131  CLabel::eDefault, &m_DS->GetScope());
132  }
133  return row.feat2_label;
134 
135  case CAnnotCompareWidget::eFeat2Location:
136  if (row.feat2_loc_label.empty() && row.feat2_loc) {
137  CLabel::GetLabel(*row.feat2_loc, &row.feat2_loc_label,
138  CLabel::eDefault, &m_DS->GetScope());
139  }
140  return row.feat2_loc_label;
141 
142  case CAnnotCompareWidget::eFeat2Sequence:
143  if (row.feat2_seq_label.empty() && row.feat2_seq) {
144  CLabel::GetLabel(*row.feat2_seq.GetSeqId(), &row.feat2_seq_label,
145  CLabel::eDefault, &m_DS->GetScope());
146  }
147  return row.feat2_seq_label;
148 
149  case CAnnotCompareWidget::eFeatType:
150  if (row.feat_type_label.empty()) {
151  if (row.feat1) {
152  row.feat_type_label = row.feat1->GetData().GetKey();
153  } else if (row.feat2) {
154  row.feat_type_label = row.feat2->GetData().GetKey();
155  }
156  }
157  return row.feat_type_label;
158 
159  case CAnnotCompareWidget::eLocationCompare:
160  switch (row.loc_state & CAnnotCompare::eLocationMask) {
161  case CAnnotCompare::eLocation_Missing:
162  {{
163  static string str("Not found");
164  return str;
165  }}
166  case CAnnotCompare::eLocation_Same:
167  {{
168  static string str("Identical");
169  return str;
170  }}
171  case CAnnotCompare::eLocation_MissingExon:
172  {{
173  static string str("Missing Exons");
174  return str;
175  }}
176  case CAnnotCompare::eLocation_5PrimeExtension:
177  {{
178  static string str("5' Extension");
179  return str;
180  }}
181  case CAnnotCompare::eLocation_3PrimeExtension:
182  {{
183  static string str("3' Extension");
184  return str;
185  }}
186  case CAnnotCompare::eLocation_Complex:
187  {{
188  static string str("Complex");
189  return str;
190  }}
191 
192  default:
193  {{
194  _ASSERT(false);
195  static string str("Unknown");
196  return str;
197  }}
198  }
199 
200  case CAnnotCompareWidget::eSequenceCompare:
201  if (row.loc_state & CAnnotCompare::eSequence_SameSeq) {
202  static string str("Identical");
203  return str;
204  } else if (row.loc_state & CAnnotCompare::eSequence_DifferentSeq) {
205  static string str("Different");
206  return str;
207  } else {
208  return kEmptyStr;
209  }
210  break;
211 
212  case CAnnotCompareWidget::eProductCompare:
213  if (row.loc_state & CAnnotCompare::eSequence_SameProduct) {
214  static string str("Identical");
215  return str;
216  } else if (row.loc_state & CAnnotCompare::eSequence_DifferentProduct) {
217  static string str("Different");
218  return str;
219  } else {
220  return kEmptyStr;
221  }
222  break;
223 
224  default:
225  _ASSERT(false);
226  throw runtime_error("Invalid column in CAnnotCompareModel");
227  }
228 }
229 
230 
231 const type_info& CAnnotCompareModel::GetColumnType(int col) const
232 {
233  return typeid(string);
234 }
235 
236 
237 const CAnyType CAnnotCompareModel::GetColumnName(int col) const
238 {
239  static const string sc_ColNames[] = {
240  string("Feature 1"),
241  string("Sequence 1"),
242  string("Location 1"),
243  string("Feature 2"),
244  string("Sequence 2"),
245  string("Location 2"),
246  string("Feature Type"),
247  string("Location Comparison"),
248  string("Sequence Comparison"),
249  string("Product Comparison")
250  };
251 
252  _ASSERT(col < (int)(sizeof(sc_ColNames) / sizeof(string)));
253  return sc_ColNames[col];
254 }
255 
256 
257 /// setters - to be called to push data in from the outside
258 void CAnnotCompareModel::SetDataSource(CAnnotCompareDS& ds)
259 {
260  m_DS.Reset(&ds);
261  Update();
262 }
263 
264 
265 void CAnnotCompareModel::Update()
266 {
267  FireDataChanged();
268 }
269 */
270 
271 
272 /////////////////////////////////////////////////////////////////////////////
273 // CAnnotCompareWidget
274 
275 const int kStatusBarHeght = 18;
276 
277 
279  wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style
280 )
281  : CwxTableListCtrl( parent, id, pos, size, style )
282 {
283  m_Model.Reset( new CAnnotCompareDS() );
284 
285  SetModel( m_Model );
286 
287 }
288 
289 
290 
292 {
293  RemoveModel();
294 }
295 
296 
297 /*
298 BEGIN_EVENT_MAP(CAnnotCompareWidget, CEventHandler)
299  ON_EVENT(CEvent, CViewEvent::eWidgetDataChanged,
300  &CAnnotCompareWidget::x_OnDataSourceUpdated)
301 END_EVENT_MAP()
302 
303 
304 void CAnnotCompareWidget::SaveSettings(CRegistryWriteView& view) const
305 {
306  ncbi::SaveTableSettings(*m_Table, view);
307 }
308 
309 
310 void CAnnotCompareWidget::LoadSettings(CRegistryReadView& view)
311 {
312  ncbi::LoadTableSettings(*m_Table, view);
313 }
314 */
315 
317 {
318 /*
319  if (m_Data) {
320  float val = m_Data->GetProgress();
321 
322  m_LabelStr = "Computing comparisons, " +
323  NStr::IntToString( (int)(100 * val) ) + "% completed";
324  m_Label->label(m_LabelStr.c_str());
325  m_Label->redraw();
326  }
327  */
328 }
329 
330 
332 {
333 /*
334  SAnnotCompareFilter& filt =
335  dynamic_cast<SAnnotCompareFilter&>(*m_Table->GetFilter());
336 
337  CAnnotCompareFilterDlg dlg(filt);
338  if (dlg.ShowModal() == eOK) {
339  m_Table->ApplyFiltering();
340  redraw();
341  }
342  */
343 }
344 
346 {
347  /*
348  CNcbiOstrstream ostr;
349  m_Data->DumpTextReport(ostr);
350 
351  if ( !m_TextDlg.get() ) {
352  m_TextDlg.reset(new CTextReportDlg());
353  m_TextDlg->SetTitle("Annotation Comparison Report");
354  }
355  m_TextDlg->SetText(string(CNcbiOstrstreamToString(ostr)));
356  m_TextDlg->CenterOnActive();
357  m_TextDlg->Show();
358  */
359 }
360 
361 
363 {
364  return dynamic_cast<CAnnotCompareDS&>(*m_Model);
365 }
366 
367 
369 {
370  m_Model.Reset(&ds);
371  m_Model->RegisterListener(this);
373 }
374 
375 /*
376 void CAnnotCompareWidget::GetSelection(TConstObjects& objs) const
377 {
378  if( m_Table && m_Model.get() ){
379  CAnyRef<ISelectionModel> sel_model = m_Table->GetSelectionModel();
380  for (int row = 0; row < m_Model->GetNumRows(); ++row) {
381  if (sel_model->IsSelectedIndex(row)) {
382  int row_i = m_Table->RowVisibleToData(row);
383  const CAnnotCompareDS::SRow& row = m_Data->GetRow(row_i);
384 
385  if (row.feat1) {
386  objs.push_back(CConstRef<CObject>(&*row.feat1));
387  }
388  if (row.feat2) {
389  objs.push_back(CConstRef<CObject>(&*row.feat2));
390  }
391  }
392  }
393  }
394 }
395 
396 void CAnnotCompareWidget::SelectionChanged(const ISelectionModel::CSMNotice& msg)
397 {
398  CEvent evt(CEvent::eEvent_Message, CViewEvent::eWidgetSelectionChanged);
399  Send(&evt, CEventHandler::eDispatch_Default, ePool_Parent);
400 }
401 
402 bool CAnnotCompareWidget::PerformAction(CAnyType& aSource, TSignal aSignal)
403 {
404  if (aSignal == CStandardEP::sm_SigContextAction) {
405  /// double-click
406  x_OnDoubleClick();
407  }
408  return false;
409 }
410 */
411 
412 
414 {
417 }
418 
419 
421 {
422 /*
423  if (m_Table && m_Model.get()) {
424  CAnyRef<ISelectionModel> sel_model = m_Table->GetSelectionModel();
425  for (int row = 0; row < m_Model->GetNumRows(); ++row) {
426  if (sel_model->IsSelectedIndex(row)) {
427  int row_i = m_Table->RowVisibleToData(row);
428  const CAnnotCompareDS::SRow& row = m_Data->GetRow(row_i);
429 
430  if (row.feat1_loc) {
431  locs.push_back(row.feat1_loc);
432  }
433  if (row.feat2_loc) {
434  locs.push_back(row.feat2_loc);
435  }
436  }
437  }
438  }
439  */
440 }
441 
442 
444 {
445  //m_Panel->hide();
446 
447 // m_Timer.Init(1, 2, true, this);
448  //m_Timer.Start();
449  GetDataSource().Update();
450  UpdateModel();
451 }
452 
453 
455 {
456  if (m_Model) {
457  m_Model->Update();
458  }
459 }
460 
462 {
463  UpdateModel();
464  m_Timer.Stop();
465 // m_StatusBar->SetMessage("Found " + NStr::IntToString(m_Model->GetNumRows()) + " comparisons");
466 }
467 
CEvent - generic event implementation TODO TODO - Attachments.
Definition: event.hpp:85
void SetModel(IwxTableModel *data_model, bool own=false)
void RegisterListener(CEventHandler *listener)
register a listener to respond to background job completion events
CAnnotCompareDS & GetDataSource()
CRef< CAnnotCompareDS > m_Model
the table's model
virtual bool Send(CEvent *evt, EDispatch disp_how=eDispatch_Default, int pool_name=ePool_Default)
Sends an event synchronously.
void x_OnDoubleClick()
handle row double-click events
void GetSelectedLocations(TLocs &locs) const
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:101
virtual ~CAnnotCompareWidget()
const int kStatusBarHeght
list< CConstRef< objects::CSeq_loc > > TLocs
retrieve a list of the selected locations
void x_OnDataSourceUpdated(CEvent *)
event handler for data source update events
wxTimer m_Timer
timer for progress updates
int size
notification from child to parent that the visible range has changed
Definition: view_event.hpp:73
CAnnotCompareDS.
dispatch until handled at least by one handler
CwxTableListCtrl - generic wxListCtrl-based Table Control.
void SetDataSource(CAnnotCompareDS &ds)
virtual void AddListener(CEventHandler *listener, int pool_name=ePool_Default)
Add a listener.
void OnTimeout(int timer_id)
USING_SCOPE(objects)
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:98
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:768
Modified on Thu May 24 13:02:42 2018 by modify_doxy.py rev. 546573