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

Go to the SVN repository for this file.

1 /* $Id: dot_matrix_view.cpp 43750 2019-08-28 16:05:58Z 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: Andrey Yazhuk
27  *
28  * File Description:
29  * User-modifiable implementation file for extension of Dot Matrix
30  * viewer for GBENCH
31  */
32 
33 #include <ncbi_pch.hpp>
34 
36 
40 
42 
45 
47 
52 
53 #include <gui/objutils/utils.hpp>
54 #include <gui/objutils/label.hpp>
55 
56 #include <serial/iterator.hpp>
57 #include <objmgr/util/sequence.hpp>
58 
59 //#include <objects/seqloc/Seq_id.hpp>
61 
62 #include <wx/menu.h>
63 #include <wx/sizer.h>
64 
67 
69  "Dot Matrix View", // type name
70  "dot_matrix_view", // icon alias TODO
71  "Dot Matrix View",
72  "The Dot Matrix View shows a dot-plot of a given alignment",
73  "DOT_MATRIX_VIEW", // help ID
74  "Alignment", // category
75  false, // not a singleton
76  "Seq-align",
78 );
79 
80 
82 : m_AlnWidget(NULL)
83 {
84 }
85 
86 
88 {
90  return m_AlnWidget;
91 }
92 
93 
95 {
97 
98  wxMenu* view_menu = new wxMenu();
99  wxMenu* dm_menu = new wxMenu();
100 
101  cmd_reg.AppendMenuItem(*dm_menu, eCmdChooseSeq);
102  cmd_reg.AppendMenuItem(*dm_menu, eCmdColorByScore);
103 
104  view_menu->Append(wxID_ANY, wxT("Dot Matrix"), dm_menu);
105 
106  wxMenu* bar_menu = new wxMenu();
107  bar_menu->Append( wxID_ANY, wxT("&View"), view_menu );
108 
109  m_MenuBarMenu.reset( bar_menu );
110 }
111 
112 
113 void CDotMatrixView::CreateViewWindow(wxWindow* parent)
114 {
115  _ASSERT( ! m_AlnWidget);
116 
117  m_AlnWidget = new CHitMatrixWidget(parent);
118  m_AlnWidget->Create();
119 
122 }
123 
124 
126 {
127  if(m_AlnWidget) {
128  m_AlnWidget->Destroy();
129  m_AlnWidget = NULL;
130  }
131 }
132 
133 
135 {
136  return m_TypeDescr;
137 }
138 
140 {
141  _ASSERT( !m_Aligns.empty() );
142 
143  CScope* scope = GetScope().GetPointer();
144  _ASSERT(scope);
145 
147 
148  CHitMatrixDSBuilder builder;
149  builder.Init( *scope, m_Aligns );
150 
151  //m_DataSource = builder.CreateDataSource();
152  m_DataSource = GUI_AsyncExec([&builder](ICanceled&) { return builder.CreateDataSource(); }, wxT("Creating data source..."));
153 
154  if( m_DataSource->SelectDefaultIds() ){
156  }
157 }
158 
160 {
161  TAlignVector aligns;
162 
163  if( objects.size() > 0 ){
165  const CObject* object = it->object.GetPointer();
166  const CSeq_annot* annot = dynamic_cast<const CSeq_annot*>(object);
167  if( annot ){
168  ExtractSeqAligns( *annot, aligns );
169  } else {
170  const CSeq_align* align = dynamic_cast<const CSeq_align*>(object);
171  aligns.push_back( CConstRef<CSeq_align>(align) );
172  }
173  }
174  }
175 
176  if( aligns.size() > 0 ){
177 
178  m_Aligns = aligns;
179 
180  return objects[0].scope.GetPointer();
181  }
182 
183  return NULL;
184 }
185 
187 {
188  if( x_HasProject() ){
189  x_InitWidget();
190  }
191 
193 }
194 
196 {
197  if(
200  ){
202  }
203 }
204 
206 {
207  if (m_AlnWidget && x_HasProject()) {
209  CScope* scope = x_GetScope();
210 
211  // Range selection
213  if(! s_coll.empty()) {
214  CRef<CSeq_loc> s_loc =
215  CSeqUtils::CreateSeq_loc(*m_DataSource->GetSubjectId().GetSeqId(), s_coll);
216  if (s_loc) {
217  objs.push_back(SConstScopedObject(s_loc, scope));
218  }
219  }
220 
221  const TRangeColl& q_coll = m_AlnWidget->GetQueryRangeSelection();
222  if(! q_coll.empty()) {
223  CRef<CSeq_loc> q_loc =
224  CSeqUtils::CreateSeq_loc(*m_DataSource->GetQueryId().GetSeqId(), q_coll);
225  if (q_loc) {
226  objs.push_back(SConstScopedObject(q_loc, scope));
227  }
228  }
229 
230  // Object Selection
231  TConstObjects sel_objs;
232  m_AlnWidget->GetObjectSelection(sel_objs);
233  ITERATE(TConstObjects, it, sel_objs) {
234  objs.push_back(SConstScopedObject(*it, scope));
235  }
236  }
237 }
238 
239 
241 {
242  if (x_HasProject()) {
243  // Range Selection
244  evt.AddRangeSelection(*m_DataSource->GetSubjectId().GetSeqId(),
246 
247  evt.AddRangeSelection(*m_DataSource->GetQueryId().GetSeqId(),
249 
250  // Object Selection
251  TConstObjects sel_objs;
252  m_AlnWidget->GetObjectSelection(sel_objs);
253  evt.AddObjectSelection(sel_objs);
254  }
255 }
256 
257 
258 // handles incoming selection broadcast (overriding CView virtual function)
260 {
261  CScope* scope = x_GetScope();
262 
263  _ASSERT(scope);
264 
265  if(evt.HasRangeSelection()) { // set Range Selection
268 
269  // set Range Selection on Subject
270  CConstRef<CSeq_id> id = m_DataSource->GetSubjectId().GetSeqId();
271  evt.GetRangeSelection(*id, *scope, coll);
272  if (coll.size()) {
274  }
275 
276  // ser Range Selection on Query
277  coll.clear();
278  id = m_DataSource->GetQueryId().GetSeqId();
279  evt.GetRangeSelection(*id, *scope, coll);
280  if (coll.size()) {
282  }
283  }
284 
285  if (&evt.GetScope() != scope)
286  return;
287 
288  vector<const CSeq_align*> sel_aligns;
289  if (evt.HasObjectSelection()) { // set Object Selection
290  TConstObjects sel_objs;
291  evt.GetAllObjects(sel_objs);
292 
294  const THits& hits = m_DataSource->GetHits();
295  ITERATE(THits, it_hit, hits) {
296  const IHit& hit = **it_hit;
297  const CSeq_align& align = *hit.GetSeqAlign();
298 
299  ITERATE(TConstObjects, it_obj, sel_objs) {
300  if(evt.Match(align, *scope, **it_obj, evt.GetScope())) {
301  sel_aligns.push_back(&align);
302  break;
303  }
304  }
305  }
306  }
307  m_AlnWidget->SetObjectSelection(sel_aligns);
308 }
309 
310 
312 {
313  if( m_DataSource.IsNull() ){
314  ERR_POST(Error << "CDotMatrixView: no data source while trying to GetVisibleRanges()" );
315  return;
316  }
317 
318  /// collect information
319  const CGlPane& pane = m_AlnWidget->GetPort();
320  TModelRect rect = pane.GetVisibleRect();
321 
322  CRef<CSeq_loc> loc(new CSeq_loc());
323  loc->SetInt().SetFrom((TSeqPos)rect.Left());
324  loc->SetInt().SetTo ((TSeqPos)rect.Right());
325  loc->SetId(*m_DataSource->GetSubjectId().GetSeqId());
326  vrange.AddLocation(*loc);
327 
328  loc.Reset(new CSeq_loc());
329  loc->SetInt().SetFrom((TSeqPos)rect.Bottom());
330  loc->SetInt().SetTo ((TSeqPos)rect.Top());
331  loc->SetId(*m_DataSource->GetQueryId().GetSeqId());
332  vrange.AddLocation(*loc);
333 }
334 
335 
337 {
338  const CGlPane& pane = m_AlnWidget->GetPort();
339  TModelRect rect = pane.GetVisibleRect();
340 
341  if (vrange.Match(*m_DataSource->GetQueryId().GetSeqId())) {
343  range.SetFrom((TSeqPos)rect.Bottom());
344  range.SetTo ((TSeqPos)rect.Top());
345  if (vrange.Clamp(m_DataSource->GetQueryHandle(), range)) {
347  }
348  }
349 
350  if (vrange.Match(*m_DataSource->GetSubjectId().GetSeqId())) {
352  range.SetFrom((TSeqPos)rect.Left());
353  range.SetTo ((TSeqPos)rect.Right());
354  if (vrange.Clamp(m_DataSource->GetSubjectHandle(), range)) {
356  }
357  }
358 }
359 
360 
362 {
363  if( m_Aligns.size() > 0 ){
364  return m_Aligns[0].GetPointer();
365  }
366  return NULL;
367 }
368 
369 
370 ///////////////////////////////////////////////////////////////////////////////
371 /// CDotMatrixViewFactory
373 {
374  //m_ViewManager = new CDotMatrixViewManager( *this );
375 }
376 
378 {
379  static string sid("dot_matrix_view_factory");
380  return sid;
381 }
382 
384 {
385  static string slabel("Dot Matrix View Factory");
386  return slabel;
387 }
388 
390 {
391  string alias = GetViewTypeDescriptor().GetIconAlias();
392  provider.RegisterFileAlias(ToWxString(alias), wxT("dot_matrix_view.png"));
393 }
394 
396 {
397  CHitMatrixWidget::RegisterCommands(cmd_reg, provider);
398 }
399 
401 {
403 }
404 
406 {
407  return new CDotMatrixView();
408 }
409 
411 {
412  /*TFingerprint print(CDotMatrixView::m_TypeDescr.GetLabel(), false);
413  if(print == fingerprint) {
414  return new CDotMatrixView();
415  }*/
416  return NULL;
417 }
418 
420 {
421  bool found_good = false;
422  bool found_bad = false;
423  for( size_t i = 0; i < objects.size(); i++ ){
424  const CObject* obj = objects[i].object;
425  const type_info& type = typeid(*obj);
426 
427  if (typeid(CSeq_annot) == type) {
428  const CSeq_annot* annot = dynamic_cast<const CSeq_annot*>(obj);
429  vector< CConstRef<objects::CSeq_align> > aligns;
430  ExtractSeqAligns(*annot, aligns);
431  if (aligns.size() > 0)
432  found_good = true;
433  else
434  found_bad = true;
435  }
436  else if (typeid(CSeq_align) == type)
437  found_good = true;
438  else
439  found_bad = true;
440  }
441  if( found_good ){
442  return fCanShowSeparated | (found_bad ? fCanShowSome : fCanShowAll);
443  }
444  return 0; // can show nothing
445 }
446 
448 {
449  size_t num_objects = objects.size();
450  if (num_objects == 0)
451  return vector<int>();
452  else
453  return vector<int>(num_objects, 0);
454 }
455 
CRangeCollection< TSeqPos > TRangeColl
std::invoke_result< _Fty, ICanceled & >::type GUI_AsyncExec(_Fty &&_Fnarg, const wxString &msg=wxT("Accessing network..."))
Definition: async_call.hpp:130
CDotMatrixView.
class CGlPane
Definition: glpane.hpp:62
virtual void Create()
creates controls and performs basic initialization
CHitMatrixDSBuilder.
CIRef< IHitMatrixDataSource > CreateDataSource()
void Init(objects::CScope &scope, const objects::CSeq_align &align)
initial data set from which an alignment will be build
class CHitMatrixWidget
void SetQueryRangeSelection(const TRangeColl &segs)
virtual void SetDataSource(IHitMatrixDataSource *p_ds)
const TRangeColl & GetSubjectRangeSelection() const
void SetQueryVisibleRange(const TSeqRange &range)
const TRangeColl & GetQueryRangeSelection() const
static void RegisterCommands(CUICommandRegistry &cmd_reg, wxFileArtProvider &provider)
class CHitMatrixWidget
void SetSubjectVisibleRange(const TSeqRange &range)
void GetObjectSelection(TConstObjects &objs) const
virtual CGlPane & GetPort()
implement these 2 functions in derived classes
void SetSubjectRangeSelection(const TRangeColl &segs)
void SetObjectSelection(const vector< const objects::CSeq_align * > sel_aligns)
CObject –.
Definition: ncbiobj.hpp:180
virtual void OnProjectChanged()
virtual void x_UpdateContentLabel()
virtual CRef< objects::CScope > GetScope() const
unique_ptr< const wxMenu > m_MenuBarMenu
virtual objects::CScope * x_GetScope() const
virtual bool x_HasProject() const
CProjectViewEvent.
Definition: document.hpp:62
EEventSubtype GetSubtype() const
Definition: document.hpp:96
CProjectViewTypeDescriptor - holds description of a project view type.
size_type size() const
Definition: range_coll.hpp:98
bool empty() const
Definition: range_coll.hpp:102
CScope –.
Definition: scope.hpp:92
CSelectionEvent CSelectionEvent is used for broadcasting selection between views.
Definition: obj_event.hpp:68
bool HasRangeSelection() const
Range Selection - represents a collection of selected segments.
Definition: obj_event.cpp:92
void GetAllObjects(TConstObjects &objs) const
Definition: obj_event.cpp:314
void AddRangeSelection(const objects::CSeq_id &id, const TRangeColl &segs)
static bool Match(const CObject &obj1, objects::CScope &scope1, const CObject &obj2, objects::CScope &scope2)
Definition: obj_event.cpp:346
objects::CScope & GetScope()
Definition: obj_event.hpp:95
const objects::CHandleRangeMap & GetRangeSelection() const
Definition: obj_event.cpp:98
bool HasObjectSelection()
Object Selection - represents select Objects (such as features, alignments, etc)
Definition: obj_event.cpp:171
bool AddObjectSelection(const CObject &obj)
Definition: obj_event.cpp:177
CUICommandRegistry is a centralized registry where all application commands should be registered.
Definition: ui_command.hpp:146
wxMenuItem * AppendMenuItem(wxMenu &menu, TCmdID cmd_id) const
Definition: ui_command.cpp:300
EEventType GetType() const
Definition: view_event.hpp:87
CViewTypeDescriptor - holds description of a view type.
Definition: view.hpp:98
bool Clamp(const objects::CBioseq_Handle &handle, TSeqRange &range) const
Alter the supplied range according to the rules provided in the policy and the supplied new location.
bool Match(const objects::CSeq_id &id) const
See if we can match the supplied range.
void AddLocation(const objects::CSeq_loc &loc)
Interface for testing cancellation request in a long lasting operation.
Definition: icanceled.hpp:51
vector< IHit * > THitAdapterCont
IHit.
Definition: hit.hpp:69
virtual const objects::CSeq_align * GetSeqAlign() const =0
virtual const CViewTypeDescriptor & GetViewTypeDescriptor() const
returns a Descriptor for the View Type supported by the Factory
IView - represents a standard visual part of Workbench UI.
Definition: view.hpp:73
IVisibleRangeClient - represents an object that wants notifications about visible range changes.
CFingerprint identifies an instance of IWMClient and is used for labeling layout positions.
Definition: wm_client.hpp:58
virtual void RegisterFileAlias(const wxArtID &anId, const wxArtClient &aClient, const wxSize &aSize, const wxString &aName, long aType=wxBITMAP_TYPE_ANY, int anIndex=-1)
@ eCmdChooseSeq
USING_SCOPE(objects)
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
#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
virtual CUICommandRegistry & GetUICommandRegistry()=0
returns an instance of Command Registry associated with the Workbench
static CRef< objects::CSeq_loc > CreateSeq_loc(const objects::CSeq_id &id, const CRangeCollection< TSeqPos > &ranges)
Definition: utils.cpp:555
T Top() const
Definition: glrect.hpp:84
T Bottom() const
Definition: glrect.hpp:82
T Right() const
Definition: glrect.hpp:83
T Left() const
Definition: glrect.hpp:81
TModelRect & GetVisibleRect(void)
Definition: glpane.hpp:357
virtual wxWindow * GetWindow()
returns a pointer to the wxWindow representing the client
virtual const CViewTypeDescriptor & GetTypeDescriptor() const
return an object providing meta information about thei view type
virtual IView * CreateInstanceByFingerprint(const TFingerprint &fingerprint) const
if fingerprint is recognized - creates and returns a new instance
TAlignVector m_Aligns
CIRef< IHitMatrixDataSource > m_DataSource
virtual const CObject * x_GetOrigObject() const
virtual IView * CreateInstance() const
creates a view instance
CDotMatrixViewFactory()
CDotMatrixViewFactory.
void GetSelection(CSelectionEvent &evt) const
get selection for broadcasting
virtual void OnVisibleRangeChanged(const CVisibleRange &vrange, IVisibleRangeClient *source)
virtual vector< int > CombineInputObjects(const TConstScopedObjects &objects)
CHitMatrixWidget * m_AlnWidget
virtual void x_OnSetSelection(CSelectionEvent &evt)
override in derived classes in order to handle selection broadcast
virtual void DestroyViewWindow()
destroy Window corresponding to the view
virtual string GetExtensionIdentifier() const
returns the unique human-readable identifier for the extension the id should use lowercase letters se...
virtual const CProjectViewTypeDescriptor & GetProjectViewTypeDescriptor() const
returns a Descriptor for the View Type supported by the Factory
virtual int TestInputObjects(TConstScopedObjects &objects)
tests input objects (probably using object conversion, or not) and returns a combination of ETestResu...
virtual objects::CScope * x_PreAttachToProject(TConstScopedObjects &objects)
virtual string GetExtensionLabel() const
returns a displayable label for this extension ( please capitalize the key words - "My Extension" )
vector< CConstRef< objects::CSeq_align > > TAlignVector
virtual void CreateViewWindow(wxWindow *parent)
create Window corresponding to the view
virtual void RegisterIconAliases(wxFileArtProvider &provider)
called by the framework to give Factory a chance to register images used by view
virtual void x_PostAttachToProject()
virtual void RegisterCommands(CUICommandRegistry &cmd_reg, wxFileArtProvider &provider)
called by the framework to give Factory a chance to register commands used by view
virtual void x_CreateMenuBarMenu()
initializes m_MenuBarMenu; override in derived classes
virtual void GetVisibleRanges(CVisibleRange &vrange) const
populate a visible range event for broadcasting
static CProjectViewTypeDescriptor m_TypeDescr
vector< CConstRef< CObject > > TConstObjects
Definition: objects.hpp:64
virtual const string & GetIconAlias() const
Definition: ui_object.cpp:130
virtual void AddListener(CEventHandler *listener, int pool_name=ePool_Default)
Add a listener.
vector< SConstScopedObject > TConstScopedObjects
Definition: objects.hpp:65
void SetId(CSeq_id &id)
set the 'id' field in all parts of this location
Definition: Seq_loc.cpp:3474
void SetInt(TInt &v)
Definition: Seq_loc.hpp:983
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
bool IsNull(void) const THROWS_NONE
Check if pointer is null – same effect as Empty().
Definition: ncbiobj.hpp:735
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
@ eCmdColorByScore
int i
#define wxT(x)
Definition: muParser.cpp:41
range(_Ty, _Ty) -> range< _Ty >
const CharType(& source)[N]
Definition: pointer.h:1149
@ eSimilarObjectsAccepted
static static static wxID_ANY
void ExtractSeqAligns(const T &obj, vector< CConstRef< objects::CSeq_align > > &aligns)
This is the place where elements of the new Alignment Library will be collected.
Definition: type.c:6
#define _ASSERT
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
Modified on Thu Dec 07 10:06:51 2023 by modify_doxy.py rev. 669887