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

Go to the SVN repository for this file.

1 #ifndef GUI_WIDGETS_SEQ_GRAPHIC___HISTOGRAM_GLYPH__HPP
2 #define GUI_WIDGETS_SEQ_GRAPHIC___HISTOGRAM_GLYPH__HPP
3 
4 /* $Id: histogram_glyph.hpp 44290 2019-11-22 20:05:53Z 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: Vlad Lebedev, Liangshou Wu
30  *
31  * File Description:
32  * CHistogramGlyph -- 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>
42 #include <gui/objutils/utils.hpp>
48 #include <math.h>
49 
51 
52 class CLayoutGroup;
53 
55 {
56 public:
58  {
61  eInterpolation_Linear
62  };
63 
64  CHistogramData(TSeqPos start = 0, TSeqPos stop = 0, double window = 1,
65  accum_functor* func = NULL, float def = 0);
68 
69  void SetInterpolationMethod(EInterpolationMethod interpolation_method) {
70  m_InterpolationMethod = interpolation_method;
71  }
72 
74  return m_InterpolationMethod;
75  }
76 
77  const TDataPoints& GetDataPoints() const {
78  return m_DataPoints;
79  }
81  return m_FirstPoint;
82  }
84  return m_LastPoint;
85  }
86 
87  void InitDataPoints(const TModelPoint& first_point, const TModelPoint& last_point);
88 
89  TModelPoint GetDataPoint(size_t idx) const
90  {
91  TModelPoint p(GetWindow() * m_DataPoints[idx] + GetRange().GetFrom(), (*this)[m_DataPoints[idx]]);
92  return p;
93  }
94 
95 protected:
96  // m_Bins indexes of data points of interest
101 
102 
103 
104 };
105 
107 {
108 public:
109  typedef float TDataType;
112 
114  eMode_Single, // typical mode: histogram has a single graph
116  eMode_Aggregate
117  };
118  struct max_func
119  : public binary_functor<TDataType>
120  { // functor for max
121  virtual TDataType operator()(const TDataType& left, const TDataType& right) const
122  {
123  return fabs(left) > fabs(right) ? left : right;
124  }
125 
127  {
128  return new max_func;
129  }
130  };
131 
132 
133  /// @name ctors
134  /// @{
135  CHistogramGlyph(const TMap& map, objects::CSeqFeatData::ESubtype subtype,
136  const string& title = "");
137  CHistogramGlyph(const TMap& map, const string& title);
138  CHistogramGlyph(const TMaps& maps, objects::CSeqFeatData::ESubtype subtype);
139  CHistogramGlyph(const TMaps& maps, const string& name);
140 
141  ~CHistogramGlyph();
142  /// @}
143 
144  /// @name CSeqGlyph virtual methods.
145  /// @{
146  virtual bool OnLeftDblClick(const TModelPoint& /*p*/);
147  virtual bool NeedTooltip(const TModelPoint& p, ITooltipFormatter& tt, string& t_title) const;
148  virtual void GetTooltip(const TModelPoint& /*p*/, ITooltipFormatter& tt, string& t_title) const;
149  virtual void GetHTMLActiveAreas(TAreaVector* p_areas) const;
150  virtual bool IsClickable() const;
151  ///@}
152  virtual bool IsCoverageGraph() const;
153 
154  /// Access the first density map.
155  const TMap& GetDensityMap(void) const;
156 
157  /// Access all the maps.
158  const TMaps& GetDensityMaps(void) const;
159 
160  /// Access the number of maps.
161  const int GetMapNum() const;
162 
163  // access the position of this object.
164  virtual TSeqRange GetRange(void) const;
165 
166  objects::CSeqFeatData::E_Choice GetFeatType() const;
167  objects::CSeqFeatData::ESubtype GetFeatSubtype() const;
168 
169  const string& GetTitle() const;
170 
171  void SetAnnotName(const string& name);
172  const string& GetAnnotName() const;
173 
174  void SetSubtype(objects::CSeqFeatData::ESubtype subtype);
175 
176  void SetDesc(const string& desc);
177  const string& GetDesc() const;
178 
179  void SetConfig(const CSeqGraphicConfig& config);
180 
181  /// Get the actually density max/min values.
182  TDataType GetMax() const;
183  TDataType GetMin() const;
184  /// Get the axis limits (max/min).
185  TDataType GetAxisMax() const;
186  TDataType GetAxisMin() const;
187 
188  // set vertical axis min-max values based on density map min-max values
189  void SetAxisRange();
190 
191  void SetAxisMax(TDataType max);
192  void SetAxisMin(TDataType min);
193 
194  void SetAxisMaxFixed(TDataType max);
195  void SetAxisMinFixed(TDataType min);
196 
197  void SetFixedScale(bool value);
198 
199  void SetShowTitle(bool f);
200  void SetDialogHost(IGlyphDialogHost* host);
201  CRef<CHistParams> GetHistParams() const;
202 
203  void DrawGrid(bool include_background) const;
204 
205  void SetRenderingMode(ERenderingMode mode);
206 
207  void RunSettingsDialog();
208 
209  void GetLegend(objects::CTrackConfig::TLegend& legend) const;
210 
211  // true if the feature is based on a remote file derived annotation
212  bool isRmtBased() const;
213 
214 protected:
215  virtual void x_Draw() const;
216  virtual void x_UpdateBoundingBox();
217 
218  TDataType x_ComputeDeviation(const TMap& densityMap, TDataType& mean) const;
219  TDataType x_HighestValueBelowMax(const TMap& densityMap) const;
220  TDataType x_LowesetValueBelowMin(const TMap& densityMap) const;
221 
222  void x_DrawLogRuler(bool negative) const;
223  void x_DrawLinearRuler(bool negative) const;
224  TDataType x_MapValue(TDataType val, CRgbaColor** color = 0, bool* outlier = 0) const;
225 
226  void x_DrawGraph(TMaps::const_iterator& map_iter) const;
227  void x_DrawDataPoints(const TMap& densityMap) const;
228 
229  void x_DrawHeatMap(TMaps::const_iterator& map_iter, const CHistParams& config) const;
230  void x_DrawGraphMap(TMaps::const_iterator& map_iter, const CHistParams& config) const;
231 
232  void x_DrawSmoothCurve(vector<TModelPoint>& points) const;
233 
234  void x_UpdateLegend();
235  bool x_HasLegend() const;
236 
237  TModelPoint x_PointToWorld(TModelPoint p) const;
238 
239  void x_GetLabel(string& label) const;
240 
241 protected:
244 
245  // Interactive menu debugging support
246 #ifdef ATTRIB_MENU_SUPPORT
247  static int m_SDMult;
248  static float m_SD;
249 
250  mutable TDataType m_AxisMax;
251  mutable TDataType m_AxisMin;
252 #else
255 #endif
256 
258  /// Key for accessing histogram settings.
259  /// It is used only when m_Subtype is eSubtype_any.
260  string m_AnnotName;
261 
262  // if the glyph is based on a temporary annotation created by a remote pipeline, it is stored here
264  string m_Desc;
266  objects::CSeqFeatData::ESubtype m_Subtype;
271 
273  mutable int m_NumBins = 0;
274  mutable int m_BinSize = 0;
275 
276  using SOutlier = struct {
280  };
281 
282  mutable vector<SOutlier> m_Outliers;
283 
284 
285 };
286 
287 ///////////////////////////////////////////////////////////////////////////////
288 /// CHistogramGlyph inline method implementation.
289 
290 inline
292 {
294  return iter->second;
295 }
296 
297 inline
299 {
301 }
302 
303 inline
305 {
306  return m_Maps;
307 }
308 
309 inline
310 const int CHistogramGlyph::GetMapNum() const
311 {
312  return (int)m_Maps.size();
313 }
314 
315 inline
317 {
319  ITERATE (TMaps, iter, m_Maps) {
320  range.CombineWith(iter->second.GetRange());
321  }
322  return range;
323 }
324 
325 inline
326 objects::CSeqFeatData::ESubtype CHistogramGlyph::GetFeatSubtype() const
327 { return m_Subtype; }
328 
329 inline
330 const string& CHistogramGlyph::GetTitle() const
331 { return m_Maps.begin()->first; }
332 
333 inline
334 const string& CHistogramGlyph::GetAnnotName() const
335 { return m_AnnotName; }
336 
337 inline
338 void CHistogramGlyph::SetSubtype(objects::CSeqFeatData::ESubtype subtype)
339 { m_Subtype = subtype; }
340 
341 inline
342 void CHistogramGlyph::SetDesc(const string& desc)
343 { m_Desc = desc; }
344 
345 inline
346 const string& CHistogramGlyph::GetDesc() const
347 { return m_Desc; }
348 
349 inline
351 {
352  double max_val = DBL_MIN;
353  ITERATE (TMaps, map_iter, m_Maps) {
354  max_val = max(max_val, (double)map_iter->second.GetMax());
355  }
356  return TDataType(max_val);
357 }
358 
359 inline
361 {
362  double min_val = DBL_MAX;
363  ITERATE (TMaps, map_iter, m_Maps) {
364  min_val = min(min_val, (double)map_iter->second.GetMin());
365  }
366  return TDataType(min_val);
367 }
368 
369 inline
371 { return m_AxisMax; }
372 
373 inline
375 { return m_AxisMin; }
376 
377 inline
379 {
380  m_AxisMax = ceil(max(max_a, m_AxisMax));
381 }
382 
383 inline
385 {
386  m_AxisMin = floor(min(min_a, m_AxisMin));
387 }
388 
389 inline
391 {
392  m_AxisMax = ceil(max_a);
393 }
394 
395 inline
397 {
398  m_AxisMin = floor(min_a);
399 }
400 
401 
402 inline
404 { m_ShowTitle = f; }
405 
406 inline
408 { m_DlgHost = host; }
409 
410 inline
412 {
413  if (m_gConfig.IsNull()) {
414  return CRef<CHistParams>();
415  }
416 
417  if (m_Subtype != objects::CSeqFeatData::eSubtype_any && m_Subtype != objects::CSeqFeatData::eSubtype_bad) {
419  }
421 }
422 
423 inline
425 {
427 }
428 
429 inline
431 {
432  m_Mode = mode;
433 }
434 
436 
437 /* @} */
438 
439 #endif // GUI_WIDGETS_SEQ_GRAPHIC___HISTOGRAM_GLYPH__HPP
User-defined methods of the data storage class.
class CDensityMap generates a low-resolution view of a set of features.
CRef< CHistParams > GetHistParams(TFeatSubtype subtype) const
Get histogram settings using feature subtype.
File Description:
TModelPoint GetFirstPoint() const
TModelPoint GetLastPoint() const
TModelPoint m_FirstPoint
void SetInterpolationMethod(EInterpolationMethod interpolation_method)
EInterpolationMethod m_InterpolationMethod
TModelPoint m_LastPoint
TDataPoints m_DataPoints
EInterpolationMethod GetInterpolationMethod() const
const TDataPoints & GetDataPoints() const
TModelPoint GetDataPoint(size_t idx) const
const string & GetAnnotName() const
void SetAxisMin(TDataType min)
CConstRef< CSeqGraphicConfig > m_gConfig
TDataType GetAxisMin() const
CHistogramGlyph(const TMaps &maps, objects::CSeqFeatData::ESubtype subtype)
void SetDialogHost(IGlyphDialogHost *host)
const TMap & GetDensityMap(void) const
Access the first density map.
void SetShowTitle(bool f)
TDataType GetMin() const
bool isRmtBased() const
const string & GetDesc() const
void SetAxisMaxFixed(TDataType max)
void SetAxisMax(TDataType max)
string m_AnnotName
Key for accessing histogram settings.
void SetFixedScale(bool value)
const string & GetTitle() const
const int GetMapNum() const
Access the number of maps.
TDataType GetAxisMax() const
Get the axis limits (max/min).
CHistogramData TMap
map< string, TMap > TMaps
void SetSubtype(objects::CSeqFeatData::ESubtype subtype)
struct { TSeqRange range SOutlier
IGlyphDialogHost * m_DlgHost
TDataType GetMax() const
Get the actually density max/min values.
void SetRenderingMode(ERenderingMode mode)
CRef< CLayoutGroup > m_Legend
virtual TSeqRange GetRange(void) const
get the total range of this object.
ERenderingMode m_Mode
objects::CSeqFeatData::ESubtype GetFeatSubtype() const
void SetDesc(const string &desc)
CHistogramGlyph(const TMap &map, objects::CSeqFeatData::ESubtype subtype, const string &title="")
vector< SOutlier > m_Outliers
const TMaps & GetDensityMaps(void) const
Access all the maps.
CRef< CHistParams > GetHistParams() const
objects::CSeqFeatData::ESubtype m_Subtype
void SetAxisMinFixed(TDataType min)
CLayoutGroup is a container of CSeqGlyphs (layout objects).
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
CRef< CHistParamsManager > GetHistParamsManager() const
Get histogram config manager.
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
size_type size() const
Definition: map.hpp:148
container_type::const_iterator const_iterator
Definition: map.hpp:53
const_iterator begin() const
Definition: map.hpp:151
Definition: map.hpp:338
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 NULL
Definition: ncbistd.hpp:225
objects::CSeqFeatData::ESubtype GetFeatSubtype(const string &feat_type)
Definition: macro_util.cpp:350
static bool isRmtAnnotName(const string &sAnnotname)
check if a given annotation was created by a remote file pipeline
Definition: utils.cpp:813
GLdouble TModelUnit
Definition: gltypes.hpp:48
vector< size_t > TDataPoints
static TSeqPos GetDensityMap(const objects::CBioseq_Handle &handle, TSeqPos start, TSeqPos stop, TSeqPos window, objects::SAnnotSelector sel, vector< TSeqPos > &density)
OLD static method.
CntType GetMin() const
CDensityMap< CntType > & operator=(const CDensityMap< CntType > &map)
double GetWindow() const
TSeqRange GetRange() const
CntType GetMax() const
NCBI_XOBJUTIL_EXPORT string GetTitle(const CBioseq_Handle &hnd, TGetTitleFlags flags=0)
Definition: seqtitle.cpp:106
bool IsNull(void) const THROWS_NONE
Check if pointer is null – same effect as Empty().
Definition: ncbiobj.hpp:1401
#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
range(_Ty, _Ty) -> range< _Ty >
mdb_mode_t mode
Definition: lmdb++.h:38
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
#define fabs(v)
Definition: ncbi_dispd.c:46
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
T max(T x_, T y_)
T min(T x_, T y_)
T negative(T x_)
double f(double x_, const double &y_)
Definition: njn_root.hpp:188
virtual binary_functor< TDataType > * clone() const
virtual TDataType operator()(const TDataType &left, const TDataType &right) const
TEMPLATE binary functor base struct.
Definition: density_map.hpp:59
Modified on Thu Jun 13 17:24:52 2024 by modify_doxy.py rev. 669887