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

Go to the SVN repository for this file.

1 /* $Id: alnmapprint.cpp 36612 2008-01-17 23:16:52Z todorov $
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 * CAlnMap printer.
30 *
31 * ===========================================================================
32 */
33 
34 #include <ncbi_pch.hpp>
37 
40 
41 
44  : m_AlnMap(aln_map),
45  m_IdFieldLen(28),
46  m_RowFieldLen(0),
47  m_SeqPosFieldLen(0),
48  m_NumRows(aln_map.GetNumRows()),
49  m_Out(&out)
50 {
51  m_Ids.resize(m_NumRows);
52  for (CAlnMap::TNumrow row = 0; row < m_NumRows; row++) {
53  m_Ids[row] = m_AlnMap.GetSeqId(row).AsFastaString();
54  if (m_Ids[row].length() > m_IdFieldLen) {
55  m_IdFieldLen = m_Ids[row].length();
56  }
57  }
58  m_IdFieldLen += 2;
60  m_SeqPosFieldLen = 10;
61 }
62 
63 
64 void
66 {
67  m_Out->width(m_IdFieldLen);
68  m_Out->setf(IOS_BASE::left, IOS_BASE::adjustfield);
69  *m_Out << GetId(row);
70 }
71 
72 
73 void
75 {
76  _ASSERT(row <= m_NumRows);
77  m_Out->width(m_RowFieldLen);
78  m_Out->setf(IOS_BASE::left, IOS_BASE::adjustfield);
79  *m_Out << row;
80 }
81 
82 
83 void
85 {
86  m_Out->width(m_SeqPosFieldLen);
87  m_Out->setf(IOS_BASE::left, IOS_BASE::adjustfield);
88  *m_Out << pos;
89 }
90 
91 
92 void CAlnMapPrinter::CsvTable(char delim)
93 {
94  // first row is the row numbers:
95  *m_Out << delim;
96  for (int row = 0; row < m_NumRows; row++) {
97  *m_Out << delim << row << delim;
98  }
99  *m_Out << endl;
100 
101  // each next row is a segment
102  for (int seg = 0; seg < m_AlnMap.GetNumSegs(); seg++) {
103  // first, print the length
104  *m_Out << m_AlnMap.GetLen(seg) << delim;
105  for (int row = 0; row < m_NumRows; row++) {
106  *m_Out << m_AlnMap.GetStart(row, seg) << delim
107  << m_AlnMap.GetStop(row, seg) << delim;
108  }
109  *m_Out << endl;
110  }
111 }
112 
113 
115 {
116  CAlnMap::TNumrow row;
117 
118  for (row=0; row<m_NumRows; row++) {
119  *m_Out << "Row: " << row << endl;
120  for (int seg=0; seg<m_AlnMap.GetNumSegs(); seg++) {
121 
122  // seg
123  *m_Out << "\t" << seg << ": ";
124 
125  // aln coords
126  *m_Out << m_AlnMap.GetAlnStart(seg) << "-"
127  << m_AlnMap.GetAlnStop(seg) << " ";
128 
129 
130  // type
132  if (type & CAlnMap::fSeq) {
133  // seq coords
134  *m_Out << m_AlnMap.GetStart(row, seg) << "-"
135  << m_AlnMap.GetStop(row, seg) << " (Seq)";
136  } else {
137  *m_Out << "(Gap)";
138  }
139 
140  if (type & CAlnMap::fNotAlignedToSeqOnAnchor) *m_Out << "(NotAlignedToSeqOnAnchor)";
141  if (CAlnMap::IsTypeInsert(type)) *m_Out << "(Insert)";
142  if (type & CAlnMap::fUnalignedOnRight) *m_Out << "(UnalignedOnRight)";
143  if (type & CAlnMap::fUnalignedOnLeft) *m_Out << "(UnalignedOnLeft)";
144  if (type & CAlnMap::fNoSeqOnRight) *m_Out << "(NoSeqOnRight)";
145  if (type & CAlnMap::fNoSeqOnLeft) *m_Out << "(NoSeqOnLeft)";
146  if (type & CAlnMap::fEndOnRight) *m_Out << "(EndOnRight)";
147  if (type & CAlnMap::fEndOnLeft) *m_Out << "(EndOnLeft)";
148  if (type & CAlnMap::fUnalignedOnRightOnAnchor) *m_Out << "(UnalignedOnRightOnAnchor)";
149  if (type & CAlnMap::fUnalignedOnLeftOnAnchor) *m_Out << "(UnalignedOnLeftOnAnchor)";
150 
151  *m_Out << NcbiEndl;
152  }
153  }
154 }
155 
156 
158 {
159  CAlnMap::TNumrow row;
160 
162 
163  for (row=0; row<m_NumRows; row++) {
164  *m_Out << "Row: " << row << endl;
165  //CAlnMap::TSignedRange range(m_AlnMap.GetSeqStart(row) -1,
166  //m_AlnMap.GetSeqStop(row) + 1);
168 
169  for (int i=0; i<chunk_vec->size(); i++) {
170  CConstRef<CAlnMap::CAlnChunk> chunk = (*chunk_vec)[i];
171 
172  *m_Out << "[row" << row << "|" << i << "]";
173  *m_Out << chunk->GetAlnRange().GetFrom() << "-"
174  << chunk->GetAlnRange().GetTo() << " ";
175 
176  if (!chunk->IsGap()) {
177  *m_Out << chunk->GetRange().GetFrom() << "-"
178  << chunk->GetRange().GetTo();
179  } else {
180  *m_Out << "(Gap)";
181  }
182 
183  if (chunk->GetType() & CAlnMap::fSeq) *m_Out << "(Seq)";
184  if (chunk->GetType() & CAlnMap::fNotAlignedToSeqOnAnchor) *m_Out << "(NotAlignedToSeqOnAnchor)";
185  if (CAlnMap::IsTypeInsert(chunk->GetType())) *m_Out << "(Insert)";
186  if (chunk->GetType() & CAlnMap::fUnalignedOnRight) *m_Out << "(UnalignedOnRight)";
187  if (chunk->GetType() & CAlnMap::fUnalignedOnLeft) *m_Out << "(UnalignedOnLeft)";
188  if (chunk->GetType() & CAlnMap::fNoSeqOnRight) *m_Out << "(NoSeqOnRight)";
189  if (chunk->GetType() & CAlnMap::fNoSeqOnLeft) *m_Out << "(NoSeqOnLeft)";
190  if (chunk->GetType() & CAlnMap::fEndOnRight) *m_Out << "(EndOnRight)";
191  if (chunk->GetType() & CAlnMap::fEndOnLeft) *m_Out << "(EndOnLeft)";
192  if (chunk->GetType() & CAlnMap::fUnaligned) *m_Out << "(Unaligned)";
193  if (chunk->GetType() & CAlnMap::fUnalignedOnRightOnAnchor) *m_Out << "(UnalignedOnRightOnAnchor)";
194  if (chunk->GetType() & CAlnMap::fUnalignedOnLeftOnAnchor) *m_Out << "(UnalignedOnLeftOnAnchor)";
195  *m_Out << NcbiEndl;
196  }
197  }
198 }
USING_SCOPE(ncbi)
void PrintId(CAlnMap::TNumrow row) const
Field printers.
Definition: alnmapprint.cpp:65
CNcbiOstream * m_Out
Definition: alnmap.hpp:418
size_t m_IdFieldLen
Definition: alnmap.hpp:414
const CAlnMap::TNumrow m_NumRows
Definition: alnmap.hpp:417
void Chunks(CAlnMap::TGetChunkFlags flags=CAlnMap::fAlnSegsOnly)
const CAlnMap & m_AlnMap
Definition: alnmap.hpp:410
CAlnMapPrinter(const CAlnMap &aln_map, CNcbiOstream &out)
Constructor.
Definition: alnmapprint.cpp:42
size_t m_RowFieldLen
Definition: alnmap.hpp:415
size_t m_SeqPosFieldLen
Definition: alnmap.hpp:416
void CsvTable(char delim=',')
Printing methods.
Definition: alnmapprint.cpp:92
const string & GetId(CAlnMap::TNumrow row) const
Fasta style Ids.
Definition: alnmap.hpp:737
vector< string > m_Ids
Definition: alnmap.hpp:411
void PrintNumRow(CAlnMap::TNumrow row) const
Definition: alnmapprint.cpp:74
void PrintSeqPos(TSeqPos pos) const
Definition: alnmapprint.cpp:84
TSignedSeqPos GetStop(TNumrow row, TNumseg seg, int offset=0) const
Definition: alnmap.hpp:635
TDim TNumrow
Definition: alnmap.hpp:69
TSegTypeFlags GetSegType(TNumrow row, TNumseg seg, int offset=0) const
Definition: alnmap.hpp:503
TSignedSeqPos GetStart(TNumrow row, TNumseg seg, int offset=0) const
Definition: alnmap.hpp:614
const CSeq_id & GetSeqId(TNumrow row) const
Definition: alnmap.hpp:645
int TGetChunkFlags
Definition: alnmap.hpp:110
@ fUnalignedOnRight
Definition: alnmap.hpp:55
@ fEndOnRight
Definition: alnmap.hpp:59
@ fUnaligned
Definition: alnmap.hpp:61
@ fNoSeqOnRight
Definition: alnmap.hpp:57
@ fUnalignedOnLeftOnAnchor
Definition: alnmap.hpp:63
@ fUnalignedOnRightOnAnchor
Definition: alnmap.hpp:62
@ fNoSeqOnLeft
Definition: alnmap.hpp:58
@ fNotAlignedToSeqOnAnchor
Definition: alnmap.hpp:53
@ fSeq
Definition: alnmap.hpp:52
@ fUnalignedOnLeft
Definition: alnmap.hpp:56
@ fEndOnLeft
Definition: alnmap.hpp:60
TSeqPos GetAlnStop(TNumseg seg) const
Definition: alnmap.hpp:488
CRef< CAlnChunkVec > GetAlnChunks(TNumrow row, const TSignedRange &range, TGetChunkFlags flags=fAlnSegsOnly) const
Definition: alnmap.cpp:1002
unsigned int TSegTypeFlags
Definition: alnmap.hpp:50
TSeqPos GetLen(TNumseg seg, int offset=0) const
Definition: alnmap.hpp:621
TSeqPos GetAlnStart(TNumseg seg) const
Definition: alnmap.hpp:481
TNumseg GetNumSegs(void) const
Definition: alnmap.hpp:510
static bool IsTypeInsert(TSegTypeFlags type)
Definition: alnmap.hpp:723
CConstRef –.
Definition: ncbiobj.hpp:1266
CRef –.
Definition: ncbiobj.hpp:618
static uch flags
std::ofstream out("events_result.xml")
main entry point for tests
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
const string AsFastaString(void) const
Definition: Seq_id.cpp:2265
#define NcbiEndl
Definition: ncbistre.hpp:548
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5083
int i
range(_Ty, _Ty) -> range< _Ty >
Magic spell ;-) needed for some weird compilers... very empiric.
Definition: type.c:6
#define _ASSERT
Modified on Wed Nov 29 02:24:55 2023 by modify_doxy.py rev. 669887