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

Go to the SVN repository for this file.

1 #ifndef GUI_WIDGETS_SEQ_GRAPHIC___ALIGN_STATISTICS_GLYPH__HPP
2 #define GUI_WIDGETS_SEQ_GRAPHIC___ALIGN_STATISTICS_GLYPH__HPP
3 
4 /* $Id: align_statistics_glyph.hpp 42508 2019-03-15 18:24:51Z 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: Liangshou Wu
30  *
31  * File Description:
32  * CAlnStatGlyph -- utility class for having
33  * feature density histograms his in graphical layouts.
34  *
35  */
36 
37 
38 #include <corelib/ncbiobj.hpp>
40 #include <gui/utils/rgba_color.hpp>
44 #include <array>
45 
47 
48 
50 {
51 public:
53  : m_StatZoomLevel(1)
54  , m_Display(fDefault)
55  , m_ShowLabel(true)
56  {
57  m_Colors = {
58  CRgbaColor("green3"),
59  CRgbaColor("0 114 178"),
60  CRgbaColor("204 33 00"),
61  CRgbaColor("grey50"),
62  CRgbaColor("0 0 0"),
63  CRgbaColor("grey50"),
64  CRgbaColor("grey80"),
65  CRgbaColor("255 0 0"),
66  CRgbaColor("0 0 255"),
67  CRgbaColor("grey50") };
68  }
69 
70  /// statistics enum.
71  /// some stats can be derived from others. E.g. eStat_Match is
72  /// of of A, G, T and C that matches reference sequence, and eStat_Mismatch
73  /// is the sum of all other three, and eStat_Total is the sum of
74  /// gaps, matches, and mismatches.
75  enum EStatType {
76  eStat_A = 0,
81  eStat_Intron, ///< intron (for mRNA-to-genome alignments)
82  eStat_Match, ///< matches
83  eStat_Mismatch, ///< mismatches (A+G+T+C - matches)
84  eStat_Ambig, ///< ambiguous consensus (for MSA pileup)
85  eStat_Total ///< total alignment count at this base (A+G+T+C+Gap)
86  };
87 
88  enum FDisplay {
89  fBarGraph = 1 << 0, ///< otherwise, shown as density table
90  fShowCount = 1 << 1, ///< otherwise, shown percentage
91  fShowMismatch = 1 << 2, ///< otherwise, shown individual count
92  fShowTotal = 1 << 3,
93  fDefault = fBarGraph | fShowCount | fShowMismatch | fShowTotal
94  };
95 
96  typedef int TDisplay;
97 
98  static int GetRefSeqIdex(char base)
99  {
100  switch (base) {
101  case 'A':
102  return eStat_A;
103  case 'G':
104  return eStat_G;
105  case 'T':
106  return eStat_T;
107  case 'C':
108  return eStat_C;
109  case 'N':
110  return eStat_Intron;
111  case '-':
112  return eStat_Gap;
113  default:
114  break;
115  }
116  return eStat_Gap;
117  }
118 
119  static string GetStatLabel(int stat)
120  {
121  EStatType stat_t = (EStatType)stat;
122  string label = "";
123  switch (stat_t) {
125  label = "A";
126  break;
128  label = "G";
129  break;
131  label = "T";
132  break;
134  label = "C";
135  break;
137  label = "Gap";
138  break;
140  label = "Match";
141  break;
143  label = "Mismatch";
144  break;
146  label = "Intron";
147  break;
149  label = "Total";
150  break;
151  default:
152  break;
153  }
154  return label;
155  }
156 
157  bool IsBarGraph() const;
158  bool ShowCount() const;
159  bool ShowAGTC() const;
160  bool ShowTotal() const;
161  bool ShowLabel() const;
162  void SetShowLabel(bool flag);
163 
164  void SetDisplayFlag(FDisplay bit, bool f);
166  int m_StatZoomLevel; ///< at what zoom level to turn on statistics
169  bool m_HasAmbigBases = false; // MSA Viewer uses it
170 };
171 
172 
174 {
175 public:
176  struct SStatStruct {
178  {
179  for (size_t i = 0; i < CAlnStatConfig::eStat_Total + 1; ++i) {
180  m_Data[i] = 0;
181  }
182  }
183 
185  };
186 
187  typedef vector<SStatStruct> TStatVec;
188  /// @name ctors
189  /// @{
190  CAlnStatGlyph(TSeqPos start, TModelUnit sacle);
191  /// @}
192 
193  /// @name CSeqGlyph virtual methods.
194  /// @{
195  virtual bool OnLeftDblClick(const TModelPoint& p);
196  virtual bool NeedTooltip(const TModelPoint& p, ITooltipFormatter& tt, string& t_title) const;
197  virtual void GetTooltip(const TModelPoint& p, ITooltipFormatter& tt, string& t_title) const;
198  virtual void GetHTMLActiveAreas(TAreaVector* p_areas) const;
199  virtual bool IsClickable() const;
200  ///@}
201 
202  void SetConfig(CRef<CAlnStatConfig> conf, CRef<CHistParams> params);
203  const TStatVec& GetStatVec() const;
204  TStatVec& GetStatVec();
205 
206  void SetCgiMode(bool cgi_mode = true);
207 
208  void SetDialogHost(IGlyphDialogHost* host);
209 
210  void ShowIntrons(bool show = true) { m_ShowIntrons = show; }
211 
212  static CRef<objects::CChoice> CreateDisplayOptions(const string& option_name, int display_flag);
213 protected:
214  virtual void x_Draw() const;
215  virtual void x_UpdateBoundingBox();
216 
217 private:
218  void x_DrawBarGraph() const;
219  void x_DrawDensityTable() const;
220  int x_GetMaxTotal() const;
221  vector<int> x_GetShowList() const;
222 
223 private:
229 
230  /// zoom scale when this statistics are computed.
231  /// needed for rendering.
233  bool m_CgiMode = false;
234  bool m_ShowIntrons = false;
235 };
236 
237 
238 
239 ///////////////////////////////////////////////////////////////////////////////
240 /// CAlnStatConfig inline method implementation.
241 inline
243 {
245 }
246 
247 inline
249 {
251 }
252 
253 inline
255 {
257 }
258 
259 inline
261 {
263 }
264 
265 inline
267 {
268  return m_ShowLabel;
269 }
270 
271 inline
273 {
274  m_ShowLabel = flag;
275 }
276 
277 inline
279 {
280  if (f) {
281  m_Display |= bit;
282  } else {
283  m_Display &= ~bit;
284  }
285 }
286 
287 
288 ///////////////////////////////////////////////////////////////////////////////
289 /// CAlnStatGlyph inline method implementation.
290 inline
292 {
293  m_Config = conf;
294  m_GraphParams = params;
295 }
296 
297 inline
299 { return m_StatVec; }
300 
301 inline
303 { return m_StatVec; }
304 
305 inline
307 { m_DlgHost = host; }
308 
309 inline
310 void CAlnStatGlyph::SetCgiMode(bool cgi_mode)
311 {
312  m_CgiMode = cgi_mode;
313 }
315 
316 /* @} */
317 
318 #endif // GUI_WIDGETS_SEQ_GRAPHIC___ALIGN_STATISTICS_GLYPH__HPP
static string GetStatLabel(int stat)
@ fBarGraph
otherwise, shown as density table
@ fShowCount
otherwise, shown percentage
@ fShowMismatch
otherwise, shown individual count
void SetDisplayFlag(FDisplay bit, bool f)
int m_StatZoomLevel
at what zoom level to turn on statistics
static int GetRefSeqIdex(char base)
void SetShowLabel(bool flag)
array< CRgbaColor, eStat_Total+1 > m_Colors
color settings
EStatType
statistics enum.
@ eStat_Intron
intron (for mRNA-to-genome alignments)
@ eStat_Ambig
ambiguous consensus (for MSA pileup)
@ eStat_Mismatch
mismatches (A+G+T+C - matches)
@ eStat_Total
total alignment count at this base (A+G+T+C+Gap)
bool IsBarGraph() const
CAlnStatConfig inline method implementation.
const TStatVec & GetStatVec() const
void SetCgiMode(bool cgi_mode=true)
void SetConfig(CRef< CAlnStatConfig > conf, CRef< CHistParams > params)
CAlnStatGlyph inline method implementation.
TModelUnit m_ZoomScale
zoom scale when this statistics are computed.
void SetDialogHost(IGlyphDialogHost *host)
vector< SStatStruct > TStatVec
CRef< CAlnStatConfig > m_Config
void ShowIntrons(bool show=true)
CRef< CHistParams > m_GraphParams
IGlyphDialogHost * m_DlgHost
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
vector< CHTMLActiveArea > TAreaVector
Definition: seq_glyph.hpp:84
IGlyphDialogHost An interface used for handling issues related to any dialog pops up that requires so...
Definition: seq_glyph.hpp:399
primitive interface to arrange tabular data in the tooltips
Definition: tooltip.hpp:55
#define true
Definition: bool.h:35
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
GLdouble TModelUnit
Definition: gltypes.hpp:48
#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[]
int i
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
Modified on Thu May 02 14:33:22 2024 by modify_doxy.py rev. 669887