1 #ifndef OBJECTS_OBJMGR_IMPL___BIOSEQ_BASE_INFO__HPP
2 #define OBJECTS_OBJMGR_IMPL___BIOSEQ_BASE_INFO__HPP
3
4 /* $Id: bioseq_base_info.hpp 585552 2019-04-30 18:43:36Z dondosha $
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 * Bioseq info for data source
33 *
34 */
35
36 #include <corelib/ncbiobj.hpp>
37 #include <objmgr/impl/tse_info_object.hpp>
38
39 #include <objects/seq/seq_id_handle.hpp>
40 #include <objects/seq/Seq_descr.hpp>
41
42 #include <vector>
43 #include <list>
44
45 BEGIN_NCBI_SCOPE
46 BEGIN_SCOPE(objects)
47
48 class CDataSource;
49 class CTSE_Info;
50 class CSeq_entry;
51 class CSeq_entry_Info;
52 class CSeq_annot;
53 class CSeq_annot_Info;
54 class CSeq_descr;
55 class CSeqdesc;
56
57 // ID-5570 : Set of user object names
58 typedef set<string> TUserObjectTypesSet;
59
60 ////////////////////////////////////////////////////////////////////
61 //
62 // CBioseq_Info::
63 //
64 // Structure to keep bioseq's parent seq-entry along with the list
65 // of seq-id synonyms for the bioseq.
66 //
67
68
69 class NCBI_XOBJMGR_EXPORT CBioseq_Base_Info : public CTSE_Info_Object
70 {
71 typedef CTSE_Info_Object TParent;
72 public:
73 // 'ctors
74 CBioseq_Base_Info(void);
75 CBioseq_Base_Info(const CBioseq_Base_Info& src, TObjectCopyMap* copy_map);
76 virtual ~CBioseq_Base_Info(void);
77
78 // info tree
79 const CSeq_entry_Info& GetParentSeq_entry_Info(void) const;
80 CSeq_entry_Info& GetParentSeq_entry_Info(void);
81
82 // member modification
83 // descr
84 typedef CSeq_descr TDescr;
85 bool IsSetDescr(void) const;
86 bool CanGetDescr(void) const;
87 const TDescr& GetDescr(void) const;
88 TDescr& SetDescr(void);
89 void SetDescr(TDescr& v);
90 void ResetDescr(void);
91 bool AddSeqdesc(CSeqdesc& d);
92 CRef<CSeqdesc> RemoveSeqdesc(const CSeqdesc& d);
93 CRef<CSeqdesc> ReplaceSeqdesc(const CSeqdesc& old_desc, CSeqdesc& new_desc);
94 void AddSeq_descr(const TDescr& v);
95
96 virtual bool x_IsSetDescr(void) const = 0;
97 virtual bool x_CanGetDescr(void) const = 0;
98 virtual const TDescr& x_GetDescr(void) const = 0;
99 virtual TDescr& x_SetDescr(void) = 0;
100 virtual void x_SetDescr(TDescr& v) = 0;
101 virtual void x_ResetDescr(void) = 0;
102
103
104 // low level access for CSeqdesc_CI in case sequence is split
105 typedef TDescr::Tdata TDescList;
106 typedef TDescList::const_iterator TDesc_CI;
107 typedef unsigned TDescTypeMask;
108
109 const TDescList& x_GetDescList(void) const;
110 TDesc_CI x_GetFirstDesc(TDescTypeMask types) const;
111 TDesc_CI x_GetNextDesc(TDesc_CI iter, TDescTypeMask types) const;
112 bool x_IsEndDesc(TDesc_CI iter) const;
113 TDesc_CI x_FindDesc(TDesc_CI iter, TDescTypeMask types) const;
114 void x_PrefetchDesc(TDesc_CI last, TDescTypeMask types) const;
115
116 const CSeqdesc* x_SearchFirstDesc(TDescTypeMask type) const;
117
118 TDescTypeMask x_GetExistingDescrMask(void) const;
119
120 void x_AddExistingUserObjectTypes(TUserObjectTypesSet& uo_types) const;
121
122 // annot
123 typedef vector< CRef<CSeq_annot_Info> > TAnnot;
124 typedef list< CRef<CSeq_annot> > TObjAnnot;
125 bool IsSetAnnot(void) const;
126 bool HasAnnots(void) const;
127 const TAnnot& GetAnnot(void) const;
128 const TAnnot& GetLoadedAnnot(void) const;
129
130 void ResetAnnot(void);
131 CRef<CSeq_annot_Info> AddAnnot(CSeq_annot& annot, int chunk_id = 0);
132 void AddAnnot(CRef<CSeq_annot_Info> annot);
133 void RemoveAnnot(CRef<CSeq_annot_Info> annot);
134
135 // object initialization
136 void x_AttachAnnot(CRef<CSeq_annot_Info> info);
137 void x_DetachAnnot(CRef<CSeq_annot_Info> info);
138
139 // info tree initialization
140 virtual void x_DSAttachContents(CDataSource& ds);
141 virtual void x_DSDetachContents(CDataSource& ds);
142
143 virtual void x_TSEAttachContents(CTSE_Info& tse);
144 virtual void x_TSEDetachContents(CTSE_Info& tse);
145
146 virtual void x_ParentAttach(CSeq_entry_Info& parent);
147 virtual void x_ParentDetach(CSeq_entry_Info& parent);
148
149 // index support
150 void x_UpdateAnnotIndexContents(CTSE_Info& tse);
151
152 void x_SetAnnot(void);
153 void x_SetAnnot(const CBioseq_Base_Info& info, TObjectCopyMap* copy_map);
154
155 void x_AddDescrChunkId(const TDescTypeMask& types, TChunkId chunk_id);
156 void x_AddAnnotChunkId(TChunkId chunk_id);
157
158 virtual TObjAnnot& x_SetObjAnnot(void) = 0;
159 virtual void x_ResetObjAnnot(void) = 0;
160
161 void x_DoUpdate(TNeedUpdateFlags flags);
162 void x_SetNeedUpdateParent(TNeedUpdateFlags flags);
163
164 protected:
165 bool x_IsEndNextDesc(TDesc_CI iter) const; // internal inlined method
166
167 friend class CAnnotTypes_CI;
168 friend class CSeq_annot_CI;
169
170 // members
171 TAnnot m_Annot;
172 TObjAnnot* m_ObjAnnot;
173
174 TChunkIds m_DescrChunks;
175 typedef vector<TDescTypeMask> TDescTypeMasks;
176 TDescTypeMasks m_DescrTypeMasks;
177 TChunkIds m_AnnotChunks;
178
179 };
180
181
182
183 /////////////////////////////////////////////////////////////////////
184 //
185 // Inline methods
186 //
187 /////////////////////////////////////////////////////////////////////
188
189
190 inline
IsSetDescr(void) const191 bool CBioseq_Base_Info::IsSetDescr(void) const
192 {
193 return x_NeedUpdate(fNeedUpdate_descr) || x_IsSetDescr();
194 }
195
196
197 inline
CanGetDescr(void) const198 bool CBioseq_Base_Info::CanGetDescr(void) const
199 {
200 return x_NeedUpdate(fNeedUpdate_descr) || x_CanGetDescr();
201 }
202
203
204 inline
IsSetAnnot(void) const205 bool CBioseq_Base_Info::IsSetAnnot(void) const
206 {
207 return m_ObjAnnot != 0 || x_NeedUpdate(fNeedUpdate_annot);
208 }
209
210
211 inline
HasAnnots(void) const212 bool CBioseq_Base_Info::HasAnnots(void) const
213 {
214 return !m_Annot.empty() || x_NeedUpdate(fNeedUpdate_annot);
215 }
216
217
218 inline
GetAnnot(void) const219 const CBioseq_Base_Info::TAnnot& CBioseq_Base_Info::GetAnnot(void) const
220 {
221 x_Update(fNeedUpdate_annot);
222 return m_Annot;
223 }
224
225 inline
GetLoadedAnnot(void) const226 const CBioseq_Base_Info::TAnnot& CBioseq_Base_Info::GetLoadedAnnot(void) const
227 {
228 return m_Annot;
229 }
230
231
232 END_SCOPE(objects)
233 END_NCBI_SCOPE
234
235 #endif//OBJECTS_OBJMGR_IMPL___BIOSEQ_BASE_INFO__HPP
236