1 #ifndef OBJECTS_OBJMGR_IMPL___SEQ_ENTRY_INFO__HPP
2 #define OBJECTS_OBJMGR_IMPL___SEQ_ENTRY_INFO__HPP
3
4 /* $Id: seq_entry_info.hpp 603374 2020-03-10 19:52:03Z 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: Eugene Vasilchenko
30 *
31 * File Description:
32 * Seq_entry info -- entry for data source
33 *
34 */
35
36
37 #include <objmgr/impl/tse_info_object.hpp>
38 #include <objects/seqset/Seq_entry.hpp>
39 #include <objects/seqset/Bioseq_set.hpp>
40 #include <objects/seq/Seq_descr.hpp>
41 #include <vector>
42 #include <list>
43
44 BEGIN_NCBI_SCOPE
45 BEGIN_SCOPE(objects)
46
47
48 // forward declaration
49 class CSeq_entry;
50 class CBioseq;
51 class CBioseq_set;
52 class CSeq_annot;
53
54 class CDataSource;
55 class CTSE_Info;
56 class CSeq_entry_Info;
57 class CBioseq_Base_Info;
58 class CBioseq_set_Info;
59 class CBioseq_Info;
60 class CSeq_annot_Info;
61 class CSeq_descr;
62 class CSeqdesc;
63
64 ////////////////////////////////////////////////////////////////////
65 //
66 // CSeq_entry_Info::
67 //
68 // General information and indexes for seq-entries
69 //
70
71
72 class NCBI_XOBJMGR_EXPORT CSeq_entry_Info : public CTSE_Info_Object
73 {
74 typedef CTSE_Info_Object TParent;
75 public:
76 // 'ctors
77 CSeq_entry_Info(void);
78 explicit CSeq_entry_Info(const CSeq_entry_Info& info,
79 TObjectCopyMap* copy_map);
80 explicit CSeq_entry_Info(CSeq_entry& entry);
81 virtual ~CSeq_entry_Info(void);
82
83 const CBioseq_set_Info& GetParentBioseq_set_Info(void) const;
84 CBioseq_set_Info& GetParentBioseq_set_Info(void);
85
86 const CSeq_entry_Info& GetParentSeq_entry_Info(void) const;
87 CSeq_entry_Info& GetParentSeq_entry_Info(void);
88
89 const CSeq_entry_Info& GetXrefTSE() const;
90
91 // Get unique bio object id
92 virtual const CBioObjectId& GetBioObjectId(void) const;
93
94 typedef CSeq_entry TObject;
95
96 bool HasNoSeq_entry(void) const;
97 CConstRef<TObject> GetCompleteSeq_entry(void) const;
98 CConstRef<TObject> GetSeq_entryCore(void) const;
99 CConstRef<TObject> GetSeq_entrySkeleton(void) const;
100
101 // Seq-entry access
102 typedef TObject::E_Choice E_Choice;
103 E_Choice Which(void) const;
104 void x_CheckWhich(E_Choice which) const;
105 void Reset(void);
106
107 typedef CBioseq_set_Info TSet;
108 bool IsSet(void) const;
109 const TSet& GetSet(void) const;
110 TSet& SetSet(void);
111
112 // SelectSet switches Seq-entry to e_Set variant
113 TSet& SelectSet(void);
114 TSet& SelectSet(TSet& seqset);
115 TSet& SelectSet(CBioseq_set& seqset);
116
117 typedef CBioseq_Info TSeq;
118 bool IsSeq(void) const;
119 const TSeq& GetSeq(void) const;
120 TSeq& SetSeq(void);
121
122 // SelectSeq switches Seq-entry to e_Seq variant
123 TSeq& SelectSeq(TSeq& seq);
124 TSeq& SelectSeq(CBioseq& seq);
125
126 typedef CSeq_descr TDescr;
127 // Bioseq-set access
128 bool IsSetDescr(void) const;
129 const TDescr& GetDescr(void) const;
130 void ResetDescr(void);
131 void SetDescr(TDescr& v);
132 TDescr& SetDescr(void);
133 bool AddSeqdesc(CSeqdesc& d);
134 CRef<CSeqdesc> RemoveSeqdesc(const CSeqdesc& d);
135 CRef<CSeqdesc> ReplaceSeqdesc(const CSeqdesc& old_desc, CSeqdesc& new_desc);
136 // void AddDescr(CSeq_entry_Info& src);
137 void AddSeq_descr(const TDescr& v);
138
139 // get current content no matter what type it is
140 const CBioseq_Base_Info& x_GetBaseInfo(void) const;
141
142 // low level access for CSeqdesc_CI in case sequence is split
143 typedef CSeq_descr::Tdata::const_iterator TDesc_CI;
144 typedef unsigned TDescTypeMask;
145 bool x_IsEndDesc(TDesc_CI iter) const;
146 TDesc_CI x_GetFirstDesc(TDescTypeMask types) const;
147 TDesc_CI x_GetNextDesc(TDesc_CI iter, TDescTypeMask types) const;
148
149 CRef<CSeq_annot_Info> AddAnnot(CSeq_annot& annot);
150 void AddAnnot(CRef<CSeq_annot_Info> annot);
151 void RemoveAnnot(CRef<CSeq_annot_Info> annot);
152
153 typedef vector< CRef<CSeq_annot_Info> > TAnnot;
154 const TAnnot& GetLoadedAnnot(void) const;
155
156 CRef<CSeq_entry_Info> AddEntry(CSeq_entry& entry, int index = -1);
157 void AddEntry(CRef<CSeq_entry_Info> entry, int index = -1);
158 void RemoveEntry(CRef<CSeq_entry_Info> entry);
159
160 // tree initialization
161 void x_ParentAttach(CBioseq_set_Info& parent);
162 void x_ParentDetach(CBioseq_set_Info& parent);
163
164 // attaching/detaching to CDataSource (it's in CTSE_Info)
165 virtual void x_DSAttachContents(CDataSource& ds);
166 virtual void x_DSDetachContents(CDataSource& ds);
167
168 // attaching/detaching to CTSE_Info
169 virtual void x_TSEAttachContents(CTSE_Info& tse_info);
170 virtual void x_TSEDetachContents(CTSE_Info& tse_info);
171
172 void UpdateAnnotIndex(void) const;
173
174 void x_SetBioseqChunkId(TChunkId chunk_id);
175
176 typedef vector<CSeq_id_Handle> TSeqIds;
177 // fill ids with all Bioseqs Seq-ids from this TSE
178 // the result will be sorted and contain no duplicates
179 void x_GetBioseqsIds(TSeqIds& ids) const;
180 virtual void GetBioseqsIds(TSeqIds& ids) const;
181 // fill ids with all Annot Seq-ids from this TSE
182 // the result will be sorted and contain no duplicates
183 void x_GetAnnotIds(TSeqIds& ids) const;
184 virtual void GetAnnotIds(TSeqIds& ids) const;
185 // fill seq_ids with all Bioseqs Seq-ids and annot_ids with annotations ids
186 // the result will be sorted and contain no duplicates
187 virtual void GetSeqAndAnnotIds(TSeqIds& seq_ids, TSeqIds& annot_ids) const;
188
189 protected:
190 friend class CScope_Impl;
191 friend class CDataSource;
192
193 friend class CAnnot_Collector;
194 friend class CSeq_annot_CI;
195
196 friend class CTSE_Info;
197 friend class CBioseq_Base_Info;
198 friend class CBioseq_Info;
199 friend class CBioseq_set_Info;
200 friend class CSeq_annot_Info;
201
202 void x_AttachContents(void);
203 void x_DetachContents(void);
204
205 TObject& x_GetObject(void);
206 const TObject& x_GetObject(void) const;
207
208 void x_SetObject(TObject& obj);
209 void x_SetObject(const CSeq_entry_Info& info, TObjectCopyMap* copy_map);
210
211 void x_Select(CSeq_entry::E_Choice which,
212 CBioseq_Base_Info* contents);
213 void x_Select(CSeq_entry::E_Choice which,
214 CRef<CBioseq_Base_Info> contents);
215
216 void x_DSMapObject(CConstRef<TObject> obj, CDataSource& ds);
217 void x_DSUnmapObject(CConstRef<TObject> obj, CDataSource& ds);
218
219 void x_UpdateAnnotIndexContents(CTSE_Info& tse);
220
221 void x_UpdateSkeleton() const;
222 void x_Update(TNeedUpdateFlags flags) const;
223
224 void x_DoUpdate(TNeedUpdateFlags flags);
225 void x_SetNeedUpdateContents(TNeedUpdateFlags flags);
226
227 static CRef<TObject> sx_ShallowCopy(TObject& obj);
228
229 // Seq-entry pointer
230 CRef<TObject> m_Object;
231
232 // Bioseq/Bioseq_set info
233 E_Choice m_Which;
234 CRef<CBioseq_Base_Info> m_Contents;
235
236 // Hide copy methods
237 CSeq_entry_Info& operator= (const CSeq_entry_Info&);
238
239 };
240
241
242
243 /////////////////////////////////////////////////////////////////////
244 //
245 // Inline methods
246 //
247 /////////////////////////////////////////////////////////////////////
248
249 inline
HasNoSeq_entry(void) const250 bool CSeq_entry_Info::HasNoSeq_entry(void) const
251 {
252 return !m_Object;
253 }
254
255
256 inline
IsSet(void) const257 bool CSeq_entry_Info::IsSet(void) const
258 {
259 return Which() == CSeq_entry::e_Set;
260 }
261
262
263 inline
IsSeq(void) const264 bool CSeq_entry_Info::IsSeq(void) const
265 {
266 return Which() == CSeq_entry::e_Seq;
267 }
268
269
270 END_SCOPE(objects)
271 END_NCBI_SCOPE
272
273 #endif /* OBJECTS_OBJMGR_IMPL___SEQ_ENTRY_INFO__HPP */
274