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

Go to the SVN repository for this file.

1 /* $Id: aggregate_feature_track.cpp 47029 2022-05-16 18:09:35Z asztalos $
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: Vladislav Evgeniev
27 *
28 * File Description: Defines a track, combining a set of features into a single track. The list of features is defined in the registry and identified by the subkey.
29 *
30 */
31 
32 #include <ncbi_pch.hpp>
33 
37 #include <gui/objutils/utils.hpp>
38 #include <gui/objutils/label.hpp>
40 #include <vector>
41 
44 
45 
46 ///////////////////////////////////////////////////////////////////////////////
47 /// CAggregateFeatureTrack
48 ///////////////////////////////////////////////////////////////////////////////
49 
50 static const string kTrackName = "Aggregate Features";
51 static const string kBaseKey = "GBPlugins.SeqGraphicAggregateFeatureTrack";
52 
53 CTrackTypeInfo CAggregateFeatureTrack::m_TypeInfo("aggregate_feature_track",
54  "A track, showing a predefined set of features.");
55 
57  : CFeatureTrack(ds, r_cntx)
58 {
61  m_FeatSel.ExcludeNamedAnnots("SNP");
62  m_FeatSel.ExcludeNamedAnnots("STS");
63  m_FeatSel.ExcludeNamedAnnots("CDD");
64 }
65 
67 {
68  vector<string> values;
69  x_GetSubkeyStringVec(subkey, "FeatTypeList", values);
72  result.reserve(values.size());
73  for (auto &it : values) {
74  auto type = types.find(NStr::ToLower(it));
75  if (types.end() == type)
76  continue;
77 
78  result.push_back(type->second);
79  }
80  return result;
81 }
82 
84 {
85  vector<string> values;
86  x_GetSubkeyStringVec(subkey, "FeatSubtypeList", values);
88  result.reserve(values.size());
89  for (auto &it : values) {
91  if (CSeqFeatData::eSubtype_bad == subtype)
92  continue;
93  result.push_back(subtype);
94  }
95  return result;
96 }
97 
99 {
101  CRegistryReadView view;
102  string section(kBaseKey);
103  section += ".Default";
104  section += ".Subkey.";
105  section += subkey;
106  view = registry.GetReadView(section);
107  vector<string> result;
108  view.GetStringVec("FeatSubtypeList", result);
109  return result;
110 }
111 
113 {
114  for (auto s : m_subtypes)
115  subtypes.insert(s);
116 }
117 
119 {
120  for (auto &it : types) {
121  m_FeatSel.IncludeFeatType(it);
123  }
124 }
125 
127 {
128  for (auto &it : subtypes) {
129  m_FeatSel.IncludeFeatSubtype(it);
130  m_subtypes.insert(it);
131  }
132 }
133 
135 {
136  return m_TypeInfo;
137 }
138 
139 
141 {
142  string title = GetTitle();
143  if (title.empty()) {
145  title = "Aggregate Features";
146  }
147  else {
148  title = m_AnnotName;
149  }
150  }
151 
152  return title;
153 }
154 
155 void CAggregateFeatureTrack::x_GetSubkeyStringVec(const string &subkey, const string &field, vector<string> &values)
156 {
158  CRegistryReadView view;
159  string section(kBaseKey);
160  section += ".Default";
161  section += ".Subkey.";
162  section += subkey;
163  view = registry.GetReadView(section);
164  view.GetStringVec(field, values);
165 }
166 
168 {
170  result["gene"] = CSeqFeatData::e_Gene;
171  result["org"] = CSeqFeatData::e_Org;
172  result["cdregion"] = CSeqFeatData::e_Cdregion;
173  result["prot"] = CSeqFeatData::e_Prot;
174  result["rna"] = CSeqFeatData::e_Rna;
175  result["pub"] = CSeqFeatData::e_Pub;
176  result["seq"] = CSeqFeatData::e_Seq;
177  result["imp"] = CSeqFeatData::e_Imp;
178  result["region"] = CSeqFeatData::e_Region;
179  result["comment"] = CSeqFeatData::e_Comment;
180  result["bond"] = CSeqFeatData::e_Bond;
181  result["site"] = CSeqFeatData::e_Site;
182  result["rsite"] = CSeqFeatData::e_Rsite;
183  result["user"] = CSeqFeatData::e_User;
184  result["txinit"] = CSeqFeatData::e_Txinit;
185  result["num"] = CSeqFeatData::e_Num;
186  result["psec_str"] = CSeqFeatData::e_Psec_str;
187  result["non_std_residue"] = CSeqFeatData::e_Non_std_residue;
188  result["het"] = CSeqFeatData::e_Het;
189  result["biosrc"] = CSeqFeatData::e_Biosrc;
190  result["clone"] = CSeqFeatData::e_Clone;
191  result["variation"] = CSeqFeatData::e_Variation;
192  return result;
193 }
194 
195 ///////////////////////////////////////////////////////////////////////////////
196 /// CAggregateFeatureTrackFactory
197 ///////////////////////////////////////////////////////////////////////////////
198 
200 {
203 }
204 
207 ISGDataSourceContext* ds_context,
208 CRenderingContext* r_cntx,
209 const SExtraParams& params,
210 const TAnnotMetaDataList& src_annots) const
211 {
212  TTrackMap tracks;
213  TAnnotNameTitleMap annots;
214 
215  if (!params.m_Annots.empty()) {
216  ITERATE(SExtraParams::TAnnots, iter, params.m_Annots) {
217  annots.insert(TAnnotNameTitleMap::value_type(*iter, ""));
218  }
219  }
220 
223 
224 
225  ITERATE(TAnnotNameTitleMap, iter, annots) {
226  CIRef<ISGDataSource> ds = ds_context->GetDS(
227  typeid(CSGFeatureDSType).name(), object);
228  CSGFeatureDS* seq_ds = dynamic_cast<CSGFeatureDS*>(ds.GetPointer());
229  seq_ds->SetDepth(params.m_Level);
230  seq_ds->SetAdaptive(params.m_Adaptive);
231 
232  CRef<CAggregateFeatureTrack> feat_track(new CAggregateFeatureTrack(seq_ds, r_cntx));
233  feat_track->SetAnnot(iter->first);
234  feat_track->SetFeatTypes(types);
235  feat_track->SetFeatSubtypes(subtypes);
236  if (!iter->second.empty()) {
237  feat_track->SetTitle(iter->second);
238  }
239  seq_ds->SetFilter(params.m_Filter);
240  seq_ds->SetSortBy(params.m_SortBy);
241 
242  // potentially slow operations should not be done during track discovery
243  if(!params.m_FastConfig) {
244  seq_ds->SetGraphLevels(iter->first);
245  }
246  tracks[iter->first] = feat_track.GetPointer();
247  }
248 
249  return tracks;
250 }
251 
253  const TAnnotMetaDataList& src_annots,
254  const ILayoutTrackFactory::SExtraParams& params,
255  TAnnotNameTitleMap& out_annots) const
256 {
257  // Skip named annotations
258  ILayoutTrackFactory::GetMatchedAnnots(src_annots, params.m_Annots, params.m_Subkey, "", out_annots);
259 }
260 
262 {
264 }
265 
267 {
269 }
270 
271 
274  const TKeyValuePairs& settings,
275  const CTempTrackProxy* track_proxy) const
276 {
277  CRef<CTrackConfigSet> config_set(new CTrackConfigSet);
278  config_set->Set().push_back(x_GetSettings(settings, track_proxy, false));
279  return config_set;
280 }
281 
USING_SCOPE(objects)
static const string kTrackName
CAggregateFeatureTrack.
static const string kBaseKey
CAggregateFeatureTrackFactory()
CAggregateFeatureTrackFactory.
virtual string GetExtensionIdentifier() const
returns the unique human-readable identifier for the extension the id should use lowercase letters se...
virtual string GetExtensionLabel() const
returns a displayable label for this extension ( please capitalize the key words - "My Extension" )
virtual CRef< objects::CTrackConfigSet > GetSettings(const string &profile, const TKeyValuePairs &settings, const CTempTrackProxy *track_proxy) 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
Create a biological region track based on the input object and extra parameters.
CAggregateFeatureTrack - combines a set of features into a single track.
static CTrackTypeInfo m_TypeInfo
std::vector< objects::CSeqFeatData::E_Choice > TTypeVec
void SetFeatSubtypes(const TSubtypeVec &subtypes)
static vector< string > GetSubtypeListAsString(const std::string &subkey)
virtual string GetFullTitle() const
get a more meaningful title.
static TTypeMap x_GetFeatTypeMap()
Initializes the feature name to type map.
set< objects::CSeqFeatData::ESubtype > m_subtypes
CAggregateFeatureTrack(CSGFeatureDS *ds, CRenderingContext *r_cntx)
std::map< std::string, objects::CSeqFeatData::E_Choice > TTypeMap
static TSubtypeVec GetSubtypeList(const std::string &subkey)
virtual void GetFeatSubtypes(set< objects::CSeqFeatData::ESubtype > &subtypes) const
static TTypeVec GetTypeList(const std::string &subkey)
static void x_GetSubkeyStringVec(const string &subkey, const string &field, vector< string > &values)
Reads the string vector for the specified subkey from the registry.
virtual const CTrackTypeInfo & GetTypeInfo() const
std::vector< objects::CSeqFeatData::ESubtype > TSubtypeVec
void SetFeatTypes(const TTypeVec &types)
CRef< objects::CTrackConfig > x_GetSettings(const TKeyValuePairs &settings, const CTempTrackProxy *track_proxy, bool is_intron_track) const
CFeatureTrack::ELayout m_DefaultLayout
ELinkedFeatDisplay m_DefaultLinkedFeat
CFeatureTrack –.
objects::SAnnotSelector m_FeatSel
@ eLayout_ExpandedLayered
show all features with layered layout
ELinkedFeatDisplay m_LinkedFeat
static CGuiRegistry & GetInstance()
access the application-wide singleton
Definition: registry.cpp:400
string GetTitle() const
get the track title.
CRef –.
Definition: ncbiobj.hpp:618
class CRegistryReadView provides a nested hierarchical view at a particular key.
Definition: reg_view.hpp:58
void GetStringVec(const string &key, vector< string > &val) const
Definition: reg_view.cpp:263
CRenderingContext offers the basic context and utility methods for rendering layout objects in featur...
CSGFeatureDSType.
Definition: feature_ds.hpp:156
CSGFeatureDS.
Definition: feature_ds.hpp:49
void SetSortBy(const string &sortby)
Definition: feature_ds.hpp:184
void SetFilter(const string &filter)
CSGFeatureDS inline method.
Definition: feature_ds.hpp:176
void SetGraphLevels(const string &annot)
void SetDepth(int depth)
Set the annotation selector resolving depth.
void SetAdaptive(bool flag)
@ eSubtype_bad
These no longer need to match the FEATDEF values in the C toolkit's objfdef.h.
static ESubtype SubtypeNameToValue(CTempString sName)
Turn a string into its ESubtype which is NOT necessarily related to the identifier of the enum.
File Description:
CTrackConfigSet –.
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.
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
Definition: set.hpp:45
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
static CMemoryRegistry registry
Definition: cn3d_tools.cpp:81
@ eLFD_Expanded
static const struct type types[]
Definition: type.c:22
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
string
Definition: cgiapp.hpp:687
static bool IsUnnamed(const string &annot)
check if a given annotation is a unnamed annotation.
Definition: utils.hpp:525
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 string & ToLower(string &str)
Convert string to lower case – string& version.
Definition: ncbistr.cpp:405
Tdata & Set(void)
Assign a value to data member.
@ e_Het
cofactor, prosthetic grp, etc, bound to seq
@ e_Region
named region (globin locus)
@ e_Seq
to annotate origin from another seq
@ e_Txinit
transcription initiation
@ e_Num
a numbering system
@ e_Pub
publication applies to this seq
@ e_User
user defined structure
@ e_Rsite
restriction site (for maps really)
@ e_Comment
just a comment
@ e_Non_std_residue
non-standard residue here in seq
void GetSubtypesForType(set< objects::CSeqFeatData::ESubtype > &subtypes, objects::CSeqFeatData::E_Choice feat)
const struct ncbi::grid::netcache::search::fields::SUBKEY subkey
extra parameter for initializing a track.
bool m_Adaptive
Adaptive/Exact selector.
TAnnots m_Annots
particular annotations the track will be looking at.
string m_Filter
potential track-specific filter.
string m_SortBy
potential track-specific sort_by.
int m_Level
layout level that limits feature retrieving used by annotation selector.
bool m_FastConfig
when set to true, indicates that that the factory is used by seqconfig this means that some operation...
string m_Subkey
A subkey for creating feature-specific layout track for a generic layout track type.
Definition: type.c:6
else result
Definition: token2.c:20
Modified on Tue Apr 23 07:39:29 2024 by modify_doxy.py rev. 669887