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

Go to the SVN repository for this file.

1 /* $Id: aln_serial.cpp 53721 2012-04-12 15:23:21Z grichenk $
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 * Author: Kamen Todorov, NCBI
27 *
28 * File Description:
29 * Alignments Serialization
30 *
31 * ===========================================================================
32 */
33 
34 
35 #include <ncbi_pch.hpp>
37 
38 
41 
42 
43 ostream& operator<<(ostream& out, const CPairwiseAln::TRng& rng)
44 {
45  if (rng.GetFrom() < rng.GetToOpen()) {
46  out << "["
47  << rng.GetFrom() << ", "
48  << rng.GetToOpen()
49  << ")"
50  << " len: "
51  << rng.GetLength();
52  } else {
53  out << "<"
54  << rng.GetFrom() << ", "
55  << rng.GetTo()
56  << ">"
57  << " len: "
58  << rng.GetLength();
59  }
60  return out;
61 }
62 
63 
64 ostream& operator<<(ostream& out, const IAlnSegment::ESegTypeFlags& flags)
65 {
66  return out
67  << (flags & IAlnSegment::fAligned ? "fAligned " : "")
68  << (flags & IAlnSegment::fGap ? "fGap " : "")
69  << (flags & IAlnSegment::fIndel ? "fIndel " : "")
70  << (flags & IAlnSegment::fUnaligned ? "fUnaligned " : "")
71  << (flags & IAlnSegment::fReversed ? "fReversed " : "")
72  << (flags & IAlnSegment::fInvalid ? "fInvalid " : "");
73 }
74 
75 
76 ostream& operator<<(ostream& out, const IAlnSegment& aln_seg)
77 {
78  return out
79  << " Anchor Rng: " << aln_seg.GetAlnRange()
80  << " Rng: " << aln_seg.GetRange()
81  << " type: " << (IAlnSegment::ESegTypeFlags) aln_seg.GetType();
82 }
83 
84 
85 ostream& operator<<(ostream& out, const CPairwiseAln::TAlnRng& aln_rng)
86 {
87  return out
88  << "["
89  << aln_rng.GetFirstFrom() << ", "
90  << aln_rng.GetSecondFrom() << ", "
91  << aln_rng.GetLength() << ", "
92  << (aln_rng.IsDirect() ? "direct" : "reverse")
93  << "]";
94 }
95 
96 
97 ostream& operator<<(ostream& out, const CPairwiseAln::EFlags& flags)
98 {
99  out << " Flags = " << NStr::UIntToString(flags, 0, 2)
100  << ":" << endl;
101 
102  if (flags & CPairwiseAln::fKeepNormalized) out << "fKeepNormalized" << endl;
103  if (flags & CPairwiseAln::fAllowMixedDir) out << "fAllowMixedDir" << endl;
104  if (flags & CPairwiseAln::fAllowOverlap) out << "fAllowOverlap" << endl;
105  if (flags & CPairwiseAln::fAllowAbutting) out << "fAllowAbutting" << endl;
106  if (flags & CPairwiseAln::fNotValidated) out << "fNotValidated" << endl;
107  if (flags & CPairwiseAln::fInvalid) out << "fInvalid" << endl;
108  if (flags & CPairwiseAln::fUnsorted) out << "fUnsorted" << endl;
109  if (flags & CPairwiseAln::fDirect) out << "fDirect" << endl;
110  if (flags & CPairwiseAln::fReversed) out << "fReversed" << endl;
111  if ((flags & CPairwiseAln::fMixedDir) == CPairwiseAln::fMixedDir) out << "fMixedDir" << endl;
112  if (flags & CPairwiseAln::fOverlap) out << "fOverlap" << endl;
113  if (flags & CPairwiseAln::fAbutting) out << "fAbutting" << endl;
114 
115  return out;
116 }
117 
118 
119 ostream& operator<<(ostream& out, const TAlnSeqIdIRef& aln_seq_id_iref)
120 {
121  out << aln_seq_id_iref->AsString()
122  << " (base_width=" << aln_seq_id_iref->GetBaseWidth()
123  << ")";
124  return out;
125 }
126 
127 
128 ostream& operator<<(ostream& out, const CPairwiseAln& pairwise_aln)
129 {
130  out << "CPairwiseAln between ";
131 
132  out << pairwise_aln.GetFirstId() << " and "
133  << pairwise_aln.GetSecondId();
134 
135  cout << " with flags=" << pairwise_aln.GetFlags() << " and segments:" << endl;
136 
137  ITERATE (CPairwiseAln, aln_rng_it, pairwise_aln) {
138  out << *aln_rng_it;
139  }
140  return out << endl;
141 }
142 
143 
144 ostream& operator<<(ostream& out, const CAnchoredAln& anchored_aln)
145 {
146  out << "CAnchorAln has score of " << anchored_aln.GetScore() << " and contains "
147  << anchored_aln.GetDim() << " pair(s) of rows:" << endl;
148  ITERATE(CAnchoredAln::TPairwiseAlnVector, pairwise_aln_i, anchored_aln.GetPairwiseAlns()) {
149  out << **pairwise_aln_i;
150  }
151  return out << endl;
152 }
153 
154 
USING_SCOPE(objects)
ostream & operator<<(ostream &out, const CPairwiseAln::TRng &rng)
Definition: aln_serial.cpp:43
@ fAllowOverlap
allow segments with different orientation
@ fAllowAbutting
allow segments overlapping on the first sequence
@ fInvalid
collection was modified and not validated
@ fAllowMixedDir
enforce all policies after any modification
CAlignRange Represents an element of pairwise alignment of two sequences.
Definition: align_range.hpp:63
Query-anchored alignment can be 2 or multi-dimentional.
const TPairwiseAlnVector & GetPairwiseAlns(void) const
The vector of pairwise alns.
vector< CRef< CPairwiseAln > > TPairwiseAlnVector
TDim GetDim(void) const
How many rows.
int GetScore(void) const
What is the total score?
A pairwise aln is a collection of ranges for a pair of rows.
const TAlnSeqIdIRef & GetFirstId(void) const
Get first sequence id.
const TAlnSeqIdIRef & GetSecondId(void) const
Get second sequence id.
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...
virtual TSegTypeFlags GetType(void) const =0
Get current segment type.
virtual const TSignedRange & GetAlnRange(void) const =0
Get alignment range for the segment.
static uch flags
std::ofstream out("events_result.xml")
main entry point for tests
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
position_type GetLength(void) const
Definition: range.hpp:158
position_type GetToOpen(void) const
Definition: range.hpp:138
bool IsDirect() const
Definition: align_range.hpp:96
position_type GetSecondFrom(void) const
position_type GetFirstFrom(void) const
position_type GetLength(void) const
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static string UIntToString(unsigned int value, TNumToStringFlags flags=0, int base=10)
Convert UInt to string.
Definition: ncbistr.hpp:5108
TTo GetTo(void) const
Get the To member data.
Definition: Range_.hpp:269
TFrom GetFrom(void) const
Get the From member data.
Definition: Range_.hpp:222
Modified on Fri Dec 01 04:43:49 2023 by modify_doxy.py rev. 669887