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

Go to the SVN repository for this file.

1 /* $Id: alnvec_row_handle.cpp 45564 2020-09-08 19:05:27Z shkeda $
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 
29 #include <ncbi_pch.hpp>
30 
31 #include <corelib/ncbistd.hpp>
32 
34 #include <gui/objutils/utils.hpp>
35 #include <gui/objutils/label.hpp>
36 
37 
40 
41 ///////////////////////////////////////////////////////////////////////////////
42 /// CAlnVecRowHandle
43 
45 {
46  return m_Row;
47 }
48 
49 const string& CAlnVecRowHandle::GetText() const
50 {
51  if (m_Text.empty()) {
52  m_Text = GetSeq_id().GetSeqIdString();
54  m_Text.clear();
56  }
57  }
58  return m_Text;
59 }
60 
61 
63 {
64  return m_AlnVec->GetSeqAlnStart(m_Row);
65 }
66 
67 
69 {
70  return m_AlnVec->GetSeqAlnStop(m_Row);
71 }
72 
73 
75 {
76  return m_AlnVec->GetSeqStart(m_Row);
77 }
78 
79 
81 {
82  return m_AlnVec->GetSeqStop(m_Row);
83 }
84 
85 
87 {
88  return m_AlnVec->IsNegativeStrand(m_Row);
89 }
90 
91 
93 {
94  return m_AlnVec->GetSeqAlnRange(m_Row);
95 }
96 
97 
100  bool try_reverse_dir) const
101 {
103  switch(dir) {
104  case IAlnExplorer::eLeft:
105  av_dir = CAlnVec::eLeft;
106  break;
108  av_dir = CAlnVec::eRight;
109  break;
110  default:
111  break;
112  }
113  return m_AlnVec->GetAlnPosFromSeqPos(m_Row, seq_pos, av_dir, try_reverse_dir);
114 }
115 
116 
119  bool try_reverse_dir) const
120 {
122  switch(dir) {
123  case IAlnExplorer::eLeft:
124  av_dir = CAlnVec::eLeft;
125  break;
127  av_dir = CAlnVec::eRight;
128  break;
129  default:
130  break;
131  }
132  return m_AlnVec->GetSeqPosFromAlnPos(m_Row, aln_pos, av_dir, try_reverse_dir);
133 }
134 
135 
139 {
140  int av_flags = 0;
141  switch(flags) {
143  av_flags = CAlnVec::fAllChunks;
144  break;
146  av_flags = CAlnVec::fSkipAllGaps;
147  break;
149  av_flags = CAlnVec::fInsertsOnly;
150  break;
152  av_flags = CAlnVec::fSkipInserts;
153  break;
154  default:
155  _ASSERT(false);
156  }
157  bool reversed = m_AlnVec->IsNegativeStrand(m_Row);
158  return new CAlnVecIterator(*m_AlnVec->GetAlnChunks(m_Row, range, av_flags), reversed);
159 }
160 
161 
163 {
164  return true;
165 }
166 
167 
169  const IAlnExplorer::TRange &seq_rng) const
170 {
171  return m_AlnVec->GetSeqString(buffer, m_Row, seq_rng);
172 }
173 
174 
176  const IAlnExplorer::TSignedRange &aln_rng) const
177 {
178  if (!CanGetBioseqHandle())
179  return buffer;
180  // the widths will be set only if the alignment is mix of na/aa rows
181  if (m_AlnVec->GetWidth(m_Row) == 3 && m_GenCode == -1) {
182  m_AlnVec->SetGenCode(GetGenCode(), m_Row);
183  }
184 
185  return m_AlnVec->GetAlnSeqString(buffer, m_Row, aln_rng);
186 }
187 
188 
190 {
191  if (m_CanGetBioseq == -1) {
192  CBioseq_Handle bsh;
193  try {
194  bsh = m_AlnVec->GetBioseqHandle(m_Row);
195  m_CanGetBioseq = bsh ? 1 : 0;
196  } catch (CAlnException& e) {
197  if (e.GetErrCode() == CAlnException::eInvalidSeqId)
198  m_CanGetBioseq = 0;
199  }
200 
201  }
202  return m_CanGetBioseq == 1;
203 }
204 
205 
206 const objects::CBioseq_Handle& CAlnVecRowHandle::GetBioseqHandle() const
207 {
208  return m_AlnVec->GetBioseqHandle(m_Row);
209 }
210 
211 const objects::CSeq_id& CAlnVecRowHandle::GetSeq_id() const
212 {
213  return m_AlnVec->GetSeqId(m_Row);
214 }
215 
216 objects::CScope& CAlnVecRowHandle::GetScope() const
217 {
218  return m_AlnVec->GetScope();
219 }
220 
221 
222 
224 {
225  if (!CanGetBioseqHandle())
226  return false;
227  if (m_AlnVec->GetBioseqHandle(m_Row).IsAa())
228  return true;
229 
230  return (m_AlnVec->GetWidth(m_Row) == 3);
231 }
232 
234 {
235  return m_AlnVec->IsSetAnchor() && m_AlnVec->GetAnchor() == m_Row;
236 }
237 
238 
240 {
241  TNumrow num_rows = m_AlnVec->GetNumRows();
242  if (num_rows <= 1)
243  return false;
244  int base_width = m_AlnVec->GetWidth(0);
245  for (TNumrow row = 1; row < num_rows; ++row) {
246  if (base_width != m_AlnVec->GetWidth(row))
247  return true;
248  }
249  return false;
250 }
251 
252 
254 {
255  if (IsNucProtAlignment())
256  return 1;
257  return m_AlnVec->GetWidth(m_Row);
258 }
259 
261 {
262  if (m_GenCode == -1)
264  return m_GenCode;
265 }
266 
USING_SCOPE(objects)
@ fSkipInserts
Definition: alnmap.hpp:94
@ fAllChunks
Definition: alnmap.hpp:77
@ fSkipAllGaps
Definition: alnmap.hpp:93
@ fInsertsOnly
Definition: alnmap.hpp:97
CAlnVecIterator - IAlnSegmentIterator implementation for CAlnMap::CAlnChunkVec.
const string & GetText() const
virtual TSignedSeqPos GetAlnPosFromSeqPos(TSeqPos seq_pos, IAlnExplorer::ESearchDirection dir=IAlnExplorer::eNone, bool try_reverse_dir=true) const
virtual IAlnSegmentIterator * CreateSegmentIterator(const IAlnExplorer::TSignedRange &range, IAlnSegmentIterator::EFlags flags) const
virtual const objects::CBioseq_Handle & GetBioseqHandle() const
virtual TSignedSeqPos GetSeqStop() const
virtual string & GetAlnSeqString(string &buffer, const IAlnExplorer::TSignedRange &aln_rng) const
virtual string & GetSeqString(string &buffer, const IAlnExplorer::TRange &seq_rng) const
virtual TSignedSeqPos GetSeqPosFromAlnPos(TSeqPos aln_pos, IAlnExplorer::ESearchDirection dir=IAlnExplorer::eNone, bool try_reverse_dir=true) const
virtual TSignedSeqPos GetSeqAlnStart() const
virtual IAlnExplorer::TSignedRange GetSeqAlnRange() const
virtual bool UsesAATranslation() const
virtual bool CanGetSeqString() const
objects::CAlnVec * m_AlnVec
virtual int GetGenCode() const
virtual bool CanGetBioseqHandle() const
virtual const objects::CSeq_id & GetSeq_id() const
virtual TSignedSeqPos GetSeqStart() const
virtual bool IsNucProtAlignment() const
virtual TNumrow GetRowNum() const
CAlnVecRowHandle.
virtual bool IsNegativeStrand() const
virtual TSignedSeqPos GetSeqAlnStop() const
virtual objects::CScope & GetScope() const
virtual bool IsAnchor() const
virtual size_t GetBaseWidth() const
CBioseq_Handle –.
IAlnExplorer::TNumrow TNumrow
Definition: alnmulti_ds.hpp:61
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)
Alignment segment iterator interface.
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)
Include a standard set of the NCBI C++ Toolkit most basic headers.
static uch flags
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
int TSignedSeqPos
Type for signed sequence position.
Definition: ncbimisc.hpp:887
static bool IsVDBAccession(const string &acc)
Check if string starts with ("SRA", "SRR", "DRR", "ERR")
Definition: utils.cpp:887
static int GetGenCode(const objects::CBioseq_Handle &handle)
Returns Bioseq's Genetic Code.
Definition: utils.cpp:2358
static void GetLabel(const CObject &obj, string *label, ELabelType type=eDefault)
Definition: label.cpp:140
@ eDefault
Definition: label.hpp:73
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
range(_Ty, _Ty) -> range< _Ty >
static pcre_uint8 * buffer
Definition: pcretest.c:1051
#define _ASSERT
Modified on Tue Dec 05 02:16:31 2023 by modify_doxy.py rev. 669887