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

Go to the SVN repository for this file.

1 /* $Id: hapmap_track.cpp 37640 2017-01-31 18:24:42Z shkeda $
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: Melvin Quintos
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
41 
42 #include <gui/utils/rgba_color.hpp>
43 #include <gui/objutils/utils.hpp>
44 #include <gui/objutils/label.hpp>
45 
46 #include <objmgr/util/feature.hpp>
47 #include <objmgr/util/sequence.hpp>
48 #include <objmgr/annot_ci.hpp>
49 
51 
52 #include <wx/menu.h>
53 
56 
57 ///////////////////////////////////////////////////////////////////////////////
58 /// CHapmapTrack
59 ///////////////////////////////////////////////////////////////////////////////
60 
62  "A haplotype map of the human genome \
63 which describes the common patterns of human DNA sequence variation.");
64 
66  : CDataTrack(r_cntx)
67  , m_DS(ds)
68  , m_IconLayout(eIcon_Layout, "Layout", true, "track_layout")
69 {
70 
71  m_DS->SetJobListener(this);
72 
73  // initialize annotation selector
75 }
76 
77 
79 {
80  if ( !m_DS->AllJobsFinished() ) {
82  }
83 }
84 
86 {
87  static double kNPP_Cutoff= 50; // Nucliotides per pixel cutoff for SNP Overview
88  return (m_Context->GetScale() > kNPP_Cutoff);
89 }
90 
91 /// @name CLayoutTrack reimplemented methods.
92 /// @{
94 {
95  return m_TypeInfo;
96 }
97 
99 {
100  bool bIsLayoutOnlyChange = true;
101 
102  if (id == eIcon_Layout) {
103  wxMenu menu;
104 
105  //menu.AppendRadioItem(eLayout_Default, wxT(("Default"));
106  menu.AppendRadioItem(eLayout_Labels, wxT("Labels"));
107 
108  menu.Check(m_eLayout, true);
109 
110  m_LTHost->LTH_PopupMenu(&menu);
111 
112  wxMenuItemList& item_list = menu.GetMenuItems();
113  ITERATE (wxMenuItemList, iter, item_list) {
114  ELayout new_layout = (ELayout)((*iter)->GetId());
115  if ((*iter)->IsChecked() && id != m_eLayout) {
116 
117  // Reload data if switching back or forth to Labels
118  if ( (m_eLayout ==eLayout_Labels) ||
119  (new_layout==eLayout_Labels) )
120  {
121  bIsLayoutOnlyChange = false;
122  }
123 
124  m_eLayout = new_layout;
125  break; // stop processing loop
126  }
127  }
128  } else {
129  // use default handlers
131  }
132 
133  Update(bIsLayoutOnlyChange);
135 }
136 /// @}
137 
138 
139 void CHapmapTrack::x_LoadSettings(const string& /*preset_style*/,
140  const TKeyValuePairs& /*settings*/)
141 {
143 }
144 
145 
146 /// @name CDataTrack pure virtual interfaces
147 /// @{
148 
150 {
151  bool bShowLabels = (m_eLayout == eLayout_Labels);
152  m_DS->DeleteAllJobs();
155  m_Context->GetScale(),
156  bShowLabels, // fetch features if we show labels.
157  x_IsOverviewMode());
158 }
159 
160 
162 {
163  m_DS->ClearJobID(notify.GetJobID());
164  CRef<CObject> res_obj = notify.GetResult();
165  SHapmapJobResult* result = dynamic_cast<SHapmapJobResult*>(&*res_obj);
166  if (!result) {
167  ERR_POST("CHapmapTrack::x_OnJobCompleted() notification for job \
168  does not contain results.");
169  return;
170  }
171 
172  // Depending on view, setup icon
173  if (x_IsOverviewMode())
175  else
177 
178  m_Msg = "";
179  /*
180  switch (result->eDataType) {
181  default:
182  case SHapmapJobResult::eHistFromFeats:
183  m_Msg += ", density (seq-feats)";
184  break;
185  case SHapmapJobResult::eHistFromGraphs:
186  m_Msg += ", density (seq-graphs)";
187  break;
188  case SHapmapJobResult::eFeats:
189  {
190  unsigned int size = (unsigned int) result->listObjs.size();
191  m_Msg += ", " + NStr::UIntToString(size) + " features";
192  }
193  break;
194  }
195  */
197 }
198 
199 /// @}
200 
202 {
203  const CSeqGlyph::TObjects& objs = result.listObjs;
204 
205  if (objs.empty()) {
206  Update(true);
208  return;
209  }
210 
211  m_Group.Clear();
212 
213  ITERATE(CSeqGlyph::TObjects, it, objs) {
214  CSeqGlyph *glyph = const_cast<CSeqGlyph*> (it->GetPointer());
215  CHistogramGlyph *hist= dynamic_cast<CHistogramGlyph *>(glyph);
216  hist->SetConfig(*x_GetGlobalConfig());
217  Add(glyph);
218  }
219 
220 
221  Update(true);
223 }
224 
225 
226 
227 ///////////////////////////////////////////////////////////////////////////////
228 /// CHapmapTrackFactory
229 ///////////////////////////////////////////////////////////////////////////////
232  ISGDataSourceContext* ds_context,
233  CRenderingContext* r_cntx,
234  const SExtraParams& params,
235  const TAnnotMetaDataList& src_annots) const
236 {
237  TTrackMap tracks;
238  TAnnotNameTitleMap annots;
239 
240  if (params.m_SkipGenuineCheck && !params.m_Annots.empty()) {
241  ITERATE (SExtraParams::TAnnots, iter, params.m_Annots) {
242  annots.insert(TAnnotNameTitleMap::value_type(*iter, ""));
243  }
244  } else {
245  CSGHapmapDS::GetTrackNames(object, annots, r_cntx->GetVisSeqRange(), params);
246 
247  // collect NA tracks
248  if ( !src_annots.empty() ) {
249  GetMatchedAnnots(src_annots, params, annots);
250  }
251  }
252 
253  // create feature tracks
254  ITERATE (TAnnotNameTitleMap, iter, annots) {
255  // Create a new DS object for each track
256  CIRef<ISGDataSource> pre_ds = ds_context->GetDS(typeid(CSGHapmapDSType).name(),
257  object);
258  CSGHapmapDS* seq_ds = dynamic_cast<CSGHapmapDS*>(pre_ds.GetPointer());
259  seq_ds->SetDepth(params.m_Level);
260  seq_ds->SetAdaptive(params.m_Adaptive);
261  seq_ds->SetName(iter->first);
262 
263  CRef<CHapmapTrack> track(new CHapmapTrack(seq_ds, r_cntx));
264  if ( !iter->second.empty() ) {
265  track->SetTitle(iter->second);
266  }
267  tracks[iter->first] = track.GetPointer();
268  }
269 
270  return tracks;
271 }
272 
274  const TAnnotMetaDataList& src_annots,
275  const ILayoutTrackFactory::SExtraParams& params,
276  TAnnotNameTitleMap& out_annots) const
277 {
278  ILayoutTrackFactory::GetMatchedAnnots(src_annots, params.m_Annots, "graph", "HapMapRR", out_annots);
279 }
280 
282 CHapmapTrackFactory::GetSettings(const string& /*profile*/,
283  const TKeyValuePairs& settings,
284  const CTempTrackProxy* /*track_proxy*/) const
285 {
286  CRef<CTrackConfigSet> config_set(new CTrackConfigSet);
288  config_set->Set().push_back(config);
289  config->SetHelp() = GetThisTypeInfo().GetDescr();
290  return config_set;
291 }
292 
294 {
296 }
297 
299 {
301 }
302 
303 
CAppJobNotification Notification send by CAppJobEventTranslator.
CDataTrack - a abstract base class for layout tracks which need to deal with background data retrieva...
Definition: data_track.hpp:55
virtual void Update(bool layout_only)
Update content and layout including the bounding box.
Definition: data_track.cpp:52
void Add(CSeqGlyph *obj)
Append a layout object to the end.
CRef< CLayeredLayout > m_Layered
virtual string GetExtensionLabel() const
returns a displayable label for this extension ( please capitalize the key words - "My Extension" )
CRef< objects::CTrackConfigSet > GetSettings(const string &profile, const TKeyValuePairs &settings, const CTempTrackProxy *track_proxy) const
virtual string GetExtensionIdentifier() const
returns the unique human-readable identifier for the extension the id should use lowercase letters se...
virtual const CTrackTypeInfo & GetThisTypeInfo() const
virtual void GetMatchedAnnots(const TAnnotMetaDataList &src_annots, const ILayoutTrackFactory::SExtraParams &params, TAnnotNameTitleMap &out_annots) const
virtual TTrackMap CreateTracks(SConstScopedObject &object, ISGDataSourceContext *ds_context, CRenderingContext *r_cntx, const SExtraParams &params=SExtraParams(), const TAnnotMetaDataList &src_annots=TAnnotMetaDataList()) const
CHapmapTrackFactory.
virtual void x_LoadSettings(const string &preset_style, const TKeyValuePairs &settings)
load the track settings.
virtual void x_UpdateData()
update track content.
objects::SAnnotSelector m_FeatSel
@ eLayout_Labels
Show labels and cascade features (CLayeredLayoutPolicy)
virtual const CTrackTypeInfo & GetTypeInfo() const
CRef< CSGHapmapDS > m_DS
bool x_IsOverviewMode() const
virtual ~CHapmapTrack()
static CTrackTypeInfo m_TypeInfo
CHapmapTrack.
void x_CreateLayout(const SHapmapJobResult &result)
virtual void x_OnIconClicked(TIconID id)
Mouse left-click event handler on an icon.
CHapmapTrack(CSGHapmapDS *ds, CRenderingContext *r_cntx)
SIconInfo m_IconLayout
virtual void x_OnJobCompleted(CAppJobNotification &notify)
void SetConfig(const CSeqGraphicConfig &config)
void x_DeregisterIcon(TIconID id)
deregister an icon if already registered.
@ eIcon_Layout
icon id for setting layout style
ILayoutTrackHost * m_LTHost
Top level host owning the tracks.
string m_Msg
special message need to show on title bar
void x_OnLayoutChanged()
update the layout.
virtual void x_OnIconClicked(TIconID id)
Mouse left-click event handler on an icon.
CConstRef< CSeqGraphicConfig > x_GetGlobalConfig() const
Method for getting global configuration from rendering context.
CRef< CSeqGraphicConfig > m_gConfig
global configuration.
int TIconID
use int as TIconID instead of EIconID.
void x_RegisterIcon(const SIconInfo &icon)
register track icons.
CRenderingContext offers the basic context and utility methods for rendering layout objects in featur...
const TSeqRange & GetVisSeqRange() const
const TModelUnit & GetScale() const
virtual bool AllJobsFinished() const
void SetJobListener(CEventHandler *listener)
Set JobDispatcher listener.
virtual void ClearJobID(TJobID job_id)
void SetDepth(int depth)
Set the annotation selector resolving depth.
virtual void DeleteAllJobs()
Remove waiting jobs from queue or cancel the unfinished jobs.
void SetAdaptive(bool flag)
void LoadData(const TSeqRange &range, TModelUnit scale, bool preferFeats, bool isOverview)
Definition: hapmap_ds.cpp:229
void SetName(const string &)
Definition: hapmap_ds.cpp:224
static void GetTrackNames(SConstScopedObject &object, TAnnotNameTitleMap &names, const TSeqRange &range, const ILayoutTrackFactory::SExtraParams &params)
Definition: hapmap_ds.cpp:200
class CSeqGlyph defines an interface that wraps a rectilinear abstract object.
Definition: seq_glyph.hpp:82
CRenderingContext * m_Context
the rendering context
Definition: seq_glyph.hpp:346
list< CRef< CSeqGlyph > > TObjects
Definition: seq_glyph.hpp:85
int GetObjectSpace() const
File Description:
CTrackConfigSet –.
CTrackConfig –.
Definition: TrackConfig.hpp:66
CTrackTypeInfo - holds description of a layout track type.
const string & GetDescr() const
const string & GetId() const
static void GetMatchedAnnots(const TAnnotMetaDataList &src_annots, const vector< string > &target_annots, const string &annot_type, const string &track_type, TAnnotNameTitleMap &out_annots)
Help function to find matched annotations.
virtual void LTH_PopupMenu(wxMenu *menu)=0
show track-specific context menu.
ISGDSManager is seqgraphic data source manage that serves as an data source context.
virtual CIRef< ISGDataSource > GetDS(const string &type, SConstScopedObject &object)=0
Get a seqgraphic data source instance of the specified type.
iterator_bool insert(const value_type &val)
Definition: map.hpp:165
bool empty() const
Definition: map.hpp:149
struct config config
#define true
Definition: bool.h:35
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
Definition: ncbidiag.hpp:186
static objects::SAnnotSelector GetAnnotSelector(TAnnotFlags flags=0)
request an annotation selector for a given type
Definition: utils.cpp:168
CRef< CObject > GetResult() const
returns non-null pointer only if Completed or Running and has temporary results available
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
Tdata & Set(void)
Assign a value to data member.
USING_SCOPE(objects)
#define wxT(x)
Definition: muParser.cpp:41
TIconID m_Id
must be unique within the context
extra parameter for initializing a track.
bool m_Adaptive
Adaptive/Exact selector.
TAnnots m_Annots
particular annotations the track will be looking at.
int m_Level
layout level that limits feature retrieving used by annotation selector.
bool m_SkipGenuineCheck
Flag indicating if track verification is required.
SHapmapJobResult.
Definition: hapmap_ds.hpp:109
else result
Definition: token2.c:20
Modified on Fri Sep 20 14:57:22 2024 by modify_doxy.py rev. 669887