NCBI C++ ToolKit
feature_graph.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef __GUI_WIDGETS_ALNMULTI___ALIGN_FEATURE_GRAPH__HPP
2 #define __GUI_WIDGETS_ALNMULTI___ALIGN_FEATURE_GRAPH__HPP
3 
4 /* $Id: feature_graph.hpp 46021 2021-01-21 13:48:42Z grichenk $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Andrey Yazhuk
30  *
31  * File Description:
32  *
33  */
34 
35 #include <gui/opengl/glpane.hpp>
38 
40 
41 #include <gui/utils/app_job.hpp>
44 
47 
50 
52 
54 
55 #include <util/range_coll.hpp>
56 
57 #include <objmgr/feat_ci.hpp>
59 #include <objmgr/bioseq_handle.hpp>
62 #include <objmgr/mapped_feat.hpp>
63 
64 
66 
68 class IAlignRowHandle;
69 
71  class CSeq_loc;
72  class CScope;
74 
75 
76 ////////////////////////////////////////////////////////////////////////////////
77 ///
79  objects::CMappedFeat m_Feature;
80  //CConstRef<objects::CSeq_feat> m_Feature;
82 
84  {}
85  SMappedFeatLoc(const objects::CMappedFeat& feat, objects::CSeq_loc& loc)
86  : m_Feature(feat), m_MappedLoc(&loc) {}
87 // SMappedFeatLoc(const objects::CSeq_feat& feat, objects::CSeq_loc& loc)
88 // : m_Feature(&feat), m_MappedLoc(&loc) {}
89 };
90 
91 
92 ////////////////////////////////////////////////////////////////////////////////
93 /// CFeatureLoadingJobResult
95  public CObject
96 {
97 public:
98  typedef vector< CIRef<IRenderable> > TGraphs;
99 
100  string m_Descr;
101  //TFeatures m_Features;
103 };
104 
105 
106 ////////////////////////////////////////////////////////////////////////////////
107 /// CFeatureLoadingJob
109 {
110 public:
111  typedef objects::CMappingRanges TMapRanges;
112 
113  CFeatureLoadingJob(const objects::CBioseq_Handle& handle,
114  objects::SAnnotSelector& sel,
115  const CRange<TSeqPos>& total_range,
116  TMapRanges& ranges,
117  const string& descr,
118  bool separate_types,
119  bool link_genes,
120  int track_order);
121  virtual ~CFeatureLoadingJob();
122 
123  /// @name IAppJob implementation
124  /// @{
125  virtual EJobState Run();
126  virtual CConstIRef<IAppJobProgress> GetProgress();
127  virtual CRef<CObject> GetResult();
128  virtual CConstIRef<IAppJobError> GetError();
129  virtual string GetDescr() const;
130  /// @}};
131 
132 protected:
133  typedef vector< CConstRef<objects::CSeq_feat> > TFeatures;
134  typedef vector<SMappedFeatLoc> TMappedFeatLocs;
135 
137  x_CreateGraph(TMappedFeatLocs& feat_locs, const string& descr);
138 
139 protected:
140  objects::CBioseq_Handle m_Handle;
141  objects::SAnnotSelector m_Sel;
144 
145  bool m_SeparateTypes; ///< separate features by different graphs
146  bool m_LinkGenes; ///< links genes with CDS and mRNA
147 
148  CMutex m_Mutex; ///< synchronizes access to the Job members
149 
150  string m_Descr;
151  int m_Order;
154 };
155 
156 
157 ////////////////////////////////////////////////////////////////////////////////
158 /// CFeatureGraphProperties
159 
162 {
163 public:
164  typedef objects::CFeatListItem TFeatTypeItem;
166 
167  /// defines what feature types / subtypes shall be shown
169 };
170 
171 
172 ////////////////////////////////////////////////////////////////////////////////
173 /// CFeatureGraph
175  public CGraphContainer,
176  public IAlnVecRowGraph
177 {
178 public:
181  typedef objects::CMappingRanges TMapRanges;
182  typedef vector<SMappedFeatLoc> TMappedFeatLocs;
184 
185  CFeatureGraph(const IAlignRowHandle& row_handle, bool isDataReadSync);
186 
187  /// @name IRenderable implementation
188  /// @{
190  virtual void Layout();
191  /// @}
192 
193  /// @name IAlnVecRowGraph implementaion
194  /// @{
195  virtual ~CFeatureGraph();
196 
197  virtual bool IsCreated() const;
198  virtual bool Create();
199  virtual void Destroy();
200  virtual void Update(double start, double stop);
201 
202  virtual const IAlnRowGraphProperties* GetProperties() const;
203  virtual void SetProperties(IAlnRowGraphProperties* props);
204 
205  virtual void Render(CGlPane& pane, IAlnSegmentIterator& it);
206  /// @}
207 
208  void OnAJNotification(CEvent* evt);
209 
210 protected:
212 
214 
215  void x_RenderStatusText(CGlPane& pane);
216 
217  CRef<TMapRanges> x_CreateMapRanges();
218 
219  void x_StartJob(const TFeatTypeItemSet& feat_set,
220  const TSubtypeSet& filter,
221  bool positive,
222  CRange<TSeqPos>& total_range,
223  TMapRanges& map_ranges,
224  const string& descr,
225  bool separate_types,
226  bool link_genes,
227  int order);
228 
229  bool x_StartJob(objects::SAnnotSelector& sel,
230  CRange<TSeqPos>& total_range,
231  TMapRanges& map_ranges,
232  const string& descr,
233  bool separate_types,
234  bool link_genes,
235  int order);
236 
237  bool x_CancelJob(TJobID job_id);
238  /// Cancel all active jobs
239  void x_CancelJobs();
240 
241  void x_OnJobCompleted(CAppJobNotification& notify);
242  void x_OnJobFailed(CAppJobNotification& notify);
243  void x_Create(double start, double stop);
244 
245 protected:
247 
249  bool m_Created;
251 
252  string m_StatusText;
254 
256 
257 private:
259  bool m_Updated; // to prevent multiple updates in synchronous mode
260 
261  /// Candidate graphs waiting for replacing the current ones.
263 };
264 
265 
266 
267 ////////////////////////////////////////////////////////////////////////////////
268 /// CFeatureGraph
269 
271  public CObjectEx,
272  public CRenderableImpl
273 {
274 public:
275  typedef vector<SMappedFeatLoc> TMappedFeatLocs;
276 
278 
280  objects::CScope& scope,
281  const string& label,
282  bool link_genes);
283 
284  virtual ~CAlignedFeatureGraph();
285 
286  /// @name IRenderable implementation
287  /// @{
288  virtual void Render(CGlPane& pane);
289 
290  virtual TVPPoint PreferredSize();
291 
292  virtual bool NeedTooltip(CGlPane& pane, int vp_x, int vp_y);
293  virtual string GetTooltip();
294  /// @}
295 
296  struct SFeatRec {
297 
298  public:
300  : m_ClusterIndex(-1) {}
301  SFeatRec(SMappedFeatLoc& feat_loc, int cluster_index = -1)
302  : m_FeatLoc(feat_loc), m_ClusterIndex(cluster_index) {
303  }
304  SFeatRec(CFeatGlyph& glyph, int cluster_index = -1)
305  : m_ClusterIndex(-1)
306  , m_FeatGlyph(&glyph)
307  {
308  m_FeatLoc.m_Feature = glyph.GetMappedFeature();
309  m_FeatLoc.m_MappedLoc.Reset(new objects::CSeq_loc);
310  m_FeatLoc.m_MappedLoc->Assign(glyph.GetMappedFeature().GetLocation());
311  }
312  const objects::CSeq_feat& GetFeature(void) const
313  {
314  return m_FeatLoc.m_Feature.GetOriginalFeature();
315  }
316  const objects::CSeq_loc& GetLocation(void) const {
317  return *m_FeatLoc.m_MappedLoc;
318  }
319  void SetClusterIndex(int value) {
320  m_ClusterIndex = value;
321  }
322  int GetClusterIndex() const {
323  return m_ClusterIndex;
324  }
325 
326  CFeatGlyph& GetGlyph() const {
327  if (!m_FeatGlyph) {
328  m_FeatGlyph = new CFeatGlyph(m_FeatLoc.m_Feature, *m_FeatLoc.m_MappedLoc);
329 
331  conf->m_BarHeight = 10.;
332  conf->m_HeadHeight = 1.;
333  conf->m_TailHeight = 1;
334  conf->m_LineWidth = 1;
336  m_FeatGlyph->SetConfig(conf);
337 
338  }
339  return *m_FeatGlyph;
340  }
341  protected:
345  };
346  typedef vector<SFeatRec> TFeatRecs;
347  typedef vector<SFeatRec*> TFeatRecPtrs;
348 
349 
350  // defines a cluster consisting of a Gene with associated mRNAs and CDS-es
351  // Cluster occupies 1 or more consequent layers. The horz. range belonging
352  // to the cluster may different for every layer, it is defined as a union of
353  // all features in cluster that are placed on this particular layer
354  // plus m_Offset additional positions on every side
355 
356  struct SCluster {
359  int m_Offset; // horz size in residues of zone
360 
361  SCluster(int first, int last, int offset)
362  : m_FirstLayer(first), m_LastLayer(last), m_Offset(offset) {}
363  };
364 
365  // define a horizontal feature layer
366  struct SLayer
367  {
368  TFeatRecPtrs m_FeatRecPtrs; // pointers to SFeatRecs
369  };
370 
371  typedef vector<SCluster> TClusters;
372  typedef vector<SLayer*> TLayers;
374  typedef vector<TColl*> TCollVector;
375  typedef pair<SFeatRec*, TSeqPos> TFeatRecPtrLenPair;
376  typedef list< CConstRef<objects::CSeq_feat> > TFeatList;
377 
379 
380  virtual void x_Init(TMappedFeatLocs& feat_locs,
381  objects::CScope& scope,
382  const string& label,
383  bool link_genes);
385  objects::CScope& scope,
386  const string& label,
387  bool link_genes);
388 
389  void x_Clear();
390 
391  void x_Layout();
392  void x_SimpleLayout(TFeatRecPtrs& feat_recs);
393  void x_LinkedLayout(TFeatRecPtrs& feat_recs);
394 
395  void x_GatherCluster(SFeatRec& feat_rec,
396  TFeatRecPtrs& cluster);
397  void x_GetRecsSortedByLength(const TFeatList& input,
398  vector<TFeatRecPtrLenPair>& pairs);
399  void x_PlaceCluster(TFeatRecPtrs& cluster);
400  bool x_mRNA_CDS_ToBePlaced(const objects::CSeq_feat& feat);
401  void x_TryPlaceCDSFeature(SFeatRec& rec);
402 
403  void x_PlaceFeature(SFeatRec& rec);
404 
405  void x_RenderFeature(CGlPane& pane, const SFeatRec& rec, int layer,
406  TModelUnit top, TModelUnit bottom);
407 
408  virtual string x_GetTooltip(const SFeatRec& rec);
409 
410 protected:
412  string m_Label;
414 
415  TFeatRecs m_FeatRecs; // mapped feature records
416  TClusters m_Clusters; // feature clusters
418 
420  TCollVector m_Occupied; // layer index -> collection of ranges occupied by features
421 
423  int m_LayerH;
424 
425 };
426 
427 
428 ///////////////////////////////////////////////////////////////////////////////
429 /// CFeatHistogramDS
431  : public CObject
432  , public IHistogramGraphDS
433 {
434 public:
435  typedef vector<SMappedFeatLoc> TMappedFeatLocs;
436 
437  CFeatHistogramDS(TMappedFeatLocs& feat_locs, const string& label);
438 
439  /// @name IHistogramDS implementation
440  /// @{
441  virtual double GetLimit() const;
442 
443  virtual double GetStart() const;
444  virtual double GetStop() const;
445  virtual double GetStep() const;
446 
447  virtual size_t GetCount() const;
448  virtual double GetValue(size_t index);
449 
450  virtual double GetMaxValue();
451 
452  virtual string GetLabel() const;
453 
454  virtual void Update(double start, double stop);
455  /// @}
456 
457 protected:
460 
461  string m_Label;
464  unique_ptr<TMap> m_Map;
465 };
466 
467 
469 
470 #endif // __GUI_WIDGETS_ALNMULTI___ALIGN_FEATURE_GRAPH__HPP
CAlignedFeatureGraph(TMappedFeatLocs &feat_locs, objects::CScope &scope, const string &label, bool link_genes)
CRangeCollection< TSeqPos > TColl
vector< SCluster > TClusters
vector< TColl * > TCollVector
virtual void x_Init(TMappedFeatLocs &feat_locs, objects::CScope &scope, const string &label, bool link_genes)
map< const objects::CSeq_feat *, pair< SFeatRec *, bool > > TFeatToRecFlag
list< CConstRef< objects::CSeq_feat > > TFeatList
pair< SFeatRec *, TSeqPos > TFeatRecPtrLenPair
CRef< objects::CScope > m_Scope
TFeatToRecFlag m_FeatToRecFlag
void x_Init(CSeqGlyph::TObjects &glyphs, objects::CScope &scope, const string &label, bool link_genes)
vector< SMappedFeatLoc > TMappedFeatLocs
vector< SFeatRec > TFeatRecs
vector< SLayer * > TLayers
vector< SFeatRec * > TFeatRecPtrs
CAppJobNotification Notification send by CAppJobEventTranslator.
class CDensityMap generates a low-resolution view of a set of features.
CEvent - generic event implementation TODO TODO - Attachments.
Definition: event.hpp:86
const objects::CMappedFeat & GetMappedFeature(void) const
Access a new, fully remapped feature.
CFeatHistogramDS.
virtual void Update(double start, double stop)
vector< SMappedFeatLoc > TMappedFeatLocs
CRange< TSeqPos > TFeatRange
CFeatHistogramDS(TMappedFeatLocs &feat_locs, const string &label)
CFeatHistogramDS.
virtual string GetLabel() const
TFeatRange m_FeatRange
virtual double GetStop() const
virtual double GetValue(size_t index)
value of the sample with the given index
CDensityMap< int > TMap
virtual double GetMaxValue()
virtual double GetLimit() const
returns start of the series in model space
TMappedFeatLocs m_FeatLocs
virtual double GetStart() const
unique_ptr< TMap > m_Map
virtual double GetStep() const
discrete size in model space
virtual size_t GetCount() const
number of samples in the series
CFeatureGraphProperties.
objects::CFeatListItem TFeatTypeItem
set< TFeatTypeItem > TFeatTypeItemSet
TFeatTypeItemSet m_FeatureTypes
defines what feature types / subtypes shall be shown
CFeatureGraph.
TGraphs m_PendingGraphs
Candidate graphs waiting for replacing the current ones.
vector< SMappedFeatLoc > TMappedFeatLocs
CFeatureGraphProperties m_Properties
CGlTextureFont m_Font
map< TJobID, CRef< CFeatureLoadingJob > > TJobMap
const IAlignRowHandle & m_RowHandle
CFeatureGraphProperties::TFeatTypeItemSet TFeatTypeItemSet
CAppJobDispatcher::TJobID TJobID
bool x_StartJob(objects::SAnnotSelector &sel, CRange< TSeqPos > &total_range, TMapRanges &map_ranges, const string &descr, bool separate_types, bool link_genes, int order)
objects::CMappingRanges TMapRanges
CFeatureGraphProperties::TFeatTypeItem TFeatTypeItem
virtual TVPPoint PreferredSize()
set< objects::CSeqFeatData::ESubtype > TSubtypeSet
CFeatureLoadingJobResult.
vector< CIRef< IRenderable > > TGraphs
CFeatureLoadingJob.
CRef< CFeatureLoadingJobResult > m_Result
CRange< TSeqPos > m_TotalRange
vector< CConstRef< objects::CSeq_feat > > TFeatures
objects::CBioseq_Handle m_Handle
bool m_LinkGenes
links genes with CDS and mRNA
objects::CMappingRanges TMapRanges
vector< SMappedFeatLoc > TMappedFeatLocs
CMutex m_Mutex
synchronizes access to the Job members
objects::SAnnotSelector m_Sel
bool m_SeparateTypes
separate features by different graphs
CIRef< IAppJobError > m_Error
CRef< TMapRanges > m_MapRanges
CFeatureParams: the data structure holding feature rendering parameters.
TModelUnit m_LineWidth
absolute value (in pixel)
TModelUnit m_HeadHeight
ratio to bar height
TModelUnit m_TailHeight
ratio to bar height
ELabelPosition m_LabelPos
TModelUnit m_BarHeight
absolute size (in pixel)
@ ePos_Inside
inside the rendered bar
class CGlPane
Definition: glpane.hpp:62
CGraphContainer CGraphContainer a composite IRenderable that manages several child IRenderable graphs...
vector< TGraphRef > TGraphs
Base class to build jobs with cancel functionality.
CMutex –.
Definition: ncbimtx.hpp:749
CObjectEx –.
Definition: ncbiobj.hpp:2531
CObject –.
Definition: ncbiobj.hpp:180
CRenderableImpl.
Definition: irenderable.hpp:82
CScope –.
Definition: scope.hpp:92
list< CRef< CSeqGlyph > > TObjects
Definition: seq_glyph.hpp:85
IAlignRowHandle provides an abstract way to access alignment row data.
Definition: alnmulti_ds.hpp:59
IAlnRowGraphProperties.
Alignment segment iterator interface.
IAlnVecRowGraph - abstract graph that can be rendered in the "expandable" space below the CAlnVecRow.
IHistogramGraphDS interface.
Definition: map.hpp:338
static DLIST_TYPE *DLIST_NAME() first(DLIST_LIST_TYPE *list)
Definition: dlist.tmpl.h:46
static DLIST_TYPE *DLIST_NAME() last(DLIST_LIST_TYPE *list)
Definition: dlist.tmpl.h:51
int offset
Definition: replacements.h:160
GLdouble TModelUnit
Definition: gltypes.hpp:48
EJobState
Job states (describe FSM)
Definition: app_job.hpp:86
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
void Run(void)
Enter the main loop.
#define NCBI_GUIWIDGETS_ALNMULTIPLE_EXPORT
Definition: gui_export.h:520
static const char label[]
static int input()
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
T positive(T x_)
SCluster(int first, int last, int offset)
CFeatGlyph & GetGlyph() const
SFeatRec(SMappedFeatLoc &feat_loc, int cluster_index=-1)
SFeatRec(CFeatGlyph &glyph, int cluster_index=-1)
const objects::CSeq_loc & GetLocation(void) const
const objects::CSeq_feat & GetFeature(void) const
objects::CMappedFeat m_Feature
CRef< objects::CSeq_loc > m_MappedLoc
SMappedFeatLoc(const objects::CMappedFeat &feat, objects::CSeq_loc &loc)
Modified on Mon May 06 04:52:48 2024 by modify_doxy.py rev. 669887