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

Go to the SVN repository for this file.

1 /* $Id: scope_impl.cpp 102071 2024-03-26 15:29:05Z 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 * Authors:
27 * Andrei Gourianov
28 * Aleksey Grichenko
29 * Michael Kimelman
30 * Denis Vakatov
31 * Eugene Vasilchenko
32 *
33 * File Description:
34 * Scope is top-level object available to a client.
35 * Its purpose is to define a scope of visibility and reference
36 * resolution and provide access to the bio sequence data
37 *
38 */
39 
40 #include <ncbi_pch.hpp>
41 #include <objmgr/scope.hpp>
42 #include <objmgr/bioseq_handle.hpp>
49 #include <objmgr/seq_vector.hpp>
50 
52 #include <objmgr/impl/tse_info.hpp>
58 #include <objmgr/impl/priority.hpp>
59 #include <objmgr/impl/synonyms.hpp>
61 
62 #include <objects/seq/Bioseq.hpp>
69 
74 
75 #include <objmgr/seq_annot_ci.hpp>
76 #include <objmgr/error_codes.hpp>
77 #include <util/checksum.hpp>
78 #include <math.h>
79 #include <algorithm>
80 
81 #define USE_OBJMGR_SHARED_POOL 0
82 
83 #define NCBI_USE_ERRCODE_X ObjMgr_Scope
84 
87 
88 
89 NCBI_PARAM_DECL(bool, OBJMGR, KEEP_EXTERNAL_FOR_EDIT);
90 NCBI_PARAM_DEF(bool, OBJMGR, KEEP_EXTERNAL_FOR_EDIT, false);
91 
92 
93 //#define EXCLUDE_EDITED_BIOSEQ_ANNOT_SET
94 
95 /////////////////////////////////////////////////////////////////////////////
96 //
97 // CScope_Impl
98 //
99 /////////////////////////////////////////////////////////////////////////////
100 
101 
103  : m_HeapScope(0),
104  m_ObjMgr(0),
105  m_Transaction(NULL),
106  m_BioseqChangeCounter(0),
107  m_AnnotChangeCounter(0),
108  m_KeepExternalAnnotsForEdit(CScope::GetDefaultKeepExternalAnnotsForEdit())
109 {
110  TConfWriteLockGuard guard(m_ConfLock);
111  x_AttachToOM(objmgr);
112 }
113 
114 
116 {
118  x_DetachFromOM();
119 }
120 
121 
123 {
125  return *m_HeapScope;
126 }
127 
128 
130 {
131  _ASSERT(!m_ObjMgr);
132  m_ObjMgr.Reset(&objmgr);
133  m_ObjMgr->RegisterScope(*this);
134 }
135 
136 
138 {
139  _ASSERT(m_ObjMgr);
140  // Drop and release all TSEs
141  ResetScope();
142  m_ObjMgr->RevokeScope(*this);
143  m_ObjMgr.Reset();
144 }
145 
146 
148 {
149  return NCBI_PARAM_TYPE(OBJMGR, KEEP_EXTERNAL_FOR_EDIT)::GetDefault();
150 }
151 
152 
154 {
155  NCBI_PARAM_TYPE(OBJMGR, KEEP_EXTERNAL_FOR_EDIT)::SetDefault(keep);
156 }
157 
158 
160 {
162 }
163 
164 
166 {
168 }
169 
170 
172 {
176 }
177 
178 
180 {
183 
186  m_setDataSrc.Insert(*x_GetDSInfo(const_cast<CDataSource&>(**it)),
187  (priority == CScope::kPriority_Default) ?
188  (*it)->GetDefaultPriority() : priority);
189  }
191 }
192 
193 
194 void CScope_Impl::AddDataLoader(const string& loader_name, TPriority priority)
195 {
196  CRef<CDataSource> ds = m_ObjMgr->AcquireDataLoader(loader_name);
197 
200  (priority == CScope::kPriority_Default) ?
201  ds->GetDefaultPriority() : priority);
203 }
204 
205 
207 {
208  TConfReadLockGuard src_guard(scope.m_ConfLock);
209  CPriorityTree tree(*this, scope.m_setDataSrc);
210  src_guard.Release();
211 
214  (priority == CScope::kPriority_Default) ? 9 : priority);
216 }
217 
218 
220  TPriority priority,
221  TExist action)
222 {
224 
225  // first check if object already added to the scope
227  if ( lock.first ) {
228  if ( action == CScope::eExist_Throw ) {
229  NCBI_THROW(CObjMgrException, eAddDataError,
230  "Seq-entry already added to the scope");
231  }
232  return CSeq_entry_Handle(*lock.first, *lock.second);
233  }
234 
235  CRef<CDataSource_ScopeInfo> ds_info = GetEditDS(priority);
236  CTSE_Lock tse_lock = ds_info->GetDataSource().AddStaticTSE(entry);
237  x_ClearCacheOnNewData(*tse_lock);
238 
239  return CSeq_entry_Handle(*tse_lock, *ds_info->GetTSE_Lock(tse_lock));
240 }
241 
242 
244  TPriority priority,
245  TExist action)
246 {
248 
249  // first check if object already added to the scope
251  if ( lock.first ) {
252  if ( action == CScope::eExist_Throw ) {
253  NCBI_THROW(CObjMgrException, eAddDataError,
254  "Seq-entry already added to the scope");
255  }
256  return CSeq_entry_Handle(*lock.first, *lock.second);
257  }
258 
259 #if USE_OBJMGR_SHARED_POOL
261  CRef<CDataSource_ScopeInfo> ds_info = AddDS(ds, priority);
262  CTSE_Lock tse_lock = ds->GetSharedTSE();
263 #else
264  CRef<CDataSource_ScopeInfo> ds_info = GetConstDS(priority);
265  CTSE_Lock tse_lock = ds_info->GetDataSource().AddStaticTSE(const_cast<CSeq_entry&>(entry));
266 #endif
267  x_ClearCacheOnNewData(*tse_lock);
268  _ASSERT(tse_lock->GetTSECore() == &entry);
269 
270  return CSeq_entry_Handle(*tse_lock, *ds_info->GetTSE_Lock(tse_lock));
271 }
272 
273 
275  TPriority priority,
276  TExist action)
277 {
279 
280  // first check if object already added to the scope
282  if ( lock ) {
283  if ( action == CScope::eExist_Throw ) {
284  NCBI_THROW(CObjMgrException, eAddDataError,
285  "Bioseq already added to the scope");
286  }
287  return CBioseq_Handle(CSeq_id_Handle(), *lock);
288  }
289 
290  CRef<CDataSource_ScopeInfo> ds_info = GetEditDS(priority);
291  CRef<CSeq_entry> entry = x_MakeDummyTSE(bioseq);
292  CTSE_Lock tse_lock = ds_info->GetDataSource().AddStaticTSE(*entry);
294  x_ClearCacheOnNewData(*tse_lock);
295 
296  return x_GetBioseqHandle(tse_lock->GetSeq(),
297  *ds_info->GetTSE_Lock(tse_lock));
298 }
299 
300 
302  TPriority priority,
303  TExist action)
304 {
306 
307  // first check if object already added to the scope
309  if ( lock ) {
310  if ( action == CScope::eExist_Throw ) {
311  NCBI_THROW(CObjMgrException, eAddDataError,
312  "Bioseq already added to the scope");
313  }
314  return CBioseq_Handle(CSeq_id_Handle(), *lock);
315  }
316 
317 #if USE_OBJMGR_SHARED_POOL
319  CRef<CDataSource_ScopeInfo> ds_info = AddDS(ds, priority);
320  CTSE_Lock tse_lock = ds->GetSharedTSE();
321 #else
322  CRef<CDataSource_ScopeInfo> ds_info = GetConstDS(priority);
323  CRef<CSeq_entry> entry = x_MakeDummyTSE(const_cast<CBioseq&>(bioseq));
324  CTSE_Lock tse_lock = ds_info->GetDataSource().AddStaticTSE(*entry);
326 #endif
327  _ASSERT(tse_lock->IsSeq() &&
328  tse_lock->GetSeq().GetBioseqCore() == &bioseq);
329 
330  return x_GetBioseqHandle(tse_lock->GetSeq(),
331  *ds_info->GetTSE_Lock(tse_lock));
332 }
333 
334 
336  TPriority priority,
337  TExist action)
338 {
340 
341  // first check if object already added to the scope
343  if ( lock.first ) {
344  if ( action == CScope::eExist_Throw ) {
345  NCBI_THROW(CObjMgrException, eAddDataError,
346  "Seq-annot already added to the scope");
347  }
348  return CSeq_annot_Handle(*lock.first, *lock.second);
349  }
350 
351  CRef<CDataSource_ScopeInfo> ds_info = GetEditDS(priority);
352  CRef<CSeq_entry> entry = x_MakeDummyTSE(annot);
353  CTSE_Lock tse_lock = ds_info->GetDataSource().AddStaticTSE(*entry);
355  x_ClearCacheOnNewAnnot(*tse_lock);
356 
357  return CSeq_annot_Handle(*tse_lock->GetSet().GetAnnot()[0],
358  *ds_info->GetTSE_Lock(tse_lock));
359 }
360 
361 
363  TPriority priority,
364  TExist action)
365 {
367 
368  // first check if object already added to the scope
370  if ( lock.first ) {
371  if ( action == CScope::eExist_Throw ) {
372  NCBI_THROW(CObjMgrException, eAddDataError,
373  "Seq-annot already added to the scope");
374  }
375  return CSeq_annot_Handle(*lock.first, *lock.second);
376  }
377 
378 #if USE_OBJMGR_SHARED_POOL
380  CRef<CDataSource_ScopeInfo> ds_info = AddDS(ds, priority);
381  CTSE_Lock tse_lock = ds->GetSharedTSE();
382 #else
383  CRef<CDataSource_ScopeInfo> ds_info = GetConstDS(priority);
384  CRef<CSeq_entry> entry = x_MakeDummyTSE(const_cast<CSeq_annot&>(annot));
385  CTSE_Lock tse_lock = ds_info->GetDataSource().AddStaticTSE(*entry);
387 #endif
388  _ASSERT(tse_lock->IsSet() &&
389  tse_lock->GetSet().IsSetAnnot() &&
390  tse_lock->GetSet().GetAnnot().size() == 1 &&
391  tse_lock->GetSet().GetAnnot()[0]->GetSeq_annotCore() == &annot);
392 
393  return CSeq_annot_Handle(*tse_lock->GetSet().GetAnnot()[0],
394  *ds_info->GetTSE_Lock(tse_lock));
395 }
396 
397 
399  TPriority priority)
400 {
402 
403  CRef<CDataSource_ScopeInfo> ds_info = GetEditDS(priority);
404  CRef<CSeq_entry> entry = x_MakeDummyTSE(submit);
405  CTSE_Lock tse_lock = ds_info->GetDataSource().AddStaticTSE(*entry);
406  const_cast<CTSE_Info&>(*tse_lock).SetTopLevelObject(CTSE_Handle::eTopLevel_Seq_submit, &submit);
407  x_ClearCacheOnNewAnnot(*tse_lock);
408 
409  return CSeq_entry_Handle(*tse_lock, *ds_info->GetTSE_Lock(tse_lock));
410 }
411 
412 
413 namespace {
414  class CClearCacheOnRemoveGuard
415  {
416  public:
417  CClearCacheOnRemoveGuard(CScope_Impl* scope)
418  : m_Scope(scope)
419  {
420  }
421  ~CClearCacheOnRemoveGuard(void)
422  {
423  if ( m_Scope ) {
424  m_Scope->x_ClearCacheOnRemoveData();
425  }
426  }
427 
428  void Done(void)
429  {
430  m_Scope = 0;
431  }
432  private:
434 
435  private:
436  CClearCacheOnRemoveGuard(const CClearCacheOnRemoveGuard&);
437  void operator=(const CClearCacheOnRemoveGuard&);
438  };
439 }
440 
441 
442 void CScope_Impl::RemoveDataLoader(const string& name,
443  int action)
444 {
447  TDSMap::iterator ds_it = m_DSMap.find(ds);
448  if ( ds_it == m_DSMap.end() ) {
449  NCBI_THROW(CObjMgrException, eFindFailed,
450  "CScope_Impl::RemoveDataLoader: "
451  "data loader not found in the scope");
452  }
453  CRef<CDataSource_ScopeInfo> ds_info = ds_it->second;
454  {{
455  CClearCacheOnRemoveGuard guard2(this);
456  ds_info->ResetHistory(action);
457  guard2.Done();
458  }}
459  if ( action != CScope::eRemoveIfLocked ) {
460  // we need to process each TSE individually checking if it's unlocked
462  {{
464  (ds_info->GetTSE_InfoMapMutex());
465  tse_map = ds_info->GetTSE_InfoMap();
466  }}
467  ITERATE( CDataSource_ScopeInfo::TTSE_InfoMap, tse_it, tse_map ) {
468  {{
469  CClearCacheOnRemoveGuard guard2(this);
470  tse_it->second.GetNCObject().RemoveFromHistory(0, CScope::eThrowIfLocked);
471  guard2.Done();
472  }}
473  }
474  }
475  _VERIFY(m_setDataSrc.Erase(*ds_info));
476  _VERIFY(m_DSMap.erase(ds));
477  ds.Reset();
478  ds_info->DetachScope();
480 }
481 
482 
484 {
486  if ( !tse ) {
487  NCBI_THROW(CObjMgrException, eInvalidHandle,
488  "CScope_Impl::RemoveTopLevelSeqEntry: "
489  "TSE not found in the scope");
490  }
491  CRef<CTSE_ScopeInfo> tse_info(&tse.x_GetScopeInfo());
492  CRef<CDataSource_ScopeInfo> ds_info(&tse_info->GetDSInfo());
493  CTSE_Lock tse_lock(tse_info->GetTSE_Lock());
494  _ASSERT(tse_lock);
495  if ( &ds_info->GetScopeImpl() != this ) {
496  NCBI_THROW(CObjMgrException, eInvalidHandle,
497  "CScope_Impl::RemoveTopLevelSeqEntry: "
498  "TSE doesn't belong to the scope");
499  }
500  if ( ds_info->GetDataLoader() ) {
501  NCBI_THROW(CObjMgrException, eInvalidHandle,
502  "CScope_Impl::RemoveTopLevelSeqEntry: "
503  "can not remove a loaded TSE");
504  }
505  x_ClearCacheOnRemoveData(&*tse_lock);
506  tse_lock.Reset();
508  _ASSERT(!tse_info->IsAttached());
509  _ASSERT(!tse);
510  if ( !ds_info->CanBeEdited() ) { // shared -> remove whole DS
511  CRef<CDataSource> ds(&ds_info->GetDataSource());
512  _VERIFY(m_setDataSrc.Erase(*ds_info));
513  _VERIFY(m_DSMap.erase(ds));
514  ds.Reset();
515  ds_info->DetachScope();
516  }
517  /*
518  else { // private -> remove TSE only
519  CRef<CTSE_Info> info(&const_cast<CTSE_Info&>(*tse_lock));
520  tse_lock.Reset();
521  ds_info->GetDataSource().DropStaticTSE(*info);
522  }
523  */
525 }
526 
527 
530  CRef<CSeq_entry_Info> entry,
531  int index)
532 {
534 
535  _ASSERT(seqset);
536  _ASSERT(entry);
537 
538  seqset.x_GetInfo().AddEntry(entry, index, true);
539 
540  x_ClearCacheOnNewData(entry->GetTSE_Info(), *entry);
541 
542  return CSeq_entry_EditHandle(*entry, seqset.GetTSE_Handle());
543 }
544 
545 
547  const CSeq_entry_EditHandle& entry,
548  int index)
549 {
551 
552  _ASSERT(seqset);
553  _ASSERT(entry.IsRemoved());
554  _ASSERT(!entry);
555 
556  seqset.GetTSE_Handle().x_GetScopeInfo()
557  .AddEntry(seqset.x_GetScopeInfo(), entry.x_GetScopeInfo(), index);
558 
560 
561  _ASSERT(entry);
562 }
563 
564 
567  CRef<CBioseq_Info> bioseq)
568 {
569  CBioseq_EditHandle ret;
570 
572 
573  _ASSERT(entry);
574  _ASSERT(entry.Which() == CSeq_entry::e_not_set);
575  _ASSERT(bioseq);
576 
577  // duplicate bioseq info
578  entry.x_GetInfo().SelectSeq(*bioseq);
579 
580  x_ClearCacheOnNewData(bioseq->GetTSE_Info(), entry.x_GetInfo());
581 
583  .GetBioseqLock(null, bioseq);
585  return ret;
586 }
587 
588 
591  CRef<CBioseq_set_Info> seqset)
592 {
594 
595  _ASSERT(entry);
596  _ASSERT(entry.Which() == CSeq_entry::e_not_set);
597  _ASSERT(seqset);
598 
599  // duplicate bioseq info
600  entry.x_GetInfo().SelectSet(*seqset);
601 
602  x_ClearCacheOnNewData(seqset->GetTSE_Info(), entry.x_GetInfo());
603 
604  return CBioseq_set_EditHandle(*seqset, entry.GetTSE_Handle());
605 }
606 
607 
609  const CBioseq_EditHandle& bioseq)
610 {
612 
613  _ASSERT(entry);
614  _ASSERT(entry.Which() == CSeq_entry::e_not_set);
615  _ASSERT(bioseq.IsRemoved());
616  _ASSERT(!bioseq);
617 
618  entry.GetTSE_Handle().x_GetScopeInfo()
619  .SelectSeq(entry.x_GetScopeInfo(), bioseq.x_GetScopeInfo());
620 
622 
623  _ASSERT(bioseq);
624 }
625 
626 
628  const CBioseq_set_EditHandle& seqset)
629 {
631 
632  _ASSERT(entry);
633  _ASSERT(entry.Which() == CSeq_entry::e_not_set);
634  _ASSERT(seqset.IsRemoved());
635  _ASSERT(!seqset);
636 
637  entry.GetTSE_Handle().x_GetScopeInfo()
638  .SelectSet(entry.x_GetScopeInfo(), seqset.x_GetScopeInfo());
639 
641 
642  _ASSERT(seqset);
643 }
644 
645 
648  CRef<CSeq_annot_Info> annot)
649 {
651 
652  _ASSERT(entry);
653  _ASSERT(annot);
654 
655  entry.x_GetInfo().AddAnnot(annot);
656 
657  x_ClearCacheOnNewAnnot(annot->GetTSE_Info());
658 
659  return CSeq_annot_EditHandle(*annot, entry.GetTSE_Handle());
660 }
661 
662 
664  const CSeq_annot_EditHandle& annot)
665 {
667 
668  _ASSERT(entry);
669  _ASSERT(annot.IsRemoved());
670  _ASSERT(!annot);
671 
672  entry.GetTSE_Handle().x_GetScopeInfo()
673  .AddAnnot(entry.x_GetScopeInfo(), annot.x_GetScopeInfo());
674 
676 
677  _ASSERT(annot);
678 }
679 
680 
681 #define CHECK_HANDLE(func, handle) \
682  if ( !handle ) { \
683  NCBI_THROW(CObjMgrException, eInvalidHandle, \
684  "CScope_Impl::" #func ": null " #handle " handle"); \
685  }
686 
687 #define CHECK_REMOVED_HANDLE(func, handle) \
688  if ( !handle.IsRemoved() ) { \
689  NCBI_THROW(CObjMgrException, eInvalidHandle, \
690  "CScope_Impl::" #func ": " \
691  #handle " handle is not removed"); \
692  }
693 
694 
697  CSeq_entry& entry,
698  int index)
699 {
700  return AttachEntry(seqset, Ref(new CSeq_entry_Info(entry)), index);
701 }
702 
705  CRef<CSeq_entry_Info> entry,
706  int index)
707 {
708  CHECK_HANDLE(AttachEntry, seqset);
709  _ASSERT(seqset);
710  return x_AttachEntry(seqset,entry, index);
711 }
712 
713 /*
714 CSeq_entry_EditHandle
715 CScope_Impl::CopyEntry(const CBioseq_set_EditHandle& seqset,
716  const CSeq_entry_Handle& entry,
717  int index)
718 {
719  CHECK_HANDLE(CopyEntry, seqset);
720  CHECK_HANDLE(CopyEntry, entry);
721  _ASSERT(seqset);
722  _ASSERT(entry);
723  return x_AttachEntry(seqset,
724  Ref(new CSeq_entry_Info(entry.x_GetInfo(), 0)),
725  index);
726 }
727 
728 
729 CSeq_entry_EditHandle
730 CScope_Impl::TakeEntry(const CBioseq_set_EditHandle& seqset,
731  const CSeq_entry_EditHandle& entry,
732  int index)
733 {
734  CHECK_HANDLE(TakeEntry, seqset);
735  CHECK_HANDLE(TakeEntry, entry);
736  _ASSERT(seqset);
737  _ASSERT(entry);
738  entry.Remove();
739  return AttachEntry(seqset, entry, index);
740 }
741 */
742 
745  const CSeq_entry_EditHandle& entry,
746  int index)
747 {
748  CHECK_HANDLE(AttachEntry, seqset);
750  _ASSERT(seqset);
751  _ASSERT(!entry);
752  _ASSERT(entry.IsRemoved());
753  x_AttachEntry(seqset, entry, index);
754  _ASSERT(!entry.IsRemoved());
755  _ASSERT(entry);
756  return entry;
757 }
758 
759 
761  CBioseq& seq)
762 {
763  return SelectSeq(entry, Ref(new CBioseq_Info(seq)));
764  /*CHECK_HANDLE(SelectSeq, entry);
765  _ASSERT(entry);
766  return x_SelectSeq(entry, Ref(new CBioseq_Info(seq)));
767  */
768 }
770  CRef<CBioseq_Info> seq)
771 {
772  CHECK_HANDLE(SelectSeq, entry);
773  _ASSERT(entry);
774  return x_SelectSeq(entry, seq);
775 }
776 
777 /*
778 CBioseq_EditHandle CScope_Impl::CopySeq(const CSeq_entry_EditHandle& entry,
779  const CBioseq_Handle& seq)
780 {
781  CHECK_HANDLE(CopySeq, entry);
782  CHECK_HANDLE(CopySeq, seq);
783  _ASSERT(entry);
784  _ASSERT(seq);
785  return x_SelectSeq(entry,
786  Ref(new CBioseq_Info(seq.x_GetInfo(), 0)));
787 }
788 
789 
790 CBioseq_EditHandle CScope_Impl::TakeSeq(const CSeq_entry_EditHandle& entry,
791  const CBioseq_EditHandle& seq)
792 {
793  CHECK_HANDLE(TakeSeq, entry);
794  CHECK_HANDLE(TakeSeq, seq);
795  _ASSERT(entry);
796  _ASSERT(seq);
797  seq.Remove();
798  return SelectSeq(entry, seq);
799 }
800 */
801 
803  const CBioseq_EditHandle& seq)
804 {
805  CHECK_HANDLE(SelectSeq, entry);
807  _ASSERT(entry);
808  _ASSERT(seq.IsRemoved());
809  _ASSERT(!seq);
810  x_SelectSeq(entry, seq);
811  _ASSERT(seq);
812  return seq;
813 }
814 
815 
818  CBioseq_set& seqset)
819 {
820  return SelectSet(entry, Ref(new CBioseq_set_Info(seqset)));
821  /* CHECK_HANDLE(SelectSet, entry);
822  _ASSERT(entry);
823  return x_SelectSet(entry, Ref(new CBioseq_set_Info(seqset)));*/
824 }
825 
828  CRef<CBioseq_set_Info> seqset)
829 {
830  CHECK_HANDLE(SelectSet, entry);
831  _ASSERT(entry);
832  return x_SelectSet(entry, seqset);
833 }
834 
835 /*
836 CBioseq_set_EditHandle
837 CScope_Impl::CopySet(const CSeq_entry_EditHandle& entry,
838  const CBioseq_set_Handle& seqset)
839 {
840  CHECK_HANDLE(CopySet, entry);
841  CHECK_HANDLE(CopySet, seqset);
842  _ASSERT(entry);
843  _ASSERT(seqset);
844  return x_SelectSet(entry,
845  Ref(new CBioseq_set_Info(seqset.x_GetInfo(), 0)));
846 }
847 
848 
849 CBioseq_set_EditHandle
850 CScope_Impl::TakeSet(const CSeq_entry_EditHandle& entry,
851  const CBioseq_set_EditHandle& seqset)
852 {
853  CHECK_HANDLE(TakeSet, entry);
854  CHECK_HANDLE(TakeSet, seqset);
855  _ASSERT(entry);
856  _ASSERT(seqset);
857  seqset.Remove();
858  return SelectSet(entry, seqset);
859 }
860 */
861 
864  const CBioseq_set_EditHandle& seqset)
865 {
866  CHECK_HANDLE(SelectSet, entry);
868  _ASSERT(entry);
869  _ASSERT(seqset.IsRemoved());
870  _ASSERT(!seqset);
871  x_SelectSet(entry, seqset);
872  _ASSERT(seqset);
873  return seqset;
874 }
875 
876 
879  CSeq_annot& annot)
880 {
881  return AttachAnnot(entry, Ref(new CSeq_annot_Info(annot)));
882  /*CHECK_HANDLE(AttachAnnot, entry);
883  _ASSERT(entry);
884  return x_AttachAnnot(entry, Ref(new CSeq_annot_Info(annot)));
885  */
886 }
887 
890  CRef<CSeq_annot_Info> annot)
891 {
892  CHECK_HANDLE(AttachAnnot, entry);
893  _ASSERT(entry);
894  return x_AttachAnnot(entry, annot);
895 }
896 
897 /*
898 CSeq_annot_EditHandle
899 CScope_Impl::CopyAnnot(const CSeq_entry_EditHandle& entry,
900  const CSeq_annot_Handle& annot)
901 {
902  CHECK_HANDLE(CopyAnnot, entry);
903  CHECK_HANDLE(CopyAnnot, annot);
904  _ASSERT(entry);
905  _ASSERT(annot);
906  return x_AttachAnnot(entry,
907  Ref(new CSeq_annot_Info(annot.x_GetInfo(), 0)));
908 }
909 
910 
911 CSeq_annot_EditHandle
912 CScope_Impl::TakeAnnot(const CSeq_entry_EditHandle& entry,
913  const CSeq_annot_EditHandle& annot)
914 {
915  CHECK_HANDLE(TakeAnnot, entry);
916  CHECK_HANDLE(TakeAnnot, annot);
917  _ASSERT(entry);
918  _ASSERT(annot);
919  annot.Remove();
920  return AttachAnnot(entry, annot);
921 }
922 */
923 
926  const CSeq_annot_EditHandle& annot)
927 {
928  CHECK_HANDLE(AttachAnnot, entry);
930  _ASSERT(entry);
931  _ASSERT(annot.IsRemoved());
932  _ASSERT(!annot);
933  x_AttachAnnot(entry, annot);
934  _ASSERT(annot);
935  return annot;
936 }
937 
938 
940 {
941  if ( conflict_id ) {
942  LOG_POST_X(12, Info <<
943  "CScope_Impl: -- "
944  "adding new data to a scope with non-empty history "
945  "make data inconsistent on "<<conflict_id->AsString());
946  }
947  else {
948  LOG_POST_X(13, Info <<
949  "CScope_Impl: -- "
950  "adding new data to a scope with non-empty history "
951  "may cause the data to become inconsistent");
952  }
953 }
954 
955 
957 {
958  // Clear unresolved bioseq handles
959  // Clear annot cache
960  TIds seq_ids, annot_ids;
961  new_tse.GetSeqAndAnnotIds(seq_ids, annot_ids);
962  x_ClearCacheOnNewData(seq_ids, annot_ids);
963  //x_ClearCacheOnNewAnnot(new_tse);
964 }
965 
966 
968  const CSeq_id_Handle& new_id)
969 {
970  TIds seq_ids(1, new_id), annot_ids;
971  x_ClearCacheOnNewData(seq_ids, annot_ids);
972 }
973 
974 
976  const CSeq_entry_Info& new_entry)
977 {
978  TIds seq_ids, annot_ids;
979  new_entry.GetSeqAndAnnotIds(seq_ids, annot_ids);
980  x_ClearCacheOnNewData(seq_ids, annot_ids);
981 }
982 
983 
985  const TIds& annot_ids)
986 {
987  //if ( 1 ) return;
988  const CSeq_id_Handle* conflict_id = 0;
989  if ( !m_Seq_idMap.empty() && !seq_ids.empty() ) {
990  // scan for conflicts and mark new seq-ids for new scan if unresolved
991  size_t add_count = seq_ids.size();
992  size_t old_count = m_Seq_idMap.size();
993  size_t scan_time = add_count + old_count;
994  double lookup_time = (double)min(add_count, old_count) *
995  (2. * log((double)max(add_count, old_count)+2.));
996  if ( scan_time < lookup_time ) {
997  // scan both
998  TIds::const_iterator it1 = seq_ids.begin();
1000  while ( it1 != seq_ids.end() && it2 != m_Seq_idMap.end() ) {
1001  if ( *it1 < it2->first ) {
1002  ++it1;
1003  continue;
1004  }
1005  else if ( it2->first < *it1 ) {
1006  ++it2;
1007  continue;
1008  }
1009  if ( it2->second.m_Bioseq_Info ) {
1010  CBioseq_ScopeInfo& binfo = *it2->second.m_Bioseq_Info;
1011  if ( !binfo.HasBioseq() ) {
1012  // try to resolve again
1014  }
1015  conflict_id = &*it1;
1016  }
1017  ++it1;
1018  ++it2;
1019  }
1020  }
1021  else if ( add_count < old_count ) {
1022  // lookup in old
1023  ITERATE ( TIds, it1, seq_ids ) {
1025  if ( it2 != m_Seq_idMap.end() &&
1026  it2->second.m_Bioseq_Info ) {
1027  CBioseq_ScopeInfo& binfo = *it2->second.m_Bioseq_Info;
1028  if ( !binfo.HasBioseq() ) {
1029  // try to resolve again
1031  }
1032  conflict_id = &*it1;
1033  }
1034  }
1035  }
1036  else {
1037  // lookup in add
1039  if ( it2->second.m_Bioseq_Info ) {
1040  TIds::const_iterator it1 = lower_bound(seq_ids.begin(),
1041  seq_ids.end(),
1042  it2->first);
1043  if ( it1 != seq_ids.end() && *it1 == it2->first ) {
1044  CBioseq_ScopeInfo& binfo = *it2->second.m_Bioseq_Info;
1045  if ( !binfo.HasBioseq() ) {
1046  // try to resolve again
1048  }
1049  conflict_id = &*it1;
1050  }
1051  }
1052  }
1053  }
1054  }
1055  if ( conflict_id ) {
1056  x_ReportNewDataConflict(conflict_id);
1057  }
1058  if ( !annot_ids.empty() ) {
1059  // recollect annot TSEs
1061  }
1062 }
1063 
1064 
1066 {
1067  // Clear unresolved bioseq handles
1068  // Clear annot cache
1069  for ( TSeq_idMap::iterator it = m_Seq_idMap.begin();
1070  it != m_Seq_idMap.end(); ) {
1071  if ( it->second.m_Bioseq_Info ) {
1072  CBioseq_ScopeInfo& binfo = *it->second.m_Bioseq_Info;
1073  if ( binfo.HasBioseq() ) {
1074  if ( &binfo.x_GetTSE_ScopeInfo() == &replaced_tse ) {
1075  binfo.m_SynCache.Reset(); // break circular link
1076  m_Seq_idMap.erase(it++);
1077  continue;
1078  }
1079  binfo.x_ResetAnnotRef_Info();
1080  }
1081  else {
1082  // try to resolve again
1084  }
1085  }
1086  it->second.x_ResetAnnotRef_Info();
1087  ++it;
1088  }
1089 }
1090 
1091 
1093 {
1095  return;
1096 
1097  // Clear annot cache
1099  if ( it->second.m_Bioseq_Info ) {
1100  CBioseq_ScopeInfo& binfo = *it->second.m_Bioseq_Info;
1101  binfo.x_ResetAnnotRef_Info();
1102  }
1103  it->second.x_ResetAnnotRef_Info();
1104  }
1105 }
1106 
1107 
1109 {
1110  //if ( 1 ) return;
1112 }
1113 
1114 
1116 {
1117  //if ( 1 ) return;
1118  // Clear unresolved bioseq handles
1119  // Clear annot cache
1120  if ( !m_Seq_idMap.empty() ) {
1122  }
1125  return;
1126 }
1127 
1128 
1130 {
1131  // Clear removed bioseq handles
1132  for ( TSeq_idMap::iterator it = m_Seq_idMap.begin();
1133  it != m_Seq_idMap.end(); ) {
1134  it->second.x_ResetAnnotRef_Info();
1135  if ( it->second.m_Bioseq_Info ) {
1136  CBioseq_ScopeInfo& binfo = *it->second.m_Bioseq_Info;
1137  binfo.x_ResetAnnotRef_Info();
1138  if ( binfo.IsDetached() ) {
1139  binfo.m_SynCache.Reset();
1140  m_Seq_idMap.erase(it++);
1141  continue;
1142  }
1143  }
1144  ++it;
1145  }
1146 }
1147 
1148 
1150  CBioseq_ScopeInfo& seq)
1151 {
1152  if ( id ) {
1153  // clear erased id
1155  if ( it != m_Seq_idMap.end() &&
1156  &*it->second.m_Bioseq_Info == &seq ) {
1157  m_Seq_idMap.erase(it);
1158  }
1159  }
1160  else {
1161  // clear all ids
1162  ITERATE ( TIds, id_it, seq.GetIds() ) {
1163  TSeq_idMap::iterator it = m_Seq_idMap.find(*id_it);
1164  if ( it != m_Seq_idMap.end() &&
1165  &*it->second.m_Bioseq_Info == &seq ) {
1166  m_Seq_idMap.erase(it);
1167  }
1168  }
1169  }
1170  if ( seq.m_SynCache ) {
1171  // clear synonyms
1172  ITERATE ( CSynonymsSet, id_it, *seq.m_SynCache ) {
1173  TSeq_idMap::iterator it = m_Seq_idMap.find(*id_it);
1174  if ( it != m_Seq_idMap.end() &&
1175  &*it->second.m_Bioseq_Info == &seq ) {
1176  m_Seq_idMap.erase(it);
1177  }
1178  }
1179  seq.m_SynCache.Reset();
1180  }
1181 }
1182 
1183 
1185 {
1186  // Clear annot cache
1188 }
1189 
1190 
1192  const CBlobIdKey& blob_id,
1193  TMissing action)
1194 {
1197  if ( !ds ) {
1198  NCBI_THROW(CObjMgrException, eFindFailed,
1199  "CScope::GetSeq_entryHandle(loader, blob_id): "
1200  "data loader is not in the scope");
1201  }
1202  TSeq_entry_Lock lock = ds->GetSeq_entry_Lock(blob_id);
1203  if ( lock.first ) {
1204  return CSeq_entry_Handle(*lock.first, *lock.second);
1205  }
1206  if ( action == CScope::eMissing_Null ) {
1207  return CSeq_entry_Handle();
1208  }
1209  NCBI_THROW(CObjMgrException, eFindFailed,
1210  "CScope::GetSeq_entryHandle(loader, blob_id): "
1211  "entry is not found");
1212 }
1213 
1214 
1216  TMissing action)
1217 {
1218  CBioseq_set_Handle ret;
1220  TBioseq_set_Lock lock = x_GetBioseq_set_Lock(seqset, action);
1221  if ( lock.first ) {
1222  ret = CBioseq_set_Handle(*lock.first, *lock.second);
1223  }
1224  return ret;
1225 }
1226 
1227 
1229  TMissing action)
1230 {
1231  CSeq_entry_Handle ret;
1233  TSeq_entry_Lock lock = x_GetSeq_entry_Lock(entry, action);
1234  if ( lock.first ) {
1235  ret = CSeq_entry_Handle(*lock.first, *lock.second);
1236  }
1237  return ret;
1238 }
1239 
1240 
1242  TMissing action)
1243 {
1244  CSeq_annot_Handle ret;
1246  TSeq_annot_Lock lock = x_GetSeq_annot_Lock(annot, action);
1247  if ( lock.first ) {
1248  ret = CSeq_annot_Handle(*lock.first, *lock.second);
1249  }
1250  return ret;
1251 }
1252 
1253 
1255  TMissing action)
1256 {
1257  CBioseq_Handle ret;
1259  ret.m_Info = x_GetBioseq_Lock(seq, action);
1260  if ( ret.m_Info ) {
1261  x_UpdateHandleSeq_id(ret);
1262  }
1263  return ret;
1264 }
1265 
1266 
1268 {
1269  return CSeq_entry_Handle(tse.x_GetTSE_Info(), tse);
1270 }
1271 
1272 
1274  TMissing action)
1275 {
1276  CSeq_id_Handle loc_id;
1277  TSeqPos loc_pos = kInvalidSeqPos;
1278  for ( CSeq_loc_CI it = feat.GetLocation(); it; ++it ) {
1279  if ( !it.GetRange().Empty() ) {
1280  loc_id = it.GetSeq_id_Handle();
1281  loc_pos = it.GetRange().GetFrom();
1282  break;
1283  }
1284  }
1285  if ( !loc_id || loc_pos == kInvalidSeqPos ) {
1286  if ( action == CScope::eMissing_Null ) {
1287  return CSeq_feat_Handle();
1288  }
1289  NCBI_THROW(CObjMgrException, eFindFailed,
1290  "CScope_Impl::GetSeq_featHandle: "
1291  "Seq-feat location is empty");
1292  }
1293 
1295  for (CPriority_I it(m_setDataSrc); it; ++it) {
1297  it->FindSeq_feat_Lock(loc_id, loc_pos, feat);
1298  if ( lock.first.first ) {
1299  return CSeq_feat_Handle(CSeq_annot_Handle(*lock.first.first,
1300  *lock.first.second),
1301  lock.second);
1302  }
1303  }
1304  if ( action == CScope::eMissing_Null ) {
1305  return CSeq_feat_Handle();
1306  }
1307  NCBI_THROW(CObjMgrException, eFindFailed,
1308  "CScope_Impl::GetSeq_featHandle: Seq-feat not found");
1309 }
1310 
1311 
1313  TPriority priority)
1314 {
1317  m_setDataSrc.Insert(*ds_info,
1318  (priority == CScope::kPriority_Default) ?
1319  ds->GetDefaultPriority() : priority);
1320  CTSE_Lock tse_lock = ds->GetSharedTSE();
1321  if ( tse_lock ) {
1322  x_ClearCacheOnNewData(*tse_lock);
1323  }
1324  else {
1326  }
1327  return ds_info;
1328 }
1329 
1330 
1333 {
1335  typedef CPriorityTree::TPriorityMap TMap;
1336  TMap& pmap = m_setDataSrc.GetTree();
1337  TMap::iterator iter = pmap.lower_bound(priority);
1338  while ( iter != pmap.end() && iter->first == priority ) {
1339  if ( iter->second.IsLeaf() && iter->second.GetLeaf().CanBeEdited() ) {
1340  return Ref(&iter->second.GetLeaf());
1341  }
1342  ++iter;
1343  }
1345  _ASSERT(ds->CanBeEdited());
1347  _ASSERT(ds_info->CanBeEdited());
1348  pmap.insert(iter, TMap::value_type(priority, CPriorityNode(*ds_info)));
1349  return ds_info;
1350 }
1351 
1352 
1355 {
1357  typedef CPriorityTree::TPriorityMap TMap;
1358  TMap& pmap = m_setDataSrc.GetTree();
1359  TMap::iterator iter = pmap.lower_bound(priority);
1360  while ( iter != pmap.end() && iter->first == priority ) {
1361  if ( iter->second.IsLeaf() && iter->second.GetLeaf().IsConst() ) {
1362  return Ref(&iter->second.GetLeaf());
1363  }
1364  ++iter;
1365  }
1367  _ASSERT(ds->CanBeEdited());
1369  _ASSERT(ds_info->CanBeEdited());
1370  pmap.insert(iter, TMap::value_type(priority, CPriorityNode(*ds_info)));
1371  ds_info->SetConst();
1372  _ASSERT(ds_info->IsConst());
1373  _ASSERT(!ds_info->CanBeEdited());
1374  return ds_info;
1375 }
1376 
1377 
1381  const CTSE_ScopeInfo* replaced_tse)
1382 {
1385  for (CPriority_I it(m_setDataSrc); it; ++it) {
1386  if ( &*it == ds2 ) {
1387  it.InsertBefore(*ds_info);
1388  x_ClearCacheOnEdit(*replaced_tse);
1389  return ds_info;
1390  }
1391  }
1392  NCBI_THROW(CObjMgrException, eOtherError,
1393  "CScope_Impl::AddDSBefore: ds2 is not attached");
1394 }
1395 
1396 
1398 {
1399  CRef<CDataSource_ScopeInfo>& slot = m_DSMap[Ref(&ds)];
1400  if ( !slot ) {
1401  slot = new CDataSource_ScopeInfo(*this, ds);
1402  }
1403  return slot;
1404 }
1405 
1406 
1408  int action)
1409 {
1410  for (CPriority_I it(m_setDataSrc); it; ++it) {
1411  TTSE_Lock lock = it->FindTSE_Lock(tse);
1412  if ( lock ) {
1413  return lock;
1414  }
1415  }
1416  if ( action == CScope::eMissing_Null ) {
1417  return TTSE_Lock();
1418  }
1419  NCBI_THROW(CObjMgrException, eFindFailed,
1420  "CScope_Impl::x_GetTSE_Lock: entry is not attached");
1421 }
1422 
1423 
1426 {
1427  for (CPriority_I it(m_setDataSrc); it; ++it) {
1428  TSeq_entry_Lock lock = it->FindSeq_entry_Lock(entry);
1429  if ( lock.first ) {
1430  return lock;
1431  }
1432  }
1433  if ( action == CScope::eMissing_Null ) {
1434  return TSeq_entry_Lock();
1435  }
1436  NCBI_THROW(CObjMgrException, eFindFailed,
1437  "CScope_Impl::x_GetSeq_entry_Lock: entry is not attached");
1438 }
1439 
1440 
1443 {
1444  for (CPriority_I it(m_setDataSrc); it; ++it) {
1445  TSeq_annot_Lock lock = it->FindSeq_annot_Lock(annot);
1446  if ( lock.first ) {
1447  return lock;
1448  }
1449  }
1450  if ( action == CScope::eMissing_Null ) {
1451  return TSeq_annot_Lock();
1452  }
1453  NCBI_THROW(CObjMgrException, eFindFailed,
1454  "CScope_Impl::x_GetSeq_annot_Lock: annot is not attached");
1455 }
1456 
1457 
1460 {
1461  for (CPriority_I it(m_setDataSrc); it; ++it) {
1462  TBioseq_set_Lock lock = it->FindBioseq_set_Lock(seqset);
1463  if ( lock.first ) {
1464  return lock;
1465  }
1466  }
1467  if ( action == CScope::eMissing_Null ) {
1468  return TBioseq_set_Lock();
1469  }
1470  NCBI_THROW(CObjMgrException, eFindFailed,
1471  "CScope_Impl::x_GetBioseq_set_Lock: "
1472  "bioseq set is not attached");
1473 }
1474 
1475 
1477 CScope_Impl::x_GetBioseq_Lock(const CBioseq& bioseq, int action)
1478 {
1479  for (CPriority_I it(m_setDataSrc); it; ++it) {
1480  TBioseq_Lock lock = it->FindBioseq_Lock(bioseq);
1481  if ( lock ) {
1482  return lock;
1483  }
1484  }
1485  if ( action == CScope::eMissing_Null ) {
1486  return TBioseq_Lock();
1487  }
1488  NCBI_THROW(CObjMgrException, eFindFailed,
1489  "CScope_Impl::x_GetBioseq_Lock: bioseq is not attached");
1490 }
1491 
1492 
1495 {
1496  _ASSERT(&ds.GetScopeImpl() == this);
1497  return ds.GetTSE_Lock(lock);
1498 }
1499 
1500 
1503 {
1504  _ASSERT(&tse.GetScopeImpl() == this);
1505  return CTSE_ScopeUserLock(const_cast<CTSE_ScopeInfo*>(&tse));
1506 }
1507 
1508 
1510 {
1511  entry.GetCompleteSeq_entry();
1512  if ( !entry.GetParentEntry() ) {
1513  CTSE_Handle tse = entry.GetTSE_Handle();
1514  // TODO entry.Reset();
1516  return;
1517  }
1519 
1521 
1523 
1525 }
1526 
1527 
1529 {
1530  CRef<CSeq_entry> entry(new CSeq_entry);
1531  entry->SetSeq(seq);
1532  return entry;
1533 }
1534 
1535 
1537 {
1538  CRef<CSeq_entry> entry(new CSeq_entry);
1539  entry->SetSet(seqset);
1540  return entry;
1541 }
1542 
1543 
1545 {
1546  CRef<CSeq_entry> entry(new CSeq_entry);
1547  entry->SetSet().SetSeq_set(); // it's not optional
1548  entry->SetSet().SetAnnot().push_back(Ref(&annot));
1549  return entry;
1550 }
1551 
1552 
1554 {
1555  CRef<CSeq_entry> entry(new CSeq_entry);
1556  entry->SetSet().SetSeq_set(); // it's not optional
1557  switch ( submit.GetData().Which() ) {
1559  entry->SetSet().SetSeq_set() = submit.GetData().GetEntrys();
1560  break;
1562  entry->SetSet().SetAnnot() = submit.GetData().GetAnnots();
1563  break;
1564  default: // no data to add
1565  break;
1566  }
1567  return entry;
1568 }
1569 
1570 
1572  const CBioseq_Info& seq) const
1573 {
1574  if ( &tse != &seq.GetParentSeq_entry_Info() ) {
1575  return false;
1576  }
1577  return true;
1578 }
1579 
1580 
1582  const CBioseq_set_Info& seqset) const
1583 {
1584  if ( &tse != &seqset.GetParentSeq_entry_Info() ) {
1585  return false;
1586  }
1587  return true;
1588 }
1589 
1590 
1592  const CSeq_annot_Info& annot) const
1593 {
1594  if ( &tse != &annot.GetParentSeq_entry_Info() ) {
1595  return false;
1596  }
1597  if ( !tse.IsSet() ) {
1598  return false;
1599  }
1600  const CBioseq_set_Info& seqset = tse.GetSet();
1601  if ( seqset.IsSetId() ) {
1602  return false;
1603  }
1604  if ( seqset.IsSetColl() ) {
1605  return false;
1606  }
1607  if ( seqset.IsSetLevel() ) {
1608  return false;
1609  }
1610  if ( seqset.IsSetClass() ) {
1611  return false;
1612  }
1613  if ( seqset.IsSetRelease() ) {
1614  return false;
1615  }
1616  if ( seqset.IsSetDate() ) {
1617  return false;
1618  }
1619  if ( seqset.IsSetDescr() ) {
1620  return false;
1621  }
1622  if ( !seqset.IsSetSeq_set() || !seqset.IsEmptySeq_set() ) {
1623  return false;
1624  }
1625  if ( !seqset.IsSetAnnot() ||
1626  seqset.GetAnnot().size() != 1 ||
1627  seqset.GetAnnot()[0] != &annot ) {
1628  return false;
1629  }
1630  return true;
1631 }
1632 
1633 
1635 {
1637 
1639 
1641 
1643 }
1644 
1645 
1647 {
1648  _ASSERT(entry);
1649  entry.GetCompleteSeq_entry();
1650 
1652 
1654 
1656 
1658 }
1659 
1660 
1662 {
1663  SelectNone(seq.GetParentEntry());
1664 }
1665 
1666 
1668 {
1669  SelectNone(seqset.GetParentEntry());
1670 }
1671 
1672 
1674 {
1675  CTSE_Handle tse = seq.GetTSE_Handle();
1676  if ( !x_IsDummyTSE(tse.x_GetTSE_Info(), seq.x_GetInfo()) ) {
1677  NCBI_THROW(CObjMgrException, eInvalidHandle,
1678  "Not a top level Bioseq");
1679  }
1681 }
1682 
1683 
1685 {
1686  CTSE_Handle tse = seqset.GetTSE_Handle();
1687  if ( !x_IsDummyTSE(tse.x_GetTSE_Info(), seqset.x_GetInfo()) ) {
1688  NCBI_THROW(CObjMgrException, eInvalidHandle,
1689  "Not a top level Bioseq-set");
1690  }
1692 }
1693 
1694 
1696 {
1697  CTSE_Handle tse = annot.GetTSE_Handle();
1698  if ( !x_IsDummyTSE(tse.x_GetTSE_Info(), annot.x_GetInfo()) ) {
1699  NCBI_THROW(CObjMgrException, eInvalidHandle,
1700  "Not a top level Seq-annot");
1701  }
1703 }
1704 
1705 
1708 {
1711  if ( it == m_Seq_idMap.end() || it->first != id ) {
1713  }
1714  return *it;
1715 /*
1716  TSeq_idMap::iterator it;
1717  {{
1718  TSeq_idMapLock::TReadLockGuard guard(m_Seq_idMapLock);
1719  it = m_Seq_idMap.lower_bound(id);
1720  if ( it != m_Seq_idMap.end() && it->first == id ) {
1721  return *it;
1722  }
1723  }}
1724  {{
1725  TSeq_idMapLock::TWriteLockGuard guard(m_Seq_idMapLock);
1726  it = m_Seq_idMap.insert(it, TSeq_idMapValue(id, SSeq_id_ScopeInfo()));
1727  return *it;
1728  }}
1729 */
1730 /*
1731  {{
1732  TWriteLockGuard guard(m_Seq_idMapLock);
1733  TSeq_idMap::iterator it = m_Seq_idMap.lower_bound(id);
1734  if ( it == m_Seq_idMap.end() || it->first != id ) {
1735  it = m_Seq_idMap.insert(it,
1736  TSeq_idMapValue(id, SSeq_id_ScopeInfo()));
1737  }
1738  return *it;
1739  }}
1740 */
1741 /*
1742  {{
1743  TSeq_idMapLock::TReadLockGuard guard(m_Seq_idMapLock);
1744  TSeq_idMap::iterator it = m_Seq_idMap.lower_bound(id);
1745  if ( it != m_Seq_idMap.end() && it->first == id )
1746  return *it;
1747  }}
1748  {{
1749  TSeq_idMapLock::TWriteLockGuard guard(m_Seq_idMapLock);
1750  return *m_Seq_idMap.insert(
1751  TSeq_idMapValue(id, SSeq_id_ScopeInfo())).first;
1752  }}
1753 */
1754 }
1755 
1756 
1759 {
1762  if ( it != m_Seq_idMap.end() && it->first == id )
1763  return &*it;
1764  return 0;
1765 }
1766 
1767 
1770  int get_flag,
1772 {
1773  if ( get_flag != CScope::eGetBioseq_Resolved ) {
1774  // Resolve only if the flag allows
1775  CInitGuard init(info.second.m_Bioseq_Info, m_MutexPool, CInitGuard::force);
1776  if ( init || info.second.m_Bioseq_Info->NeedsReResolve(m_BioseqChangeCounter) ) {
1777  x_ResolveSeq_id(info, get_flag, match);
1778  }
1779  }
1780  else if ( info.second.m_Bioseq_Info &&
1781  info.second.m_Bioseq_Info->NeedsReResolve(m_BioseqChangeCounter) ) {
1782  // outdated
1783  return null;
1784  }
1785  return info.second.m_Bioseq_Info;
1786 }
1787 
1788 
1790  CBioseq_ScopeInfo& bioseq_info)
1791 {
1792  _ASSERT(&bioseq_info.x_GetScopeImpl() == this);
1793  {{
1794  CInitGuard init(info.second.m_Bioseq_Info, m_MutexPool, CInitGuard::force);
1795  if ( init || info.second.m_Bioseq_Info->NeedsReResolve(m_BioseqChangeCounter) ) {
1796  info.second.m_Bioseq_Info.Reset(&bioseq_info);
1797  return true;
1798  }
1799  }}
1800  return info.second.m_Bioseq_Info.GetPointerOrNull() == &bioseq_info;
1801 }
1802 
1803 
1806  int get_flag,
1808 {
1809  return x_InitBioseq_Info(x_GetSeq_id_Info(id), get_flag, match);
1810 }
1811 
1812 
1815  int get_flag,
1817 {
1820  if ( info ) {
1821  ret = x_InitBioseq_Info(*info, get_flag, match);
1822  if ( ret ) {
1823  _ASSERT(!ret->HasBioseq() || &ret->x_GetScopeImpl() == this);
1824  }
1825  }
1826  return ret;
1827 }
1828 
1829 
1831  const CTSE_Handle& tse)
1832 {
1837  CTSE_ScopeInfo& tse_info = tse.x_GetScopeInfo();
1838  if ( !info || !info->HasBioseq() ||
1839  &info->x_GetTSE_ScopeInfo() != &tse_info ) {
1840  info.Reset();
1841  if ( CSeq_id_Handle match_id = tse_info.ContainsMatchingBioseq(id) ) {
1842  match = tse_info.Resolve(match_id);
1843  if ( match ) {
1844  info = tse_info.GetBioseqInfo(match);
1845  _ASSERT(info && info->HasBioseq());
1846  }
1847  }
1848  }
1849  if ( info ) {
1850  return CBioseq_Handle(id, *info);
1851  }
1852  else {
1853  return CBioseq_Handle();
1854  }
1855 }
1856 
1857 
1859  int get_flag)
1860 {
1861  CBioseq_Handle ret;
1862  if ( id ) {
1866  info = x_GetBioseq_Info(id, get_flag & fUserFlagMask, match);
1867  if ( info ) {
1868  ret.m_Handle_Seq_id = id;
1869  if ( info->HasBioseq() && !(get_flag & fNoLockFlag) ) {
1870  ret.m_Info = info->GetLock(match.m_Bioseq);
1871  }
1872  else {
1873  ret.m_Info.Reset(info);
1874  }
1875  }
1876  }
1877  return ret;
1878 }
1879 
1880 
1882  const CSeq_id_Handle& id2,
1883  int get_flag)
1884 {
1885  if ( id1 == id2 ) {
1886  return true;
1887  }
1888  CBioseq_Handle bh1 = GetBioseqHandle(id1, get_flag | fNoLockFlag);
1889  if ( !bh1 ) {
1890  return false;
1891  }
1892  CBioseq_Handle bh2 = GetBioseqHandle(id2, get_flag | fNoLockFlag);
1893  return bh2 == bh1;
1894 }
1895 
1896 
1899  const CTSE_ScopeInfo* replaced_tse)
1900 {
1901  if ( !src_ds.m_EditDS ) {
1903  if ( !src_ds.m_EditDS ) {
1905  _ASSERT(ds->CanBeEdited());
1906  src_ds.m_EditDS = AddDSBefore(ds, Ref(&src_ds), replaced_tse);
1907  _ASSERT(src_ds.m_EditDS);
1908  _ASSERT(src_ds.m_EditDS->CanBeEdited());
1909  if ( src_ds.GetDataLoader() ) {
1911  }
1912  }
1913  }
1914  return src_ds.m_EditDS;
1915 }
1916 
1917 
1919 {
1920  _ASSERT(handle);
1921  if ( handle.CanBeEdited() ) {
1922  return handle;
1923  }
1925  if ( handle.CanBeEdited() ) {
1926  return handle;
1927  }
1928  CTSE_ScopeInfo& scope_info = handle.x_GetScopeInfo();
1929  CRef<CDataSource_ScopeInfo> old_ds_info(&scope_info.GetDSInfo());
1930  CRef<CDataSource_ScopeInfo> new_ds_info =
1931  GetEditDataSource(*old_ds_info, &scope_info);
1932  // load all missing information if split
1933  //scope_info.m_TSE_Lock->GetCompleteSeq_entry();
1934  CRef<CTSE_Info> old_tse(const_cast<CTSE_Info*>(&*scope_info.m_TSE_Lock));
1935  CRef<CTSE_Info> new_tse(new CTSE_Info(scope_info.m_TSE_Lock));
1936  CTSE_Lock new_tse_lock =
1937  new_ds_info->GetDataSource().AddStaticTSE(new_tse);
1938  scope_info.SetEditTSE(new_tse_lock, *new_ds_info);
1939  _ASSERT(handle.CanBeEdited());
1940  _ASSERT(!old_ds_info->CanBeEdited());
1941 
1942  // remove or mask original TSE
1943  CRef<CDataSource> old_ds(&old_ds_info->GetDataSource());
1944  if ( old_ds->GetSharedObject() ) {
1945  // remove old shared object
1946  _ASSERT(!old_ds->GetDataLoader());
1947  _VERIFY(m_setDataSrc.Erase(*old_ds_info));
1948  _VERIFY(m_DSMap.erase(old_ds));
1949  old_ds.Reset();
1950  old_ds_info->DetachScope();
1951  }
1952  else if ( old_ds_info->IsConst() ) {
1953  _ASSERT(!old_ds->GetDataLoader());
1954  const_cast<CTSE_Info&>(*new_tse_lock).m_BaseTSE.reset();
1955  _VERIFY(old_ds->DropStaticTSE(*old_tse));
1956  }
1957  else {
1958  scope_info.ReplaceTSE(*old_tse);
1959  }
1960  return handle;
1961 }
1962 
1963 
1965 {
1969  return CBioseq_EditHandle(h);
1970 }
1971 
1972 
1974 {
1978  return CSeq_entry_EditHandle(h);
1979 }
1980 
1981 
1983 {
1987  return CSeq_annot_EditHandle(h);
1988 }
1989 
1990 
1992 {
1996  return CBioseq_set_EditHandle(h);
1997 }
1998 
1999 
2002  const CTSE_Handle& tse)
2003 {
2004  CBioseq_Handle ret;
2005  if ( tse ) {
2006  ret = x_GetBioseqHandleFromTSE(id, tse);
2007  }
2008  return ret;
2009 }
2010 
2011 
2013 {
2014  CBioseq_Handle bh;
2015  TSeq_idSet ids;
2016  for (CSeq_loc_CI citer(loc); citer; ++citer) {
2017  ids.insert(citer.GetSeq_id_Handle());
2018  }
2019  if ( ids.empty() ) {
2020  // No ids found
2021  return bh;
2022  }
2023 
2024  // Find at least one bioseq handle
2025  ITERATE(TSeq_idSet, id, ids) {
2026  bh = GetBioseqHandle(*ids.begin(), get_flag);
2027  if ( bh ) {
2028  break;
2029  }
2030  }
2031  if ( !bh ) {
2032  if (ids.size() == 1) {
2033  return bh;
2034  }
2035  // Multiple unresolvable ids
2036  NCBI_THROW(CObjMgrException, eFindFailed,
2037  "CScope_Impl::GetBioseqHandle: "
2038  "Seq-loc references multiple unresolvable seq-ids");
2039  }
2040 
2041  const CTSE_Info& tse = bh.GetTSE_Handle().x_GetTSE_Info();
2043 
2044  bool valid = true;
2045  if ( master ) {
2047  // Segmented set - check if all ids are parts of the segset,
2048  // return master sequence.
2049  ITERATE(TSeq_idSet, id, ids) {
2050  if (segs->FindSeg(*id) < 0) {
2051  if (ids.size() > 1) {
2052  valid = false;
2053  }
2054  else {
2055  // Allow a single bioseq which is not a segment (it can be
2056  // the master sequence or a standalone sequence).
2057  master.Reset();
2058  }
2059  break;
2060  }
2061  }
2062  if (valid && master) {
2063  bh = GetBioseqHandle(*master, bh.GetTSE_Handle());
2064  }
2065  }
2066  else if (ids.size() > 1) {
2067  // Multiple ids, not a segset.
2068  valid = false;
2069  }
2070 
2071  if ( !valid ) {
2072  NCBI_THROW(CObjMgrException, eFindFailed,
2073  "CScope_Impl::GetBioseqHandle: "
2074  "Seq-loc references multiple seq-ids");
2075  }
2076 
2077  return bh;
2078 }
2079 
2080 
2082  const CTSE_Handle& tse)
2083 {
2084  CBioseq_Handle ret;
2085  {{
2087  ret = x_GetBioseqHandle(seq, tse);
2088  }}
2089  return ret;
2090 }
2091 
2092 
2094  const CTSE_Handle& tse)
2095 {
2096  CBioseq_Handle ret;
2097  ret.m_Info = tse.x_GetScopeInfo().GetBioseqLock(null, ConstRef(&seq));
2098  x_UpdateHandleSeq_id(ret);
2099  return ret;
2100 }
2101 
2102 
2104 {
2105  if ( 1 || bh.m_Handle_Seq_id ) {
2106  return;
2107  }
2108  ITERATE ( CBioseq_Handle::TId, id, bh.GetId() ) {
2110  if ( bh2 && &bh2.x_GetInfo() == &bh.x_GetInfo() ) {
2111  bh.m_Handle_Seq_id = *id;
2112  return;
2113  }
2114  }
2115 }
2116 
2117 
2119  const CSeq_id_Handle& idh,
2120  int get_flag)
2121 {
2122  SSeqMatch_Scope ret;
2123  // Process sub-tree
2124  TPriority last_priority = 0;
2125  ITERATE( CPriorityTree::TPriorityMap, mit, tree.GetTree() ) {
2126  // Search in all nodes of the same priority regardless
2127  // of previous results
2128  TPriority new_priority = mit->first;
2129  if ( new_priority != last_priority ) {
2130  // Don't process lower priority nodes if something
2131  // was found
2132  if ( ret ) {
2133  break;
2134  }
2135  last_priority = new_priority;
2136  }
2137  SSeqMatch_Scope new_ret = x_FindBioseqInfo(mit->second, idh, get_flag);
2138  if ( new_ret ) {
2139  _ASSERT(&new_ret.m_TSE_Lock->GetScopeImpl() == this);
2140  if ( ret && ret.m_Bioseq != new_ret.m_Bioseq &&
2141  ret.m_TSE_Lock->CanBeEdited() == new_ret.m_TSE_Lock->CanBeEdited() ) {
2143  ret.m_Bioseq.Reset();
2144  return ret;
2145  }
2146  if ( !ret || new_ret.m_TSE_Lock->CanBeEdited() ) {
2147  ret = new_ret;
2148  }
2149  }
2150  else if (new_ret.m_BlobState != 0) {
2151  // Remember first blob state
2152  if (!ret && ret.m_BlobState == 0) {
2153  ret = new_ret;
2154  }
2155  }
2156  }
2157  return ret;
2158 }
2159 
2160 
2162  const CSeq_id_Handle& idh,
2163  int get_flag)
2164 {
2165  _ASSERT(&ds_info.GetScopeImpl() == this);
2166  try {
2168  return ds_info.BestResolve(idh, get_flag);
2169  }
2170  catch (CBlobStateException& e) {
2171  SSeqMatch_Scope ret;
2172  ret.m_BlobState = e.GetBlobState();
2173  return ret;
2174  }
2175 }
2176 
2177 
2179  const CSeq_id_Handle& idh,
2180  int get_flag)
2181 {
2182  SSeqMatch_Scope ret;
2183  if ( node.IsTree() ) {
2184  // Process sub-tree
2185  ret = x_FindBioseqInfo(node.GetTree(), idh, get_flag);
2186  }
2187  else if ( node.IsLeaf() ) {
2188  CDataSource_ScopeInfo& ds_info =
2189  const_cast<CDataSource_ScopeInfo&>(node.GetLeaf());
2190  ret = x_FindBioseqInfo(ds_info, idh, get_flag);
2191  }
2192  return ret;
2193 }
2194 
2195 
2197  int get_flag,
2199 {
2200  // Use priority, do not scan all DSs - find the first one.
2201  // Protected by m_ConfLock in upper-level functions
2202  match = x_FindBioseqInfo(m_setDataSrc, id_info.first, get_flag);
2203  if ( !match ) {
2204  // Map unresoved ids only if loading was requested
2205  if (get_flag == CScope::eGetBioseq_All) {
2206  CRef<CBioseq_ScopeInfo> bioseq;
2207  if ( !id_info.second.m_Bioseq_Info ) {
2208  // first time
2209  bioseq = new CBioseq_ScopeInfo(match.m_BlobState, m_BioseqChangeCounter);
2210  id_info.second.m_Bioseq_Info = bioseq;
2211  }
2212  else {
2213  // update unresolved state
2214  bioseq = id_info.second.m_Bioseq_Info;
2215  bioseq->SetUnresolved(match.m_BlobState, m_BioseqChangeCounter);
2216  }
2217  _ASSERT(!bioseq->HasBioseq());
2218  }
2219  }
2220  else {
2221  CTSE_ScopeInfo& tse_info = *match.m_TSE_Lock;
2222  _ASSERT(&tse_info.GetScopeImpl() == this);
2223  // resolved
2224  CRef<CBioseq_ScopeInfo> bioseq = tse_info.GetBioseqInfo(match);
2225  _ASSERT(&bioseq->x_GetScopeImpl() == this);
2226  id_info.second.m_Bioseq_Info = bioseq;
2227  _ASSERT(bioseq->HasBioseq());
2228  }
2229 }
2230 
2231 
2233  TTSE_LockMatchSet& lock)
2234 {
2235  {{
2238  SSeqMatch_Scope seq_match;
2239  CRef<CBioseq_ScopeInfo> binfo =
2241  if ( binfo->HasBioseq() ) {
2242  x_GetTSESetWithAnnots(lock, *binfo);
2243  }
2244  else {
2245  x_GetTSESetWithAnnots(lock, info);
2246  }
2247  }}
2248 }
2249 
2250 
2252  TTSE_LockMatchSet& lock)
2253 {
2254  if ( bh ) {
2257  (&const_cast<CBioseq_ScopeInfo&>(bh.x_GetScopeInfo()));
2258 
2259  _ASSERT(binfo->HasBioseq());
2260  x_GetTSESetWithAnnots(lock, *binfo);
2261  }
2262 }
2263 
2264 
2266  TTSE_LockMatchSet& lock,
2267  const SAnnotSelector& sel)
2268 {
2271  SSeqMatch_Scope seq_match;
2272  CRef<CBioseq_ScopeInfo> binfo =
2274  if ( binfo->HasBioseq() ) {
2275  x_GetTSESetWithAnnots(lock, *binfo, &sel);
2276  }
2277  else {
2278  x_GetTSESetWithAnnots(lock, info, &sel);
2279  }
2280 }
2281 
2282 
2284  TTSE_LockMatchSet& lock,
2285  const SAnnotSelector& sel)
2286 {
2287  if ( bh ) {
2290  (&const_cast<CBioseq_ScopeInfo&>(bh.x_GetScopeInfo()));
2291 
2292  _ASSERT(binfo->HasBioseq());
2293  x_GetTSESetWithAnnots(lock, *binfo, &sel);
2294  }
2295 }
2296 
2297 
2302 {
2303  if ( sel && sel->IsIncludedAnyNamedAnnotAccession() ) {
2305  const auto& accs = sel->GetNamedAnnotAccessions();
2306  int adjust = 0;
2307  if (accs.find("SNP") != accs.end() && sel->GetSNPScaleLimit() != CSeq_id::eSNPScaleLimit_Default) {
2308  adjust = sel->GetSNPScaleLimit();
2309  }
2310  return na_info[{sel->GetNamedAnnotAccessions(), adjust}];
2311  }
2312  else {
2313  return main_info;
2314  }
2315 }
2316 
2317 
2319  CBioseq_ScopeInfo& binfo,
2320  const SAnnotSelector* sel)
2321 {
2322  CBioseq_ScopeInfo::TAnnotRefInfo& annot_ref_info =
2324  {{
2325  CInitGuard init(annot_ref_info, m_MutexPool, CInitGuard::force);
2326  if ( init ||
2327  (annot_ref_info->m_SearchTimestamp !=
2329  CRef<CBioseq_ScopeInfo::SAnnotSetCache> cache = annot_ref_info;
2330  if ( !cache ) {
2332  }
2333  else {
2334  cache->match.clear();
2335  }
2336  x_GetTSESetWithAnnots(lock, &cache->match, binfo, sel);
2337  cache->m_SearchTimestamp = m_AnnotChangeCounter+binfo.GetObjectInfo().m_IdChangeCounter;
2338  annot_ref_info = cache;
2339  return;
2340  }
2341  }}
2342  // use cached set
2343  x_LockMatchSet(lock, annot_ref_info->match);
2344 
2345 #ifdef EXCLUDE_EDITED_BIOSEQ_ANNOT_SET
2346  if ( binfo.x_GetTSE_ScopeInfo().CanBeEdited() ) {
2347  x_GetTSESetWithBioseqAnnots(lock, binfo, sel);
2348  return;
2349  }
2350 #endif
2351 }
2352 
2353 
2356  const SAnnotSelector* sel)
2357 {
2358  CBioseq_ScopeInfo::TAnnotRefInfo& annot_ref_info =
2359  x_GetAnnotRef_Info(sel, info.second.m_AllAnnotRef_Info, info.second.m_NAAllAnnotRef_Info);
2360  {{
2361  CInitGuard init(annot_ref_info, m_MutexPool, CInitGuard::force);
2362  if ( init || annot_ref_info->m_SearchTimestamp != m_AnnotChangeCounter ) {
2363  CRef<CBioseq_ScopeInfo::SAnnotSetCache> cache = annot_ref_info;
2364  if ( !cache ) {
2366  }
2367  else {
2368  cache->match.clear();
2369  }
2370  x_GetTSESetWithAnnots(lock, &cache->match, info, sel);
2371  cache->m_SearchTimestamp = m_AnnotChangeCounter.load();
2372  annot_ref_info = cache;
2373  return;
2374  }
2375  }}
2376  // use cached set
2377  x_LockMatchSet(lock, annot_ref_info->match);
2378 }
2379 
2380 
2382  TTSE_MatchSet* save_match,
2383  CBioseq_ScopeInfo& binfo,
2384  const SAnnotSelector* sel)
2385 {
2386  x_GetTSESetWithBioseqAnnots(lock, save_match, binfo, sel);
2387 }
2388 
2389 
2391  TTSE_MatchSet* save_match,
2393  const SAnnotSelector* sel)
2394 {
2396  info.first.GetReverseMatchingHandles(ids);
2397  x_GetTSESetWithOrphanAnnots(lock, save_match, ids, 0, sel);
2398 }
2399 
2400 
2402  TTSE_MatchSet* save_match,
2403  const TTSE_LockMatchSet_DS& add,
2404  CDataSource_ScopeInfo& ds_info,
2405  CDataLoader::TProcessedNAs* filter_nas)
2406 {
2407  lock.reserve(lock.size()+add.size());
2408  if ( save_match ) {
2409  save_match->reserve(save_match->size()+add.size());
2410  }
2411  ITERATE( TTSE_LockMatchSet_DS, it, add ) {
2412  if ( filter_nas &&
2413  it->first->GetName().IsNamed() &&
2414  filter_nas->count(it->first->GetName().GetName()) ) {
2415  // filter out this name
2416  continue;
2417  }
2418  TTSE_Lock tse_lock = x_GetTSE_Lock(it->first, ds_info);
2419  if ( !tse_lock ) {
2420  continue;
2421  }
2422  CTSE_Handle tse(*tse_lock);
2423  CTSE_ScopeInfo& tse_info = tse.x_GetScopeInfo();
2424  if ( save_match ) {
2425  save_match->push_back(TTSE_MatchSet::value_type(Ref(&tse_info),
2426  it->second));
2427  }
2428  lock.push_back(pair<CTSE_Handle, CSeq_id_Handle>(tse, it->second));
2429  }
2430 }
2431 
2432 
2434  const TTSE_MatchSet& match)
2435 {
2436  size_t size = match.size();
2437  lock.resize(size);
2438  for ( size_t i = 0; i < size; ++i ) {
2439  lock[i].first = *x_GetTSE_Lock(*match[i].first);
2440  lock[i].second = match[i].second;
2441  }
2442 }
2443 
2444 
2446  unique_ptr<SAnnotSelector>& sel_copy,
2447  CDataLoader::TProcessedNAs& filter_nas,
2448  CDataLoader::TProcessedNAs& processed_nas)
2449 {
2450  if ( !processed_nas.empty() ) {
2451  if ( sel && !sel_copy ) {
2452  sel_copy.reset(new SAnnotSelector(*sel));
2453  sel = sel_copy.get();
2454  }
2455  for ( auto& na : processed_nas ) {
2456  if ( sel_copy ) {
2457  sel_copy->ExcludeNamedAnnotAccession(na);
2458  }
2459  filter_nas.insert(na);
2460  }
2461  processed_nas.clear();
2462  }
2463 }
2464 
2465 
2467  TTSE_MatchSet* save_match,
2468  const TSeq_idSet& ids,
2469  CBioseq_ScopeInfo* binfo,
2470  const SAnnotSelector* sel)
2471 {
2472  TBioseq_Lock bioseq;
2473  CDataSource_ScopeInfo* excl_ds = 0;
2474  if ( binfo ) {
2475  bioseq = binfo->GetLock(null);
2476  excl_ds = &binfo->x_GetTSE_ScopeInfo().GetDSInfo();
2477  }
2478 
2479  unique_ptr<SAnnotSelector> sel_copy;
2480  CDataLoader::TProcessedNAs processed_nas, filter_nas;
2481 
2482  for (CPriority_I it(m_setDataSrc); it; ++it) {
2484  if ( &*it == excl_ds ) {
2485  // skip non-orphan annotations
2486  continue;
2487  }
2488  CDataSource& ds = it->GetDataSource();
2489  TTSE_LockMatchSet_DS ds_lock;
2490  if ( excl_ds && it->m_EditDS == excl_ds &&
2492  // add external annotations for edited sequences
2493  ds.GetTSESetWithExternalAnnots(bioseq->GetObjectInfo(),
2494  binfo->x_GetTSE_ScopeInfo().m_TSE_Lock,
2495  ds_lock, sel, &processed_nas);
2496  }
2497  else {
2498  ds.GetTSESetWithOrphanAnnots(ids, ds_lock, sel, &processed_nas);
2499  }
2500  x_AddTSESetWithAnnots(lock, save_match, ds_lock, *it, &filter_nas);
2501  x_UpdateProcessedNAs(sel, sel_copy, filter_nas, processed_nas);
2502  }
2503 }
2504 
2505 
2507  TTSE_MatchSet* save_match,
2508  CBioseq_ScopeInfo& binfo,
2509  const SAnnotSelector* sel)
2510 {
2511  TBioseq_Lock bioseq = binfo.GetLock(null);
2512  CDataSource_ScopeInfo* ds_info = &binfo.x_GetTSE_ScopeInfo().GetDSInfo();
2513 
2514  unique_ptr<SAnnotSelector> sel_copy;
2515  CDataLoader::TProcessedNAs processed_nas, filter_nas;
2516 
2517  // orphan annotations on all synonyms of Bioseq
2518  TSeq_idSet ids;
2519  if ( m_setDataSrc.HasSeveralNodes() ) {
2520  // collect ids
2521  CConstRef<CSynonymsSet> syns = x_GetSynonyms(binfo);
2522  ITERATE ( CSynonymsSet, syn_it, *syns ) {
2523  // CSynonymsSet already contains all matching ids
2524  ids.insert(syns->GetSeq_id_Handle(syn_it));
2525  }
2526  }
2527 
2528  // add all annots
2529  for (CPriority_I it(m_setDataSrc); it; ++it) {
2531 
2532  CDataSource& ds = it->GetDataSource();
2533  TTSE_LockMatchSet_DS ds_lock;
2534 
2535  if ( &*it == ds_info ) {
2536  // load from
2537  ds_info->GetDataSource()
2538  .GetTSESetWithBioseqAnnots(bioseq->GetObjectInfo(),
2539  bioseq->x_GetTSE_ScopeInfo().m_TSE_Lock,
2540  ds_lock, sel, &processed_nas);
2541  }
2542  if ( it->m_EditDS == ds_info ) {
2543  // edited sequence
2544  if ( GetKeepExternalAnnotsForEdit() ) {
2545  // add external annotations for edited sequences
2546  ds.GetTSESetWithExternalAnnots(bioseq->GetObjectInfo(),
2548  ds_lock, sel, &processed_nas);
2549  }
2550  else {
2551  // skip external annotations for edited sequences
2552  continue;
2553  }
2554  }
2555  else {
2556  ds.GetTSESetWithOrphanAnnots(ids, ds_lock, sel, &processed_nas);
2557  }
2558  x_AddTSESetWithAnnots(lock, save_match, ds_lock, *it, &filter_nas);
2559  x_UpdateProcessedNAs(sel, sel_copy, filter_nas, processed_nas);
2560  }
2561  sort(lock.begin(), lock.end());
2562  lock.erase(unique(lock.begin(), lock.end()), lock.end());
2563 }
2564 
2565 
2567  CBioseq_ScopeInfo& binfo,
2568  const SAnnotSelector* sel)
2569 {
2570  CDataSource_ScopeInfo& ds_info = binfo.x_GetTSE_ScopeInfo().GetDSInfo();
2571 
2572  // datasource annotations on all ids of Bioseq
2573  // add external annots
2574  TBioseq_Lock bioseq = binfo.GetLock(null);
2575  TTSE_LockMatchSet_DS ds_lock;
2576  ds_info.GetDataSource()
2577  .GetTSESetWithBioseqAnnots(bioseq->GetObjectInfo(),
2578  bioseq->x_GetTSE_ScopeInfo().m_TSE_Lock,
2579  ds_lock, sel);
2580  x_AddTSESetWithAnnots(lock, 0, ds_lock, ds_info);
2581  sort(lock.begin(), lock.end());
2582  lock.erase(unique(lock.begin(), lock.end()), lock.end());
2583 }
2584 
2585 
2586 void CScope_Impl::RemoveFromHistory(const CTSE_Handle& tse, int action)
2587 {
2588  if ( !tse ) {
2589  return;
2590  }
2592  if ( !tse ) {
2593  return;
2594  }
2595  CTSE_ScopeInfo::RemoveFromHistory(tse, action);
2596  if ( !tse ) {
2597  // removed
2599  }
2600  else {
2601  _ASSERT(action == CScope::eKeepIfLocked);
2602  }
2603 }
2604 
2605 
2607 {
2608  if ( !seq_id ) {
2609  return;
2610  }
2612  // Clear removed bioseq handles
2613  TSeq_idMap::iterator it = m_Seq_idMap.find(seq_id);
2614  if ( it != m_Seq_idMap.end() ) {
2615  it->second.x_ResetAnnotRef_Info();
2616  if ( it->second.m_Bioseq_Info ) {
2617  CBioseq_ScopeInfo& binfo = *it->second.m_Bioseq_Info;
2618  binfo.x_ResetAnnotRef_Info();
2619  if ( binfo.IsDetached() ) {
2620  binfo.m_SynCache.Reset();
2621  m_Seq_idMap.erase(it);
2622  }
2623  }
2624  }
2625 }
2626 
2627 
2629 {
2631  NON_CONST_ITERATE ( TDSMap, it, m_DSMap ) {
2632  it->second->ResetHistory(action);
2633  }
2635  //m_Seq_idMap.clear();
2636 }
2637 
2638 
2640 {
2642  NON_CONST_ITERATE ( TDSMap, it, m_DSMap ) {
2643  it->second->ResetHistory(CScope::eRemoveIfLocked);
2644  }
2646  m_Seq_idMap.clear();
2647  NON_CONST_ITERATE ( TDSMap, it, m_DSMap ) {
2648  CDataSource_ScopeInfo& ds_info = *it->second;
2649  if ( ds_info.IsConst() || ds_info.CanBeEdited() ) {
2650  ds_info.ResetDS();
2651  ds_info.GetDataSource().DropAllTSEs();
2652  }
2653  }
2654 }
2655 
2656 
2658 {
2660 
2661  while ( !m_DSMap.empty() ) {
2662  TDSMap::iterator iter = m_DSMap.begin();
2663  CRef<CDataSource_ScopeInfo> ds_info(iter->second);
2664  m_DSMap.erase(iter);
2665  ds_info->DetachScope();
2666  }
2667  m_setDataSrc.Clear();
2668  m_Seq_idMap.clear();
2669 }
2670 
2671 
2673  TBioseq_HandleSet& handles,
2674  CSeq_inst::EMol filter,
2675  TBioseqLevelFlag level)
2676 {
2677  if ( seh ) {
2679  const CSeq_entry_Info& info = seh.x_GetInfo();
2681  info.GetDataSource().GetBioseqs(info, info_set, filter, level);
2682  // Convert each bioseq info into bioseq handle
2683  ITERATE (CDataSource::TBioseq_InfoSet, iit, info_set) {
2684  CBioseq_Handle bh = x_GetBioseqHandle(**iit, seh.GetTSE_Handle());
2685  if ( bh ) {
2686  handles.push_back(bh);
2687  }
2688  }
2689  }
2690 }
2691 
2693 {
2694  return GetSequenceType(id,0) != CSeq_inst::eMol_not_set;
2695 }
2696 
2698  TGetFlags flags)
2699 {
2700  if ( !idh ) {
2701  NCBI_THROW(CObjMgrException, eInvalidHandle,
2702  "CScope::GetIds(): null Seq-id handle");
2703  }
2704 
2706 
2707  if ( !(flags & CScope::fForceLoad) ) {
2708  // Look in existing resolution information
2712  if ( info && info->HasBioseq() ) {
2713  // sequence is already loaded
2714  return info->GetIds();
2715  }
2716  }
2717 
2718  for (CPriority_I it(m_setDataSrc); it; ++it) {
2720  TIds ret;
2721  it->GetDataSource().GetIds(idh, ret);
2722  if ( !ret.empty() ) {
2723  return ret;
2724  }
2725  }
2726 
2727  // the sequence is not found
2729  NCBI_THROW_FMT(CObjMgrException, eFindFailed,
2730  "CScope::GetIds("<<idh<<"): sequence not found");
2731  }
2732  return TIds();
2733 }
2734 
2735 
2737  TGetFlags flags)
2738 {
2739  if ( !idh ) {
2740  NCBI_THROW(CObjMgrException, eInvalidHandle,
2741  "CScope::GetAccVer(): null Seq-id handle");
2742  }
2743 
2744  if ( !(flags & CScope::fForceLoad) ) {
2745  if ( idh.IsAccVer() ) {
2746  return idh;
2747  }
2748  }
2749 
2751 
2752  if ( !(flags & CScope::fForceLoad) ) {
2756  if ( info && info->HasBioseq() ) {
2757  // sequence is already loaded
2758  CSeq_id_Handle ret = CScope::x_GetAccVer(info->GetIds());
2759  if ( !ret && (flags & CScope::fThrowOnMissingData) ) {
2760  // no accession on the sequence
2761  NCBI_THROW_FMT(CObjMgrException, eMissingData,
2762  "CScope::GetAccVer("<<idh<<"): no accession");
2763  }
2764  return ret;
2765  }
2766  }
2767 
2768  for (CPriority_I it(m_setDataSrc); it; ++it) {
2770  CDataSource::SAccVerFound data = it->GetDataSource().GetAccVer(idh);
2771  if ( data.sequence_found ) {
2772  // sequence is found
2773  if ( !data.acc_ver && (flags & CScope::fThrowOnMissingData) ) {
2774  // no accession on the sequence
2775  NCBI_THROW_FMT(CObjMgrException, eMissingData,
2776  "CScope::GetAccVer("<<idh<<"): no accession");
2777  }
2778  return data.acc_ver;
2779  }
2780  }
2781 
2782  // the sequence is not found
2784  NCBI_THROW_FMT(CObjMgrException, eFindFailed,
2785  "CScope::GetAccVer("<<idh<<"): sequence not found");
2786  }
2787  return null;
2788 }
2789 
2790 
2792  TGetFlags flags)
2793 {
2794  if ( !idh ) {
2795  NCBI_THROW(CObjMgrException, eInvalidHandle,
2796  "CScope::GetGi(): null Seq-id handle");
2797  }
2798 
2800 
2801  if ( !(flags & CScope::fForceLoad) ) {
2805  if ( info && info->HasBioseq() ) {
2806  // sequence is already loaded
2807  TGi ret = CScope::x_GetGi(info->GetIds());
2808  if ( ret != ZERO_GI && (flags & CScope::fThrowOnMissingData) ) {
2809  // no GI on the sequence
2810  NCBI_THROW_FMT(CObjMgrException, eMissingData,
2811  "CScope::GetGi("<<idh<<"): no GI");
2812  }
2813  return ret;
2814  }
2815  }
2816 
2817  for (CPriority_I it(m_setDataSrc); it; ++it) {
2819  CDataSource::SGiFound data = it->GetDataSource().GetGi(idh);
2820  if ( data.sequence_found ) {
2821  // sequence is found
2822  if ( data.gi == ZERO_GI && (flags & CScope::fThrowOnMissingData) ) {
2823  // no accession on the sequence
2824  NCBI_THROW_FMT(CObjMgrException, eMissingData,
2825  "CScope::GetGi("<<idh<<"): no GI");
2826  }
2827  return data.gi;
2828  }
2829  }
2830 
2832  NCBI_THROW_FMT(CObjMgrException, eFindFailed,
2833  "CScope::GetGi("<<idh<<"): sequence not found");
2834  }
2835  return ZERO_GI;
2836 }
2837 
2838 
2840 {
2841  if ( !idh ) {
2842  NCBI_THROW(CObjMgrException, eInvalidHandle,
2843  "CScope::GetLabel(): null Seq-id handle");
2844  }
2845 
2846  if ( !(flags & CScope::fForceLoad) ) {
2847  string ret = GetDirectLabel(idh);
2848  if ( !ret.empty() ) {
2849  return ret;
2850  }
2851  }
2852 
2854 
2855  if ( !(flags & CScope::fForceLoad) ) {
2859  if ( info && info->HasBioseq() ) {
2860  return objects::GetLabel(info->GetIds());
2861  }
2862  }
2863 
2864  // Unknown bioseq, try to find in data sources
2865  for (CPriority_I it(m_setDataSrc); it; ++it) {
2866  string ret = it->GetDataSource().GetLabel(idh);
2867  if ( !ret.empty() ) {
2868  return ret;
2869  }
2870  }
2871 
2873  NCBI_THROW(CObjMgrException, eFindFailed,
2874  "CScope::GetLabel(): sequence not found");
2875  }
2876  return string();
2877 }
2878 
2879 
2881 {
2882  if ( !idh ) {
2883  NCBI_THROW(CObjMgrException, eInvalidHandle,
2884  "CScope::GetTaxId(): null Seq-id handle");
2885  }
2886 
2887  if ( !(flags & CScope::fForceLoad) ) {
2888  if ( idh.Which() == CSeq_id::e_General ) {
2889  CConstRef<CSeq_id> id = idh.GetSeqId();
2890  const CDbtag& dbtag = id->GetGeneral();
2891  const CObject_id& obj_id = dbtag.GetTag();
2892  if ( obj_id.IsId() && dbtag.GetDb() == "TAXID" ) {
2893  return TAX_ID_FROM(int, obj_id.GetId());
2894  }
2895  }
2896  }
2897 
2899 
2900  if ( !(flags & CScope::fForceLoad) ) {
2904  if ( info && info->HasBioseq() ) {
2905  TBioseq_Lock bioseq = info->GetLock(null);
2906  TTaxId ret = info->GetObjectInfo().GetTaxId();
2907  if ( ret == ZERO_TAX_ID && (flags & CScope::fThrowOnMissingData) ) {
2908  // no TaxID on the sequence
2909  NCBI_THROW_FMT(CObjMgrException, eMissingData,
2910  "CScope::GetTaxId("<<idh<<"): no TaxID");
2911  }
2912  return ret;
2913  }
2914  }
2915 
2916  for (CPriority_I it(m_setDataSrc); it; ++it) {
2917  TTaxId ret = it->GetDataSource().GetTaxId(idh);
2918  if ( ret != INVALID_TAX_ID ) {
2919  if ( ret == ZERO_TAX_ID && (flags & CScope::fThrowOnMissingData) ) {
2920  // no TaxID on the sequence
2921  NCBI_THROW_FMT(CObjMgrException, eMissingData,
2922  "CScope::GetTaxId("<<idh<<"): no TaxID");
2923  }
2924  return ret;
2925  }
2926  }
2927 
2929  NCBI_THROW_FMT(CObjMgrException, eFindFailed,
2930  "CScope::GetTaxId("<<idh<<"): sequence not found");
2931  }
2932  return INVALID_TAX_ID;
2933 }
2934 
2935 
2937  TGetFlags flags)
2938 {
2939  if ( !idh ) {
2940  NCBI_THROW(CObjMgrException, eInvalidHandle,
2941  "CScope::GetSequenceLength(): null Seq-id handle");
2942  }
2943 
2945 
2946  if ( !(flags & CScope::fForceLoad) ) {
2950  if ( info && info->HasBioseq() ) {
2951  TBioseq_Lock bioseq = info->GetLock(null);
2952  return info->GetObjectInfo().GetBioseqLength();
2953  }
2954  }
2955 
2956  for (CPriority_I it(m_setDataSrc); it; ++it) {
2958  TSeqPos length = it->GetDataSource().GetSequenceLength(idh);
2959  if ( length != kInvalidSeqPos ) {
2960  return length;
2961  }
2962  }
2963 
2965  NCBI_THROW_FMT(CObjMgrException, eFindFailed,
2966  "CScope::GetSequenceLength("<<idh<<"): "
2967  "sequence not found");
2968  }
2969  return kInvalidSeqPos;
2970 }
2971 
2972 
2974  TGetFlags flags)
2975 {
2976  if ( !idh ) {
2977  NCBI_THROW(CObjMgrException, eInvalidHandle,
2978  "CScope::GetSequenceType(): null Seq-id handle");
2979  }
2980 
2982 
2983  if ( !(flags & CScope::fForceLoad) ) {
2987  if ( info && info->HasBioseq() ) {
2988  TBioseq_Lock bioseq = info->GetLock(null);
2989  return info->GetObjectInfo().GetInst_Mol();
2990  }
2991  }
2992 
2993  for (CPriority_I it(m_setDataSrc); it; ++it) {
2995  CDataSource::STypeFound ret = it->GetDataSource().GetSequenceType(idh);
2996  if ( ret.sequence_found ) {
2997  return ret.type;
2998  }
2999  }
3000 
3002  NCBI_THROW_FMT(CObjMgrException, eFindFailed,
3003  "CScope::GetSequenceType("<<idh<<"): "
3004  "sequence not found");
3005  }
3006  return CSeq_inst::eMol_not_set;
3007 }
3008 
3009 
3011  TGetFlags flags)
3012 {
3013  if ( !idh ) {
3014  NCBI_THROW(CObjMgrException, eInvalidHandle,
3015  "CScope::GetSequenceState(): null Seq-id handle");
3016  }
3017 
3019 
3020  if ( !(flags & CScope::fForceLoad) ) {
3024  if ( info && info->HasBioseq() ) {
3025  return info->GetBlobState();
3026  }
3027  }
3028 
3029  for (CPriority_I it(m_setDataSrc); it; ++it) {
3031  int state = it->GetDataSource().GetSequenceState(idh);
3033  return state;
3034  }
3035  }
3036 
3038  NCBI_THROW_FMT(CObjMgrException, eFindFailed,
3039  "CScope::GetSequenceState("<<idh<<"): "
3040  "sequence not found");
3041  }
3043 }
3044 
3045 
3046 static
3048 {
3050  CSeqVector sv(bh, bh.eCoding_Iupac);
3051  for ( CSeqVector_CI it(sv); it; ) {
3052  TSeqPos size = it.GetBufferSize();
3053  sum.AddChars(it.GetBufferPtr(), size);
3054  it += size;
3055  }
3056  return sum.GetChecksum();
3057 }
3058 
3059 
3061 {
3062  if ( !idh ) {
3063  NCBI_THROW(CObjMgrException, eInvalidHandle,
3064  "CScope::GetSequenceState(): null Seq-id handle");
3065  }
3066 
3068 
3069  bool found = false;
3070  for (CPriority_I it(m_setDataSrc); it; ++it) {
3073  it->GetDataSource().GetSequenceHash(idh);
3074  if ( data.sequence_found ) {
3075  if ( data.hash_known ) {
3076  // known by loader
3077  return data.hash;
3078  }
3079  else {
3080  // not known but may be recalculated
3081  // sequence is found so no more loaders to ask
3082  found = true;
3083  break;
3084  }
3085  }
3086  }
3087 
3088  if ( found && !(flags & CScope::fDoNotRecalculate) ) {
3090  if ( bh ) {
3091  return sx_CalcHash(bh);
3092  }
3093  // failure to find the sequence again
3094  found = false;
3095  }
3096  if ( found ) {
3097  if ( (flags & CScope::fThrowOnMissingData) ) {
3098  NCBI_THROW_FMT(CObjMgrException, eMissingData,
3099  "CScope::GetSequenceHash("<<idh<<"): no hash");
3100  }
3101  return 0;
3102  }
3103 
3105  NCBI_THROW_FMT(CObjMgrException, eFindFailed,
3106  "CScope::GetSequenceHash("<<idh<<"): "
3107  "sequence not found");
3108  }
3109  return 0;
3110 }
3111 
3112 
3114  int get_flag)
3115 {
3116  _ASSERT(id);
3120  if ( !info ) {
3121  return CConstRef<CSynonymsSet>(0);
3122  }
3123  return x_GetSynonyms(*info);
3124 }
3125 
3126 
3128 {
3129  if ( !bh ) {
3130  return CConstRef<CSynonymsSet>();
3131  }
3133  return x_GetSynonyms(const_cast<CBioseq_ScopeInfo&>(bh.x_GetScopeInfo()));
3134 }
3135 
3136 
3138  CSynonymsSet& syn_set,
3140 {
3141  // Check current ID for conflicts, add to the set.
3142  TSeq_idMapValue& seq_id_info = x_GetSeq_id_Info(idh);
3143  if ( x_InitBioseq_Info(seq_id_info, info) ) {
3144  // the same bioseq - add synonym
3145  if ( !syn_set.ContainsSynonym(seq_id_info.first) ) {
3146  syn_set.AddSynonym(seq_id_info.first);
3147  }
3148  }
3149  else {
3150  CRef<CBioseq_ScopeInfo> info2 = seq_id_info.second.m_Bioseq_Info;
3151  _ASSERT(info2 != &info);
3152  ERR_POST_X(17, Warning << "CScope::GetSynonyms: "
3153  "Bioseq["<<info.IdString()<<"]: "
3154  "id "<<idh.AsString()<<" is resolved to another "
3155  "Bioseq["<<info2->IdString()<<"]");
3156  }
3157 }
3158 
3159 
3162 {
3163  CInitGuard init(info.m_SynCache, m_MutexPool);
3164  if ( init ) {
3165  // It's OK to use CRef, at least one copy should be kept
3166  // alive by the id cache (for the ID requested).
3167  CRef<CSynonymsSet> syn_set(new CSynonymsSet);
3168  //syn_set->AddSynonym(id);
3169  if ( info.HasBioseq() ) {
3170  ITERATE ( CBioseq_ScopeInfo::TIds, it, info.GetIds() ) {
3171  if ( it->HaveReverseMatch() ) {
3173  it->GetReverseMatchingHandles(hset);
3174  ITERATE ( CSeq_id_Handle::TMatches, mit, hset ) {
3175  x_AddSynonym(*mit, *syn_set, info);
3176  }
3177  }
3178  else {
3179  x_AddSynonym(*it, *syn_set, info);
3180  }
3181  if ( it->IsAccVer() ) {
3182  // add no-name and no-release version of Seq-id explicitly
3183  auto seq_id = it->GetSeqId();
3184  auto text_id = seq_id->GetTextseq_Id();
3185  if ( text_id->IsSetAccession() &&
3186  (text_id->IsSetName() || text_id->IsSetRelease()) ) {
3187  CRef<CSeq_id> new_id(SerialClone(*seq_id));
3188  auto new_text_id = const_cast<CTextseq_id*>(new_id->GetTextseq_Id());
3189  new_text_id->ResetName();
3190  new_text_id->ResetRelease();
3191  x_AddSynonym(CSeq_id_Handle::GetHandle(*new_id), *syn_set, info);
3192  }
3193  }
3194  }
3195  }
3196  info.m_SynCache = syn_set;
3197  }
3198  return info.m_SynCache;
3199 }
3200 
3201 
3203 {
3205  for (CPriority_I it(m_setDataSrc); it; ++it) {
3206  if (it->GetDataLoader() && kind == CScope::eManualTSEs) {
3207  // Skip data sources with loaders
3208  continue;
3209  }
3211  guard(it->GetTSE_InfoMapMutex());
3212  ITERATE(CDataSource_ScopeInfo::TTSE_InfoMap, j, it->GetTSE_InfoMap()) {
3213  tses.push_back(CTSE_Handle(*x_GetTSE_Lock(*j->second)));
3214  }
3215  }
3216 }
3217 
3218 
3220 {
3222  for (CPriority_I it(m_setDataSrc); it; ++it) {
3223  if ( it->GetDataLoader() ) {
3224  return &it->GetDataSource();
3225  }
3226  }
3227  return 0;
3228 }
3229 
3230 
3232 {
3233  if( !m_Transaction )
3235  return *m_Transaction;
3236 }
3237 
3238 
3240 {
3241  /* if ( m_Transaction ) {
3242  m_Transaction = new CScopeSubTransaction_Impl(*this);
3243  } else {
3244  m_Transaction = new CScopeTransaction_Impl(*this);
3245  }*/
3247  return m_Transaction;
3248 }
3249 
3251 {
3252  if (m_Transaction && (transaction && !transaction->HasScope(*this))) {
3253  NCBI_THROW(CObjMgrException, eModifyDataError,
3254  "CScope_Impl::AttachToTransaction: already attached to another transaction");
3255  }
3256  if (transaction)
3257  transaction->AddScope(*this);
3258  m_Transaction = transaction;
3259 }
3260 
3262 {
3263  return m_Transaction != 0;
3264 }
3265 
3266 
3267 static size_t sx_CountFalse(const vector<bool>& loaded)
3268 {
3269 #ifdef NCBI_COMPILER_WORKSHOP
3270  int tmp_count = 0;
3271  std::count(loaded.begin(), loaded.end(), false, tmp_count);
3272  return size_t(tmp_count);
3273 #else
3274  return std::count(loaded.begin(), loaded.end(), false);
3275 #endif
3276 }
3277 
3278 
3279 /// Bulk retrieval methods
3280 
3282  size_t from,
3283  size_t count,
3284  TBioseqHandles& ret)
3285 {
3287  // Keep locks to prevent cleanup of the loaded TSEs.
3288  typedef CDataSource_ScopeInfo::TSeqMatchMap TSeqMatchMap;
3289  TSeqMatchMap match_map;
3290  for ( size_t i = from; i < from + count; ++i ) {
3292  if ( !ret[i] ) {
3293  match_map[ids[i]];
3294  }
3295  }
3296  if ( match_map.empty() ) {
3297  return;
3298  }
3299  for (CPriority_I it(m_setDataSrc); it; ++it) {
3300  it->GetBlobs(match_map);
3301  }
3302  for ( size_t i = from; i < from + count; ++i ) {
3303  if ( ret[i] ) {
3304  continue;
3305  }
3306  TSeqMatchMap::iterator match = match_map.find(ids[i]);
3307  if (match != match_map.end() && match->second) {
3309  }
3310  else {
3311  TSeq_idMapValue& id_info = x_GetSeq_id_Info(ids[i]);
3312  CInitGuard init(id_info.second.m_Bioseq_Info, m_MutexPool, CInitGuard::force);
3313  if ( init || id_info.second.m_Bioseq_Info->NeedsReResolve(m_BioseqChangeCounter) ) {
3314  if ( !id_info.second.m_Bioseq_Info ) {
3315  id_info.second.m_Bioseq_Info.Reset(new CBioseq_ScopeInfo(CBioseq_Handle::fState_not_found, m_BioseqChangeCounter));
3316  }
3317  else {
3318  id_info.second.m_Bioseq_Info->SetUnresolved(CBioseq_Handle::fState_not_found, m_BioseqChangeCounter);
3319  }
3320  }
3321  CRef<CBioseq_ScopeInfo> info = id_info.second.m_Bioseq_Info;
3322  ret[i].m_Handle_Seq_id = ids[i];
3323  ret[i].m_Info.Reset(info);
3324  }
3325  }
3326 }
3327 
3328 
3330 {
3331  CSortedSeq_ids sorted_seq_ids(ids);
3332  TIds sorted_ids;
3333  sorted_seq_ids.GetSortedIds(sorted_ids);
3334 
3335  TBioseqHandles ret;
3336  size_t count = sorted_ids.size();
3337  ret.resize(count);
3338  if ( count > 200 ) {
3339  // split batch into smaller pieces to avoid problems with GC
3340  for ( size_t pos = 0; pos < count; ) {
3341  size_t cnt = count - pos;
3342  if ( cnt > 150 ) cnt = 100;
3343  x_GetBioseqHandlesSorted(sorted_ids, pos, cnt, ret);
3344  pos += cnt;
3345  }
3346  }
3347  else {
3348  x_GetBioseqHandlesSorted(sorted_ids, 0, count, ret);
3349  }
3350  sorted_seq_ids.RestoreOrder(ret);
3351  return ret;
3352 }
3353 
3354 
3356 {
3357  TBioseqHandles bhs = GetBioseqHandles(ids);
3358  return GetCDDAnnots(bhs);
3359 }
3360 
3361 
3363 {
3364  CSortedBioseqs sorted_bioseqs(unsorted_bhs);
3365  TBioseqHandles bhs;
3366  sorted_bioseqs.GetSortedBioseqs(bhs);
3367 
3368  size_t count = bhs.size(), remaining = count;
3369  vector<bool> loaded(count);
3370  CDataSource::TCDD_Locks cdd_locks(count);
3371 
3372  CDataSource::TSeqIdSets id_sets;
3373  for (const auto& bh : bhs) {
3374  id_sets.push_back(bh.x_GetScopeInfo().GetIds());
3375  }
3376 
3378  for (CPriority_I it(m_setDataSrc); it; ++it) {
3379  if ( !remaining ) {
3380  break;
3381  }
3383  it->GetDataSource().GetCDDAnnots(id_sets, loaded, cdd_locks);
3384  remaining = sx_CountFalse(loaded);
3385  }
3386  TCDD_Entries ret(count);
3387  for (size_t i = 0; i < count; ++i) {
3388  if (!loaded[i] || !cdd_locks[i]) continue;
3389  CDataSource& ds = cdd_locks[i]->GetDataSource();
3390  auto ds_info = x_GetDSInfo(ds);
3391  TTSE_Lock tse_lock = x_GetTSE_Lock(cdd_locks[i], *ds_info);
3392  if ( !tse_lock ) {
3393  continue;
3394  }
3395  ret[i] = *tse_lock;
3396  }
3397  sorted_bioseqs.RestoreOrder(ret);
3398  return ret;
3399 }
3400 
3401 
3403  const TIds& unsorted_ids,
3404  TGetFlags flags)
3405 {
3406  CSortedSeq_ids sorted_seq_ids(unsorted_ids);
3407  TIds ids;
3408  sorted_seq_ids.GetSortedIds(ids);
3409 
3410  size_t count = ids.size(), remaining = count;
3411  ret.assign(count, TIds());
3412  vector<bool> loaded(count);
3413  if ( remaining ) {
3415 
3416  if ( !(flags & CScope::fForceLoad) ) {
3417  for ( size_t i = 0; i < count; ++i ) {
3418  if ( loaded[i] ) {
3419  continue;
3420  }
3423  x_FindBioseq_Info(ids[i],
3425  match);
3426  if ( info ) {
3427  if ( info->HasBioseq() ) {
3428  ret[i] = info->GetIds();
3429  loaded[i] = true;
3430  --remaining;
3431  }
3432  else {
3433  ret[i].clear();
3434  loaded[i] = true;
3435  --remaining;
3436  }
3437  }
3438  }
3439  }
3440 
3441  // Unknown bioseq, try to find in data sources
3442  for (CPriority_I it(m_setDataSrc); it; ++it) {
3443  if ( !remaining ) {
3444  break;
3445  }
3447  it->GetDataSource().GetBulkIds(ids, loaded, ret);
3448  remaining = sx_CountFalse(loaded);
3449  }
3450  }
3451  if ( remaining && (flags & CScope::fThrowOnMissingSequence) ) {
3452  NCBI_THROW(CObjMgrException, eFindFailed,
3453  "CScope::GetBulkIds(): some sequences not found");
3454  }
3455 
3456  sorted_seq_ids.RestoreOrder(ret);
3457 }
3458 
3459 
3461  const TIds& unsorted_ids,
3462  TGetFlags flags)
3463 {
3464  CSortedSeq_ids sorted_seq_ids(unsorted_ids);
3465  TIds ids;
3466  sorted_seq_ids.GetSortedIds(ids);
3467 
3468  size_t count = ids.size(), remaining = count;
3469  ret.assign(count, CSeq_id_Handle());
3470  vector<bool> loaded(count);
3471  if ( !(flags & CScope::fForceLoad) ) {
3472  for ( size_t i = 0; i < count; ++i ) {
3473  if ( ids[i].IsAccVer() ) {
3474  ret[i] = ids[i];
3475  loaded[i] = true;
3476  --remaining;
3477  }
3478  }
3479  }
3480  if ( remaining ) {
3482 
3483  if ( !(flags & CScope::fForceLoad) ) {
3484  for ( size_t i = 0; i < count; ++i ) {
3485  if ( loaded[i] ) {
3486  continue;
3487  }
3490  x_FindBioseq_Info(ids[i],
3492  match);
3493  if ( info ) {
3494  if ( info->HasBioseq() ) {
3495  ret[i] = CScope::x_GetAccVer(info->GetIds());
3496  loaded[i] = true;
3497  --remaining;
3498  }
3499  }
3500  }
3501  }
3502 
3503  // Unknown bioseq, try to find in data sources
3504  for (CPriority_I it(m_setDataSrc); it; ++it) {
3505  if ( !remaining ) {
3506  break;
3507  }
3509  it->GetDataSource().GetAccVers(ids, loaded, ret);
3510  remaining = sx_CountFalse(loaded);
3511  }
3512  }
3513  if ( remaining && (flags & CScope::fThrowOnMissingSequence) ) {
3514  NCBI_THROW(CObjMgrException, eFindFailed,
3515  "CScope::GetAccVers(): some sequences not found");
3516  }
3517  if ( (flags & CScope::fThrowOnMissingData) ) {
3518  // check if each requested id has accession
3519  for ( size_t i = 0; i < count; ++i ) {
3520  if ( loaded[i] && !ret[i] ) {
3521  NCBI_THROW(CObjMgrException, eMissingData,
3522  "CScope::GetAccVers(): some sequences have no acc");
3523  }
3524  }
3525  }
3526 
3527  sorted_seq_ids.RestoreOrder(ret);
3528 }
3529 
3530 
3532  const TIds& unsorted_ids,
3533  TGetFlags flags)
3534 {
3535  CSortedSeq_ids sorted_seq_ids(unsorted_ids);
3536  TIds ids;
3537  sorted_seq_ids.GetSortedIds(ids);
3538 
3539  size_t count = ids.size(), remaining = count;
3540  ret.assign(count, ZERO_GI);
3541  vector<bool> loaded(count);
3542  if ( !(flags & CScope::fForceLoad) ) {
3543  for ( size_t i = 0; i < count; ++i ) {
3544  if ( ids[i].IsGi() ) {
3545  ret[i] = ids[i].GetGi();
3546  loaded[i] = true;
3547  --remaining;
3548  }
3549  }
3550  }
3551  if ( remaining ) {
3553 
3554  if ( !(flags & CScope::fForceLoad) ) {
3555  for ( size_t i = 0; i < count; ++i ) {
3556  if ( loaded[i] ) {
3557  continue;
3558  }
3561  x_FindBioseq_Info(ids[i],
3563  match);
3564  if ( info ) {
3565  if ( info->HasBioseq() ) {
3566  ret[i] = CScope::x_GetGi(info->GetIds());
3567  loaded[i] = true;
3568  --remaining;
3569  }
3570  }
3571  }
3572  }
3573 
3574  // Unknown bioseq, try to find in data sources
3575  for (CPriority_I it(m_setDataSrc); it; ++it) {
3576  if ( !remaining ) {
3577  break;
3578  }
3580  it->GetDataSource().GetGis(ids, loaded, ret);
3581  remaining = sx_CountFalse(loaded);
3582  }
3583  }
3584  if ( remaining && (flags & CScope::fThrowOnMissingSequence) ) {
3585  NCBI_THROW(CObjMgrException, eFindFailed,
3586  "CScope::GetGis(): some sequences not found");
3587  }
3588  if ( (flags & CScope::fThrowOnMissingData) ) {
3589  // check if each requested id has accession
3590  for ( size_t i = 0; i < count; ++i ) {
3591  if ( loaded[i] && ret[i] == ZERO_GI ) {
3592  NCBI_THROW(CObjMgrException, eMissingData,
3593  "CScope::GetGis(): some sequences have no GI");
3594  }
3595  }
3596  }
3597 
3598  sorted_seq_ids.RestoreOrder(ret);
3599 }
3600 
3601 
3603  const TIds& unsorted_ids,
3604  TGetFlags flags)
3605 {
3606  CSortedSeq_ids sorted_seq_ids(unsorted_ids);
3607  TIds ids;
3608  sorted_seq_ids.GetSortedIds(ids);
3609 
3610  size_t count = ids.size(), remaining = count;
3611  ret.assign(count, string());
3612  vector<bool> loaded(count);
3613  if ( !(flags & CScope::fForceLoad) ) {
3614  for ( size_t i = 0; i < count; ++i ) {
3615  ret[i] = GetDirectLabel(ids[i]);
3616  if ( !ret[i].empty() ) {
3617  loaded[i] = true;
3618  --remaining;
3619  }
3620  }
3621  }
3622  if ( remaining ) {
3624 
3625  if ( !(flags & CScope::fForceLoad) ) {
3626  for ( size_t i = 0; i < count; ++i ) {
3627  if ( loaded[i] ) {
3628  continue;
3629  }
3632  x_FindBioseq_Info(ids[i],
3634  match);
3635  if ( info ) {
3636  if ( info->HasBioseq() ) {
3637  ret[i] = objects::GetLabel(info->GetIds());
3638  loaded[i] = true;
3639  --remaining;
3640  }
3641  }
3642  }
3643  }
3644 
3645  // Unknown bioseq, try to find in data sources
3646  for (CPriority_I it(m_setDataSrc); it; ++it) {
3647  if ( !remaining ) {
3648  break;
3649  }
3651  it->GetDataSource().GetLabels(ids, loaded, ret);
3652  remaining = sx_CountFalse(loaded);
3653  }
3654  }
3655  if ( remaining && (flags & CScope::fThrowOnMissing) ) {
3656  NCBI_THROW(CObjMgrException, eFindFailed,
3657  "CScope::GetLabels(): some sequences not found");
3658  }
3659 
3660  sorted_seq_ids.RestoreOrder(ret);
3661 }
3662 
3663 
3665  const TIds& unsorted_ids,
3666  TGetFlags flags)
3667 {
3668  CSortedSeq_ids sorted_seq_ids(unsorted_ids);
3669  TIds ids;
3670  sorted_seq_ids.GetSortedIds(ids);
3671 
3672  size_t count = ids.size(), remaining = count;
3673  ret.assign(count, INVALID_TAX_ID);
3674  vector<bool> loaded(count);
3675  if ( !(flags & CScope::fForceLoad) ) {
3676  for ( size_t i = 0; i < count; ++i ) {
3677  if ( ids[i].Which() == CSeq_id::e_General ) {
3678  CConstRef<CSeq_id> id = ids[i].GetSeqId();
3679  const CDbtag& dbtag = id->GetGeneral();
3680  const CObject_id& obj_id = dbtag.GetTag();
3681  if ( obj_id.IsId() && dbtag.GetDb() == "TAXID" ) {
3682  ret[i] = TAX_ID_FROM(int, obj_id.GetId());
3683  loaded[i] = true;
3684  --remaining;
3685  }
3686  }
3687  }
3688  }
3689  if ( remaining ) {
3691 
3692  if ( !(flags & CScope::fForceLoad) ) {
3693  for ( size_t i = 0; i < count; ++i ) {
3694  if ( loaded[i] ) {
3695  continue;
3696  }
3699  x_FindBioseq_Info(ids[i],
3701  match);
3702  if ( info ) {
3703  if ( info->HasBioseq() ) {
3704  TBioseq_Lock bioseq = info->GetLock(null);
3705  ret[i] = info->GetObjectInfo().GetTaxId();
3706  loaded[i] = true;
3707  --remaining;
3708  }
3709  }
3710  }
3711  }
3712 
3713  // Unknown bioseq, try to find in data sources
3714  for (CPriority_I it(m_setDataSrc); it; ++it) {
3715  if ( !remaining ) {
3716  break;
3717  }
3719  it->GetDataSource().GetTaxIds(ids, loaded, ret);
3720  remaining = sx_CountFalse(loaded);
3721  }
3722  }
3723  if ( remaining && (flags & CScope::fThrowOnMissing) ) {
3724  NCBI_THROW(CObjMgrException, eFindFailed,
3725  "CScope::GetTaxIds(): some sequences not found");
3726  }
3727 
3728  sorted_seq_ids.RestoreOrder(ret);
3729 }
3730 
3731 
3733  const TIds& unsorted_ids,
3734  TGetFlags flags)
3735 {
3736  CSortedSeq_ids sorted_seq_ids(unsorted_ids);
3737  TIds ids;
3738  sorted_seq_ids.GetSortedIds(ids);
3739 
3740  size_t count = ids.size(), remaining = count;
3741  ret.assign(count, kInvalidSeqPos);
3742  vector<bool> loaded(count);
3743 
3745 
3746  if ( !(flags & CScope::fForceLoad) ) {
3747  for ( size_t i = 0; i < count; ++i ) {
3748  if ( loaded[i] ) {
3749  continue;
3750  }
3753  x_FindBioseq_Info(ids[i],
3755  match);
3756  if ( info ) {
3757  if ( info->HasBioseq() ) {
3758  TBioseq_Lock bioseq = info->GetLock(null);
3759  ret[i] = info->GetObjectInfo().GetBioseqLength();
3760  loaded[i] = true;
3761  --remaining;
3762  }
3763  }
3764  }
3765  }
3766 
3767  // Unknown bioseq, try to find in data sources
3768  for (CPriority_I it(m_setDataSrc); it; ++it) {
3769  if ( !remaining ) {
3770  break;
3771  }
3773  it->GetDataSource().GetSequenceLengths(ids, loaded, ret);
3774  remaining = sx_CountFalse(loaded);
3775  }
3776  if ( remaining && (flags & CScope::fThrowOnMissing) ) {
3777  NCBI_THROW(CObjMgrException, eFindFailed,
3778  "CScope::GetSequenceLengths(): some sequences not found");
3779  }
3780 
3781  sorted_seq_ids.RestoreOrder(ret);
3782 }
3783 
3784 
3786  const TIds& unsorted_ids,
3787  TGetFlags flags)
3788 {
3789  CSortedSeq_ids sorted_seq_ids(unsorted_ids);
3790  TIds ids;
3791  sorted_seq_ids.GetSortedIds(ids);
3792 
3793  size_t count = ids.size(), remaining = count;
3794  ret.assign(count, CSeq_inst::eMol_not_set);
3795  vector<bool> loaded(count);
3796 
3798 
3799  if ( !(flags & CScope::fForceLoad) ) {
3800  for ( size_t i = 0; i < count; ++i ) {
3801  if ( loaded[i] ) {
3802  continue;
3803  }
3806  x_FindBioseq_Info(ids[i],
3808  match);
3809  if ( info ) {
3810  if ( info->HasBioseq() ) {
3811  TBioseq_Lock bioseq = info->GetLock(null);
3812  ret[i] = info->GetObjectInfo().GetInst_Mol();
3813  loaded[i] = true;
3814  --remaining;
3815  }
3816  }
3817  }
3818  }
3819 
3820  // Unknown bioseq, try to find in data sources
3821  for (CPriority_I it(m_setDataSrc); it; ++it) {
3822  if ( !remaining ) {
3823  break;
3824  }
3826  it->GetDataSource().GetSequenceTypes(ids, loaded, ret);
3827  remaining = sx_CountFalse(loaded);
3828  }
3829  if ( remaining && (flags & CScope::fThrowOnMissing) ) {
3830  NCBI_THROW(CObjMgrException, eFindFailed,
3831  "CScope::GetSequenceTypes(): some sequences not found");
3832  }
3833 
3834  sorted_seq_ids.RestoreOrder(ret);
3835 }
3836 
3837 
3839  const TIds& unsorted_ids,
3840  TGetFlags flags)
3841 {
3842  CSortedSeq_ids sorted_seq_ids(unsorted_ids);
3843  TIds ids;
3844  sorted_seq_ids.GetSortedIds(ids);
3845 
3846  const int kNotFound = (CBioseq_Handle::fState_not_found |
3848 
3849  size_t count = ids.size(), remaining = count;
3850  ret.assign(count, kNotFound);
3851  vector<bool> loaded(count);
3852 
3854 
3855  if ( !(flags & CScope::fForceLoad) ) {
3856  for ( size_t i = 0; i < count; ++i ) {
3857  if ( loaded[i] ) {
3858  continue;
3859  }
3862  x_FindBioseq_Info(ids[i],
3864  match);
3865  if ( info ) {
3866  if ( info->HasBioseq() ) {
3867  TBioseq_Lock bioseq = info->GetLock(null);
3868  ret[i] = info->GetBlobState();
3869  loaded[i] = true;
3870  --remaining;
3871  }
3872  }
3873  }
3874  }
3875 
3876  // Unknown bioseq, try to find in data sources
3877  for (CPriority_I it(m_setDataSrc); it; ++it) {
3878  if ( !remaining ) {
3879  break;
3880  }
3882  it->GetDataSource().GetSequenceStates(ids, loaded, ret);
3883  remaining = sx_CountFalse(loaded);
3884  }
3885  if ( remaining && (flags & CScope::fThrowOnMissing) ) {
3886  NCBI_THROW(CObjMgrException, eFindFailed,
3887  "CScope::GetSequenceStates(): some sequences not found");
3888  }
3889 
3890  sorted_seq_ids.RestoreOrder(ret);
3891 }
3892 
3893 
3895  const TIds& unsorted_ids,
3896  TGetFlags flags)
3897 {
3898  CSortedSeq_ids sorted_seq_ids(unsorted_ids);
3899  TIds ids;
3900  sorted_seq_ids.GetSortedIds(ids);
3901 
3902  size_t count = ids.size(), remaining = count;
3903  ret.assign(count, 0);
3904  vector<bool> loaded(count);
3905  vector<bool> known(count);
3906 
3908  // Unknown bioseq, try to find in data sources
3909  for (CPriority_I it(m_setDataSrc); it; ++it) {
3910  if ( !remaining ) {
3911  break;
3912  }
3914  it->GetDataSource().GetSequenceHashes(ids, loaded, ret, known);
3915  remaining = sx_CountFalse(loaded);
3916  }
3917  if ( !(flags & CScope::fDoNotRecalculate) ) {
3918  for ( size_t i = 0; i < count; ++i ) {
3919  if ( known[i] ) {
3920  // already calculated
3921  continue;
3922  }
3923  if ( !loaded[i] ) {
3924  // sequence not found
3925  continue;
3926  }
3928  ret[i] = sx_CalcHash(bh);
3929  }
3930  else {
3931  if ( (flags & CScope::fThrowOnMissingData) ) {
3932  NCBI_THROW_FMT(CObjMgrException, eMissingData,
3933  "CScope::GetSequenceHash("<<ids[i]<<"): "
3934  "no hash");
3935  }
3936  }
3937  }
3938  }
3939  if ( remaining && (flags & CScope::fThrowOnMissing) ) {
3940  NCBI_THROW(CObjMgrException, eFindFailed,
3941  "CScope::GetSequenceHashes(): some sequences not found");
3942  }
3943 
3944  sorted_seq_ids.RestoreOrder(ret);
3945 }
3946 
3947 
static CRef< CScope > m_Scope
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
Checksum and hash calculation classes.
bool IsSetDescr(void) const
bool IsSetAnnot(void) const
const TAnnot & GetAnnot(void) const
const CSeq_entry_Info & GetParentSeq_entry_Info(void) const
CBioseq_EditHandle –.
CBioseq_Handle –.
CConstRef< TObject > GetBioseqCore(void) const
atomic< int > m_IdChangeCounter
bool HasBioseq(void) const
TAnnotRefInfo m_BioseqAnnotRef_Info
Definition: scope_info.hpp:615
string IdString(void) const
const CBioseq_Info & GetObjectInfo(void) const
Definition: scope_info.hpp:553
void SetUnresolved(TBlobStateFlags flag, int timestamp)
CInitMutex< CSynonymsSet > m_SynCache
Definition: scope_info.hpp:613
atomic< int > m_UnresolvedTimestamp
Definition: scope_info.hpp:610
const TIds & GetIds(void) const
Definition: scope_info.hpp:562
TBioseq_Lock GetLock(CConstRef< CBioseq_Info > bioseq)
void x_ResetAnnotRef_Info()
Definition: scope_info.hpp:597
TNAAnnotRefInfo m_NABioseqAnnotRef_Info
Definition: scope_info.hpp:616
CBioseq_set_EditHandle –.
CBioseq_set_Handle –.
bool IsSetClass(void) const
bool IsEmptySeq_set(void) const
bool IsSetSeq_set(void) const
bool IsSetDate(void) const
CRef< CSeq_entry_Info > AddEntry(CSeq_entry &entry, int index, bool set_uniqid=false)
bool IsSetId(void) const
bool IsSetLevel(void) const
bool IsSetColl(void) const
bool IsSetRelease(void) const
Blob state exceptions, used by GenBank loader.
CChecksum – Checksum calculator.
Definition: checksum.hpp:302
const TTSE_InfoMap & GetTSE_InfoMap(void) const
Definition: scope_info.cpp:181
void SetCanRemoveOnResetHistory(void)
Definition: scope_info.cpp:159
pair< TSeq_annot_Lock, int > TSeq_feat_Lock
Definition: scope_info.hpp:265
TTSE_InfoMapMutex & GetTSE_InfoMapMutex(void) const
Definition: scope_info.hpp:680
CScope_Impl & GetScopeImpl(void) const
Definition: scope_info.cpp:128
CDataSource & GetDataSource(void)
Definition: scope_info.hpp:665
void ResetHistory(int action_if_locked)
Definition: scope_info.cpp:651
TTSE_Lock GetTSE_Lock(const CTSE_Lock &tse)
Definition: scope_info.cpp:444
CRef< CDataSource_ScopeInfo > m_EditDS
Definition: scope_info.hpp:321
SSeqMatch_Scope BestResolve(const CSeq_id_Handle &idh, int get_flag)
Definition: scope_info.cpp:832
bool IsConst(void) const
Definition: scope_info.cpp:144
CDataLoader * GetDataLoader(void)
Definition: scope_info.cpp:138
bool CanBeEdited(void) const
Definition: scope_info.hpp:694
TSeq_entry_Lock GetSeq_entry_Lock(const CBlobIdKey &blob_id)
Definition: scope_info.cpp:738
TTSE_Lock GetSharedTSE(void) const
TTSE_Lock AddStaticTSE(CSeq_entry &se)
bool CanBeEdited(void) const
bool DropStaticTSE(CTSE_Info &info)
TPriority GetDefaultPriority(void) const
CDataLoader * GetDataLoader(void) const
void DropAllTSEs(void)
Get TSE info by seq-id handle.
const CConstRef< CObject > & GetSharedObject(void) const
vector< CConstRef< CBioseq_Info > > TBioseq_InfoSet
vector< CTSE_Lock > TCDD_Locks
void GetTSESetWithOrphanAnnots(const TSeq_idSet &ids, TTSE_LockMatchSet &tse_set, const SAnnotSelector *sel, CDataLoader::TProcessedNAs *processed_nas=0)
void GetTSESetWithBioseqAnnots(const CBioseq_Info &bioseq, const TTSE_Lock &tse, TTSE_LockMatchSet &tse_set, const SAnnotSelector *sel, CDataLoader::TProcessedNAs *processed_nas=0, bool external_only=false)
vector< vector< CSeq_id_Handle > > TSeqIdSets
void GetTSESetWithExternalAnnots(const CBioseq_Info &bioseq, const TTSE_Lock &tse, TTSE_LockMatchSet &tse_set, const SAnnotSelector *sel, CDataLoader::TProcessedNAs *processed_nas=0)
Definition: Dbtag.hpp:53
void Release()
Manually force the resource to be released.
Definition: guard.hpp:166
void Reset()
Definition: mutex_pool.hpp:153
int FindSeg(const CSeq_id_Handle &h) const
Base class for all object manager exceptions.
CObjectManager –.
bool IsTree(void) const
Definition: priority.hpp:181
TLeaf & GetLeaf(void)
Definition: priority.hpp:193
CPriorityTree & GetTree(void)
Definition: priority.hpp:207
bool IsLeaf(void) const
Definition: priority.hpp:187
TPriorityMap & GetTree(void)
Definition: priority.hpp:160
bool Insert(const CPriorityNode &node, TPriority priority)
Definition: priority.cpp:67
size_t Erase(const TLeaf &leaf)
Definition: priority.cpp:94
void Clear(void)
Definition: priority.cpp:110
bool HasSeveralNodes(void)
Definition: priority.cpp:116
bool IsDetached(void) const
Definition: tse_handle.hpp:403
CScope_Impl & x_GetScopeImpl(void) const
Definition: tse_handle.cpp:477
CTSE_ScopeInfo & x_GetTSE_ScopeInfo(void) const
Definition: tse_handle.hpp:438
void Reset(void)
Definition: tse_handle.hpp:654
CSeq_entry_EditHandle x_AttachEntry(const CBioseq_set_EditHandle &seqset, CRef< CSeq_entry_Info > entry, int index)
Definition: scope_impl.cpp:529
CRef< CBioseq_ScopeInfo > x_GetBioseq_Info(const CSeq_id_Handle &id, int get_flag, SSeqMatch_Scope &match)
void x_ClearAnnotCache(void)
CRef< CDataSource_ScopeInfo > GetConstDS(TPriority priority)
TBioseq_Lock x_GetBioseq_Lock(const CBioseq &bioseq, int action)
friend class CSeq_entry_Handle
Definition: scope_impl.hpp:669
TSeqPos GetSequenceLength(const CSeq_id_Handle &id, TGetFlags flags)
CDataSource::TTSE_LockMatchSet TTSE_LockMatchSet_DS
Definition: scope_impl.hpp:586
IScopeTransaction_Impl & GetTransaction()
string GetLabel(const CSeq_id_Handle &idh, TGetFlags flags)
void ResetDataAndHistory(void)
CBioseq_ScopeInfo::TTSE_MatchSet TTSE_MatchSet
Definition: scope_impl.hpp:585
TBioseqHandles GetBioseqHandles(const TIds &ids)
friend class CSeq_annot_EditHandle
Definition: scope_impl.hpp:673
CPriorityTree m_setDataSrc
Definition: scope_impl.hpp:638
CSeq_annot_EditHandle x_AttachAnnot(const CSeq_entry_EditHandle &entry, CRef< CSeq_annot_Info > annot)
Definition: scope_impl.cpp:647
void x_ReportNewDataConflict(const CSeq_id_Handle *conflict_id=0)
Definition: scope_impl.cpp:939
SSeqMatch_Scope x_FindBioseqInfo(const CPriorityTree &tree, const CSeq_id_Handle &idh, int get_flag)
void x_UpdateHandleSeq_id(CBioseq_Handle &bh)
int TBioseqLevelFlag
Definition: scope_impl.hpp:559
CConstRef< CSynonymsSet > x_GetSynonyms(CBioseq_ScopeInfo &info)
CRef< CSeq_entry > x_MakeDummyTSE(CBioseq &seq) const
friend class CBioseq_set_Handle
Definition: scope_impl.hpp:668
CRef< CObjectManager > m_ObjMgr
Definition: scope_impl.hpp:637
CBioseq_Handle AddBioseq(CBioseq &bioseq, TPriority pri, TExist action)
Definition: scope_impl.cpp:274
void GetSequenceStates(TSequenceStates &ret, const TIds &idhs, TGetFlags flags)
vector< TTaxId > TTaxIds
Definition: scope_impl.hpp:369
void x_ClearCacheOnRemoveAnnot(const CTSE_Info &old_tse)
bool Exists(const CSeq_id_Handle &id)
void GetTaxIds(TTaxIds &ret, const TIds &idhs, TGetFlags flags)
vector< CBioseq_Handle > TBioseqHandles
Bulk retrieval methods.
Definition: scope_impl.hpp:347
CSeq_entry_Handle AddSeq_entry(CSeq_entry &entry, TPriority pri, TExist action)
Definition: scope_impl.cpp:219
void x_ClearCacheOnRemoveSeqId(const CSeq_id_Handle &id, CBioseq_ScopeInfo &seq)
TSeq_idMapValue * x_FindSeq_id_Info(const CSeq_id_Handle &id)
int GetSequenceHash(const CSeq_id_Handle &id, TGetFlags flags)
TCDD_Entries GetCDDAnnots(const TIds &idhs)
void SetKeepExternalAnnotsForEdit(bool keep=true)
Definition: scope_impl.cpp:171
TConfLock m_ConfLock
Definition: scope_impl.hpp:649
CTSE_ScopeUserLock TTSE_Lock
Definition: scope_impl.hpp:133
CBioseq_Handle x_GetBioseqHandle(const CBioseq_Info &seq, const CTSE_Handle &tse)
vector< CTSE_Handle > TCDD_Entries
Definition: scope_impl.hpp:350
friend class CBioseq_Handle
Definition: scope_impl.hpp:667
void AddDefaults(TPriority priority)
Definition: scope_impl.cpp:179
IScopeTransaction_Impl * m_Transaction
Definition: scope_impl.hpp:654
CSeq_entry_Handle GetSeq_entryHandle(CDataLoader *loader, const CBlobIdKey &blob_id, TMissing action)
void GetGis(TGIs &ret, const TIds &idhs, TGetFlags flags)
void RemoveBioseq(const CBioseq_EditHandle &seq)
CSeq_annot_Handle AddSharedSeq_annot(const CSeq_annot &annot, TPriority pri, TExist action)
Definition: scope_impl.cpp:362
TSeq_idMap::value_type TSeq_idMapValue
Definition: scope_impl.hpp:137
CBioseq_Handle GetBioseqHandleFromTSE(const CSeq_id_Handle &id, const CTSE_Handle &tse)
CBioseq_Handle x_GetBioseqHandleFromTSE(const CSeq_id_Handle &id, const CTSE_Handle &tse)
void x_ClearCacheOnNewAnnot(const CTSE_Info &new_tse)
void RemoveFromHistory(const CTSE_Handle &tse, int action)
void x_ClearCacheOnRemoveData(const CTSE_Info *old_tse=0)
bool GetKeepExternalAnnotsForEdit() const
Definition: scope_impl.hpp:550
vector< TIds > TBulkIds
Definition: scope_impl.hpp:144
void SetActiveTransaction(IScopeTransaction_Impl *)
virtual ~CScope_Impl(void)
Definition: scope_impl.cpp:115
void x_ResolveSeq_id(TSeq_idMapValue &id, int get_flag, SSeqMatch_Scope &match)
CSeq_annot_Handle AddSeq_annot(CSeq_annot &annot, TPriority pri, TExist action)
Definition: scope_impl.cpp:335
void GetAccVers(TIds &ret, const TIds &idhs, TGetFlags flags)
void x_GetTSESetWithAnnots(TTSE_LockMatchSet &lock, CBioseq_ScopeInfo &binfo, const SAnnotSelector *sel=0)
TSeq_annot_Lock x_GetSeq_annot_Lock(const CSeq_annot &annot, int action)
bool m_KeepExternalAnnotsForEdit
Definition: scope_impl.hpp:658
vector< TSeqPos > TSequenceLengths
Definition: scope_impl.hpp:391
void RemoveAnnot(const CSeq_annot_EditHandle &annot)
pair< CConstRef< CSeq_entry_Info >, TTSE_Lock > TSeq_entry_Lock
Definition: scope_impl.hpp:521
vector< TGi > TGIs
Definition: scope_impl.hpp:361
void x_ClearCacheOnNewData(const TIds &seq_ids, const TIds &annot_ids)
Definition: scope_impl.cpp:984
CRef< CDataSource_ScopeInfo > GetEditDataSource(CDataSource_ScopeInfo &ds, const CTSE_ScopeInfo *replaced_tse=0)
void RemoveEntry(const CSeq_entry_EditHandle &entry)
void AddScope(CScope_Impl &scope, TPriority priority)
Definition: scope_impl.cpp:206
CBioseq_set_EditHandle SelectSet(const CSeq_entry_EditHandle &entry, CBioseq_set &seqset)
Definition: scope_impl.cpp:817
vector< pair< CTSE_Handle, CSeq_id_Handle > > TTSE_LockMatchSet
Definition: scope_impl.hpp:139
vector< CBioseq_Handle > TBioseq_HandleSet
Definition: scope_impl.hpp:558
void x_GetTSESetWithOrphanAnnots(TTSE_LockMatchSet &lock, TTSE_MatchSet *save_match, const TSeq_idSet &ids, CBioseq_ScopeInfo *binfo, const SAnnotSelector *sel)
CBioseq_ScopeInfo::TAnnotRefInfo & x_GetAnnotRef_Info(const SAnnotSelector *sel, CBioseq_ScopeInfo::TAnnotRefInfo &main_info, CBioseq_ScopeInfo::TNAAnnotRefInfo &na_info)
void GetAllTSEs(TTSE_Handles &tses, int kind)
void SelectNone(const CSeq_entry_EditHandle &entry)
void x_PopulateBioseq_HandleSet(const CSeq_entry_Handle &tse, TBioseq_HandleSet &handles, CSeq_inst::EMol filter, TBioseqLevelFlag level)
friend class CBioseq_EditHandle
Definition: scope_impl.hpp:670
void RemoveTopLevelBioseq(const CBioseq_Handle &seq)
void x_GetTSESetWithBioseqAnnots(TTSE_LockMatchSet &lock, TTSE_MatchSet *save_match, CBioseq_ScopeInfo &binfo, const SAnnotSelector *sel)
void x_ClearCacheOnNewDS(void)
void GetBulkIds(TBulkIds &ret, const TIds &idhs, TGetFlags flags)
CDataSource_ScopeInfo::TBioseq_Lock TBioseq_Lock
Definition: scope_impl.hpp:524
void AddDataLoader(const string &loader_name, TPriority priority)
Definition: scope_impl.cpp:194
void RemoveTopLevelAnnot(const CSeq_annot_Handle &annot)
CSeq_inst::TMol GetSequenceType(const CSeq_id_Handle &id, TGetFlags flags)
CInitMutexPool m_MutexPool
Definition: scope_impl.hpp:642
friend class CScopeTransaction_Impl
Definition: scope_impl.hpp:680
vector< int > TSequenceStates
Definition: scope_impl.hpp:399
TBioseq_set_Lock x_GetBioseq_set_Lock(const CBioseq_set &seqset, int action)
CSeq_annot_Handle GetSeq_annotHandle(const CSeq_annot &annot, TMissing action)
bool IsSameBioseq(const CSeq_id_Handle &id1, const CSeq_id_Handle &id2, int get_flag)
void ResetHistory(int action)
CSeq_entry_Handle AddSeq_submit(CSeq_submit &submit, TPriority pri)
Definition: scope_impl.cpp:398
friend class CBioseq_ScopeInfo
Definition: scope_impl.hpp:682
void x_AddTSESetWithAnnots(TTSE_LockMatchSet &lock, TTSE_MatchSet *save_match, const TTSE_LockMatchSet_DS &add, CDataSource_ScopeInfo &ds_info, CDataLoader::TProcessedNAs *filter_nas=0)
void ResetScope(void)
CSeq_entry_Handle AddSharedSeq_entry(const CSeq_entry &entry, TPriority pri, TExist action)
Definition: scope_impl.cpp:243
atomic< int > m_AnnotChangeCounter
Definition: scope_impl.hpp:657
CSeq_annot_EditHandle AttachAnnot(const CSeq_entry_EditHandle &entry, CSeq_annot &annot)
Definition: scope_impl.cpp:878
vector< CSeq_entry_Handle > TTSE_Handles
Definition: scope_impl.hpp:145
CSeq_feat_Handle GetSeq_featHandle(const CSeq_feat &feat, TMissing action)
atomic< int > m_BioseqChangeCounter
Definition: scope_impl.hpp:656
void x_ClearCacheOnEdit(const CTSE_ScopeInfo &replaced_tse)
friend class CDataSource_ScopeInfo
Definition: scope_impl.hpp:678
void GetSequenceTypes(TSequenceTypes &ret, const TIds &idhs, TGetFlags flags)
CBioseq_Handle AddSharedBioseq(const CBioseq &bioseq, TPriority pri, TExist action)
Definition: scope_impl.cpp:301
TDSMap m_DSMap
Definition: scope_impl.hpp:640
vector< CSeq_inst::TMol > TSequenceTypes
Definition: scope_impl.hpp:395
CConstRef< CSynonymsSet > GetSynonyms(const CSeq_id_Handle &id, int get_flag)
TSeq_entry_Lock x_GetSeq_entry_Lock(const CSeq_entry &entry, int action)
void RemoveDataLoader(const string &loader_name, int action)
Definition: scope_impl.cpp:442
TSeq_idMapLock m_Seq_idMapLock
Definition: scope_impl.hpp:652
CRef< CBioseq_ScopeInfo > x_FindBioseq_Info(const CSeq_id_Handle &id, int get_flag, SSeqMatch_Scope &match)
void GetSequenceLengths(TSequenceLengths &ret, const TIds &idhs, TGetFlags flags)
vector< CSeq_id_Handle > TIds
Definition: scope_impl.hpp:143
void x_DetachFromOM(void)
Definition: scope_impl.cpp:137
CSeq_entry_EditHandle AttachEntry(const CBioseq_set_EditHandle &seqset, CSeq_entry &entry, int index=-1)
Definition: scope_impl.cpp:696
void x_AttachToOM(CObjectManager &objmgr)
Definition: scope_impl.cpp:129
TSeq_idMap m_Seq_idMap
Definition: scope_impl.hpp:651
CRef< CDataSource_ScopeInfo > AddDSBefore(CRef< CDataSource > ds, CRef< CDataSource_ScopeInfo > ds2, const CTSE_ScopeInfo *replaced_tse=0)
void GetSequenceHashes(TSequenceHashes &ret, const TIds &idhs, TGetFlags flags)
CBioseq_set_EditHandle x_SelectSet(const CSeq_entry_EditHandle &entry, CRef< CBioseq_set_Info > seqset)
Definition: scope_impl.cpp:590
void RemoveTopLevelBioseq_set(const CBioseq_set_Handle &seqset)
CSeq_id_Handle GetAccVer(const CSeq_id_Handle &idh, TGetFlags flags)
void GetLabels(TLabels &ret, const TIds &idhs, TGetFlags flags)
CDataSource * GetFirstLoaderSource(void)
vector< string > TLabels
Definition: scope_impl.hpp:365
bool x_IsDummyTSE(const CTSE_Info &tse, const CBioseq_Info &seq) const
CBioseq_Handle GetBioseqHandle(const CSeq_id_Handle &id, int get_flag)
CBioseq_set_Handle GetBioseq_setHandle(const CBioseq_set &seqset, TMissing action)
friend class CSeq_entry_EditHandle
Definition: scope_impl.hpp:672
CRef< CDataSource_ScopeInfo > AddDS(CRef< CDataSource > ds, TPriority priority)
CRef< CBioseq_ScopeInfo > x_InitBioseq_Info(TSeq_idMapValue &info, int get_flag, SSeqMatch_Scope &match)
TIds GetIds(const CSeq_id_Handle &idh, TGetFlags flags=0)
void x_GetBioseqHandlesSorted(const TIds &ids, size_t from, size_t count, TBioseqHandles &ret)
Bulk retrieval methods.
pair< CConstRef< CSeq_annot_Info >, TTSE_Lock > TSeq_annot_Lock
Definition: scope_impl.hpp:522
void RemoveBioseq_set(const CBioseq_set_EditHandle &seqset)
CRef< CDataSource_ScopeInfo > GetEditDS(TPriority priority)
TTSE_Lock x_GetTSE_Lock(const CSeq_entry &tse, int action)
CBioseq_EditHandle SelectSeq(const CSeq_entry_EditHandle &entry, CBioseq &seq)
Definition: scope_impl.cpp:760
pair< CConstRef< CBioseq_set_Info >, TTSE_Lock > TBioseq_set_Lock
Definition: scope_impl.hpp:523
TGi GetGi(const CSeq_id_Handle &idh, TGetFlags flags)
CTSE_Handle GetEditHandle(const CTSE_Handle &src_tse)
TSeq_idMapValue & x_GetSeq_id_Info(const CSeq_id_Handle &id)
CRef< CDataSource_ScopeInfo > x_GetDSInfo(CDataSource &ds)
void GetTSESetWithAnnots(const CSeq_id_Handle &idh, TTSE_LockMatchSet &tse_set)
friend class CBioseq_set_EditHandle
Definition: scope_impl.hpp:671
CBioseq_EditHandle x_SelectSeq(const CSeq_entry_EditHandle &entry, CRef< CBioseq_Info > bioseq)
Definition: scope_impl.cpp:566
CScope & GetScope(void)
Definition: scope_impl.cpp:122
TTaxId GetTaxId(const CSeq_id_Handle &idh, TGetFlags flags)
void x_AddSynonym(const CSeq_id_Handle &idh, CSynonymsSet &syn_set, CBioseq_ScopeInfo &info)
void x_LockMatchSet(TTSE_LockMatchSet &lock, const TTSE_MatchSet &match)
void x_UpdateProcessedNAs(const SAnnotSelector *&sel, unique_ptr< SAnnotSelector > &sel_copy, CDataLoader::TProcessedNAs &filter_nas, CDataLoader::TProcessedNAs &processed_nas)
CScope * m_HeapScope
Definition: scope_impl.hpp:635
void RemoveTopLevelSeqEntry(const CTSE_Handle &entry)
Definition: scope_impl.cpp:483
bool IsTransactionActive() const
int GetSequenceState(const CSeq_id_Handle &id, TGetFlags flags)
IScopeTransaction_Impl * CreateTransaction()
CScope –.
Definition: scope.hpp:92
CSeqVector –.
Definition: seq_vector.hpp:65
CSeq_annot_Handle –.
const CSeq_entry_Info & GetParentSeq_entry_Info(void) const
CSeq_entry_Handle –.
CSeq_entry_Handle –.
TSet & SelectSet(void)
TSeq & SelectSeq(TSeq &seq)
CRef< CSeq_annot_Info > AddAnnot(CSeq_annot &annot)
const TSeq & GetSeq(void) const
virtual void GetSeqAndAnnotIds(TSeqIds &seq_ids, TSeqIds &annot_ids) const
bool IsSet(void) const
bool IsSeq(void) const
const TSet & GetSet(void) const
Definition: Seq_entry.hpp:56
CSeq_feat_Handle –.
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
Seq-loc iterator class – iterates all intervals from a seq-loc in the correct order.
Definition: Seq_loc.hpp:453
void GetSortedBioseqs(TBioseqs &bioseqs) const
Definition: bioseq_sort.cpp:69
void RestoreOrder(vector< TValue > &values) const
Definition: bioseq_sort.hpp:86
void RestoreOrder(vector< TValue > &values) const
void GetSortedIds(TIds &ids) const
bool ContainsSynonym(const CSeq_id_Handle &id) const
void AddSynonym(const value_type &syn)
@ eTopLevel_Seq_submit
Definition: tse_handle.hpp:132
bool CanBeEdited(void) const
Return true if this TSE handle is local to scope and can be edited.
Definition: tse_handle.cpp:229
TScopeInfo & x_GetScopeInfo(void) const
Definition: tse_handle.hpp:360
const CTSE_Info & x_GetTSE_Info(void) const
Definition: tse_handle.cpp:116
const CTSE_Info & GetTSE_Info(void) const
void SetTopLevelObject(ETopLevelObjectType type, CSerialObject *ptr)
Definition: tse_info.cpp:2078
CConstRef< CSeq_entry > GetTSECore(void) const
Definition: tse_info.cpp:557
CConstRef< CMasterSeqSegments > GetMasterSeqSegments(void) const
Definition: tse_info.cpp:803
void SetTopLevelObjectType(ETopLevelObjectType type)
Definition: tse_info.cpp:2155
unique_ptr< SBaseTSE > m_BaseTSE
Definition: tse_info.hpp:771
CConstRef< CBioseq_Info > GetSegSetMaster(void) const
Definition: tse_info.cpp:783
void Reset(void)
Definition: tse_lock.hpp:108
CDataSource_ScopeInfo & GetDSInfo(void) const
Definition: scope_info.hpp:734
void AddAnnot(CSeq_entry_ScopeInfo &entry, CSeq_annot_ScopeInfo &info)
void ResetEntry(CSeq_entry_ScopeInfo &info)
CRef< CBioseq_ScopeInfo > GetBioseqInfo(const SSeqMatch_Scope &match)
CSeq_id_Handle ContainsMatchingBioseq(const CSeq_id_Handle &id) const
void ReplaceTSE(const CTSE_Info &old_tse)
void RemoveFromHistory(const CTSE_Handle *tseh, int action_if_locked, bool drop_from_ds=false)
void RemoveAnnot(CSeq_annot_ScopeInfo &info)
void SelectSet(CSeq_entry_ScopeInfo &entry, CBioseq_set_ScopeInfo &info)
SSeqMatch_Scope Resolve(const CSeq_id_Handle &id)
bool CanBeEdited(void) const
Definition: scope_info.hpp:742
CScope_Impl & GetScopeImpl(void) const
Definition: scope_info.hpp:749
TBioseq_Lock GetBioseqLock(CRef< CBioseq_ScopeInfo > info, CConstRef< CBioseq_Info > bioseq)
void SelectSeq(CSeq_entry_ScopeInfo &entry, CBioseq_ScopeInfo &info)
CTSE_Lock m_TSE_Lock
Definition: scope_info.hpp:503
void SetEditTSE(const CTSE_Lock &new_tse_lock, CDataSource_ScopeInfo &new_ds)
void RemoveEntry(CSeq_entry_ScopeInfo &info)
void AddEntry(CBioseq_set_ScopeInfo &seqset, CSeq_entry_ScopeInfo &info, int index)
virtual void AddScope(CScope_Impl &)=0
virtual bool HasScope(CScope_Impl &) const =0
void erase(iterator pos)
Definition: map.hpp:167
size_type size() const
Definition: map.hpp:148
const_iterator begin() const
Definition: map.hpp:151
const_iterator end() const
Definition: map.hpp:152
const_iterator lower_bound(const key_type &key) const
Definition: map.hpp:154
iterator_bool insert(const value_type &val)
Definition: map.hpp:165
bool empty() const
Definition: map.hpp:149
void clear()
Definition: map.hpp:169
const_iterator find(const key_type &key) const
Definition: map.hpp:153
const_iterator lower_bound(const key_type &key) const
Definition: map.hpp:294
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
const_iterator begin() const
Definition: set.hpp:135
size_type size() const
Definition: set.hpp:132
bool empty() const
Definition: set.hpp:133
static uch flags
#define Done
Definition: fastme.h:82
#define false
Definition: bool.h:36
static void DLIST_NAME() init(DLIST_LIST_TYPE *list)
Definition: dlist.tmpl.h:40
static DLIST_TYPE *DLIST_NAME() first(DLIST_LIST_TYPE *list)
Definition: dlist.tmpl.h:46
char data[12]
Definition: iconv.c:80
#define ZERO_TAX_ID
Definition: ncbimisc.hpp:1115
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 INVALID_TAX_ID
Definition: ncbimisc.hpp:1116
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
SStrictId_Tax::TId TTaxId
Taxon id type.
Definition: ncbimisc.hpp:1048
const TSeqPos kInvalidSeqPos
Define special value for invalid sequence position.
Definition: ncbimisc.hpp:878
#define TAX_ID_FROM(T, value)
Definition: ncbimisc.hpp:1111
#define ZERO_GI
Definition: ncbimisc.hpp:1088
string
Definition: cgiapp.hpp:687
#define NULL
Definition: ncbistd.hpp:225
Uint4 GetChecksum(void) const
Return calculated checksum.
Definition: checksum.hpp:341
void AddChars(const char *str, size_t len)
Update current control sum with data provided.
Definition: checksum.hpp:602
#define _VERIFY(expr)
Definition: ncbidbg.hpp:161
#define LOG_POST_X(err_subcode, message)
Definition: ncbidiag.hpp:553
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
Definition: ncbidiag.hpp:550
#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 Warning(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1191
#define NCBI_THROW_FMT(exception_class, err_code, message)
The same as NCBI_THROW but with message processed as output to ostream.
Definition: ncbiexpt.hpp:719
void Info(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1185
C * SerialClone(const C &src)
Create on heap a clone of the source object.
Definition: serialbase.hpp:512
string GetDirectLabel(const CSeq_id &id)
Return best label for a sequence from single Seq-id, or set of Seq-ids.
CConstRef< CSeq_id > GetSeqId(void) const
bool IsAccVer(void) const
static CSeq_id_Handle GetHandle(const CSeq_id &id)
Normal way of getting a handle, works for any seq-id.
string AsString(void) const
CSeq_id::E_Choice Which(void) const
string GetLabel(const CSeq_id &id)
const CTextseq_id * GetTextseq_Id(void) const
Return embedded CTextseq_id, if any.
Definition: Seq_id.cpp:169
@ eSNPScaleLimit_Default
Definition: Seq_id.hpp:848
void AcquireDefaultDataSources(TDataSourcesLock &sources)
void SetKeepExternalAnnotsForEdit(bool keep=true)
Change this scope's KeepExternalAnnotsForEdit flag.
Definition: scope_impl.cpp:165
static bool IsActive(void)
TDataSourceLock AcquireSharedSeq_entry(const CSeq_entry &object)
bool GetKeepExternalAnnotsForEdit() const
Return this scope's KeepExternalAnnotsForEdit flag.
Definition: scope_impl.cpp:159
CSeq_inst::TMol type
void RevokeScope(CScope_Impl &scope)
TBlobState GetBlobState(void)
CDataSource * GetDataSource(void) const
Definition: data_loader.cpp:92
TDataSourceLock AcquireSharedBioseq(const CBioseq &object)
static CSeq_id_Handle x_GetAccVer(const TIds &ids)
Definition: scope.cpp:425
TDataSourceLock AcquireSharedSeq_annot(const CSeq_annot &object)
void RegisterScope(CScope_Impl &scope)
TDataSourceLock AcquireDataLoader(CDataLoader &loader)
static TGi x_GetGi(const TIds &ids)
Definition: scope.cpp:448
static bool GetDefaultKeepExternalAnnotsForEdit()
Return current application-wide KeepExternalAnnotsForEdit flag.
Definition: scope_impl.cpp:147
static void SetDefaultKeepExternalAnnotsForEdit(bool keep=true)
Set new application-wide KeepExternalAnnotsForEdit flag.
Definition: scope_impl.cpp:153
CRef< CScope_Impl > m_Impl
Definition: scope.hpp:709
@ eManualTSEs
Definition: scope.hpp:642
@ eExist_Throw
Definition: scope.hpp:259
@ eKeepIfLocked
Definition: scope.hpp:343
@ eThrowIfLocked
Definition: scope.hpp:344
@ eRemoveIfLocked
Definition: scope.hpp:345
@ fThrowOnMissing
throw exception if sequence or requested data aren't found
Definition: scope.hpp:435
@ fThrowOnMissingData
fThrowOnMissingData will cause exception to be thrown if sequence is found but doesn't have the data ...
Definition: scope.hpp:429
@ fDoNotRecalculate
avoid time-consuming recalculation of missing data
Definition: scope.hpp:438
@ fThrowOnMissingSequence
fThrowOnMissingSequence will cause exception to be thrown if sequence not found.
Definition: scope.hpp:423
@ fForceLoad
ignore already loaded information and alway request data loader
Definition: scope.hpp:417
@ eGetBioseq_Resolved
Search only in already resolved ids.
Definition: scope.hpp:126
@ eGetBioseq_Loaded
Search in all loaded TSEs in the scope.
Definition: scope.hpp:127
@ eGetBioseq_All
Search bioseq, load if not loaded yet.
Definition: scope.hpp:128
@ kPriority_Default
Use default priority for added data.
Definition: scope.hpp:100
@ eMissing_Null
Definition: scope.hpp:157
vector< CSeq_id_Handle > TId
TScopeInfo & x_GetScopeInfo(void) const
const CTSE_Handle & GetTSE_Handle(void) const
const CTSE_Handle & GetTSE_Handle(void) const
Get CTSE_Handle of containing TSE.
CSeq_annot_Info & x_GetInfo(void) const
TScopeInfo & x_GetScopeInfo(void) const
E_Choice Which(void) const
const CTSE_Handle & GetTSE_Handle(void) const
bool IsRemoved(void) const
bool IsRemoved(void) const
const CTSE_Handle & GetTSE_Handle(void) const
const CBioseq_ScopeInfo & x_GetScopeInfo(void) const
const CSeq_entry_Info & x_GetInfo(void) const
bool IsRemoved(void) const
Check if handle points to a removed bioseq.
CSeq_id_Handle m_Handle_Seq_id
bool IsRemoved(void) const
const CBioseq_set_Info & x_GetInfo(void) const
CBioseq_set_Info & x_GetInfo(void) const
CConstRef< CSeq_entry > GetCompleteSeq_entry(void) const
Complete and get const reference to the seq-entry.
const CSeq_annot_Info & x_GetInfo(void) const
CSeq_entry_EditHandle GetParentEntry(void) const
Navigate object tree.
const CBioseq_Info & x_GetInfo(void) const
CSeq_entry_EditHandle GetParentEntry(void) const
Get parent seq-entry edit handle.
CSeq_entry_Info & x_GetInfo(void) const
CBioseq_ScopeInfo & x_GetScopeInfo(void) const
const TId & GetId(void) const
CSeq_entry_EditHandle GetParentEntry(void) const
Navigate object tree.
TScopeInfo & x_GetScopeInfo(void) const
@ eCoding_Iupac
Set coding to printable coding (Iupacna or Iupacaa)
bool IsIncludedAnyNamedAnnotAccession(void) const
check if any named annot accession is included in the search
TSNPScaleLimit GetSNPScaleLimit(void) const
const TNamedAnnotAccessions & GetNamedAnnotAccessions(void) const
SAnnotSelector & ExcludeNamedAnnotAccession(const string &acc)
CConstRef< C > ConstRef(const C *object)
Template function for conversion of const object pointer to CConstRef.
Definition: ncbiobj.hpp:2024
CRef< C > Ref(C *object)
Helper functions to get CRef<> and CConstRef<> objects.
Definition: ncbiobj.hpp:2015
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:1439
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#define NCBI_PARAM_TYPE(section, name)
Generate typename for a parameter from its {section, name} attributes.
Definition: ncbi_param.hpp:149
#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 TTag & GetTag(void) const
Get the Tag member data.
Definition: Dbtag_.hpp:267
bool IsId(void) const
Check if variant Id is selected.
Definition: Object_id_.hpp:264
const TDb & GetDb(void) const
Get the Db member data.
Definition: Dbtag_.hpp:220
TId GetId(void) const
Get the variant data.
Definition: Object_id_.hpp:270
const TLocation & GetLocation(void) const
Get the Location member data.
Definition: Seq_feat_.hpp:1117
void ResetName(void)
Reset Name data member.
Definition: Textseq_id_.cpp:50
@ e_General
for other databases
Definition: Seq_id_.hpp:105
TSet & SetSet(void)
Select the variant.
Definition: Seq_entry_.cpp:130
TAnnot & SetAnnot(void)
Assign a value to Annot data member.
TSeq & SetSeq(void)
Select the variant.
Definition: Seq_entry_.cpp:108
TSeq_set & SetSeq_set(void)
Assign a value to Seq_set data member.
@ e_not_set
No variant selected.
Definition: Seq_entry_.hpp:88
EMol
molecule class in living organism
Definition: Seq_inst_.hpp:108
@ eMol_not_set
> cdna = rna
Definition: Seq_inst_.hpp:109
E_Choice Which(void) const
Which variant is currently selected.
const TEntrys & GetEntrys(void) const
Get the variant data.
const TAnnots & GetAnnots(void) const
Get the variant data.
const TData & GetData(void) const
Get the Data member data.
Definition of all error codes used in objmgr libraries (xobjmgr.lib, xobjutil.lib and others).
int i
static MDB_envinfo info
Definition: mdb_load.c:37
constexpr auto sort(_Init &&init)
constexpr bool empty(list< Ts... >) noexcept
double value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:228
const struct ncbi::grid::netcache::search::fields::SIZE size
T max(T x_, T y_)
T min(T x_, T y_)
The Object manager core.
static unsigned cnt[256]
static int match(register const pcre_uchar *eptr, register const pcre_uchar *ecode, const pcre_uchar *mstart, int offset_top, match_data *md, eptrblock *eptrb, unsigned int rdepth)
Definition: pcre_exec.c:513
static int sx_CalcHash(const CBioseq_Handle &bh)
NCBI_PARAM_DEF(bool, OBJMGR, KEEP_EXTERNAL_FOR_EDIT, false)
static size_t sx_CountFalse(const vector< bool > &loaded)
#define CHECK_REMOVED_HANDLE(func, handle)
Definition: scope_impl.cpp:687
NCBI_PARAM_DECL(bool, OBJMGR, KEEP_EXTERNAL_FOR_EDIT)
#define CHECK_HANDLE(func, handle)
Definition: scope_impl.cpp:681
Better replacement of GetAccVer(), this method should be defined in data loaders, GetAccVer() is left...
Better replacement of GetGi(), this method should be defined in data loaders, GetGi() is left for com...
Better replacement of GetSequenceHash(), this method should be defined in data loaders,...
Better replacement of GetSequenceType(), this method should be defined in data loaders,...
SAnnotSelector –.
TBlobStateFlags m_BlobState
Definition: scope_impl.hpp:126
CTSE_ScopeUserLock m_TSE_Lock
Definition: scope_impl.hpp:125
CConstRef< CBioseq_Info > m_Bioseq
Definition: tse_info.hpp:138
#define _ASSERT
CRef< CTSE_ScopeInfo, CTSE_ScopeUserLocker > CTSE_ScopeUserLock
Modified on Fri Jul 19 17:13:16 2024 by modify_doxy.py rev. 669887