NCBI C++ ToolKit
std_seg_hit.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: std_seg_hit.cpp 25706 2012-04-25 00:21:04Z voronov $
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  * Authors: Andrey Yazhuk
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
35 
37 
39 
42 
43 
44 ///////////////////////////////////////////////////////////////////////////////
45 /// CStdSegHit
46 
47 inline bool IsStrandGood(ENa_strand strand)
48 {
49  return strand == eNa_strand_plus ||
50  strand == eNa_strand_minus ||
51  strand == eNa_strand_unknown;
52 }
53 
54  // returns "true" if an alignment can be created from the specified rows of
55  // the given alignment and with the required orientation
56 bool CStdSegHit::HasAlignment(const TStd& std_list,
57  size_t q_index, size_t s_index,
58  TDirection dir)
59 {
60  ITERATE(TStd, it, std_list) {
61  const CStd_seg& stdseg = **it;
62  const CSeq_loc& q_loc = *stdseg.GetLoc()[q_index];
63  const CSeq_loc& s_loc = *stdseg.GetLoc()[s_index];
64  if(! q_loc.IsEmpty() && ! s_loc.IsEmpty()) {
65  ENa_strand q_strand = q_loc.GetStrand();
66  ENa_strand s_strand = s_loc.GetStrand();
67  bool good_strand = IsStrandGood(q_strand) && IsStrandGood(q_strand);
68 
69  if(good_strand) {
70  bool reversed =
71  ((q_strand == eNa_strand_minus) != (s_strand == eNa_strand_minus));
72  bool match = (reversed && dir != CAlnUserOptions::eDirect) ||
73  (! reversed && dir != CAlnUserOptions::eReverse);
74  if(match) {
75  // we have a non empty alignment with correct strands and proper
76  // orientation
77  return true;
78  }
79  }
80  }
81  }
82  return false;
83 }
84 
85 
86 CStdSegHit::CStdSegHit(const objects::CSeq_align& align, int q_index, int s_index)
87 : m_SeqAlign(&align),
88  m_QueryIndex(q_index),
89  m_SubjectIndex(s_index)
90 {
91  _ASSERT(align.GetSegs().IsStd());
92 
93  typedef CStd_seg::TDim TDim;
94  typedef list< CRef< CStd_seg > > TStd;
95  const TStd& std_list = align.GetSegs().GetStd();
96 
97  ITERATE(TStd, it, std_list) {
98  const CStd_seg& stdseg = **it;
99 
100  _ASSERT(q_index < stdseg.GetDim() && q_index >= 0);
101  _ASSERT(s_index < stdseg.GetDim() && s_index >= 0);
102 
103  const CSeq_loc& q_loc = *stdseg.GetLoc()[q_index];
104  const CSeq_loc& s_loc = *stdseg.GetLoc()[s_index];
105 
106  if(! q_loc.IsEmpty() && ! s_loc.IsEmpty()) {
107  // the alignment between the two is defined
108 
109  ENa_strand q_strand = q_loc.GetStrand();
110  ENa_strand s_strand = s_loc.GetStrand();
111  bool good_strand = IsStrandGood(q_strand) && IsStrandGood(q_strand);
112 
113  if(good_strand) {
114  CRange<TSignedSeqPos> q_range = stdseg.GetSeqRange(q_index);
115  CRange<TSignedSeqPos> s_range = stdseg.GetSeqRange(s_index);
116 
117  CStdSegHitElement* elem =
118  new CStdSegHitElement(*this, q_range, s_range, q_strand, s_strand);
119  m_Elements.push_back(elem);
120  }
121  }
122  }
123 }
124 
125 
127 {
128  for(size_t i = 0; i < m_Elements.size(); i++) {
129  delete m_Elements[i];
130  }
131 }
132 
133 
135 {
136  return m_Elements.size();
137 }
138 
139 
140 const IHitElement& CStdSegHit::GetElem(TDim elem_index) const
141 {
142  _ASSERT(size_t(elem_index) < m_Elements.size());
143  return *m_Elements[elem_index];
144 }
145 
146 
147 double CStdSegHit::GetScoreValue(const string& score_name) const
148 {
149  const objects::CSeq_align::TScore& scores = m_SeqAlign->GetScore();
150  ITERATE(objects::CSeq_align::TScore, itS, scores) {
151  const objects::CScore& score = **itS;
152  _ASSERT(score.CanGetId());
153 
154  if(score.GetId().GetStr() == score_name) { // Match
155  const objects::CScore::TValue& val = score.GetValue();
156  switch(val.Which()) {
157  case objects::CScore::TValue::e_Real: return val.GetReal(); break;
158  case objects::CScore::TValue::e_Int: return val.GetInt(); break;
159  default: _ASSERT(false);
160  }
161  }
162  }
163  _ASSERT(false);
164  return -1;
165 }
166 
167 
168 const objects::CSeq_align* CStdSegHit::GetSeqAlign() const
169 {
170  return m_SeqAlign.GetPointer();
171 }
172 
173 
174 ///////////////////////////////////////////////////////////////////////////////
175 ///
177 : m_Hit(NULL)
178 {
179 }
180 
181 
183 {
184 }
185 
186 
188  const TRange& q_r, const TRange& s_r,
189  ENa_strand q_strand,
190  ENa_strand s_strand)
191 : m_Hit(&hit),
192  m_QueryRange(q_r),
193  m_SubjectRange(s_r),
194  m_QueryStrand(q_strand),
195  m_SubjectStrand(s_strand)
196 {
197  // on proteins strand is reported as eNa_strand_unknown, from our stand
198  // point it is equavalent to eNa_strand_plus
201  }
204  }
205 }
206 
207 
209 {
210  return *m_Hit;
211 }
212 
213 
215 {
216  return m_QueryRange.GetFrom();
217 }
218 
219 
221 {
222  return m_SubjectRange.GetFrom();
223 }
224 
225 
227 {
228  return m_QueryRange.GetLength();
229 }
230 
231 
233 {
234  return m_SubjectRange.GetLength();
235 }
236 
237 
239 {
240  return m_QueryStrand;
241 }
242 
243 
245 {
246  return m_SubjectStrand;
247 }
248 
249 
250 
EDirection
Row direction flags.
@ eDirect
Use only sequences whose strand is the same as that of the anchor.
@ eReverse
Use only sequences whose strand is opposite to that of the anchor.
CStdSegHitElement - IHitElement implementation for CStd_seg-based alignments.
Definition: std_seg_hit.hpp:61
virtual TSeqPos GetSubjectLength() const
const CStdSegHit * m_Hit
Definition: std_seg_hit.hpp:82
virtual const IHit & GetHit() const
virtual objects::ENa_strand GetQueryStrand() const
objects::ENa_strand m_SubjectStrand
Definition: std_seg_hit.hpp:86
objects::ENa_strand m_QueryStrand
Definition: std_seg_hit.hpp:85
virtual ~CStdSegHitElement()
virtual objects::ENa_strand GetSubjectStrand() const
virtual TSignedSeqPos GetSubjectStart() const
virtual TSignedSeqPos GetQueryStart() const
virtual TSeqPos GetQueryLength() const
Wraps a CSeq_align containing CStd_seg and provides a simple API for interpreting it as a pairwise al...
Definition: std_seg_hit.hpp:96
static bool HasAlignment(const TStd &std_list, size_t q_index, size_t s_index, TDirection dir)
Definition: std_seg_hit.cpp:56
objects::CSeq_align::TSegs::TStd TStd
virtual double GetScoreValue(const string &score_name) const
CStdSegHit(const objects::CSeq_align &align, int q_index, int s_index)
Definition: std_seg_hit.cpp:86
virtual ~CStdSegHit()
CConstRef< objects::CSeq_align > m_SeqAlign
virtual const IHitElement & GetElem(TDim elem_index) const
TElements m_Elements
virtual const objects::CSeq_align * GetSeqAlign() const
virtual TDim GetElemsCount() const
CRange< TSignedSeqPos > GetSeqRange(TDim row) const
Definition: Std_seg.cpp:145
IHitElement.
Definition: hit.hpp:50
IHit.
Definition: hit.hpp:69
IHitElement::TDim TDim
Definition: hit.hpp:71
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
int TSignedSeqPos
Type for signed sequence position.
Definition: ncbimisc.hpp:887
#define NULL
Definition: ncbistd.hpp:225
ENa_strand GetStrand(void) const
Get the location's strand.
Definition: Seq_loc.cpp:882
TObjectType * GetPointer(void) const THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:1684
position_type GetLength(void) const
Definition: range.hpp:158
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
TFrom GetFrom(void) const
Get the From member data.
Definition: Range_.hpp:222
const TLoc & GetLoc(void) const
Get the Loc member data.
Definition: Std_seg_.hpp:357
TDim GetDim(void) const
Get the Dim member data.
Definition: Std_seg_.hpp:295
bool IsEmpty(void) const
Check if variant Empty is selected.
Definition: Seq_loc_.hpp:516
ENa_strand
strand of nucleic acid
Definition: Na_strand_.hpp:64
@ eNa_strand_plus
Definition: Na_strand_.hpp:66
@ eNa_strand_minus
Definition: Na_strand_.hpp:67
@ eNa_strand_unknown
Definition: Na_strand_.hpp:65
int i
static int match(register const pcre_uchar *eptr, register const pcre_uchar *ecode, const pcre_uchar *mstart, int offset_top, match_data *md, eptrblock *eptrb, unsigned int rdepth)
Definition: pcre_exec.c:513
USING_SCOPE(ncbi::objects)
bool IsStrandGood(ENa_strand strand)
CStdSegHit.
Definition: std_seg_hit.cpp:47
#define _ASSERT
Modified on Mon Dec 11 02:41:08 2023 by modify_doxy.py rev. 669887