NCBI C++ ToolKit
bioseq_set_handle.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef OBJMGR__BIOSEQ_SET_HANDLE__HPP
2 #define OBJMGR__BIOSEQ_SET_HANDLE__HPP
3 
4 /* $Id: bioseq_set_handle.hpp 84799 2018-12-12 19:07:08Z vasilche $
5 * ===========================================================================
6 *
7 * PUBLIC DOMAIN NOTICE
8 * National Center for Biotechnology Information
9 *
10 * This software/database is a "United States Government Work" under the
11 * terms of the United States Copyright Act. It was written as part of
12 * the author's official duties as a United States Government employee and
13 * thus cannot be copyrighted. This software/database is freely available
14 * to the public for use. The National Library of Medicine and the U.S.
15 * Government have not placed any restriction on its use or reproduction.
16 *
17 * Although all reasonable efforts have been taken to ensure the accuracy
18 * and reliability of the software and data, the NLM and the U.S.
19 * Government do not and cannot warrant the performance or results that
20 * may be obtained by using this software or data. The NLM and the U.S.
21 * Government disclaim all warranties, express or implied, including
22 * warranties of performance, merchantability or fitness for any particular
23 * purpose.
24 *
25 * Please cite the author in any work or product based on this material.
26 *
27 * ===========================================================================
28 *
29 * Author: Aleksey Grichenko, Eugene Vasilchenko
30 *
31 * File Description:
32 * Handle to Seq-entry object
33 *
34 */
35 
36 #include <corelib/ncbiobj.hpp>
37 
39 
40 #include <objmgr/tse_handle.hpp>
41 
44 
45 /** @addtogroup ObjectManagerHandles
46  *
47  * @{
48  */
49 
50 
51 /////////////////////////////////////////////////////////////////////////////
52 // CSeq_entry_Handle
53 /////////////////////////////////////////////////////////////////////////////
54 
55 
56 class CSeq_annot;
57 class CSeq_entry;
58 class CBioseq;
59 class CBioseq_set;
60 class CSeqdesc;
61 
62 class CScope;
63 
64 class CSeq_entry_Handle;
65 class CBioseq_set_Handle;
66 class CBioseq_Handle;
67 class CSeq_annot_Handle;
70 class CBioseq_EditHandle;
72 class CSeq_entry_Info;
73 
74 class CBioseq_set_Info;
75 class CBioObjectId;
76 
78 {
79 public:
81 
83  : CScopeInfo_Base(tse, reinterpret_cast<const CTSE_Info_Object&>(info))
84  {
85  }
86 
87  const TObjectInfo& GetObjectInfo(void) const
88  {
89  return reinterpret_cast<const TObjectInfo&>(GetObjectInfo_Base());
90  }
92  {
93  return const_cast<TObjectInfo&>(GetObjectInfo());
94  }
95 };
96 
97 
98 
99 /////////////////////////////////////////////////////////////////////////////
100 ///
101 /// CBioseq_set_Handle --
102 ///
103 /// Proxy to access the bioseq_set objects
104 ///
105 
107 {
108 public:
109  // Default constructor
110  CBioseq_set_Handle(void);
111 
112  /// Get scope this handle belongs to
113  CScope& GetScope(void) const;
114 
115  /// Return a handle for the parent seq-entry of the bioseq
116  CSeq_entry_Handle GetParentEntry(void) const;
117 
118  /// Return a handle for the parent Bioseq-set, or null handle
119  CBioseq_set_Handle GetParentBioseq_set(void) const;
120 
121  /// Return a handle for the top-level seq-entry
122  CSeq_entry_Handle GetTopLevelEntry(void) const;
123 
124  /// Get 'edit' version of handle
125  CBioseq_set_EditHandle GetEditHandle(void) const;
126 
127  /// Return the complete bioseq-set object.
128  /// Any missing data will be loaded and put in the bioseq members.
129  CConstRef<CBioseq_set> GetCompleteBioseq_set(void) const;
130 
131  /// Return core data for the bioseq-set.
132  /// The object is guaranteed to have basic information loaded.
133  /// Some information may be not loaded yet.
134  CConstRef<CBioseq_set> GetBioseq_setCore(void) const;
135 
136  /// Unified interface for templates
138  CConstRef<TObject> GetCompleteObject(void) const;
139  CConstRef<TObject> GetObjectCore(void) const;
140 
141  /// Get unique object id
142  const CBioObjectId& GetBioObjectId(void) const;
143 
144  /// Check if the bioseq set is empty
145  bool IsEmptySeq_set(void) const;
146 
147  // member access
149  bool IsSetId(void) const;
150  bool CanGetId(void) const;
151  const TId& GetId(void) const;
152 
154  bool IsSetColl(void) const;
155  bool CanGetColl(void) const;
156  const TColl& GetColl(void) const;
157 
159  bool IsSetLevel(void) const;
160  bool CanGetLevel(void) const;
161  TLevel GetLevel(void) const;
162 
164  bool IsSetClass(void) const;
165  bool CanGetClass(void) const;
166  TClass GetClass(void) const;
167 
169  bool IsSetRelease(void) const;
170  bool CanGetRelease(void) const;
171  const TRelease& GetRelease(void) const;
172 
174  bool IsSetDate(void) const;
175  bool CanGetDate(void) const;
176  const TDate& GetDate(void) const;
177 
179  bool IsSetDescr(void) const;
180  bool CanGetDescr(void) const;
181  const TDescr& GetDescr(void) const;
182 
183  // annot
184  bool HasAnnots(void) const;
185 
186  // Utility methods/operators
187 
188  /// Check if handle points to a bioseq-set
189  ///
190  /// @sa
191  /// operator !()
192  DECLARE_OPERATOR_BOOL(m_Info.IsValid());
193 
194  bool IsRemoved(void) const;
195 
196  // Get CTSE_Handle of containing TSE
197  const CTSE_Handle& GetTSE_Handle(void) const;
198 
199  // Reset handle and make it not to point to any bioseq-set
200  void Reset(void);
201 
202  /// Check if handles point to the same bioseq
203  ///
204  /// @sa
205  /// operator!=()
206  bool operator ==(const CBioseq_set_Handle& handle) const;
207 
208  // Check if handles point to different bioseqs
209  ///
210  /// @sa
211  /// operator==()
212  bool operator !=(const CBioseq_set_Handle& handle) const;
213 
214  /// For usage in containers
215  bool operator <(const CBioseq_set_Handle& handle) const;
216 
217  /// Go up to a certain complexity level (or the nearest level of the same
218  /// priority if the required class is not found).
219  CSeq_entry_Handle GetComplexityLevel(CBioseq_set::EClass cls) const;
220 
221  /// Return level with exact complexity, or empty handle if not found.
222  CSeq_entry_Handle GetExactComplexityLevel(CBioseq_set::EClass cls) const;
223 
224  int GetSeq_entry_Index(const CSeq_entry_Handle& handle) const;
225 
226 protected:
227  friend class CScope_Impl;
228  friend class CBioseq_Handle;
229  friend class CSeq_entry_Handle;
230  friend class CSeq_entry_EditHandle;
231 
232  friend class CSeqMap_CI;
233  friend class CSeq_entry_CI;
234  friend class CSeq_annot_CI;
235  friend class CAnnotTypes_CI;
236 
240  CBioseq_set_Handle(const TLock& lock);
241 
242  CScope_Impl& x_GetScopeImpl(void) const;
243 
245 
246  typedef int TComplexityTable[25];
247  static const TComplexityTable& sx_GetComplexityTable(void);
248 
249  static TComplexityTable sm_ComplexityTable;
250 
251 public: // non-public section
252 
253  const TScopeInfo& x_GetScopeInfo(void) const;
254  const CBioseq_set_Info& x_GetInfo(void) const;
255 };
256 
257 
258 /////////////////////////////////////////////////////////////////////////////
259 ///
260 /// CBioseq_set_EditHandle --
261 ///
262 /// Proxy to access and edit the bioseq_set objects
263 ///
264 
266 {
267 public:
268  // Default constructor
270  /// create edit interface class to the object which already allows editing
271  /// throw an exception if the argument is not in editing mode
272  explicit CBioseq_set_EditHandle(const CBioseq_set_Handle& h);
273 
274  /// Navigate object tree
275  CSeq_entry_EditHandle GetParentEntry(void) const;
276 
277  // Member modification
278  void ResetId(void) const;
279  void SetId(TId& id) const;
280 
281  void ResetColl(void) const;
282  void SetColl(TColl& v) const;
283 
284  void ResetLevel(void) const;
285  void SetLevel(TLevel v) const;
286 
287  void ResetClass(void) const;
288  void SetClass(TClass v) const;
289 
290  void ResetRelease(void) const;
291  void SetRelease(TRelease& v) const;
292 
293  void ResetDate(void) const;
294  void SetDate(TDate& v) const;
295 
296  void ResetDescr(void) const;
297  void SetDescr(TDescr& v) const;
298  TDescr& SetDescr(void) const;
299  bool AddSeqdesc(CSeqdesc& d) const;
300  CRef<CSeqdesc> RemoveSeqdesc(const CSeqdesc& d) const;
301  CRef<CSeqdesc> ReplaceSeqdesc(const CSeqdesc& old_desc, CSeqdesc& new_desc) const;
302  void AddSeq_descr(TDescr& v) const;
303 
304  /// Create new empty seq-entry
305  ///
306  /// @param index
307  /// Start index is 0, and -1 means end
308  ///
309  /// @return
310  /// Edit handle to the new seq-entry
311  ///
312  /// @sa
313  /// AttachEntry()
314  /// CopyEntry()
315  /// TakeEntry()
316  CSeq_entry_EditHandle AddNewEntry(int index) const;
317 
318  /// Attach an annotation
319  ///
320  /// @param annot
321  /// Reference to this annotation will be attached
322  ///
323  /// @return
324  /// Edit handle to the attached annotation
325  ///
326  /// @sa
327  /// CopyAnnot()
328  /// TakeAnnot()
329  CSeq_annot_EditHandle AttachAnnot(CSeq_annot& annot) const;
330 
331  /// Attach a copy of the annotation
332  ///
333  /// @param annot
334  /// Copy of the annotation pointed by this handle will be attached
335  ///
336  /// @return
337  /// Edit handle to the attached annotation
338  ///
339  /// @sa
340  /// AttachAnnot()
341  /// TakeAnnot()
342  CSeq_annot_EditHandle CopyAnnot(const CSeq_annot_Handle& annot) const;
343 
344  /// Remove the annotation from its location and attach to current one
345  ///
346  /// @param annot
347  /// An annotation pointed by this handle will be removed and attached
348  ///
349  /// @return
350  /// Edit handle to the attached annotation
351  ///
352  /// @sa
353  /// AttachAnnot()
354  /// CopyAnnot()
355  CSeq_annot_EditHandle TakeAnnot(const CSeq_annot_EditHandle& annot) const;
356 
357  /// Attach a bioseq
358  ///
359  /// @param seq
360  /// Reference to this bioseq will be attached
361  /// @param index
362  /// Start index is 0 and -1 means end
363  ///
364  /// @return
365  /// Edit handle to the attached bioseq
366  ///
367  /// @sa
368  /// CopyBioseq()
369  /// TakeBioseq()
370  CBioseq_EditHandle AttachBioseq(CBioseq& seq,
371  int index = -1) const;
372 
373  /// Attach a copy of the bioseq
374  ///
375  /// @param seq
376  /// Copy of the bioseq pointed by this handle will be attached
377  /// @param index
378  /// Start index is 0 and -1 means end
379  ///
380  /// @return
381  /// Edit handle to the attached bioseq
382  ///
383  /// @sa
384  /// AttachBioseq()
385  /// TakeBioseq()
386  CBioseq_EditHandle CopyBioseq(const CBioseq_Handle& seq,
387  int index = -1) const;
388 
389  /// Remove bioseq from its location and attach to current one
390  ///
391  /// @param seq
392  /// bioseq pointed by this handle will be removed and attached
393  /// @param index
394  /// Start index is 0 and -1 means end
395  ///
396  /// @return
397  /// Edit handle to the attached bioseq
398  ///
399  /// @sa
400  /// AttachBioseq()
401  /// CopyBioseq()
402  CBioseq_EditHandle TakeBioseq(const CBioseq_EditHandle& seq,
403  int index = -1) const;
404 
405  /// Attach an existing seq-entry
406  ///
407  /// @param entry
408  /// Reference to this seq-entry will be attached
409  /// @param index
410  /// Start index is 0 and -1 means end
411  ///
412  /// @return
413  /// Edit handle to the attached seq-entry
414  ///
415  /// @sa
416  /// AddNewEntry()
417  /// CopyEntry()
418  /// TakeEntry()
419  CSeq_entry_EditHandle AttachEntry(CSeq_entry& entry,
420  int index = -1) const;
421  CSeq_entry_EditHandle AttachEntry(CRef<CSeq_entry_Info> entry,
422  int index = -1) const;
423 
424  /// Attach a copy of the existing seq-entry
425  ///
426  /// @param entry
427  /// Copy of this seq-entry will be attached
428  /// @param index
429  /// Start index is 0 and -1 means end
430  ///
431  /// @return
432  /// Edit handle to the attached seq-entry
433  ///
434  /// @sa
435  /// AddNewEntry()
436  /// AttachEntry()
437  /// TakeEntry()
438  CSeq_entry_EditHandle CopyEntry(const CSeq_entry_Handle& entry,
439  int index = -1) const;
440 
441  /// Remove seq-entry from its location and attach to current one
442  ///
443  /// @param entry
444  /// seq-entry pointed by this handle will be removed and attached
445  /// @param index
446  /// Start index is 0 and -1 means end
447  ///
448  /// @return
449  /// Edit handle to the attached seq-entry
450  ///
451  /// @sa
452  /// AddNewEntry()
453  /// AttachEntry()
454  /// CopyEntry()
455  CSeq_entry_EditHandle TakeEntry(const CSeq_entry_EditHandle& entry,
456  int index = -1) const;
457 
458  /// Attach seq-entry previously removed from another place.
459  ///
460  /// @param entry
461  /// Edit handle to seq-entry to be attached
462  /// Must be removed.
463  /// @param index
464  /// Start index is 0 and -1 means end
465  ///
466  /// @return
467  /// Edit handle to the attached seq-entry
468  ///
469  /// @sa
470  /// AddNewEntry()
471  /// CopyEntry()
472  /// TakeEntry()
473  CSeq_entry_EditHandle AttachEntry(const CSeq_entry_EditHandle& entry,
474  int index = -1) const;
475 
476  enum ERemoveMode {
478  eKeepSeq_entry
479  };
480  /// Remove current seqset-entry from its location
481  void Remove(ERemoveMode mode = eRemoveSeq_entry) const;
482 
483 protected:
484  friend class CScope_Impl;
485  friend class CBioseq_EditHandle;
486  friend class CSeq_entry_EditHandle;
487 
489  const CTSE_Handle& tse);
490 
491  void x_Detach(void) const;
492 
493 public: // non-public section
494  TScopeInfo& x_GetScopeInfo(void) const;
495  CBioseq_set_Info& x_GetInfo(void) const;
496 
497 public:
498 
499  void x_RealResetDescr(void) const;
500  void x_RealSetDescr(TDescr& v) const;
501  bool x_RealAddSeqdesc(CSeqdesc& d) const;
503  CRef<CSeqdesc> x_RealReplaceSeqdesc(const CSeqdesc& old_desc, CSeqdesc& new_desc) const;
504  void x_RealAddSeq_descr(TDescr& v) const;
505 
506  void x_RealResetId(void) const;
507  void x_RealSetId(TId& id) const;
508  void x_RealResetColl(void) const;
509  void x_RealSetColl(TColl& v) const;
510  void x_RealResetLevel(void) const;
511  void x_RealSetLevel(TLevel v) const;
512  void x_RealResetClass(void) const;
513  void x_RealSetClass(TClass v) const;
514  void x_RealResetRelease(void) const;
515  void x_RealSetRelease(TRelease& v) const;
516  void x_RealResetDate(void) const;
517  void x_RealSetDate(TDate& v) const;
518 
519 };
520 
521 
522 /////////////////////////////////////////////////////////////////////////////
523 // CBioseq_set_Handle inline methods
524 /////////////////////////////////////////////////////////////////////////////
525 
526 
527 inline
529 {
530 }
531 
532 
533 inline
535 {
536  return m_Info->GetTSE_Handle();
537 }
538 
539 
540 inline
542 {
543  return GetTSE_Handle().GetScope();
544 }
545 
546 
547 inline
549 {
550  return GetTSE_Handle().x_GetScopeImpl();
551 }
552 
553 
554 inline
556 {
557  return *m_Info;
558 }
559 
560 
561 inline
563 {
564  return m_Info.IsRemoved();
565 }
566 
567 
568 inline
570 {
571  return m_Info == handle.m_Info;
572 }
573 
574 
575 inline
577 {
578  return m_Info != handle.m_Info;
579 }
580 
581 
582 inline
584 {
585  return m_Info < handle.m_Info;
586 }
587 
588 
589 inline
591 {
592  return GetCompleteBioseq_set();
593 }
594 
595 
596 inline
598 {
599  return GetBioseq_setCore();
600 }
601 
602 
603 /////////////////////////////////////////////////////////////////////////////
604 // CBioseq_set_EditHandle
605 /////////////////////////////////////////////////////////////////////////////
606 
607 
608 inline
610 {
611 }
612 
613 
614 inline
616 {
617  return m_Info.GetNCObject();
618 }
619 
620 /* @} */
621 
622 
625 
626 #endif//OBJMGR__BIOSEQ_SET_HANDLE__HPP
bool operator!=(const _Ht_iterator< _Val, _Nonconst_traits< _Val >, _Key, _HF, _ExK, _EqK, _All > &__x, const _Ht_iterator< _Val, _Const_traits< _Val >, _Key, _HF, _ExK, _EqK, _All > &__y)
Definition: _hashtable.h:173
CBioseq_EditHandle –.
CBioseq_Handle –.
CBioseq_set_EditHandle –.
CBioseq_set_Handle –.
Definition: Date.hpp:53
Definition: Dbtag.hpp:53
const CTSE_Handle & GetTSE_Handle(void) const
Definition: tse_handle.hpp:445
const CTSE_Info_Object & GetObjectInfo_Base(void) const
Definition: tse_handle.hpp:452
bool IsRemoved(void) const
Definition: tse_handle.hpp:633
TScopeInfo & GetNCObject(void) const
Definition: tse_handle.hpp:671
CScope –.
Definition: scope.hpp:92
Iterator over CSeqMap.
Definition: seq_map_ci.hpp:252
CSeq_annot_CI –.
CSeq_annot_Handle –.
@Seq_descr.hpp User-defined methods of the data storage class.
Definition: Seq_descr.hpp:55
CSeq_entry_CI –.
CSeq_entry_Handle –.
CSeq_entry_Handle –.
Definition: Seq_entry.hpp:56
CScope_Impl & x_GetScopeImpl(void) const
Definition: tse_handle.hpp:332
CScope & GetScope(void) const
Returns scope.
Definition: tse_handle.hpp:325
bool operator<(const CEquivRange &A, const CEquivRange &B)
bool operator==(const CEquivRange &A, const CEquivRange &B)
const CSeq_id & GetId(const CSeq_loc &loc, CScope *scope)
If all CSeq_ids embedded in CSeq_loc refer to the same CBioseq, returns the first CSeq_id found,...
const TScopeInfo & x_GetScopeInfo(void) const
CBioseq_set::TClass TClass
CBioseq_set::TDate TDate
DECLARE_OPERATOR_BOOL(m_Info.IsValid())
Check if handle points to a bioseq-set.
const CTSE_Handle & GetTSE_Handle(void) const
TScopeInfo & x_GetScopeInfo(void) const
void x_RealResetDescr(void) const
CBioseq_set TObject
Unified interface for templates.
CBioseq_set::TLevel TLevel
CBioseq_set::TColl TColl
CConstRef< TObject > GetObjectCore(void) const
CScope & GetScope(void) const
Get scope this handle belongs to.
void x_RealSetDescr(TDescr &v) const
CBioseq_set_ScopeInfo(const CTSE_Handle &tse, const TObjectInfo &info)
bool IsRemoved(void) const
CBioseq_set::TId TId
CConstRef< CBioseq_set > GetCompleteBioseq_set(void) const
Return the complete bioseq-set object.
TObjectInfo & GetNCObjectInfo(void)
CBioseq_set_Info TObjectInfo
bool operator==(const CBioseq_set_Handle &handle) const
Check if handles point to the same bioseq.
CConstRef< TObject > GetCompleteObject(void) const
CBioseq_set_ScopeInfo TScopeInfo
static TComplexityTable sm_ComplexityTable
bool operator<(const CBioseq_set_Handle &handle) const
For usage in containers.
void x_RealAddSeq_descr(TDescr &v) const
CBioseq_set::TRelease TRelease
bool operator!=(const CBioseq_set_Handle &handle) const
bool x_RealAddSeqdesc(CSeqdesc &v) const
CScope_Impl & x_GetScopeImpl(void) const
CRef< CSeqdesc > x_RealRemoveSeqdesc(const CSeqdesc &v) const
CRef< CSeqdesc > x_RealReplaceSeqdesc(const CSeqdesc &old_desc, CSeqdesc &new_desc) const
CScopeInfo_Ref< TScopeInfo > TLock
CSeq_entry_Info & x_GetInfo(void) const
CBioseq_set::TDescr TDescr
CConstRef< CBioseq_set > GetBioseq_setCore(void) const
Return core data for the bioseq-set.
friend class CBioseq_set_EditHandle
TScopeInfo & x_GetScopeInfo(void) const
const TObjectInfo & GetObjectInfo(void) const
#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
#define NCBI_XOBJMGR_EXPORT
Definition: ncbi_export.h:1307
static MDB_envinfo info
Definition: mdb_load.c:37
mdb_mode_t mode
Definition: lmdb++.h:38
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
CScope & GetScope()
#define const
Definition: zconf.h:230
Modified on Sat Dec 02 09:22:47 2023 by modify_doxy.py rev. 669887