NCBI C++ ToolKit
intron_track.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /*
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Andrei Shkeda
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
36 
39 
40 ///////////////////////////////////////////////////////////////////////////////
41 /// CIntronTrack
42 ///////////////////////////////////////////////////////////////////////////////
43 
45  : CFeatureTrack(ds, r_cntx)
46 
47 {
48  // commented out in hope for gbench implementation
49  //x_RegisterIcon(SIconInfo(eIcon_Settings, "Settings", true, "track_settings"));
50 }
51 
53 {
54  // commented out in hope for gbench implementation
55  switch (id) {
56  case eIcon_Settings:
58  break;
59  default:
60  // use default handlers
62  }
63 }
64 
65 
67 {
68 /* commented out in hope for gbench implementation
69  wxMenu menu;
70  UseDefaultMarginWidth(menu);
71  int id_base = 10000;
72  wxMenuItem* item = menu.AppendCheckItem(id_base, ToWxString("Hide introns with no splice junctions in the current view"));
73  if (m_HideIntrons)
74  item->Check();
75  m_LTHost->LTH_PopupMenu(&menu);
76  wxMenuItemList& item_list = menu.GetMenuItems();
77  ITERATE(wxMenuItemList, iter, item_list) {
78  if ((*iter)->GetId() == id_base) {
79  m_HideIntrons = (*iter)->IsChecked();
80  x_UpdateData();
81  }
82  }
83 */
84 }
85 void CIntronTrack::x_LoadFeatures(const TSeqRange& range, int feat_limit)
86 {
87  list<string> f;
88  string tmp;
89  if (m_HideIntrons) {
90  tmp = "(from >= ";
91  tmp += NStr::NumericToString(range.GetFrom());
92  tmp += " or to <= ";
93  tmp += NStr::NumericToString(range.GetTo());
94  tmp += ")";
95  f.push_back(tmp);
96  }
97  if (m_NoReadFilter == false) {
98  if (m_ReadsCountMin > 0) {
99  tmp = "reads >=";
101  f.push_back(tmp);
102  }
103  if (m_ReadsCountMax > 0) {
104  tmp = "reads <=";
106  f.push_back(tmp);
107  }
108  }
109  string filter = "";
110  if (!f.empty())
111  filter = NStr::Join(f, " and ");
112 
113  m_DS->SetSortBy(m_SortStrand ? "strand" : "");
114  m_DS->LoadFeatures(m_FeatSel, range, m_Context->GetScale(), -1, feat_limit, m_LinkedFeat, filter);
115 }
116 
117 
119 {
121  // feature track doesn't use profile
122  ITERATE(TKeyValuePairs, iter, settings) {
123  try {
124  if (NStr::EqualNocase(iter->first, "sort_reads")) {
125  m_SortReads = NStr::StringToBool(iter->second);
126  } else if (NStr::EqualNocase(iter->first, "sort_strands")) {
127  m_SortStrand = NStr::StringToBool(iter->second);
128  } else if (NStr::EqualNocase(iter->first, "hide_feats")) {
129  m_HideIntrons = NStr::StringToBool(iter->second);
130  } else if (NStr::EqualNocase(iter->first, "read_range")) {
131  string read_range = iter->second;
132  if (!read_range.empty()) {
133  string range_min, range_max;
134  CTrackConfigUtils::DecodeValueRange(read_range, range_min, range_max, m_NoReadFilter);
135  if (!range_min.empty() && range_min != "inf") {
136  m_ReadsCountMin = NStr::StringToNumeric<float>(range_min, NStr::fConvErr_NoThrow);
137  }
138  if (!range_max.empty() && range_max != "inf") {
139  m_ReadsCountMax = NStr::StringToNumeric<float>(range_max, NStr::fConvErr_NoThrow);
140  }
143  }
144  }
145  }
146  } catch (CException& e) {
147  LOG_POST(Warning << "CIntronTrack::x_ParseSettings() " << e.GetMsg());
148  }
149  }
150 }
151 
152 
154 {
156  ILayoutPolicy::TSorter sorter = nullptr;
157  if (m_SortReads) {
158  sorter = [](const CRef<CSeqGlyph>& gl, const CRef<CSeqGlyph>& gr) {
159  const auto& fl = *dynamic_cast<const CIntronGlyph*>(gl.GetPointer());
160  const auto& fr = *dynamic_cast<const CIntronGlyph*>(gr.GetPointer());
161  return fl.GetReadCount() > fr.GetReadCount();
162  };
163  }
164  switch (m_Layout) {
167  m_Simple->SetSorter(sorter);
168  break;
170  m_Inline->SetSorter(sorter);
171  break;
173  m_Column->SetSorter(sorter);
174  break;
175  default:
177  m_Layered->SetSorter(sorter);
178  break;
179  }
180 
181 }
183 {
185 
186  if (m_NoReadFilter == false) {
187  string msg = "Filtered (read count from ";
188  msg += (m_ReadsCountMin > 0) ? to_string(m_ReadsCountMin) : "min";
189  msg += " to ";
190  msg += (m_ReadsCountMax > 0) ? to_string(m_ReadsCountMax) : "max";
191  msg += ")";
192 
193  CHTMLActiveArea area;
195  area.m_Bounds.SetTop(area.m_Bounds.Top() + x_GetTBHeight());
196  // left = 1 right = 0, makes it right-aligned
197  area.m_Bounds.SetLeft(1);
198  area.m_Bounds.SetRight(0);
204  area.m_ID = msg;
205  area.m_ParentId = GetId();
206  // required, but nonsense fields
207  area.m_PositiveStrand = true;
208  area.m_SeqRange.SetFrom(0);
209  area.m_SeqRange.SetTo(0);
210  p_areas->push_back(area);
211  }
212 
213 }
214 
216 {
218  // if read count filter is set and not in printing mode
219  // then make room for "Filtered" message
220  if (m_NoReadFilter == false) {
221  IRender& gl = GetGl();
222  if (gl.IsPrinterFriendly() == false) {
223  m_Group.SetTop(m_Group.GetTop() + 16);
224  SetHeight(GetHeight() + 16);
225  }
226  }
227 }
228 
CFeatureTrack –.
virtual void x_OnIconClicked(TIconID id)
Mouse left-click event handler on an icon.
virtual void x_OnLayoutPolicyChanged()
CRef< CColumnLayout > m_Column
CRef< CSGFeatureDS > m_DS
objects::SAnnotSelector m_FeatSel
virtual void x_ParseSettings(const TKeyValuePairs &settings)
@ eLayout_ExpandedColumn
show all features with column layout
@ eLayout_AdaptiveInline
adaptively switch between packed and inline
@ eLayout_ExpandedByPos
show all features, one per row sorted by pos
@ eLayout_ExpandedBySize
one feature per row sorted by size
ELinkedFeatDisplay m_LinkedFeat
virtual void x_UpdateBoundingBox()
Update the bounding box assuming children's sizes are fixed if any.
virtual void GetHTMLActiveAreas(TAreaVector *p_areas) const
Get html active areas.
CRef< CInlineLayout > m_Inline
CRef< CLayeredLayout > m_Layered
CRef< CSimpleLayout > m_Simple
@ fNoHighlight
no highlighting on mouse over
@ fDrawBackground
highlight background for this area
@ fComment
render a label/comment on client side
@ fNoSelection
the object can't be selected
@ fTooltipEmbedded
tooltip embedded
string m_ID
area identifier
int m_Flags
area flags, will need to replace m_Type
string m_ParentId
parent entity idendifier, such as track_id
bool m_PositiveStrand
the default is true
int GetReadCount() const
virtual void x_UpdateBoundingBox()
Update the bounding box assuming children's sizes are fixed if any.
virtual void x_OnIconClicked(TIconID id)
Mouse left-click event handler on an icon.
virtual void x_LoadFeatures(const TSeqRange &range, int feat_limit)
void x_OnSettingsIconClicked()
virtual void x_OnLayoutPolicyChanged()
virtual void x_ParseSettings(const TKeyValuePairs &settings)
CIntronTrack(CSGFeatureDS *ds, CRenderingContext *r_cntx)
CIntronTrack.
virtual void GetHTMLActiveAreas(TAreaVector *p_areas) const
Get html active areas.
void SetFillEmptySpaces(bool f=true)
@ eIcon_Settings
icon id for track settings
const string & GetId() const
TModelUnit x_GetTBHeight() const
Get title bar height including margin.
int TIconID
use int as TIconID instead of EIconID.
CRenderingContext offers the basic context and utility methods for rendering layout objects in featur...
const TModelUnit & GetScale() const
CSGFeatureDS.
Definition: feature_ds.hpp:49
void SetSortBy(const string &sortby)
Definition: feature_ds.hpp:184
virtual void LoadFeatures(objects::SAnnotSelector &sel, const TSeqRange &range, TModelUnit window, TJobToken token=-1, int max_feat=-1, ELinkedFeatDisplay LinkedFeatDisplay=ELinkedFeatDisplay::eLFD_Default, const string &extra_filter="")
void x_InitHTMLActiveArea(CHTMLActiveArea &area) const
initialize the basic information for a given active area.
Definition: seq_glyph.cpp:380
CRenderingContext * m_Context
the rendering context
Definition: seq_glyph.hpp:346
virtual void SetHeight(TModelUnit h)
Definition: seq_glyph.hpp:650
virtual TModelUnit GetTop() const
Definition: seq_glyph.hpp:599
virtual TModelUnit GetHeight() const
Definition: seq_glyph.hpp:587
virtual void SetTop(TModelUnit b)
Definition: seq_glyph.hpp:658
vector< CHTMLActiveArea > TAreaVector
Definition: seq_glyph.hpp:84
static void DecodeValueRange(const string &value_range, string &range_min, string &range_max, bool &range_auto)
void SetSorter(TSorter &sorter)
std::function< bool(const CRef< CSeqGlyph > &, const CRef< CSeqGlyph > &)> TSorter
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
void swap(NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair1, NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair2)
Definition: ncbimisc.hpp:1508
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
Definition: ncbidiag.hpp:226
const string & GetMsg(void) const
Get message string.
Definition: ncbiexpt.cpp:461
void Warning(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1191
void SetRight(T right)
Definition: glrect.hpp:114
T Top() const
Definition: glrect.hpp:84
IRender & GetGl()
convenience function for getting current render manager
virtual bool IsPrinterFriendly() const =0
void SetLeft(T left)
Definition: glrect.hpp:112
void SetTop(T top)
Definition: glrect.hpp:115
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static bool StringToBool(const CTempString str)
Convert string to bool.
Definition: ncbistr.cpp:2819
static string Join(const TContainer &arr, const CTempString &delim)
Join strings using the specified delimiter.
Definition: ncbistr.hpp:2697
static bool EqualNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive equality of a substring with another string.
Definition: ncbistr.hpp:5352
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
Definition: ncbistr.hpp:673
@ fConvErr_NoThrow
Do not throw an exception on error.
Definition: ncbistr.hpp:285
void SetFrom(TFrom value)
Assign a value to From data member.
Definition: Range_.hpp:231
void SetTo(TTo value)
Assign a value to To data member.
Definition: Range_.hpp:278
USING_SCOPE(objects)
range(_Ty, _Ty) -> range< _Ty >
double f(double x_, const double &y_)
Definition: njn_root.hpp:188
static char tmp[2048]
Definition: utf8.c:42
Modified on Sat Dec 09 04:47:40 2023 by modify_doxy.py rev. 669887