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

Go to the SVN repository for this file.

1 /* $Id: ld_ds.cpp 39658 2017-10-24 20:52:55Z katargir $
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  * Description: This file defines CLDBlockJob, CLDBlockDS, and CLDBlockDSType
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
37 
38 #include <gui/objutils/utils.hpp>
41 
42 #include <objmgr/graph_ci.hpp>
45 #include <objmgr/seqdesc_ci.hpp>
46 #include <objmgr/table_field.hpp>
47 #include <objmgr/util/feature.hpp>
48 #include <objmgr/util/sequence.hpp>
49 #include <objmgr/util/sequence.hpp>
50 
52 #include <cmath>
53 
56 
57 ///////////////////////////////////////////////////////////////////////////////
58 /// Static Helper functions
59 ///////////////////////////////////////////////////////////////////////////////
60 static bool s_PassesFilter(const CMappedFeat& feat, CLDBlockDS::SParams& params)
61 {
62  const CSeq_feat& or_feat = feat.GetOriginalFeature();
63  const CUser_object &user = or_feat.GetData().GetUser();
64 
65  TSeqRange range = feat.GetTotalRange();
66  float score = user.GetField("score").GetData().GetReal();
67 
68  TSeqPos dist = range.GetLength();
69 
70  return ( ((int)dist >= params.filterLength) && (score >= params.filterScore) );
71 }
72 
73 ///////////////////////////////////////////////////////////////////////////////
74 /// CLDBlockJob
75 ///////////////////////////////////////////////////////////////////////////////
76 class CLDBlockJob : public CSGAnnotJob
77 {
78 public:
79  CLDBlockJob(const CBioseq_Handle& handle, const CLDBlockDS::SParams& params)
80  : CSGAnnotJob("SNP", handle, SAnnotSelector(), params.range)
81  , m_Params(params) {}
82 
83  virtual EJobState x_Execute();
84 
85 private:
86  //bool x_IsOverview() const;
88  void x_LoadFtable(CFeat_CI& feats, CSeqGlyph::TObjects* glyphs);
89 
90 private:
92 };
93 
95 {
97 
98  try {
99  // variation data comes in pairs: graph & feature_table
100  // Resolve Graph in overview mode. Resolve feature table otherwise
102  CSeqGlyph::TObjects glyphs;
103 
104  x_Load(&glyphs);
105 
108 
109  result->m_ObjectList.swap(glyphs);
110  } catch (CException& ex) {
111  m_Error.Reset(new CAppJobError(ex.GetMsg()));
112  state = eFailed;
113  } catch (std::exception& ex) {
114  m_Error.Reset(new CAppJobError(ex.what()));
115  state = eFailed;
116  }
117 
118  return state;
119 }
120 
122 {
123  SAnnotSelector sel =
127 
128  CRef<CSeq_loc> loc = m_Handle.GetRangeSeq_loc(m_Range.GetFrom(), m_Range.GetTo());
129 
130  CFeat_CI iter(m_Handle.GetScope(), *loc, sel);
131  x_LoadFtable(iter, objs);
132 }
133 
135 {
136  // Place feats in separate lists based on popid
137  // For each list, create a new CLDBlockLine
138 
139  typedef std::map<string, CLDBlockLine::TListFeats> TMapPopNames;
140  TMapPopNames mapPopName;
141 
142  for ( ; feat; ++feat) {
143  if (s_PassesFilter(*feat, m_Params)) {
144  const CSeq_feat& or_feat = feat->GetOriginalFeature();
145  const CUser_object &user = or_feat.GetData().GetUser();
146 
147  string pop = user.GetField("pop_name").GetData().GetStr();
148 
149  mapPopName[pop].push_back(*feat);
150  }
151  }
152 
153  // Check if we are showing histograms or real features
154  if (m_Params.scale > 10000 && feat.GetSize() > 20) {
155  // Show histogram
156 
157  ITERATE(TMapPopNames, mapIter, mapPopName) {
158  const string& title = mapIter->first;
161 
162  ITERATE(CLDBlockLine::TListFeats, feat_iter, mapIter->second) {
163  dmap.AddRange(feat_iter->GetTotalRange());
164  }
165 
166  CHistogramGlyph* hist = new CHistogramGlyph(dmap, title);
167  glyphs->push_back(CRef<CSeqGlyph>(hist));
168  hist->SetAnnotName("LDBlock");
169  }
170  }
171  else {
172  // Show features
173  ITERATE(TMapPopNames, mapIter, mapPopName) {
174  CLayoutGroup::TObjectList the_feats;
175 
176  ITERATE(CLDBlockLine::TListFeats, iter, mapIter->second) {
177  CRef<CLDBlockGlyph> ldblock;
178  ldblock.Reset(new CLDBlockGlyph(*iter) );
179 
180  CRef<CSeqGlyph> fref(ldblock.GetPointer());
181  the_feats.push_back(fref);
182  }
183 
184  string title = mapIter->first;
185 
187  CRef<CSeqGlyph> ref_line(dynamic_cast<CSeqGlyph*>(ld_line));
188  glyphs->push_back(ref_line);
189 
190  ld_line->SetObjects(the_feats);
191  ld_line->SetTitle(title);
192  }
193  }
194 }
195 
196 
197 ///////////////////////////////////////////////////////////////////////////////
198 /// CLDBlockDS
199 ///////////////////////////////////////////////////////////////////////////////
201  : CSGGenBankDS(scope, id)
202 {}
203 
206  const TSeqRange& range,
207  const ILayoutTrackFactory::SExtraParams& params)
208 {
209  const CSeq_id& id = dynamic_cast<const CSeq_id&>(object.object.GetObject());
210  CBioseq_Handle handle = object.scope->GetBioseqHandle(id);
211 
212  // Find NHGRI Catalog
214  CSeqUtils::SetResolveDepth(sel, params.m_Adaptive, params.m_Level);
215  sel.SetCollectNames();
216 
217  CFeat_CI feat_iter(handle, range, sel);
218  ITERATE (CFeat_CI::TAnnotNames, iter, feat_iter.GetAnnotNames()) {
219  if (iter->IsNamed()) {
220  names.insert(TAnnotNameTitleMap::value_type(iter->GetName(), ""));
221  } else {
222  names.insert(TAnnotNameTitleMap::value_type("Unnamed", ""));
223  }
224  }
225 }
226 
227 
228 void CLDBlockDS::SetName(const string& name)
229 {
230  m_Name = name;
231 }
232 
233 void CLDBlockDS::LoadData(const SParams& param)
234 {
235  CRef<CLDBlockJob> job;
236 
237  SParams p(param);
238  p.name = m_Name;
240  p.depth = m_Depth;
241  job.Reset(new CLDBlockJob(m_Handle, p));
242 
243  x_LaunchJob(*job);
244 }
245 
246 ///////////////////////////////////////////////////////////////////////////////
247 /// CLDBlockDSType
248 ///////////////////////////////////////////////////////////////////////////////
249 
252 {
253  const CSeq_id& id = dynamic_cast<const CSeq_id&>(object.object.GetObject());
254  return new CLDBlockDS(object.scope.GetObject(), id);
255 }
256 
257 
259 {
260  static string sid("seqgraphic_ldblock_ds_type");
261  return sid;
262 }
263 
265 {
266  static string slabel("Graphical View SNP Data Source Type");
267  return slabel;
268 }
269 
271 {
272  return false;
273 }
274 
275 
User-defined methods of the data storage class.
const TAnnotNames & GetAnnotNames(void) const
size_t GetSize(void) const
CAppJobError Default implementation for IAppJobError - encapsulates a text error message.
CBioseq_Handle –.
CFeat_CI –.
Definition: feat_ci.hpp:64
File Description:
void SetObjects(const CLayoutGroup::TObjectList &objs)
void SetAnnotName(const string &name)
virtual string GetExtensionLabel() const
returns a displayable label for this extension ( please capitalize the key words - "My Extension" )
Definition: ld_ds.cpp:264
virtual ISGDataSource * CreateDS(SConstScopedObject &object) const
CLDBlockDSType.
Definition: ld_ds.cpp:251
virtual string GetExtensionIdentifier() const
returns the unique human-readable identifier for the extension the id should use lowercase letters se...
Definition: ld_ds.cpp:258
virtual bool IsSharable() const
check if the data source can be shared.
Definition: ld_ds.cpp:270
void SetName(const string &)
Definition: ld_ds.cpp:228
void LoadData(const SParams &param)
Definition: ld_ds.cpp:233
CLDBlockDS(objects::CScope &scope, const objects::CSeq_id &id)
CLDBlockDS.
Definition: ld_ds.cpp:200
string m_Name
Definition: ld_ds.hpp:91
static void GetTrackNames(SConstScopedObject &object, TAnnotNameTitleMap &names, const TSeqRange &range, const ILayoutTrackFactory::SExtraParams &params)
Definition: ld_ds.cpp:204
CLDBlockJob.
Definition: ld_ds.cpp:77
CLDBlockDS::SParams m_Params
Definition: ld_ds.cpp:91
CLDBlockJob(const CBioseq_Handle &handle, const CLDBlockDS::SParams &params)
Definition: ld_ds.cpp:79
virtual EJobState x_Execute()
method truly doing the job.
Definition: ld_ds.cpp:94
void x_LoadFtable(CFeat_CI &feats, CSeqGlyph::TObjects *glyphs)
Definition: ld_ds.cpp:134
void x_Load(CSeqGlyph::TObjects *)
Definition: ld_ds.cpp:121
std::list< objects::CMappedFeat > TListFeats
Definition: ld_line.hpp:50
ILayoutPolicy::TObjectList TObjectList
void SetTitle(const string &label, const string &default_title=NcbiEmptyString)
CMappedFeat –.
Definition: mapped_feat.hpp:59
TSeqRange m_Range
target range
objects::CBioseq_Handle m_Handle
target sequence
TJobID x_LaunchJob(IAppJob &job, int report_period=1, const string &pool="ObjManagerEngine")
Launch either a background or foreground job.
bool m_Adaptive
adaptive/exact annot selector
int m_Depth
annotation resolving depth
objects::CBioseq_Handle m_Handle
CSGJobResult – the data structure holding the seqgraphic job results.
CScope –.
Definition: scope.hpp:92
class CSeqGlyph defines an interface that wraps a rectilinear abstract object.
Definition: seq_glyph.hpp:82
list< CRef< CSeqGlyph > > TObjects
Definition: seq_glyph.hpp:85
CRef< CObject > m_Result
CRef< CAppJobError > m_Error
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
const CUser_field & GetField(const string &str, const string &delim=".", NStr::ECase use_case=NStr::eCase) const
Access a named field in this user object.
Definition: User_object.cpp:71
File Description:
static const struct name_t names[]
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
const string & GetMsg(void) const
Get message string.
Definition: ncbiexpt.cpp:461
virtual const char * what(void) const noexcept
Standard report (includes full backlog).
Definition: ncbiexpt.cpp:342
static objects::SAnnotSelector GetAnnotSelector(TAnnotFlags flags=0)
request an annotation selector for a given type
Definition: utils.cpp:167
static void SetResolveDepth(objects::SAnnotSelector &sel, bool adaptive, int depth=-1)
help function for setting selector resolve depth.
Definition: utils.cpp:405
virtual void AddRange(TSeqRange range, CntType score=1, bool expand=false)
EJobState
Job states (describe FSM)
Definition: app_job.hpp:86
@ eCompleted
Definition: app_job.hpp:89
@ eFailed
Definition: app_job.hpp:90
TRange GetTotalRange(void) const
Definition: mapped_feat.hpp:93
const CSeq_feat & GetOriginalFeature(void) const
Get original feature with unmapped location/product.
SAnnotSelector & SetCollectNames(bool value=true)
Collect available annot names rather than annots.
SAnnotSelector & AddNamedAnnots(const CAnnotName &name)
Add named annot to set of annots names to look for.
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
TTo GetTo(void) const
Get the To member data.
Definition: Range_.hpp:269
TFrom GetFrom(void) const
Get the From member data.
Definition: Range_.hpp:222
const TStr & GetStr(void) const
Get the variant data.
const TData & GetData(void) const
Get the Data member data.
TReal GetReal(void) const
Get the variant data.
const TData & GetData(void) const
Get the Data member data.
Definition: Seq_feat_.hpp:925
const TUser & GetUser(void) const
Get the variant data.
USING_SCOPE(objects)
static bool s_PassesFilter(const CMappedFeat &feat, CLDBlockDS::SParams &params)
Static Helper functions.
Definition: ld_ds.cpp:60
range(_Ty, _Ty) -> range< _Ty >
CRenderingContext * r_cntx
Definition: ld_ds.hpp:65
TModelUnit scale
Definition: ld_ds.hpp:67
bool bAdaptiveSelector
Definition: ld_ds.hpp:71
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.
SAnnotSelector –.
else result
Definition: token2.c:20
Modified on Sat Jul 20 11:10:54 2024 by modify_doxy.py rev. 669887