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

Go to the SVN repository for this file.

1 /* $Id: tse_assigner.cpp 100100 2023-06-15 14:04: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 
35 #include <objmgr/impl/tse_info.hpp>
41 
42 #include <objmgr/seq_map.hpp>
44 
46 
49 
50 CBioseq_Info& ITSE_Assigner::x_GetBioseq(CTSE_Info& tse_info,
51  const TBioseqId& place_id)
52 {
53  return tse_info.x_GetBioseq(place_id);
54 }
55 
56 
58  TBioseq_setId place_id)
59 {
60  return tse_info.x_GetBioseq_set(place_id);
61 }
62 
63 
65  const TPlace& place)
66 {
67  if ( place.first ) {
68  return x_GetBioseq(tse_info, place.first);
69  }
70  else if ( place.second ) {
71  return x_GetBioseq_set(tse_info, place.second);
72  }
73  else {
74  return const_cast<CBioseq_Base_Info&>(tse_info.x_GetBaseInfo());
75  }
76 }
77 
78 
80  const TPlace& place)
81 {
82  if ( place.first ) {
83  return x_GetBioseq(tse_info, place.first);
84  }
85  else {
86  NCBI_THROW(CObjMgrException, eOtherError,
87  "Bioseq-set id where gi is expected");
88  }
89 }
90 
91 
93  const TPlace& place)
94 {
95  if ( place.first ) {
96  NCBI_THROW(CObjMgrException, eOtherError,
97  "Gi where Bioseq-set id is expected");
98  }
99  else {
100  return x_GetBioseq_set(tse_info, place.second);
101  }
102 }
103 /////////////////////////////////////////////////////////////////////////////
104 /////////////////////////////////////////////////////////////////////////////
105 /////////////////////////////////////////////////////////////////////////////
107 {
108 }
109 
111 {
112 }
113 
115  const TDescInfo& info,
116  TChunkId chunk_id)
117 {
118  x_GetBase(tse, info.second)
119  .x_AddDescrChunkId(info.first, chunk_id);
120 }
121 
123  const TPlace& place,
124  TChunkId chunk_id)
125 {
126  x_GetBase(tse, place)
127  .x_AddAnnotChunkId(chunk_id);
128 }
130  TBioseq_setId place_id,
131  TChunkId chunk_id)
132 {
133  if ( place_id == kTSE_Place_id ) {
134  tse.x_SetBioseqChunkId(chunk_id);
135  }
136  else {
137  x_GetBioseq_set(tse, place_id).x_AddBioseqChunkId(chunk_id);
138  }
139 }
141  const TLocationSet& locations,
142  CTSE_Chunk_Info& chunk)
143 {
144  CBioseq_Info* last_bioseq = 0, *bioseq;
145  ITERATE ( TLocationSet, it, locations ) {
146  bioseq = &x_GetBioseq(tse, it->first);
147  if (bioseq != last_bioseq) {
148  // Do not add duplicate chunks to the same bioseq
149  bioseq->x_AddSeq_dataChunkId(chunk.GetChunkId());
150  }
151  last_bioseq = bioseq;
152 
153  CSeqMap& seq_map = const_cast<CSeqMap&>(bioseq->GetSeqMap());
154  seq_map.SetRegionInChunk(chunk,
155  it->second.GetFrom(),
156  it->second.GetLength());
157  }
158 }
159 
161  const TAssemblyInfo& info,
162  TChunkId chunk_id)
163 {
164  x_GetBioseq(tse, info)
165  .x_AddAssemblyChunkId(chunk_id);
166 }
167 
169  CTSE_Chunk_Info& chunk)
170 {
172  if( tse.HasDataSource() )
173  guard1.Guard(tse.GetDataSource());
175  chunk.x_UpdateAnnotIndex(tse);
176 }
177 
178  // loading results
180  const TPlace& place,
181  const CSeq_descr& descr)
182 {
183  x_GetBase(tse, place).x_RealLoadDescr(descr);
184 }
185 
187  const TPlace& place,
188  CRef<CSeq_annot> annot,
189  int chunk_id)
190 {
191  CRef<CSeq_annot_Info> annot_info;
192  {{
194  if( tse.HasDataSource() )
195  guard.Guard(tse.GetDataSource().GetMainLock());
196  annot_info.Reset(x_GetBase(tse, place).AddAnnot(*annot, chunk_id));
197  }}
198  {{
200  if( tse.HasDataSource() )
201  guard.Guard(tse.GetDataSource());
202  //tse.UpdateAnnotIndex(*annot_info);
203  }}
204 }
205 
207  const TPlace& place,
208  CRef<CSeq_entry> entry,
209  int chunk_id)
210 {
211  CRef<CSeq_entry_Info> entry_info;
212  {{
214  if( tse.HasDataSource() )
215  guard.Guard(tse.GetDataSource().GetMainLock());
216  if (place == TPlace(CSeq_id_Handle(), kTSE_Place_id)) {
217  entry_info = new CSeq_entry_Info(*entry);
218  tse.x_SetObject(*entry_info, 0); //???
219  }
220  else {
221  entry_info = x_GetBioseq_set(tse, place).AddEntry(*entry, chunk_id);
222  }
223  }}
224  if ( !entry_info->x_GetBaseInfo().GetAnnot().empty() ) {
226  if( tse.HasDataSource() )
227  guard.Guard(tse.GetDataSource());
228  //tse.UpdateAnnotIndex(*entry_info);
229  }
230 }
231 
233  const TPlace& place,
234  const list< CRef<CBioseq> >& bioseqs,
235  int chunk_id)
236 {
238  if ( tse.HasDataSource() )
239  guard.Guard(tse.GetDataSource().GetMainLock());
240  if ( place == TPlace(CSeq_id_Handle(), kTSE_Place_id) ) {
241  _ASSERT(bioseqs.size() == 1);
242  CRef<CSeq_entry> entry(new CSeq_entry);
243  entry->SetSeq(bioseqs.front().GetNCObject());
244  CRef<CSeq_entry_Info> entry_info(new CSeq_entry_Info(*entry));
245  tse.x_SetObject(*entry_info, 0); //???
246  }
247  else {
248  x_GetBioseq_set(tse, place).x_SetChunkBioseqs(bioseqs, chunk_id);
249  }
250 }
251 
253  const TPlace& place,
254  TSeqPos pos,
255  const TSequence& sequence)
256 {
257  CSeqMap& seq_map = const_cast<CSeqMap&>(x_GetBioseq(tse, place).GetSeqMap());;
258  ITERATE ( TSequence, it, sequence ) {
259  const CSeq_literal& literal = **it;
260  seq_map.LoadSeq_data(pos, literal.GetLength(), literal.GetSeq_data());
261  pos += literal.GetLength();
262  }
263 }
264 
266  const TBioseqId& seq_id,
267  const TAssembly& assembly)
268 {
269  x_GetBioseq(tse, seq_id).SetInst_Hist_Assembly(assembly);
270 }
271 
273  CSeq_entry& entry,
274  CTSE_SetObjectInfo* set_info)
275 {
276  tse.SetSeq_entry(entry, set_info);
277 }
278 
279 
280 /////////////////////////////////////////////////////////////////////////////
281 /////////////////////////////////////////////////////////////////////////////
282 
283 
User-defined methods of the data storage class.
void x_RealLoadDescr(const TDescr &v)
void x_AddDescrChunkId(const TDescTypeMask &types, TChunkId chunk_id)
void x_AddAnnotChunkId(TChunkId chunk_id)
const CSeqMap & GetSeqMap(void) const
void SetInst_Hist_Assembly(const TInst_Hist_Assembly &v)
void x_AddAssemblyChunkId(TChunkId chunk_id)
void x_AddBioseqChunkId(TChunkId chunk_id)
CRef< CSeq_entry_Info > AddEntry(CSeq_entry &entry, int index, bool set_uniqid=false)
void x_SetChunkBioseqs(const list< CRef< CBioseq > > &bioseqs, int chunk_id)
void Guard(CDataSource &ds)
TMainLock & GetMainLock() const
void Guard(resource_type &resource)
Manually force the guard to protect some other resource.
Definition: guard.hpp:175
Base class for all object manager exceptions.
CSeqMap –.
Definition: seq_map.hpp:93
@Seq_descr.hpp User-defined methods of the data storage class.
Definition: Seq_descr.hpp:55
void x_SetObject(TObject &obj)
const CBioseq_Base_Info & x_GetBaseInfo(void) const
void x_SetBioseqChunkId(TChunkId chunk_id)
Definition: Seq_entry.hpp:56
void x_UpdateAnnotIndex(CTSE_Info &tse)
TChunkId GetChunkId(void) const
virtual void AddSeq_data(CTSE_Info &, const TLocationSet &location, CTSE_Chunk_Info &chunk)
virtual void LoadAssembly(CTSE_Info &, const TBioseqId &seq_id, const TAssembly &assembly)
virtual void LoadSequence(CTSE_Info &, const TPlace &place, TSeqPos pos, const TSequence &sequence)
virtual void LoadDescr(CTSE_Info &, const TPlace &place, const CSeq_descr &descr)
virtual void LoadAnnot(CTSE_Info &, const TPlace &place, CRef< CSeq_annot > annot, int chunk_id)
virtual void UpdateAnnotIndex(CTSE_Info &, CTSE_Chunk_Info &chunk)
virtual void LoadChunkBioseqs(CTSE_Info &, const TPlace &place, const list< CRef< CBioseq > > &bioseqs, int chunk_id)
virtual void AddAnnotPlace(CTSE_Info &, const TPlace &place, TChunkId chunk_id)
virtual ~CTSE_Default_Assigner()
virtual void LoadSeq_entry(CTSE_Info &, CSeq_entry &entry, CTSE_SetObjectInfo *set_info)
virtual void LoadBioseq(CTSE_Info &, const TPlace &place, CRef< CSeq_entry > entry, int chunk_id)
virtual void AddBioseqPlace(CTSE_Info &, TBioseq_setId place_id, TChunkId chunk_id)
virtual void AddAssemblyInfo(CTSE_Info &, const TAssemblyInfo &info, TChunkId chunk_id)
virtual void AddDescInfo(CTSE_Info &, const TDescInfo &info, TChunkId chunk_id)
CDataSource & GetDataSource(void) const
Definition: tse_info.hpp:805
CBioseq_set_Info & x_GetBioseq_set(int id)
Definition: tse_info.cpp:1345
TAnnotLock & GetAnnotLock(void) const
Definition: tse_info.hpp:914
bool HasDataSource(void) const
Definition: tse_info.hpp:798
void SetSeq_entry(CSeq_entry &entry, CTSE_SetObjectInfo *set_info=0)
Definition: tse_info.cpp:351
static CBioseq_Info & x_GetBioseq(CTSE_Info &tse, const TPlace &place)
CTSE_Chunk_Info::TPlace TPlace
static CBioseq_Base_Info & x_GetBase(CTSE_Info &tse, const TPlace &place)
CTSE_Chunk_Info::TLocationSet TLocationSet
CTSE_Chunk_Info::TChunkId TChunkId
CTSE_Chunk_Info::TSequence TSequence
CTSE_Chunk_Info::TAssembly TAssembly
static CBioseq_set_Info & x_GetBioseq_set(CTSE_Info &tse, const TPlace &place)
CTSE_Chunk_Info::TDescInfo TDescInfo
CTSE_Chunk_Info::TBioseq_setId TBioseq_setId
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
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
void SetRegionInChunk(CTSE_Chunk_Info &chunk, TSeqPos pos, TSeqPos length)
Definition: seq_map.cpp:1438
void LoadSeq_data(TSeqPos pos, TSeqPos len, const CSeq_data &data)
Definition: seq_map.cpp:764
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#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
CTempString literal(const char(&str)[Size])
Templatized initialization from a string literal.
Definition: tempstr.hpp:441
TSeq & SetSeq(void)
Select the variant.
Definition: Seq_entry_.cpp:108
@ eEmptyGuard
Definition: guard.hpp:94
static MDB_envinfo info
Definition: mdb_load.c:37
#define _ASSERT
static const int kTSE_Place_id
#define const
Definition: zconf.h:232
Modified on Sat May 25 14:20:16 2024 by modify_doxy.py rev. 669887