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

Go to the SVN repository for this file.

1 #ifndef ALGO_ALIGN_UTIL_ALIGN_SHADOW__HPP
2 #define ALGO_ALIGN_UTIL_ALIGN_SHADOW__HPP
3 
4 /* $Id: align_shadow.hpp 41842 2009-05-11 13:18:03Z dicuccio $
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: Yuri Kapustin
30 *
31 * File Description:
32 * CAlignShadow class
33 *
34 * CAlignShadow is a transcript-based representation of a pairwise sequence alignment.
35 *
36 */
37 
38 
39 #include <corelib/ncbiobj.hpp>
40 
44 
46 
47 #include <math.h>
48 
49 
51 
53  class CSeq_id;
55 
56 
58 {
59 public:
60 
62  typedef TSeqPos TCoord;
63 
64  // c'tors
65  CAlignShadow(void);
66 
67  /// Create the object from a seq-align structure
68  ///
69  /// @param seq_align
70  /// Input seq-align structure to create from
71  /// @param save_xcript
72  /// If true, the alignment transcript string will be run-length encoded
73  /// and saved in m_Transcript. All diagonals are recorded
74  /// as matches.
75  CAlignShadow(const objects::CSeq_align& seq_align, bool save_xcript = false);
76 
77  /// Create the object from a transcript
78  ///
79  /// @param idquery
80  /// Query sequence ID
81  /// @param qstart
82  /// Starting coordinate on the query
83  /// @param qstrand
84  /// Query strand (direction)
85  /// @param idsubj
86  /// Subject sequence ID
87  /// @param sstart
88  /// Starting coordinate on the subject
89  /// @param sstrand
90  /// Subject strand (direction)
91  /// @param xcript
92  /// Plain alignment (edit) transcript.
93  /// Allowed characters are 'M', 'R', 'I', 'D'.
94  ///
95  CAlignShadow(const TId& idquery, TCoord qstart, bool qstrand,
96  const TId& idsubj, TCoord sstart, bool sstrand,
97  const string& xcript);
98 
99  virtual ~CAlignShadow() {}
100 
101  // getters / setters
102  const TId& GetId(Uint1 where) const;
103  const TId& GetQueryId(void) const;
104  const TId& GetSubjId(void) const;
105 
106  void SetId(Uint1 where, const TId& id);
107  void SetQueryId(const TId& id);
108  void SetSubjId(const TId& id);
109 
110  bool GetStrand(Uint1 where) const;
111  bool GetQueryStrand(void) const;
112  bool GetSubjStrand(void) const;
113 
114  void SetStrand(Uint1 where, bool strand);
115  void SetQueryStrand(bool strand);
116  void SetSubjStrand(bool strand);
117  void FlipStrands(void);
118 
119  void SwapQS(void);
120 
121  const TCoord* GetBox(void) const;
122  void SetBox(const TCoord box [4]);
123 
124  TCoord GetMin(Uint1 where) const;
125  TCoord GetMax(Uint1 where) const;
126  TCoord GetQueryMin(void) const;
127  TCoord GetQueryMax(void) const;
128  TCoord GetSubjMin(void) const;
129  TCoord GetSubjMax(void) const;
130  void SetMax(Uint1 where, TCoord pos);
131  void SetMin(Uint1 where, TCoord pos);
132  void SetQueryMin(TCoord pos);
133  void SetQueryMax(TCoord pos);
134  void SetSubjMin(TCoord pos);
135  void SetSubjMax(TCoord pos);
136 
137  TCoord GetQuerySpan(void) const;
138  TCoord GetSubjSpan(void) const;
139 
140  TCoord GetStart(Uint1 where) const;
141  TCoord GetStop(Uint1 where) const;
142  TCoord GetQueryStart(void) const;
143  TCoord GetQueryStop(void) const;
144  TCoord GetSubjStart(void) const;
145  TCoord GetSubjStop(void) const;
146  void SetStop(Uint1 where, TCoord pos);
147  void SetStart(Uint1 where, TCoord pos);
148  void SetQueryStart(TCoord pos);
149  void SetQueryStop(TCoord pos);
150  void SetSubjStart(TCoord pos);
151  void SetSubjStop(TCoord pos);
152 
153  void Shift(Int4 shift_query, Int4 shift_subj);
154 
155  // 0 = query min, 1 = query max, 2 = subj min, 3 = subj max
156  virtual void Modify(Uint1 point, TCoord new_pos);
157 
158  // tabular serialization
160  const CAlignShadow& align_shadow);
161 
162  // optional alignment transcript
163  typedef string TTranscript;
164  const TTranscript& GetTranscript(void) const;
165 
166  static string s_RunLengthEncode(const string& in);
167  static string s_RunLengthDecode(const string& in);
168 
169 
170 protected:
171 
172  std::pair<TId,TId> m_Id; // Query and subj IDs
173 
174  TCoord m_Box [4]; // [0] = query_start, [1] = query_stop
175  // [2] = subj_start,[3] = subj_stop, all zero-based;
176  // Order in which query and subj coordinates go
177  // reflects strand.
178 
179  // tabular serialization without IDs
180  virtual void x_PartialSerialize(CNcbiOstream& os) const;
181 
182  // alignment (edit) transcript is a sequence of elementary
183  // string editing commands followed by their counts (if > 1), e.g.:M23RI5M40D3M9
184 
186 };
187 
188 
189 template <typename T>
190 T round (const T& v)
191 {
192  const T fl (floor(v));
193  return v < fl + 0.5? fl: fl + 1;
194 }
195 
196 
198 
199 #endif /* ALGO_ALIGN_UTIL_ALIGN_SHADOW__HPP */
T round(const T &v)
TSeqPos TCoord
CConstRef< objects::CSeq_id > TId
TTranscript m_Transcript
std::pair< TId, TId > m_Id
virtual ~CAlignShadow()
string TTranscript
CObject –.
Definition: ncbiobj.hpp:180
#define T(s)
Definition: common.h:230
CNcbiOstream & operator<<(CNcbiOstream &out, const CEquivRange &range)
Definition: equiv_range.cpp:96
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
TSeqPos GetStop(const CSeq_loc &loc, CScope *scope, ESeqLocExtremes ext=eExtreme_Positional)
If only one CBioseq is represented by CSeq_loc, returns the position at the stop of the location.
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,...
ENa_strand GetStrand(const CSeq_loc &loc, CScope *scope=0)
Returns eNa_strand_unknown if multiple Bioseqs in loc Returns eNa_strand_other if multiple strands in...
TSeqPos GetStart(const CSeq_loc &loc, CScope *scope, ESeqLocExtremes ext=eExtreme_Positional)
If only one CBioseq is represented by CSeq_loc, returns the position at the start of the location.
uint8_t Uint1
1-byte (8-bit) unsigned integer
Definition: ncbitype.h:99
int32_t Int4
4-byte (32-bit) signed integer
Definition: ncbitype.h:102
#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
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
#define NCBI_XALGOALIGN_EXPORT
Definition: ncbi_export.h:985
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
std::istream & in(std::istream &in_, double &x_)
Modified on Mon May 27 04:38:11 2024 by modify_doxy.py rev. 669887