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

Go to the SVN repository for this file.

1 #ifndef OBJTOOLS_ALNMGR___ALN_EXPLORER__HPP
2 #define OBJTOOLS_ALNMGR___ALN_EXPLORER__HPP
3 /* $Id: aln_explorer.hpp 55096 2012-07-16 17:39:41Z grichenk $
4 * ===========================================================================
5 *
6 * PUBLIC DOMAIN NOTICE
7 * National Center for Biotechnology Information
8 *
9 * This software/database is a "United States Government Work" under the
10 * terms of the United States Copyright Act. It was written as part of
11 * the author's official duties as a United States Government employee and
12 * thus cannot be copyrighted. This software/database is freely available
13 * to the public for use. The National Library of Medicine and the U.S.
14 * Government have not placed any restriction on its use or reproduction.
15 *
16 * Although all reasonable efforts have been taken to ensure the accuracy
17 * and reliability of the software and data, the NLM and the U.S.
18 * Government do not and cannot warrant the performance or results that
19 * may be obtained by using this software or data. The NLM and the U.S.
20 * Government disclaim all warranties, express or implied, including
21 * warranties of performance, merchantability or fitness for any particular
22 * purpose.
23 *
24 * Please cite the author in any work or product based on this material.
25 *
26 * ===========================================================================
27 *
28 * Authors: Andrey Yazhuk, Kamen Todorov, NCBI
29 *
30 * File Description:
31 * Abstract alignment explorer interface
32 *
33 * ===========================================================================
34 */
35 
36 
37 #include <corelib/ncbistd.hpp>
38 
39 #include <util/range.hpp>
40 #include <objmgr/seq_vector.hpp>
41 
42 
44 
45 
46 /// Alignment explorer interface. Base class for CAlnMap and CSparseAln.
47 /// @sa CAlnMap
48 /// @sa CSparseAln
50 {
51 public:
52  typedef int TNumrow;
54 
55  enum EAlignType {
56  fDNA = 0x01,
57  fProtein = 0x02,
58  fMixed = 0x04,
60  fInvalid = 0x80000000
61  };
62 
63  /// Position search options.
65  eNone, ///< No search
66  eBackwards, ///< Towards lower seq coord (to the left if plus strand, right if minus)
67  eForward, ///< Towards higher seq coord (to the right if plus strand, left if minus)
68  eLeft, ///< Towards lower aln coord (always to the left)
69  eRight ///< Towards higher aln coord (always to the right)
70  };
71 
72  enum ESortState {
77  };
78 
81 };
82 
83 
84 /// Alignment segment interface.
85 /// @sa CAlnChunkSegment
86 /// @sa CSparseSegment
88 {
89 public:
91 
92  typedef unsigned TSegTypeFlags; /// binary OR of ESegTypeFlags
93  /// Segment type flags.
95  fAligned = 1 << 0, ///< Aligned segment.
96 
97  fGap = 1 << 1, ///< Both anchor row and the selected row are not
98  /// included in the segment (some other row is
99  /// present and the alignment range of this
100  /// segment is not empty).
101 
102  fReversed = 1 << 2, ///< The selected row is reversed (relative to
103  /// the anchor).
104 
105  fIndel = 1 << 3, ///< Either anchor or the selected row is not
106  /// present in the segment. The corresponding
107  /// range (GetAlnRange or GetRange) is empty.
108 
109  fUnaligned = 1 << 4, ///< The range on the selected sequence does not
110  /// participate in the alignment (the alignment
111  /// range of the segment is empty, the row range
112  /// is not).
113 
114  fInvalid = (TSegTypeFlags) 0x80000000, ///< The iterator is in bad state.
115 
117  };
118 
119  virtual ~IAlnSegment(void) {}
120 
121  /// Get current segment type.
122  virtual TSegTypeFlags GetType(void) const = 0;
123 
124  /// Get alignment range for the segment.
125  virtual const TSignedRange& GetAlnRange(void) const = 0;
126 
127  /// Get the selected row range.
128  virtual const TSignedRange& GetRange(void) const = 0;
129 
130  inline bool IsInvalidType(void) const { return (GetType() & fInvalid) != 0; }
131  inline bool IsAligned(void) const { return (GetType() & fAligned) != 0; }
132  /// Check if there's a gap on the selected row.
133  inline bool IsGap(void) const {
134  return !IsAligned() && GetRange().Empty();
135  }
136  inline bool IsIndel(void) const { return (GetType() & fIndel) != 0; }
137  inline bool IsReversed(void) const { return (GetType() & fReversed) != 0; }
138 };
139 
140 
141 /// Alignment segment iterator interface.
142 /// @sa CAlnVecIterator
143 /// @sa CSparse_CI
145 {
146 public:
148 
149  /// Iterator options
150  enum EFlags {
151  eAllSegments, ///< Iterate all segments
152  eSkipGaps, ///< Skip gap segments (show only aligned ranges)
153  eInsertsOnly, ///< Iterate only ranges not participating in the
154  /// alignment (unaligned segments)
155  eSkipInserts ///< Iterate segments where at least some rows are
156  /// aligned (including gap segments)
157  };
158 
159  virtual ~IAlnSegmentIterator(void) {}
160 
161  /// Create a copy of the iterator.
162  virtual IAlnSegmentIterator* Clone(void) const = 0;
163 
164  /// Returns true if iterator points to a valid segment.
165  virtual operator bool(void) const = 0;
166 
167  /// Advance to the next segment.
168  virtual IAlnSegmentIterator& operator++(void) = 0;
169 
170  /// Compare iterators.
171  virtual bool operator==(const IAlnSegmentIterator& it) const = 0;
172  virtual bool operator!=(const IAlnSegmentIterator& it) const = 0;
173 
174  virtual const value_type& operator*(void) const = 0;
175  virtual const value_type* operator->(void) const = 0;
176 };
177 
178 
180 
181 #endif // OBJTOOLS_ALNMGR___ALN_EXPLORER__HPP
Alignment explorer interface.
CRange< TSignedSeqPos > TSignedRange
CRange< TSeqPos > TRange
objects::CSeqVector::TResidue TResidue
ESearchDirection
Position search options.
@ eNone
No search.
@ eRight
Towards higher aln coord (always to the right)
@ eLeft
Towards lower aln coord (always to the left)
@ eBackwards
Towards lower seq coord (to the left if plus strand, right if minus)
@ eForward
Towards higher seq coord (to the right if plus strand, left if minus)
Alignment segment iterator interface.
virtual const value_type * operator->(void) const =0
virtual bool operator==(const IAlnSegmentIterator &it) const =0
Compare iterators.
virtual IAlnSegmentIterator & operator++(void)=0
Advance to the next segment.
virtual ~IAlnSegmentIterator(void)
virtual const value_type & operator*(void) const =0
virtual IAlnSegmentIterator * Clone(void) const =0
Create a copy of the iterator.
IAlnSegment value_type
virtual bool operator!=(const IAlnSegmentIterator &it) const =0
EFlags
Iterator options.
@ eSkipInserts
Iterate segments where at least some rows are aligned (including gap segments)
@ eInsertsOnly
Iterate only ranges not participating in the alignment (unaligned segments)
@ eAllSegments
Iterate all segments.
@ eSkipGaps
Skip gap segments (show only aligned ranges)
Alignment segment interface.
virtual const TSignedRange & GetRange(void) const =0
Get the selected row range.
ESegTypeFlags
binary OR of ESegTypeFlags
@ fAligned
Aligned segment.
@ fInvalid
The iterator is in bad state.
@ fIndel
Either anchor or the selected row is not present in the segment.
@ fUnaligned
The range on the selected sequence does not participate in the alignment (the alignment range of the ...
@ fReversed
The selected row is reversed (relative to the anchor).
@ fGap
Both anchor row and the selected row are not included in the segment (some other row is present and t...
bool IsReversed(void) const
virtual TSegTypeFlags GetType(void) const =0
Get current segment type.
bool IsIndel(void) const
bool IsAligned(void) const
bool IsInvalidType(void) const
bool IsGap(void) const
Check if there's a gap on the selected row.
virtual const TSignedRange & GetAlnRange(void) const =0
Get alignment range for the segment.
IAlnExplorer::TSignedRange TSignedRange
virtual ~IAlnSegment(void)
unsigned TSegTypeFlags
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define bool
Definition: bool.h:34
objects::CSeqVectorTypes::TResidue TResidue
bool Empty(void) const
Definition: range.hpp:148
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
Modified on Fri Sep 20 14:58:18 2024 by modify_doxy.py rev. 669887