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

Go to the SVN repository for this file.

1 #ifndef GUI_PACKAGES_SNP_TRACK__SNP_TRACK__HPP
2 #define GUI_PACKAGES_SNP_TRACK__SNP_TRACK__HPP
3 
4 /* $Id: snp_track.hpp 46990 2022-04-05 23:46:16Z evgeniev $
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: Melvin Quintos, Dmitry Rudnev
30  *
31  * File Description:
32  * This file contains class declarations for CSnpTrack and CSnpTrackFactory
33  *
34  */
35 
36 #include <corelib/ncbiobj.hpp>
37 #include <gui/utils/extension.hpp>
43 #include <gui/utils/rgba_color.hpp>
44 
48 #include <objmgr/graph_ci.hpp>
49 
51 
52 ///////////////////////////////////////////////////////////////////////////////
53 // CSnpTrack
54 ///////////////////////////////////////////////////////////////////////////////
55 
56 class CSNPFeatureParams;
57 
58 class CSnpTrack :
59  public CDataTrack, public IAsn1Generator, public IFeatureTrackBase
60 {
61  friend class CSnpTrackFactory;
62 
63 public:
64  enum ELayout {
65  eLayout_Adaptive = 260, ///< All SNPs drawn in one line
66  eLayout_Density, ///< Always show density
67  eLayout_Features, ///< Show features whenever possible
68  eLayout_Labels ///< Show labels and cascade features (CLayeredLayoutPolicy)
69  };
70 
71 public:
72  CSnpTrack(CSGSnpDS* ds, CRenderingContext* r_cntx, const string& sFilter, const string& sTitle, const string& sLayout = "");
73  virtual ~CSnpTrack();
74 
75  /// @name CDataTrack reimplemented methods.
76  /// @{
78  virtual CConstRef<CSGGenBankDS> GetDataSource() const;
79  /// @}
80 
81  /// @name CLayoutTrack reimplemented methods.
82  /// @{
83  virtual const CTrackTypeInfo& GetTypeInfo() const;
84  virtual string GetFullTitle() const;
85  /// @}
86 
87  void SetAnnot(const string& name);
88 
89  /// @name IFeatureTrackBase reimplemented methods.
90  /// @{
91  virtual void GetFeatSubtypes(set<objects::CSeqFeatData::ESubtype> &subtypes) const {}
92  virtual string GetAnnot() const {return m_AnnotName;}
93  virtual bool IsSnpTrack() const {return true;}
94  /// @}
95 
96  /// @name IAsn1Generator interface implementation
97  /// @{
98  void GenerateAsn1(objects::CSeq_entry& seq_entry, TSeqRange range);
99 
100  // if true, this track should be handled by stage 2
101  virtual bool BypassStage1() { return true; }
102 
103  // estimate number of features in the specified range
104  // returns true if range is acceptable for downloads
105  // if false, sMsg will contain a message that can be shown to the user
106  virtual bool CheckRange(TSeqRange range, string& sMsg, size_t& nFeats);
107 
108  virtual EDataType GetDataType() const { return eDataType_Snp; }
109  /// @}
110 
111 protected:
112  virtual void x_OnIconClicked(TIconID id);
113 
114  virtual void x_SaveSettings(const string& preset_style);
115  virtual void x_LoadSettings(const string& preset_style,
116  const TKeyValuePairs& settings);
117 
118  /// @name CDataTrack pure virtual interfaces
119  /// @{
120  virtual void x_UpdateData();
121  virtual void x_OnJobCompleted(CAppJobNotification& notify);
122  /// @}
123 
124  void x_ProcessJobResult();
125  void x_AddSnpsLayout(const SSnpJobResult& result);
126  void x_UpdateLayout();
127 
128 private:
129  /// @name prohibited copy constructor and assignment operator.
130  /// @{
133  /// @}
134 
135  bool x_IsOverviewMode() const;
136 
137  objects::CFeat_CI x_GetFeat_CI(const TSeqRange& range);
138  objects::CGraph_CI x_GetGraph_CI(const TSeqRange& range);
139 
140 private:
141 
143  string m_AnnotName;
144 
147 
152 
154 
155 
156 };
157 
158 ///////////////////////////////////////////////////////////////////////////////
159 // CSnpTrackFactory
160 ///////////////////////////////////////////////////////////////////////////////
162  public CObject,
163  public ILayoutTrackFactory,
164  public ITrackConfigurable,
165  public IExtension
166 {
167 public:
169 
170  static const CTrackTypeInfo& GetTypeInfo()
171  { return CSnpTrack::m_TypeInfo; }
172 
173  /// @name ILayoutTrackFactory interface implementation
174  /// @{
175  virtual TTrackMap CreateTracks(
176  SConstScopedObject& object,
177  ISGDataSourceContext* ds_context,
178  CRenderingContext* r_cntx,
179  const SExtraParams& params = SExtraParams(),
180  const TAnnotMetaDataList& src_annots = TAnnotMetaDataList()) const;
181 
182  virtual void GetMatchedAnnots(
183  const TAnnotMetaDataList& src_annots,
184  const ILayoutTrackFactory::SExtraParams& params,
185  TAnnotNameTitleMap& out_annots) const;
186 
187  virtual bool UnderstandLevel() const
188  { return true; }
189 
190  // this track supports export to ASN1
191  // this means that it is able to accept a NULL as
192  // CRenderingContext in a call to CreateTracks()
193  // the track constructor is also able to accept a NULL as well
194  // and the track implements IAsn1Generator interface
195  virtual bool SupportsExportToAsn1() const { return true; }
196 
197  virtual bool NeedBackgroundInit() const
198  { return true; }
199 
200  virtual const CTrackTypeInfo& GetThisTypeInfo() const
201  { return GetTypeInfo(); }
202  /// @}
203 
204  /// @name ITrackConfigurable reimplemented methods.
205  /// @{
207  GetSettings(const string& profile,
208  const TKeyValuePairs& settings,
209  const CTempTrackProxy* track_proxy) const;
210  /// @}
211 
212  /// @name IExtension interface implementation
213  /// @{
214  virtual string GetExtensionIdentifier() const;
215  virtual string GetExtensionLabel() const;
216  /// @}
217 protected:
219  x_GetSettings(const TKeyValuePairs& settings, const CTempTrackProxy* track_proxy, bool is_clinvar_track) const;
220 };
221 
222 ///////////////////////////////////////////////////////////////////////////////
223 /// CAlignmentTrack inline methods
224 ///////////////////////////////////////////////////////////////////////////////
225 inline /*virtual*/
227 {
229 }
230 
231 inline /*virtual*/
233 {
235 }
236 
238 {
239 public:
240  // check that the feature is a known SNP class, return a color that corresponds to it
241  // if not a SNP feature or class is unknown, returns a default color
242  static CRgbaColor GetSNPColor(const objects::CSeq_feat& feat, const CRegistryReadView& ColorView);
243 };
244 
245 
247 {
248 public:
250  : m_VariationClass(VariationClass), m_BoxStyle(BoxStyle) {}
253 };
254 
255 inline bool operator<(const SSNPFeatParamDefiner& left, const SSNPFeatParamDefiner& right)
256 {
257  return (left.m_VariationClass != right.m_VariationClass)
258  ? ((int)left.m_VariationClass < (int)right.m_VariationClass)
259  : ((int)left.m_BoxStyle < (int)right.m_BoxStyle);
260 }
261 
262 
263 // class that tries to create the least amount of diverse CRef<CFeatureParams>
265 {
266 public:
267 
268  // create all future params based on the OrigParams
269  static CRef<CSNPFeatureParams> CreateSNPFeatureParams();
270  static CRef<CSNPFeatureParams> CreateSNPFeatureParams(CConstRef<CFeatureParams> OrigParams);
271  void Reset(CConstRef<CFeatureParams> OrigParams);
272 
273  // access to the stored params template
274  CRef<CFeatureParams> SetParamsTemplate() { return m_ParamsTemplate; }
275  void UpdateLabelPos();
276 
277  // get parameters for a given SNP feature, they are based on m_ParamsTemplate, but modified according to
278  // the feature contents
279  CConstRef<CFeatureParams> GetFeatureParams(const objects::CSeq_feat& feat, const CRegistryReadView& ColorView) const;
280 
281 private:
283 
285  : m_ParamsTemplate(new CFeatureParams()) {}
287  : m_ParamsTemplate(new CFeatureParams()) { *m_ParamsTemplate = *OrigParams; }
288 
291 };
292 
294 
295 #endif // GUI_PACKAGES_SNP_TRACK__SNP_TRACK__HPP
CAppJobNotification Notification send by CAppJobEventTranslator.
CConstRef –.
Definition: ncbiobj.hpp:1266
CDataTrack - a abstract base class for layout tracks which need to deal with background data retrieva...
Definition: data_track.hpp:55
CFeatureParams: the data structure holding feature rendering parameters.
EBoxStyle
how the box of the feature is drawn
map< string, string > TKeyValuePairs
int TIconID
use int as TIconID instead of EIconID.
CObject –.
Definition: ncbiobj.hpp:180
CRef –.
Definition: ncbiobj.hpp:618
class CRegistryReadView provides a nested hierarchical view at a particular key.
Definition: reg_view.hpp:58
CRenderingContext offers the basic context and utility methods for rendering layout objects in featur...
class CRgbaColor provides a simple abstraction for managing colors.
Definition: rgba_color.hpp:58
static CRgbaColor GetSNPColor(const objects::CSeq_feat &feat, const CRegistryReadView &ColorView)
Definition: snp_track.cpp:778
map< SSNPFeatParamDefiner, CConstRef< CFeatureParams > > TParamsCache
Definition: snp_track.hpp:282
CSNPFeatureParams(CConstRef< CFeatureParams > OrigParams)
Definition: snp_track.hpp:286
CRef< CFeatureParams > SetParamsTemplate()
Definition: snp_track.hpp:274
CRef< CFeatureParams > m_ParamsTemplate
Definition: snp_track.hpp:289
TParamsCache m_ParamsCache
Definition: snp_track.hpp:290
virtual bool UnderstandLevel() const
Have any concept of level.
Definition: snp_track.hpp:187
virtual bool SupportsExportToAsn1() const
Definition: snp_track.hpp:195
virtual const CTrackTypeInfo & GetThisTypeInfo() const
Definition: snp_track.hpp:200
static const CTrackTypeInfo & GetTypeInfo()
Definition: snp_track.hpp:170
virtual bool NeedBackgroundInit() const
Background track initialization.
Definition: snp_track.hpp:197
static CTrackTypeInfo m_TypeInfo
Definition: snp_track.hpp:153
virtual void x_UpdateData()
update track content.
Definition: snp_track.cpp:319
virtual bool IsSnpTrack() const
Definition: snp_track.hpp:93
void SetAnnot(const string &name)
Definition: snp_track.cpp:200
virtual EDataType GetDataType() const
Definition: snp_track.hpp:108
virtual const CTrackTypeInfo & GetTypeInfo() const
Definition: snp_track.cpp:185
virtual string GetFullTitle() const
get a more meaningful title.
Definition: snp_track.cpp:191
virtual bool CheckRange(TSeqRange range, string &sMsg, size_t &nFeats)
Definition: snp_track.cpp:401
objects::CFeat_CI x_GetFeat_CI(const TSeqRange &range)
Definition: snp_track.cpp:360
virtual void x_SaveSettings(const string &preset_style)
save the track settings to a profile string.
Definition: snp_track.cpp:263
string m_AnnotName
Definition: snp_track.hpp:143
CRef< CSNPFeatureParams > m_Params
Definition: snp_track.hpp:146
int m_eLayout
Definition: snp_track.hpp:142
string m_PreferredTitle
Definition: snp_track.hpp:151
virtual void x_LoadSettings(const string &preset_style, const TKeyValuePairs &settings)
load the track settings.
Definition: snp_track.cpp:276
CSnpTrack(CSGSnpDS *ds, CRenderingContext *r_cntx, const string &sFilter, const string &sTitle, const string &sLayout="")
Definition: snp_track.cpp:108
virtual string GetAnnot() const
Definition: snp_track.hpp:92
bool x_IsOverviewMode() const
Definition: snp_track.cpp:178
void GenerateAsn1(objects::CSeq_entry &seq_entry, TSeqRange range)
Definition: snp_track.cpp:370
SIconInfo m_IconLayout
Definition: snp_track.hpp:148
objects::CGraph_CI x_GetGraph_CI(const TSeqRange &range)
Definition: snp_track.cpp:365
virtual void GetFeatSubtypes(set< objects::CSeqFeatData::ESubtype > &subtypes) const
Definition: snp_track.hpp:91
void x_UpdateLayout()
Definition: snp_track.cpp:147
virtual void x_OnJobCompleted(CAppJobNotification &notify)
Definition: snp_track.cpp:422
CRef< CSGSnpDS > m_DS
Definition: snp_track.hpp:145
virtual bool BypassStage1()
Definition: snp_track.hpp:101
void x_ProcessJobResult()
Definition: snp_track.cpp:434
CSnpTrack & operator=(const CSnpTrack &)
virtual void x_OnIconClicked(TIconID id)
Mouse left-click event handler on an icon.
Definition: snp_track.cpp:205
virtual ~CSnpTrack()
Definition: snp_track.cpp:140
@ eLayout_Features
Show features whenever possible.
Definition: snp_track.hpp:67
@ eLayout_Labels
Show labels and cascade features (CLayeredLayoutPolicy)
Definition: snp_track.hpp:68
@ eLayout_Density
Always show density.
Definition: snp_track.hpp:66
@ eLayout_Adaptive
All SNPs drawn in one line.
Definition: snp_track.hpp:65
virtual CRef< CSGGenBankDS > GetDataSource()
CAlignmentTrack inline methods.
Definition: snp_track.hpp:226
CRef< SSnpFilter > m_Filter
Definition: snp_track.hpp:150
void x_AddSnpsLayout(const SSnpJobResult &result)
Definition: snp_track.cpp:477
CRef< SSnpJobResult > m_JobResult
Definition: snp_track.hpp:149
CSnpTrack(const CSnpTrack &)
File Description:
CTrackTypeInfo - holds description of a layout track type.
IAsn1Generator interface for tracks capable of generating an ASN1 seq_entry for their data.
IExtension IExtension interface represents an abstract pluggable component.
Definition: extension.hpp:57
IFeatureTrackBase –.
ILayoutTrackFactory.
map< string, CRef< CAnnotMetaData > > TAnnotMetaDataList
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 TTrackMap CreateTracks(SConstScopedObject &object, ISGDataSourceContext *ds_context, CRenderingContext *r_cntx, const SExtraParams &params=SExtraParams(), const TAnnotMetaDataList &src_annots=TAnnotMetaDataList()) const =0
create layout tracks based on input object and extra parameters.
ISGDSManager is seqgraphic data source manage that serves as an data source context.
ITrackConfigurable interface for tracks that are configurable.
virtual CRef< objects::CTrackConfigSet > GetSettings(const string &profile, const TKeyValuePairs &settings, const CTempTrackProxy *track_proxy) const =0
Definition: map.hpp:338
virtual string GetExtensionLabel() const =0
returns a displayable label for this extension ( please capitalize the key words - "My Extension" )
virtual string GetExtensionIdentifier() const =0
returns the unique human-readable identifier for the extension the id should use lowercase letters se...
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
#define NCBI_GUIWIDGETS_SNP_EXPORT
Definition: gui_export.h:540
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
range(_Ty, _Ty) -> range< _Ty >
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
bool operator<(const SSNPFeatParamDefiner &left, const SSNPFeatParamDefiner &right)
Definition: snp_track.hpp:255
A help struct for storing information about a icon.
extra parameter for initializing a track.
CSnpBitfield::EVariationClass m_VariationClass
Definition: snp_track.hpp:251
SSNPFeatParamDefiner(CSnpBitfield::EVariationClass VariationClass=CSnpBitfield::eUnknownVariation, CFeatureParams::EBoxStyle BoxStyle=CFeatureParams::eBox_Filled)
Definition: snp_track.hpp:249
CFeatureParams::EBoxStyle m_BoxStyle
Definition: snp_track.hpp:252
SSnpJobResult.
Definition: snp_ds.hpp:66
else result
Definition: token2.c:20
Modified on Sat May 18 11:42:06 2024 by modify_doxy.py rev. 669887