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

Go to the SVN repository for this file.

1 #ifndef GUI_PACKAGES_SNP_BINS_TRACK__BINS_GLYPH__HPP
2 #define GUI_PACKAGES_SNP_BINS_TRACK__BINS_GLYPH__HPP
3 
4 /* $Id: bins_glyph.hpp 35413 2016-05-04 17:51:26Z evgeniev $
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: Melivn Quintos
30  *
31  * File Description:
32  * CBinsGlyph -- Glyph that represents SNP Bin Track format
33  *
34  */
35 
36 
37 #include <corelib/ncbiobj.hpp>
39 #include <objmgr/scope.hpp>
40 #include <gui/utils/rgba_color.hpp>
45 
47 
49 {
50 ////////////////////////////////////////////
51 // Public Structs/Classes/Typedefs
52 ////////////////////////////////////////////
53 public:
54 
55  struct SBinMapped {
56  CRef<objects::NSnpBins::SBin> obj; // the mapped NSnpBins::SBin object
57 
58  SBinMapped() {};
59  SBinMapped(int /*c*/) { /* this is only needed to support DensityMap usage */}
60 
61  bool operator < (const SBinMapped &rhs) const
62  {
63  if (rhs.obj.Empty()) return false;
64  if (this->obj.Empty()) return true;
65 
66  return (this->obj->range.GetFrom() < rhs.obj->range.GetFrom());
67  }
68  size_t SequentialNumber; // consecutive bin number in the density map
69  };
70 
71  friend SBinMapped operator+(const SBinMapped& val1, const SBinMapped& val2);
72 
73  struct accum_study : public binary_functor<SBinMapped> {
74  virtual SBinMapped operator() (const SBinMapped& x,
75  const SBinMapped& y) const
76  {
77  return x + y;
78  }
79 
81  {
82  return new accum_study;
83  }
84  };
85 
87 
88 //////////////////////////////////////////////
89 // Public Methods
90 //////////////////////////////////////////////
91 public:
92 
93  /// @name Static Methods
94  /// @{
95  static string GenerateBinSignature(const string& title,
96  const string& annot_name,
97  TGi gi,
99  objects::NSnpBins::TBinType BinType);
100  /// @}
101 
102  /// @name ctors
103  /// @{
104 
105  CBinsGlyph(const TDensityMap& values,
106  const objects::CSeq_loc& loc,
107  objects::CScope * scope);
108  /// @}
109 
110  /// @name CSeqGlyph virtual methods.
111  /// @{
112  virtual bool NeedTooltip(const TModelPoint& p, ITooltipFormatter& tt, string& t_title) const;
113  virtual void GetTooltip(const TModelPoint& p, ITooltipFormatter& tt, string& t_title) const;
114  virtual void GetHTMLActiveAreas(TAreaVector* p_areas) const;
115  virtual bool OnLeftDblClick(const TModelPoint& p);
116  virtual bool IsClickable() const;
117 
118  virtual TSeqRange GetRange(void) const;
119  ///@}
120 
121  /// @name Non-Inherited Getters/Setters
122  /// @{
123 
124  /// Access the first density map.
125  const TDensityMap& GetDensityMap(void) const;
126 
127  // Get range for a particular bin
129  objects::NSnpBins::TBinType GetType() const { return m_Type; }
130  void SetType(objects::NSnpBins::TBinType t) { m_Type = t; }
131 
132  ///@}
133 
134  void SetTitle(const string& title);
135  const string& GetTitle() const;
136 
137  void SetAnnotName(const string& name);
138  const string& GetAnnotName() const;
139 
140 
141 //////////////////////////////////////////////
142 // Protected Methods
143 //////////////////////////////////////////////
144 protected:
145  /// @name CSeqGlyph virtual methods.
146  /// @{
147  virtual void x_Draw() const;
148  virtual void x_UpdateBoundingBox();
149  ///@}
150 
151 
152 //////////////////////////////////////////////
153 // Private Methods
154 //////////////////////////////////////////////
155 private:
156  // This populates 'm_NonEmptyBins'. It is labeled 'const'
157  // but modifies the mutable m_listObjs
158  void x_BuildNonEmptyBinList() const;
159  TSeqRange x_GetBinRange(unsigned int bin) const;
160  string x_GetColorTheme() const;
161 
162 private:
163  string m_Title;
164  string m_AnnotName;
167  objects::NSnpBins::TBinType m_Type;
168 
169  mutable bool m_bHasObjectList;
170 
171  typedef list<SBinMapped*> TMappedBinList;
172 
173  // contains only non-empty bins
176 };
177 
178 ///////////////////////////////////////////////////////////////////////////////
179 /// CBinsGlyph inline method implementation.
180 inline
182 {
183  return m_Map;
184 }
185 
186 inline
187 void CBinsGlyph::SetTitle(const string& title)
188 { m_Title = title; }
189 
190 inline
191 const string& CBinsGlyph::GetTitle() const
192 { return m_Title; }
193 
194 inline
195 void CBinsGlyph::SetAnnotName(const string& name)
196 { m_AnnotName = name; }
197 
198 inline
199 const string& CBinsGlyph::GetAnnotName() const
200 { return m_AnnotName; }
201 
202 
203 inline
205  const CBinsGlyph::SBinMapped& val2)
206 {
207  if (val1.obj.Empty()) return val2;
208  if (val2.obj.Empty()) return val1;
209 
211  result.obj.Reset(new objects::NSnpBins::SBin);
212 
213  ITERATE(objects::NSnpBins::TBinEntryList, iter, val1.obj->m_EntryList) {
214  result.obj->m_EntryList.push_back(*iter);
215  }
216 
217  ITERATE(objects::NSnpBins::TBinEntryList, iter, val2.obj->m_EntryList) {
218  result.obj->m_EntryList.push_back(*iter);
219  }
220 
221  result.obj->count = val1.obj->count + val2.obj->count;
222  // we expect the type to be always the same
223  NCBI_ASSERT(val1.obj->type == val2.obj->type, "Merged CBinsGlyph::SBinMapped should always have the same types!");
224  result.obj->type = val1.obj->type;
225 
226  result.obj->m_SigEntry = (objects::NSnpBins::ChooseSignificant(val1.obj->m_SigEntry, val2.obj->m_SigEntry, result.obj->type) == 1)
227  ? val1.obj->m_SigEntry
228  : val2.obj->m_SigEntry;
229  // add the ranges together
230  result.obj->range = val1.obj->range.CombinationWith(val2.obj->range);
231 
232  // signature is calculated during CBinsGlyph::x_BuildObjectList
233  return result;
234 }
235 
237 
238 /* @} */
239 
240 #endif // GUI_PACKAGES_SNP_BINS_TRACK__BINS_GLYPH__HPP
CBinsGlyph::SBinMapped operator+(const CBinsGlyph::SBinMapped &val1, const CBinsGlyph::SBinMapped &val2)
Definition: bins_glyph.hpp:204
CDensityMap< SBinMapped > TDensityMap
Definition: bins_glyph.hpp:86
string m_AnnotName
Definition: bins_glyph.hpp:164
CConstRef< objects::CSeq_loc > m_Location
Definition: bins_glyph.hpp:165
TDensityMap m_Map
Definition: bins_glyph.hpp:166
TMappedBinList m_NonEmptyBins
Definition: bins_glyph.hpp:174
void SetType(objects::NSnpBins::TBinType t)
Definition: bins_glyph.hpp:130
string m_Title
Definition: bins_glyph.hpp:163
objects::NSnpBins::TBinType GetType() const
Definition: bins_glyph.hpp:129
const string & GetTitle() const
Definition: bins_glyph.hpp:191
void SetTitle(const string &title)
Definition: bins_glyph.hpp:187
const TDensityMap & GetDensityMap(void) const
Access the first density map.
Definition: bins_glyph.hpp:181
CRef< objects::CScope > m_Scope
Definition: bins_glyph.hpp:175
const string & GetAnnotName() const
Definition: bins_glyph.hpp:199
list< SBinMapped * > TMappedBinList
Definition: bins_glyph.hpp:171
bool m_bHasObjectList
Definition: bins_glyph.hpp:169
TSeqRange GetBinRangeAt(TSeqPos pos) const
objects::NSnpBins::TBinType m_Type
Definition: bins_glyph.hpp:167
void SetAnnotName(const string &name)
Definition: bins_glyph.hpp:195
class CSeqGlyph defines an interface that wraps a rectilinear abstract object.
Definition: seq_glyph.hpp:82
virtual bool IsClickable() const
Query if this glyph is clickable.
Definition: seq_glyph.hpp:195
virtual void x_Draw() const =0
The default renderer for this layout object.
virtual void GetTooltip(const TModelPoint &, ITooltipFormatter &tt, string &t_title) const
Get the tooltip if available.
Definition: seq_glyph.cpp:136
virtual bool NeedTooltip(const TModelPoint &, ITooltipFormatter &, string &) const
Check if need to show tooltip.
Definition: seq_glyph.cpp:130
virtual bool OnLeftDblClick(const TModelPoint &)
Definition: seq_glyph.cpp:76
virtual TSeqRange GetRange(void) const
get the total range of this object.
Definition: seq_glyph.hpp:513
virtual void GetHTMLActiveAreas(TAreaVector *) const
Get html active areas.
Definition: seq_glyph.hpp:148
virtual void x_UpdateBoundingBox()=0
Update the bounding box assuming children's sizes are fixed if any.
vector< CHTMLActiveArea > TAreaVector
Definition: seq_glyph.hpp:84
primitive interface to arrange tabular data in the tooltips
Definition: tooltip.hpp:55
bool operator<(const CEquivRange &A, const CEquivRange &B)
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 NCBI_ASSERT(expr, mess)
Definition: ncbidbg.hpp:130
NCBI_XOBJUTIL_EXPORT string GetTitle(const CBioseq_Handle &hnd, TGetTitleFlags flags=0)
Definition: seqtitle.cpp:106
bool Empty(void) const THROWS_NONE
Check if CRef is empty – not pointing to any object, which means having a null value.
Definition: ncbiobj.hpp:719
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_GUIWIDGETS_SNP_EXPORT
Definition: gui_export.h:540
range(_Ty, _Ty) -> range< _Ty >
EIPRangeType t
Definition: ncbi_localip.c:101
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
CRef< objects::NSnpBins::SBin > obj
Definition: bins_glyph.hpp:56
virtual binary_functor< SBinMapped > * clone() const
Definition: bins_glyph.hpp:80
TEMPLATE binary functor base struct.
Definition: density_map.hpp:59
else result
Definition: token2.c:20
static void SetTitle(CRef< CSeq_entry > entry, string title)
Modified on Sat Dec 02 09:22:37 2023 by modify_doxy.py rev. 669887