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

Go to the SVN repository for this file.

1 /* $Id: Dense_seg.hpp 76684 2017-02-27 16:18:20Z astashya $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: .......
27  *
28  * File Description:
29  * .......
30  *
31  * Remark:
32  * This code was originally generated by application DATATOOL
33  * using specifications from the data definition file
34  * 'seqalign.asn'.
35  */
36 
37 #ifndef OBJECTS_SEQALIGN_DENSE_SEG_HPP
38 #define OBJECTS_SEQALIGN_DENSE_SEG_HPP
39 
40 
41 // generated includes
43 
45 #include <util/range.hpp>
46 
47 #include <serial/objhook.hpp>
48 
49 // generated classes
50 
52 
53 BEGIN_objects_SCOPE // namespace ncbi::objects::
54 
55 // forward declarations
56 class CSeq_loc;
57 class CSeq_interval;
58 
59 
61 {
63 public:
64  // constructor
65  CDense_seg(void);
66  // destructor
67  ~CDense_seg(void);
68 
69  /// overloaded Assign()
70  void Assign(const CSerialObject& obj,
72 
73  typedef vector<int> TWidths;
74 
75  // optional
76  // typedef vector<int> TWidths
77  bool IsSetWidths(void) const;
78  bool CanGetWidths(void) const;
79  void ResetWidths(void);
80  const TWidths& GetWidths(void) const;
81  TWidths& SetWidths(void);
82 
83  // Validators
84  TDim CheckNumRows(void) const;
85  TNumseg CheckNumSegs(void) const;
86  void Validate (bool full_test = false) const;
87 
88  // GetSeqRange
89  CRange<TSeqPos> GetSeqRange(TDim row) const;
90  TSeqPos GetSeqStart(TDim row) const;
91  TSeqPos GetSeqStop(TDim row) const;
92 
93  // Get Seq_id (the first one if segments have different strands).
94  const CSeq_id& GetSeq_id(TDim row) const;
95 
96  // Get strand (the first one if segments have different strands).
97  ENa_strand GetSeqStrand(TDim row) const;
98 
99  /// Reverse the segments' orientation
100  void Reverse(void);
101 
102  /// Swap two rows (changing *order*, not content)
103  void SwapRows(TDim row1, TDim row2);
104 
105  /// Create a new dense-seg with added all unaligned pieces
106  /// (implicit inserts), if any, between segments.
107  CRef<CDense_seg> FillUnaligned() const;
108 
109  /// Extract a slice of the alignment that includes the specified range
110  CRef<CDense_seg> ExtractSlice(TDim row, TSeqPos from, TSeqPos to) const;
111 
112  /// Extract specified rows of the alignment, in specified order.
113  /// The result is compacted with Compact, but may contain
114  /// segments in which all rows have gaps, which can be removed
115  /// with RemovePureGapSegs.
116  /// The rows in the new alignment are in the order given by the
117  /// rows parameter. Thus, this can also be used for
118  /// permuting the order of rows.
119  /// @sa RemovePureGapSegs
120  CRef<CDense_seg> ExtractRows(const vector<TDim>& rows) const;
121 
122  /// Join adjacent mergeable segments to create a more compact
123  /// alignment
124  void Compact();
125 
126  /// Order adjacent gaps, so that the side with sequence is
127  /// in row-decending order
128  void OrderAdjacentGaps();
129 
130  /// Remove any segments in which every row has a gap
131  /// (these can arise when ExtractRows is used)
132  /// @sa ExtractRows
133  void RemovePureGapSegs();
134 
135  /// Trim leading/training gaps if possible
136  void TrimEndGaps();
137 
138  /// Offset row's coords
139  void OffsetRow(TDim row, TSignedSeqPos offset);
140 
141  /// @deprecated (use sequence::RemapAlignToLoc())
142  /// @sa RemapAlignToLoc
143  NCBI_DEPRECATED void RemapToLoc(TDim row, const CSeq_loc& loc,
144  bool ignore_strand = false);
145 
146  /// Initialize from pairwise alignment transcript
147  /// (a string representation produced by CNWAligner)
148  /// @sa CNWAligner
149  void FromTranscript(TSeqPos query_start, ENa_strand query_strand,
150  TSeqPos subj_start, ENa_strand subj_strand,
151  const string& transcript );
152 
153  static void SetReserveHooks(CObjectIStream& in);
154  static void SetGlobalReserveHooks(void);
155 
156  // reserve memory for "starts", "lens", and "strands" vectors
158  : public CPreReadClassMemberHook
159  {
160  virtual void PreReadClassMember(CObjectIStream& in,
161  const CObjectInfoMI& member);
162  };
163 
164  CRef<CSeq_interval> CreateRowSeq_interval(TDim row) const;
165 
166 protected:
167  TNumseg x_FindSegment(TDim row, TSignedSeqPos pos) const;
168 
169 
170 private:
171  // Prohibit copy constructor and assignment operator
174 
175  // data
176  Uint4 m_set_State1[1];
178 };
179 
180 
183 
184 
185 /////////////////// CDense_seg inline methods
186 
187 // constructor
188 inline
190 {
191  memset(m_set_State1, 0, sizeof(m_set_State1));
192 }
193 
194 
195 inline
196 bool CDense_seg::IsSetWidths(void) const
197 {
198  return ((m_set_State1[0] & 0x3) != 0);
199 }
200 
201 
202 inline
203 bool CDense_seg::CanGetWidths(void) const
204 {
205  return true;
206 }
207 
208 
209 inline
210 const vector<int>& CDense_seg::GetWidths(void) const
211 {
212  return m_Widths;
213 }
214 
215 
216 inline
217 vector<int>& CDense_seg::SetWidths(void)
218 {
219  m_set_State1[0] |= 0x1;
220  return m_Widths;
221 }
222 
223 
224 inline
226 {
227  m_Widths.clear();
228  m_set_State1[0] &= ~0x3;
229 
230 }
231 
232 
233 inline
235 {
236  return CRange<TSeqPos>(GetSeqStart(row), GetSeqStop(row));
237 }
238 
239 
240 /////////////////// end of CDense_seg inline methods
241 
242 
243 /////////////////////////////////////////////////////////////////////////////
244 // Read hooks to reserve memory of Dense-seg vector<> to estimated size.
245 /////////////////////////////////////////////////////////////////////////////
246 
247 
249  : public CReadClassMemberHook
250 {
251 public:
252  void ReadClassMember(CObjectIStream& in, const CObjectInfoMI& member);
253 
254  static void SetHook(CObjectIStream& in);
255  static void SetGlobalHook(void);
256 
257 private:
258  static CObjectTypeInfoMI x_GetMember(void);
259 };
260 
261 
263  : public CReadClassMemberHook
264 {
265 public:
266  void ReadClassMember(CObjectIStream& in, const CObjectInfoMI& member);
267 
268  static void SetHook(CObjectIStream& in);
269  static void SetGlobalHook(void);
270 
271 private:
272  static CObjectTypeInfoMI x_GetMember(void);
273 };
274 
275 
277  : public CReadClassMemberHook
278 {
279 public:
280  void ReadClassMember(CObjectIStream& in, const CObjectInfoMI& member);
281 
282  static void SetHook(CObjectIStream& in);
283  static void SetGlobalHook(void);
284 
285 private:
286  static CObjectTypeInfoMI x_GetMember(void);
287 };
288 
289 
290 END_objects_SCOPE // namespace ncbi::objects::
291 
293 
294 #endif // OBJECTS_SEQALIGN_DENSE_SEG_HPP
NCBISER_HAVE_GLOBAL_READ_MEMBER_HOOK(CDense_seg, "starts,lens,strands", new CDense_seg::CReserveHook) inline CDense_seg
Definition: Dense_seg.hpp:181
Data storage class.
ENa_strand Reverse(ENa_strand s)
Definition: Na_strand.hpp:90
Dense-seg: the densist packing for sequence alignments only.
Definition: Dense_seg_.hpp:92
CDense_seg & operator=(const CDense_seg &value)
TWidths m_Widths
Definition: Dense_seg.hpp:177
CDense_seg(void)
void ResetWidths(void)
Definition: Dense_seg.hpp:225
TSeqPos GetSeqStop(TDim row) const
Definition: Dense_seg.cpp:203
TWidths & SetWidths(void)
Definition: Dense_seg.hpp:217
TSeqPos GetSeqStart(TDim row) const
Definition: Dense_seg.cpp:165
bool IsSetWidths(void) const
Definition: Dense_seg.hpp:196
CDense_seg(const CDense_seg &value)
bool CanGetWidths(void) const
Definition: Dense_seg.hpp:203
Uint4 m_set_State1[1]
Definition: Dense_seg.hpp:176
vector< int > TWidths
Definition: Dense_seg.hpp:73
CRange< TSeqPos > GetSeqRange(TDim row) const
Definition: Dense_seg.hpp:234
CDense_seg_Base Tparent
Definition: Dense_seg.hpp:62
const TWidths & GetWidths(void) const
Definition: Dense_seg.hpp:210
CObjectIStream –.
Definition: objistr.hpp:93
CObjectInfoMI –.
Definition: objectiter.hpp:432
CObjectTypeInfoMI –.
Definition: objectiter.hpp:246
Read hook for data member of a containing object (eg, SEQUENCE)
Definition: objhook.hpp:100
Read hook for data member of a containing object (eg, SEQUENCE)
Definition: objhook.hpp:78
Base class for all serializable objects.
Definition: serialbase.hpp:150
char value[7]
Definition: config.c:431
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
int TSignedSeqPos
Type for signed sequence position.
Definition: ncbimisc.hpp:887
ESerialRecursionMode
How to assign and compare child sub-objects of serial objects.
Definition: serialdef.hpp:191
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
@ eRecursive
Recursively.
Definition: serialdef.hpp:192
#define NCBI_DEPRECATED
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_SEQALIGN_EXPORT
Definition: ncbi_export.h:744
ENa_strand
strand of nucleic acid
Definition: Na_strand_.hpp:64
std::istream & in(std::istream &in_, double &x_)
int offset
Definition: replacements.h:160
Modified on Thu Mar 28 17:11:24 2024 by modify_doxy.py rev. 669887