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

Go to the SVN repository for this file.

1 #ifndef GUI_WIDGETS_SEQ_GRAPHIC___VCF_GLYPH__HPP
2 #define GUI_WIDGETS_SEQ_GRAPHIC___VCF_GLYPH__HPP
3 
4 /* $Id: vcf_glyph.hpp 46471 2021-06-01 13:48:48Z shkeda $
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: Mike DiCuccio, Liangshou Wu
30  *
31  * File Description:
32  * CVcfGlyph -- utility class to arrange CSeq_feat objects in hierarchical
33  * (tree) order.
34  */
35 
36 #include <gui/gui.hpp>
37 #include <gui/objutils/label.hpp>
38 #include <gui/objutils/utils.hpp>
39 #include <gui/objutils/snp_gui.hpp>
44 
46 
47 #include <corelib/ncbiobj.hpp>
48 
50 
51 ///////////////////////////////////////////////////////////////////////////////
52 /// Class for storing a set of nested features.
53 /// A feature describes the genetic location in true gene coordinates of any
54 /// sort of genetic object (gene / protein / RNA / etc). Each feature has an
55 /// overall extent as well as a series of subregions
56 ///
57 BEGIN_objects_SCOPE
58 class CUser_object;
59 END_objects_SCOPE
60 
61 
63  public CSeqGlyph, public IObjectBasedGlyph
64 {
65 public:
66  /// @name ctors.
67  /// @{
68  CVcfGlyph(objects::CSeq_id& seq_id,
69  const string& sID,
70  size_t pos, ///< in VCF (i.e. 1-based coordinates)
71  const string& ref_allele,
72  const string& alt_alleles); ///< alternative alleles separated by /
73 
74  CVcfGlyph(const objects::CVcfVariant *object);
75  /// @}
76 
77  /// @name CSeqGlyph virtual method implementation.
78  /// @{
79  virtual bool NeedTooltip(const TModelPoint& /*p*/, ITooltipFormatter& /*tt*/, string& /*t_title*/) const;
80  virtual void GetTooltip(const TModelPoint& p, ITooltipFormatter& tt, string& t_title) const;
81  virtual void GetHTMLActiveAreas(TAreaVector* p_areas) const;
82  virtual TSeqRange GetRange(void) const;
83  virtual bool SetSelected(bool f);
84  virtual void SetHideLabel(bool b);
85  virtual bool HasSideLabel() const;
86  virtual bool IsClickable() const;
87  virtual bool LessBySeqPos(const CSeqGlyph& obj) const;
88  virtual bool HitTestHor(TSeqPos x, const CObject *obj);
89  /// @}
90  /// @name IObjectBasedGlyph interface implementation (needed for object inspector and search selection to work)
91  /// @{
92  virtual const objects::CSeq_loc& GetLocation(void) const;
93  virtual CConstRef<CObject> GetObject(TSeqPos pos) const;
94  virtual void GetObjects(vector<CConstRef<CObject> >& objs) const;
95  virtual bool HasObject(CConstRef<CObject> obj) const;
96  virtual string GetSignature() const;
97  virtual const TIntervals& GetIntervals(void) const;
98  /// @}
99  /// Get the customized color for a given feature.
100  /// Special color code.
101  /// For features with Var_type and identity qualifier set,
102  /// we render them using special color code:
103  /// Color dbVar features based on qual::Var_type
104  /// - Deletions/Loss=red
105  /// - Indels=red
106  /// - Gains/Insertion=green
107  /// - Inversions=gray
108  /// Color segmental duplication feature based on qual::identity
109  /// - Gray: 90-98%
110  /// - Yellow: 98-99%
111  /// - Orange:>99%
112  /// @param color the returned customized color
113  /// @return true if custom color is needed
114  bool GetCustomColor(CRgbaColor& color) const;
115  void GetCustomColor(size_t idx, CRgbaColor& color) const;
116 
117  /// determines whether the glyph should be drawn or not at all (currently children of unselected parents when m_LinkedFeat
118  /// is set to "Expandable")
119  bool isDrawn() const { return x_isDrawn(); }
120 
121  /// update the layout for everything encompassing this glyph
122  void LayoutChanged();
123  CConstRef<CFeatureParams> GetConfig() const;
124  void SetConfig(CConstRef<CFeatureParams> conf);
125 
126  /// variation additional info on the right (alleles)
127  void GetAdditionalInfo(string& sAdditionalInfo) const;
128  /// retrieve label for a given type
129  void GetLabel(string& label, CLabel::ELabelType type) const;
130 protected:
131  virtual void x_Draw() const;
132  virtual void x_UpdateBoundingBox();
133 
134  virtual void x_DrawHighlight() const;
135 
136  void x_MaybeDrawLabelAbove(TModelUnit& base) const;
137  void x_DrawVariationBar(TModelUnit base) const;
138  void x_DrawAdditionalInfo(TModelUnit base) const;
139  void x_MaybeDrawLabelOthers(TModelUnit base) const;
140 
141  bool x_RedundantLabelCheck(const string& label) const;
142  void x_DrawInsertion(TModelUnit SeqPosTriangleMidPointX,
143  TModelUnit BoundaryYLow,
144  TModelUnit BoundaryYHigh,
145  TModelUnit YCenterLine) const;
146  void x_DrawDeletion(TModelUnit SeqPosTriangleMidPointX,
147  TModelUnit BoundaryYLow,
148  TModelUnit BoundaryYHigh) const;
149  void x_DrawLabelWithXPinned(TModelUnit& base) const;
150  void x_DrawLabelWithYPinned(TModelUnit base) const;
151  void x_DrawInnerLabels(TModelUnit base, vector<TModelRange> *labels_range = nullptr, TSeqRange* interval = nullptr) const;
152 
153  /// determines whether the glyph should be drawn or not at all (currently children of unselected parents when m_LinkedFeat
154  /// is set to "Expandable")
155  bool x_isDrawn() const;
156 
157  void x_GetClinVarToolTip(ITooltipFormatter& tooltip) const;
158 
159 private:
160  TModelUnit x_GetBarHeight() const;
161  bool x_HasOuterOnly() const;
162  bool x_ShowLabel() const;
163  /// check to see if label needs to be drawn before feature bar.
164  /// for side-placed labels, returns true on positive strand if left side of the glyph is before start of the whole sequence
165  /// or on negative strand beyond the end (has no relation
166  /// to the part of sequence being drawn) i.e. most of the time it is "false"
167  bool x_LabelFirst() const;
168  /// true if a label should be placed to the left of the feature bar (provided that it is ePos_Side)
169  bool x_LabelOnLeft() const;
170 
171 private:
173  bool m_HideLabel{false};
174 
175  // object that we want to be associated with this glyph
177 
179 
180  // feature custom coolor or null
181  mutable bool m_CustomColorIsSet{false};
182  mutable unique_ptr<CRgbaColor> m_CustomColorPtr;
183 
184 
185 };
186 
187 
188 ///////////////////////////////////////////////////////////////////////////////
189 /// CVcfGlyph inline implementations
190 
191 inline
193 {
194  return m_Config;
195 }
196 
197 inline
199 {
200  m_Config = conf;
201 }
202 
203 inline
205 {
208  if (idx == 0) {
210  } else if (idx < colors.size()) {
211  color = colors[idx];
212  }
213 }
214 
216 
217 /* @} */
218 
219 #endif // GUI_WIDGETS_SEQ_GRAPHIC___VCF_GLYPH__HPP
User-defined methods of the data storage class.
vector< CRgbaColor > TColorCode
const TColorCode & GetColorCode() const
CRef< CCustomFeatureColor > m_CustomColors
custom color code for features with a special attribute.
CRgbaColor m_fgColor
CObject –.
Definition: ncbiobj.hpp:180
class CRgbaColor provides a simple abstraction for managing colors.
Definition: rgba_color.hpp:58
class CSeqGlyph defines an interface that wraps a rectilinear abstract object.
Definition: seq_glyph.hpp:82
virtual bool HitTestHor(TSeqPos x, const CObject *obj)
Definition: seq_glyph.cpp:115
virtual void SetHideLabel(bool)
Force to hide label.
Definition: seq_glyph.hpp:179
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.
void x_DrawInnerLabels(TModelUnit base, const string &label, const CRgbaColor &color, const CGlTextureFont &font, bool side_label_visible, bool inside_only, vector< TModelRange > *labels_ranges=nullptr, TSeqRange *interval=nullptr, bool XOR_mode=false) const
Definition: seq_glyph.cpp:224
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 TSeqRange GetRange(void) const
get the total range of this object.
Definition: seq_glyph.hpp:513
virtual bool LessBySeqPos(const CSeqGlyph &obj) const
compare this object to another based on glyph sequence position.
Definition: seq_glyph.hpp:534
virtual bool HasSideLabel() const
Query if there is label and label is on the side.
Definition: seq_glyph.hpp:187
virtual bool SetSelected(bool flag)
Select or deselect this glyph.
Definition: seq_glyph.hpp:525
virtual void x_DrawHighlight() const
Definition: seq_glyph.cpp:170
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
CConstRef< objects::CVcfVariant > m_Object
Definition: vcf_glyph.hpp:176
TIntervals m_Intervals
Definition: vcf_glyph.hpp:178
CVcfGlyph(const objects::CVcfVariant *object)
bool x_LabelFirst() const
check to see if label needs to be drawn before feature bar.
bool isDrawn() const
determines whether the glyph should be drawn or not at all (currently children of unselected parents ...
Definition: vcf_glyph.hpp:119
void SetConfig(CConstRef< CFeatureParams > conf)
Definition: vcf_glyph.hpp:198
bool GetCustomColor(CRgbaColor &color) const
Get the customized color for a given feature.
Definition: vcf_glyph.cpp:309
bool x_HasOuterOnly() const
CVcfGlyph(objects::CSeq_id &seq_id, const string &sID, size_t pos, const string &ref_allele, const string &alt_alleles)
alternative alleles separated by /
CConstRef< CFeatureParams > m_Config
Definition: vcf_glyph.hpp:172
unique_ptr< CRgbaColor > m_CustomColorPtr
Definition: vcf_glyph.hpp:182
CConstRef< CFeatureParams > GetConfig() const
CVcfGlyph inline implementations.
Definition: vcf_glyph.hpp:192
File Description:
virtual const TIntervals & GetIntervals(void) const =0
access sub-intervals (if any).
virtual CConstRef< CObject > GetObject(TSeqPos pos) const =0
access our core component - we wrap an object(s) of some sort.
virtual const objects::CSeq_loc & GetLocation(void) const =0
access the position of this object.
virtual string GetSignature() const =0
return signature for this glyph.
virtual bool HasObject(CConstRef< CObject > obj) const =0
check if the wrapped object(s) is the one.
vector< TSeqRange > TIntervals
primitive interface to arrange tabular data in the tooltips
Definition: tooltip.hpp:55
static const Colors colors
Definition: cn3d_colors.cpp:50
vector< CConstRef< CObject > > GetObjects(CSeq_entry_Handle seh, const string &field, CFieldNamePanel::EFieldType field_type, int subtype, const string &ncRNA_class, CConstRef< objects::CSeq_submit > submit, CRef< CEditingActionConstraint > constraint, vector< CSeq_entry_Handle > *descr_context=nullptr)
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
GLdouble TModelUnit
Definition: gltypes.hpp:48
ELabelType
Definition: label.hpp:60
string GetLabel(const CSeq_id &id)
#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_SEQGRAPHIC_EXPORT
Definition: gui_export.h:536
static const char label[]
n background color
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
double f(double x_, const double &y_)
Definition: njn_root.hpp:188
Definition: type.c:6
Modified on Thu Dec 07 10:07:02 2023 by modify_doxy.py rev. 669887