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

Go to the SVN repository for this file.

1 /* $Id: annot_finder.cpp 48409 2011-01-12 20:14:06Z vasilche $
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 * Author: Maxim Didenko
27 *
28 * File Description:
29 *
30 */
31 
32 
33 #include <ncbi_pch.hpp>
34 
36 #include <objmgr/impl/tse_info.hpp>
43 
44 #include <objmgr/annot_name.hpp>
45 
51 
54 
56 {
57 public:
58  IFindContext() : m_FoundObj(NULL) {}
59  virtual ~IFindContext() {};
60 
61  virtual void CollectRangeMaps( vector<CHandleRangeMap>& ) const = 0;
63  virtual bool CheckAnnotObject(const CAnnotObject_Info& ) = 0;
64 
65  const CAnnotObject_Info* GetFoundObj() const { return m_FoundObj; }
66 
67 protected:
69 
70 };
71 
72 ///////////////////////////////////////////////////////////////////////////////
74 {
75 public:
76  explicit CFeatFindContext(const CSeq_feat& feat) : m_Feat(feat) {}
77  virtual ~CFeatFindContext() {}
78 
79  virtual void CollectRangeMaps( vector<CHandleRangeMap>& hrmaps) const
80  {
82  }
84  {
86  ret.first = CAnnotType_Index::
88  ret.second = ret.first+1;
89  return ret;
90  }
92  {
93  if ( !info.IsFeat() ) return false;
94  if ( !info.GetFeat().Equals(m_Feat) ) return false;
95  m_FoundObj = &info;
96  return true;
97  }
98 private:
99  const CSeq_feat& m_Feat;
100 };
101 ///////////////////////////////////////////////////////////////////////////////
103 {
104 public:
105  explicit CAlignFindContext(const CSeq_align& align) : m_Align(align) {}
106  virtual ~CAlignFindContext() {}
107 
108  virtual void CollectRangeMaps( vector<CHandleRangeMap>& hrmaps) const
109  {
111  }
113  {
114  return CAnnotType_Index::
116  }
118  {
119  if ( !info.IsAlign() ) return false;
120  if ( !info.GetAlign().Equals(m_Align) ) return false;
121  m_FoundObj = &info;
122  return true;
123  }
124 private:
126 };
127 
128 ///////////////////////////////////////////////////////////////////////////////
130 {
131 public:
132  explicit CGraphFindContext(const CSeq_graph& graph) : m_Graph(graph) {}
133  virtual ~CGraphFindContext() {}
134 
135  virtual void CollectRangeMaps( vector<CHandleRangeMap>& hrmaps) const
136  {
138  }
140  {
141  return CAnnotType_Index::
143  }
145  {
146  if ( !info.IsGraph() ) return false;
147  if ( !info.GetGraph().Equals(m_Graph) ) return false;
148  m_FoundObj = &info;
149  return true;
150  }
151 private:
153 };
154 
155 ///////////////////////////////////////////////////////////////////////////////
156 
157 
158 const CAnnotObject_Info*
160  const CAnnotName& name,
161  const CSeq_feat& feat)
162 {
164  x_Find(entry, name, context);
165  return context.GetFoundObj();
166 }
167 
168 const CAnnotObject_Info*
170  const CAnnotName& name,
171  const CSeq_align& align)
172 {
173  CAlignFindContext context(align);
174  x_Find(entry, name, context);
175  return context.GetFoundObj();
176 }
177 const CAnnotObject_Info*
179  const CAnnotName& name,
180  const CSeq_graph& graph)
181 {
182  CGraphFindContext context(graph);
183  x_Find(entry, name, context);
184  return context.GetFoundObj();
185 }
186 
187 
188 const CSeq_annot_Info*
190  const CAnnotName& name,
191  const CAnnot_descr& descr)
192 {
193  ITERATE(CSeq_entry_Info::TAnnot, annot_it, entry.GetLoadedAnnot()) {
194  const CSeq_annot_Info& annot = **annot_it;
195  if (annot.GetName() == name) {
197  if (rannot->IsSetDesc() && rannot->GetDesc().Equals(descr))
198  return &annot;
199  }
200  }
201  return NULL;
202 }
203 const CSeq_annot_Info*
205  const CAnnotName& name)
206 {
207  ITERATE(CSeq_entry_Info::TAnnot, annot_it, entry.GetLoadedAnnot()) {
208  const CSeq_annot_Info& annot = **annot_it;
209  if (annot.GetName() == name) {
211  if (!rannot->IsSetDesc() || !rannot->GetDesc().IsSet() ||
212  rannot->GetDesc().Get().empty())
213  return &annot;
214  }
215  }
216  return NULL;
217 }
218 
219 
220 ///////////////////////////////////////////////////////////////////////////////
221 
223  const CAnnotName& name,
225 {
226  vector<CHandleRangeMap> hrmaps;
227  context.CollectRangeMaps(hrmaps);
228  if (hrmaps.empty()) {
229  _ASSERT(0);
230  return;
231  }
232  CHandleRangeMap& r0 = *hrmaps.begin();
233  if (r0.empty()) {
234  _ASSERT(0);
235  return;
236  }
237  const CSeq_id_Handle& idh = r0.begin()->first;
238  CHandleRange::TRange overlap_range = r0.begin()->second.GetOverlappingRange();
239 
240  m_TSE.UpdateAnnotIndex(idh);
242 
243  const SIdAnnotObjs* objs = NULL;
244  if (name.IsNamed())
245  objs = m_TSE.x_GetIdObjects(name,idh);
246  else
247  objs = m_TSE.x_GetUnnamedIdObjects(idh);
248 
249  if (!objs)
250  return;
251  CAnnotType_Index::TIndexRange range = context.GetIndexRange();
252 
253  for (size_t index = range.first; index < range.second; ++index) {
254  if (objs->x_RangeMapIsEmpty(index))
255  continue;
256 
257  const CTSE_Info::TRangeMap& rmap = objs->x_GetRangeMap(index);
258 
259  bool run_again;
260  do {
261  run_again = false;
262  CTSE_Info::TRangeMap::const_iterator it = rmap.find(overlap_range);
263  while (it && it.GetInterval() == overlap_range) {
264  const CAnnotObject_Info& annot_info = *it->second.m_AnnotObject_Info;
265  ++it;
266  if ( annot_info.IsChunkStub() ) {
267  const CTSE_Chunk_Info& chunk = annot_info.GetChunk_Info();
268  if ( chunk.NotLoaded() ) {
269  guard.Release();
270  chunk.Load();
271  guard.Guard(m_TSE.GetAnnotLock());
272  run_again = true;
273  }
274  continue;
275  }
276  if ( &entry == &annot_info.GetSeq_entry_Info() &&
277  context.CheckAnnotObject(annot_info) ) {
278  return;
279  }
280  }
281  } while ( run_again );
282  }
283 }
284 
285 
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
virtual void CollectRangeMaps(vector< CHandleRangeMap > &hrmaps) const
virtual CAnnotType_Index::TIndexRange GetIndexRange() const
virtual ~CAlignFindContext()
virtual bool CheckAnnotObject(const CAnnotObject_Info &info)
CAlignFindContext(const CSeq_align &align)
const CSeq_align & m_Align
bool IsNamed(void) const
Definition: annot_name.hpp:58
const CTSE_Chunk_Info & GetChunk_Info(void) const
const CSeq_entry_Info & GetSeq_entry_Info(void) const
static void x_ProcessFeat(vector< CHandleRangeMap > &hrmaps, const CSeq_feat &feat, const CMasterSeqSegments *master)
static void x_ProcessAlign(vector< CHandleRangeMap > &hrmaps, const CSeq_align &align, const CMasterSeqSegments *master)
static void x_ProcessGraph(vector< CHandleRangeMap > &hrmaps, const CSeq_graph &graph, const CMasterSeqSegments *master)
bool IsChunkStub(void) const
pair< size_t, size_t > TIndexRange
static size_t GetSubtypeIndex(CSeqFeatData::ESubtype subtype)
static TIndexRange GetAnnotTypeRange(CSeq_annot::C_Data::E_Choice type)
CAnnot_descr –.
Definition: Annot_descr.hpp:66
virtual void CollectRangeMaps(vector< CHandleRangeMap > &hrmaps) const
virtual CAnnotType_Index::TIndexRange GetIndexRange() const
const CSeq_feat & m_Feat
virtual bool CheckAnnotObject(const CAnnotObject_Info &info)
CFeatFindContext(const CSeq_feat &feat)
virtual ~CFeatFindContext()
virtual CAnnotType_Index::TIndexRange GetIndexRange() const
virtual ~CGraphFindContext()
virtual void CollectRangeMaps(vector< CHandleRangeMap > &hrmaps) const
virtual bool CheckAnnotObject(const CAnnotObject_Info &info)
CGraphFindContext(const CSeq_graph &graph)
const CSeq_graph & m_Graph
void Guard(resource_type &resource)
Manually force the guard to protect some other resource.
Definition: guard.hpp:175
void Release()
Manually force the resource to be released.
Definition: guard.hpp:166
const_iterator begin(void) const
bool empty(void) const
ESubtype GetSubtype(void) const
void x_Find(const CSeq_entry_Info &entry, const CAnnotName &name, IFindContext &context)
const CAnnotObject_Info * Find(const CSeq_entry_Info &entry, const CAnnotName &name, const CSeq_feat &feat)
CTSE_Info & m_TSE
CConstRef< TObject > GetCompleteSeq_annot(void) const
const CAnnotName & GetName(void) const
const TAnnot & GetLoadedAnnot(void) const
vector< CRef< CSeq_annot_Info > > TAnnot
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
void Load(void) const
bool NotLoaded(void) const
void UpdateAnnotIndex(const CSeq_id_Handle &id) const
Definition: tse_info.cpp:1009
TAnnotLock & GetAnnotLock(void) const
Definition: tse_info.hpp:914
const SIdAnnotObjs * x_GetIdObjects(const TAnnotObjs &objs, const CSeq_id_Handle &idh) const
Definition: tse_info.cpp:1134
const SIdAnnotObjs * x_GetUnnamedIdObjects(const CSeq_id_Handle &id) const
Definition: tse_info.cpp:1157
const CAnnotObject_Info * m_FoundObj
virtual ~IFindContext()
virtual void CollectRangeMaps(vector< CHandleRangeMap > &) const =0
virtual CAnnotType_Index::TIndexRange GetIndexRange() const =0
virtual bool CheckAnnotObject(const CAnnotObject_Info &)=0
const CAnnotObject_Info * GetFoundObj() const
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NULL
Definition: ncbistd.hpp:225
virtual bool Equals(const CSerialObject &object, ESerialRecursionMode how=eRecursive) const
Check if both objects contain the same values.
range_type GetInterval(void) const
Definition: rangemap.hpp:253
const_iterator find(const key_type &key) const
Definition: rangemap.hpp:484
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
const TData & GetData(void) const
Get the Data member data.
Definition: Seq_feat_.hpp:925
const Tdata & Get(void) const
Get the member data.
const TDesc & GetDesc(void) const
Get the Desc member data.
Definition: Seq_annot_.hpp:852
bool IsSetDesc(void) const
used only for stand alone Seq-annots Check if a value has been assigned to Desc data member.
Definition: Seq_annot_.hpp:840
bool IsSet(void) const
Check if a value has been assigned to data member.
static MDB_envinfo info
Definition: mdb_load.c:37
range(_Ty, _Ty) -> range< _Ty >
const TRangeMap & x_GetRangeMap(size_t index) const
Definition: tse_info.hpp:118
bool x_RangeMapIsEmpty(size_t index) const
Definition: tse_info.hpp:112
#define _ASSERT
static CS_CONTEXT * context
Definition: will_convert.c:21
Modified on Thu Apr 25 08:16:26 2024 by modify_doxy.py rev. 669887