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

Go to the SVN repository for this file.

1 #ifndef GUI_WIDGETS_ALN_MULTIPLE___ALNMULTI_DS__HPP
2 #define GUI_WIDGETS_ALN_MULTIPLE___ALNMULTI_DS__HPP
3 
4 /* $Id: alnmulti_ds.hpp 45784 2020-11-25 16:01:31Z shkeda $
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  * Authors: Mike DiCuccio, Andrey Yazhuk
30  *
31  * File Description:
32  *
33  */
34 
35 #include <corelib/ncbistd.hpp>
36 #include <corelib/ncbiobj.hpp>
37 
38 #include <util/range_coll.hpp>
39 
41 
43 
45 
47 #include <objmgr/bioseq_handle.hpp>
48 #include <objmgr/scope.hpp>
49 
50 
52 
53 
54 /// IAlignRowHandle provides an abstract way to access alignment row data.
55 ///
56 /// IAlignRowHandle-inherited classes are supposed to provide proprietary
57 /// interface depending on the nature of data being represented.
59 {
60 public:
63 
64 public:
65  virtual TNumrow GetRowNum() const = 0;
66  virtual const string& GetText() const = 0;
67  virtual TSignedSeqPos GetSeqAlnStart() const = 0;
68  virtual TSignedSeqPos GetSeqAlnStop() const = 0;
70 
71  virtual TSignedSeqPos GetSeqStart() const = 0;
72  virtual TSignedSeqPos GetSeqStop() const = 0;
73  virtual bool IsNegativeStrand() const = 0;
74 
77  bool try_reverse_dir = true) const = 0;
80  bool try_reverse_dir = true) const = 0;
81 
82  virtual IAlnSegmentIterator*
85 
86  virtual bool CanGetSeqString() const = 0;
87  virtual string& GetSeqString (string &buffer, const IAlnExplorer::TRange &seq_rng) const = 0;
88  virtual string& GetAlnSeqString(string &buffer, const IAlnExplorer::TSignedRange &aln_rng) const = 0;
89 
90 
91  virtual bool CanGetBioseqHandle() const = 0;
92  virtual const objects::CBioseq_Handle& GetBioseqHandle() const = 0;
93  virtual const objects::CSeq_id& GetSeq_id() const = 0;
94  //virtual objects::CScope& GetScope() const = 0;
95 
96  virtual bool UsesAATranslation() const = 0;
97 
98  // nuc-prot alignemnt
99  virtual bool IsNucProtAlignment() const = 0;
100 
101  virtual size_t GetBaseWidth() const = 0;
102 
103  virtual int GetGenCode() const = 0;
104 
105  virtual bool IsAnchor() const
106  {
107  return false;
108  }
110  {
111  m_fExtOrgLookup = f;
112  }
113 
114  virtual bool IsConsensus() const;
115  virtual TSeqPos GetSeqLength() const;
116  virtual const string& GetOrgLabel(bool fExtOrgLookup = false) const;
117  virtual int GetTaxId(bool fExtOrgLookup = false) const;
118  virtual void GetTaxonomy(string& taxonomy, bool fExtOrgLookup = false) const;
119 
120  virtual void GetIsolationSource(string& value) const {}
121  virtual void GetCountry(string& value) const {}
122  virtual void GetCollectionDate(string& value) const {}
123  virtual void GetHost(string& value) const {}
124  virtual void GetGeneSymbol(string& value) const {}
125 
126  virtual double GetPctIdentity() const { return 0.;}
127  virtual double GetPctCoverage() const { return 0.;}
128  virtual int GetMismatches() const { return 0;}
129 
130 protected:
131  virtual ~IAlignRowHandle() {
132  }
133  bool m_fExtOrgLookup = false;
134  mutable string m_OrgLabel;
135  mutable int m_TaxId = 0;
136 };
137 
138 ////////////////////////////////////////////////////////////////////////////////
139 /// Class CConsensusRow - Simple interface to a row that represents the
140 /// consensus for rendering purposes
141 ///
142 /// Rows need access to a consensus row, which may be a consensus or selected
143 /// master row, for rendering. It gives the row the option to not render characters
144 /// when they match the consensus
146  public CObjectEx
147 {
148 public:
150 
151 public:
153  : m_Handle(handle)
154  {}
156 
157  const IAlignRowHandle& GetHandle() const { return *m_Handle; }
158  void SetHandle(const IAlignRowHandle* h) { m_Handle = h; }
159 
160  bool IsValid() const { return m_Handle != NULL; }
161 
162  virtual string& GetAlnSeqString(string &buffer, const IAlnExplorer::TSignedRange &aln_rng) const;
163  virtual string& GetStringAtPos(string& buffer, TSignedSeqPos aln_pos) const;
164 
165 protected:
167 };
168 
169 inline string& CConsensusRow::GetAlnSeqString(string &buffer, const IAlnExplorer::TSignedRange &aln_rng) const
170 {
171  if (!m_Handle)
172  return buffer;
173 
174  return m_Handle->GetAlnSeqString(buffer, aln_rng);
175 }
176 
177 inline string& CConsensusRow::GetStringAtPos(string& buffer, TSignedSeqPos aln_pos) const
178 {
179  if (!m_Handle)
180  return buffer;
181 
183  auto pos = m_Handle->GetSeqPosFromAlnPos(aln_pos, IAlnExplorer::eRight);
184  pos = (pos / 3) * 3;
185  return m_Handle->GetSeqString(buffer, IAlnExplorer::TRange(pos, pos + 3));
186  }
187  else {
188  return GetAlnSeqString(buffer, IAlnExplorer::TSignedRange(aln_pos, aln_pos));
189  }
190 }
191 
192 
193 ///////////////////////////////////////////////////////////////////////////////
194 /// IAlnMultiDataSource - interface to a data source representing an abstract
195 /// multiple alignment.
197  : public CDataChangeNotifier,
198  public IScoringAlignment
199 {
200 public:
205 
206 
207 public:
208  virtual bool IsEmpty() const = 0;
209 
210  virtual void SetGapChar(TResidue gap_char) = 0;
211 
213 
214  /// number of rows in alignment
215  virtual TNumrow GetNumRows(void) const = 0;
216 
217  virtual TSeqPos GetAlnStart(void) const = 0;
218  virtual TSeqPos GetAlnStop(void) const = 0;
219 
220  virtual TSeqPos GetSeqStart(TNumrow row) const = 0;
221  virtual TSeqPos GetSeqStop(TNumrow row) const = 0;
222 
223  /// returns index of the Consensus row or -1 if it doesn't exist
224  virtual int GetConsensusRow() const = 0;
225 
226  virtual bool CanCreateConsensus() = 0;
227  virtual void CreateConsensus() = 0;
228  virtual void SetCreateConsensus(bool b) = 0;
229 
230  virtual const IAlignRowHandle* GetRowHandle(TNumrow row) const = 0;
231 
232  /// Anchoring methods
233  virtual bool IsSetAnchor(void) const = 0;
234  virtual TNumrow GetAnchor(void) const = 0;
235  virtual bool CanChangeAnchor(void) const = 0;
236  virtual bool SetAnchor(TNumrow anchor) = 0;
237  virtual bool UnsetAnchor(void) = 0;
238 
239  virtual bool CanGetId(TNumrow row) const = 0;
240  virtual const objects::CSeq_id& GetSeqId(TNumrow row) const = 0;
241 
242  virtual bool IsPositiveStrand(TNumrow row) const = 0;
243  virtual bool IsNegativeStrand(TNumrow row) const = 0;
244 
247  bool try_reverse_dir = true) const = 0;
248 
251  bool try_reverse_dir = true) const = 0;
252 
253  virtual string& GetAlnSeqString(TNumrow row, string &buffer,
254  const IAlnExplorer::TSignedRange& aln_range) const = 0;
255 
259 
260  virtual void GetAlnFromSeq(TNumrow row, const TRangeColl& seq_coll,
261  TRangeColl& aln_coll) const = 0;
262 
263  virtual void GetSeqFromAln(TNumrow row, const TRangeColl& aln_coll,
264  TRangeColl& seq_coll) const = 0;
265 
266  virtual bool IsDataReadSync() const {return false;}
267 
269  void CollectAlignStats(const TSignedSeqRange& range, TStatGraphs& graphs, bool translate_sequence = false) const;
270 
271 };
272 
273 
274 inline
276 {
277  return (GetSeq_id().GetSeqIdString() == "consensus");
278 }
279 
280 
281 inline
283 {
284  TSeqPos pos = 0;
285  if (CanGetBioseqHandle()) {
286  pos = GetBioseqHandle().GetBioseqLength();
287  }
288  else {
289  pos = abs(GetSeqStop() - GetSeqStart()) + 1;
290  }
291  return pos;
292 }
293 
294 
296 
297 #endif // GUI_WIDGETS_ALN_MULTIPLE___ALNMULTI_DS__HPP
Class CConsensusRow - Simple interface to a row that represents the consensus for rendering purposes.
IAlnExplorer::TSignedRange TSignedRange
const IAlignRowHandle & GetHandle() const
void SetHandle(const IAlignRowHandle *h)
CConsensusRow(const IAlignRowHandle *handle)
virtual string & GetAlnSeqString(string &buffer, const IAlnExplorer::TSignedRange &aln_rng) const
bool IsValid() const
const IAlignRowHandle * m_Handle
virtual string & GetStringAtPos(string &buffer, TSignedSeqPos aln_pos) const
Data notification relay class, sends data change notifications to the subscribed listener.
CObjectEx –.
Definition: ncbiobj.hpp:2531
IAlignRowHandle provides an abstract way to access alignment row data.
Definition: alnmulti_ds.hpp:59
virtual bool UsesAATranslation() const =0
virtual int GetMismatches() const
virtual ~IAlignRowHandle()
virtual TSignedSeqPos GetSeqStart() const =0
virtual void GetHost(string &value) const
virtual bool CanGetBioseqHandle() const =0
virtual bool IsAnchor() const
virtual TSignedSeqPos GetSeqAlnStart() const =0
virtual int GetGenCode() const =0
virtual const objects::CBioseq_Handle & GetBioseqHandle() const =0
virtual const objects::CSeq_id & GetSeq_id() const =0
virtual bool CanGetSeqString() const =0
virtual void GetCountry(string &value) const
IAlnExplorer::TNumrow TNumrow
Definition: alnmulti_ds.hpp:61
virtual double GetPctCoverage() const
virtual bool IsNucProtAlignment() const =0
virtual double GetPctIdentity() const
virtual size_t GetBaseWidth() const =0
virtual IAlnExplorer::TSignedRange GetSeqAlnRange() const =0
virtual TSeqPos GetSeqLength() const
virtual TSignedSeqPos GetSeqPosFromAlnPos(TSeqPos aln_pos, IAlnExplorer::ESearchDirection dir=IAlnExplorer::eNone, bool try_reverse_dir=true) const =0
virtual TNumrow GetRowNum() const =0
virtual string & GetAlnSeqString(string &buffer, const IAlnExplorer::TSignedRange &aln_rng) const =0
virtual TSignedSeqPos GetSeqAlnStop() const =0
virtual TSignedSeqPos GetSeqStop() const =0
virtual void GetCollectionDate(string &value) const
virtual string & GetSeqString(string &buffer, const IAlnExplorer::TRange &seq_rng) const =0
virtual void GetIsolationSource(string &value) const
virtual bool IsNegativeStrand() const =0
IAlnExplorer::TResidue TResidue
Definition: alnmulti_ds.hpp:62
void UseExternalOrganismLookup(bool f)
virtual TSignedSeqPos GetAlnPosFromSeqPos(TSeqPos seq_pos, IAlnExplorer::ESearchDirection dir=IAlnExplorer::eNone, bool try_reverse_dir=true) const =0
virtual IAlnSegmentIterator * CreateSegmentIterator(const IAlnExplorer::TSignedRange &range, IAlnSegmentIterator::EFlags flags) const =0
virtual void GetGeneSymbol(string &value) const
virtual bool IsConsensus() const
virtual const string & GetText() const =0
objects::CSeqVector::TResidue TResidue
ESearchDirection
Position search options.
@ eNone
No search.
@ eRight
Towards higher aln coord (always to the right)
IAlnMultiDataSource - interface to a data source representing an abstract multiple alignment.
virtual IAlnExplorer::EAlignType GetAlignType() const =0
virtual void SetGapChar(TResidue gap_char)=0
virtual void GetAlnFromSeq(TNumrow row, const TRangeColl &seq_coll, TRangeColl &aln_coll) const =0
virtual TSignedSeqPos GetSeqPosFromAlnPos(TNumrow for_row, TSeqPos aln_pos, IAlnExplorer::ESearchDirection dir=IAlnExplorer::eNone, bool try_reverse_dir=true) const =0
virtual const IAlignRowHandle * GetRowHandle(TNumrow row) const =0
virtual bool IsDataReadSync() const
virtual bool IsPositiveStrand(TNumrow row) const =0
virtual TSeqPos GetAlnStart(void) const =0
virtual TSignedSeqPos GetAlnPosFromSeqPos(TNumrow row, TSeqPos seq_pos, IAlnExplorer::ESearchDirection dir=IAlnExplorer::eNone, bool try_reverse_dir=true) const =0
virtual bool CanGetId(TNumrow row) const =0
virtual int GetConsensusRow() const =0
returns index of the Consensus row or -1 if it doesn't exist
CRangeCollection< TSeqPos > TRangeColl
virtual bool CanChangeAnchor(void) const =0
virtual void GetSeqFromAln(TNumrow row, const TRangeColl &aln_coll, TRangeColl &seq_coll) const =0
IAlnExplorer::TResidue TResidue
virtual IAlnSegmentIterator * CreateSegmentIterator(TNumrow row, const IAlnExplorer::TSignedRange &range, IAlnSegmentIterator::EFlags flags) const =0
IAlnExplorer::TNumrow TNumrow
virtual TNumrow GetNumRows(void) const =0
number of rows in alignment
virtual TSeqPos GetAlnStop(void) const =0
virtual bool SetAnchor(TNumrow anchor)=0
virtual TSeqPos GetSeqStop(TNumrow row) const =0
virtual TSeqPos GetSeqStart(TNumrow row) const =0
virtual bool IsSetAnchor(void) const =0
Anchoring methods.
virtual const objects::CSeq_id & GetSeqId(TNumrow row) const =0
virtual TNumrow GetAnchor(void) const =0
virtual bool CanCreateConsensus()=0
virtual bool UnsetAnchor(void)=0
virtual void SetCreateConsensus(bool b)=0
IAlnExplorer::ESearchDirection TSearchDirection
virtual bool IsNegativeStrand(TNumrow row) const =0
virtual bool IsEmpty() const =0
virtual void CreateConsensus()=0
virtual string & GetAlnSeqString(TNumrow row, string &buffer, const IAlnExplorer::TSignedRange &aln_range) const =0
Alignment segment iterator interface.
EFlags
Iterator options.
IScoringAlignment.
Definition: map.hpp:338
string GetSeqIdString(const CSeq_id &id)
Definition: compartp.cpp:100
Include a standard set of the NCBI C++ Toolkit most basic headers.
static uch flags
int GetSeqLength(const CBioseq &bioseq)
Definition: cuSequence.cpp:216
bool IsConsensus(const CRef< CSeq_id > &seqId)
Definition: cuSequence.cpp:405
static FILE * f
Definition: readconf.c:23
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
int TSignedSeqPos
Type for signed sequence position.
Definition: ncbimisc.hpp:887
#define NULL
Definition: ncbistd.hpp:225
TTaxId GetTaxId(const CBioseq_Handle &handle)
return the tax-id associated with a given sequence.
Definition: sequence.cpp:274
#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_GUIWIDGETS_ALNMULTIPLE_EXPORT
Definition: gui_export.h:520
range(_Ty, _Ty) -> range< _Ty >
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
#define abs(a)
Definition: ncbi_heapmgr.c:130
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
static uint8_t * buffer
Definition: pcre2test.c:1016
#define row(bind, expected)
Definition: string_bind.c:73
Modified on Fri Sep 20 14:57:15 2024 by modify_doxy.py rev. 669887