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

Go to the SVN repository for this file.

1 /* $Id: mask_writer_fasta.cpp 94083 2021-06-23 15:52:03Z fongah2 $
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: Aleksandr Morgulis
27  *
28  * File Description:
29  * CMaskWriterFasta class member and method definitions.
30  *
31  */
32 #include <ncbi_pch.hpp>
33 #include <objects/seq/Bioseq.hpp>
34 #include <objects/seq/Seq_inst.hpp>
35 #include <objects/seq/Seq_data.hpp>
37 #include <objects/seq/IUPACna.hpp>
38 #include <objmgr/seq_vector.hpp>
39 
41 
44 
45 //-------------------------------------------------------------------------
46 void CMaskWriterFasta::Print( objects::CBioseq_Handle& bsh,
47  const TMaskList & mask,
48  bool parsed_id )
49 {
50  PrintId( bsh, parsed_id );
51  os << endl;
52  CSeqVector data = bsh.GetSeqVector(CBioseq_Handle::eCoding_Iupac);
53 
54  /// FIXME: this can be implemented as a call to CFastaOstream, which
55  /// understands masking via a seq-loc
56 
57  // if( dest->GetIupacna().CanGet() )
58  if( true )
59  {
60  string accumulator;
61  TMaskList::const_iterator imask = mask.begin();
62 
63  for( TSeqPos i = 0; i < data.size(); ++i )
64  {
65  char letter = data[i];
66 
67  if( imask != mask.end() && i >= imask->first ) {
68  if( i <= imask->second ) {
69  if(m_HardMasking) {
70  letter = 'N';
71  }
72  else {
73  letter = tolower((unsigned char) letter);
74  }
75  }
76  else
77  {
78  ++imask;
79 
80  if(imask != mask.end()
81  && i >= imask->first && i <= imask->second ) {
82  if(m_HardMasking) {
83  letter = 'N';
84  }
85  else {
86  letter = tolower((unsigned char) letter);
87  }
88  }
89  }
90  }
91 
92  accumulator.append( 1, letter );
93 
94  if( !((i + 1)%60) )
95  {
96  os << accumulator << "\n";
97  accumulator = "";
98  }
99  }
100 
101  if( accumulator.length() ) os << accumulator << "\n";
102  }
103 }
104 
105 
User-defined methods of the data storage class.
ncbi::TMaskedQueryRegions mask
virtual void Print(objects::CBioseq_Handle &bsh, const TMaskList &mask, bool parsed_id=false)
Output masked sequence data.
virtual void PrintId(objects::CBioseq_Handle &bsh, bool parsed_id)
Output of the sequence id.
Definition: mask_writer.cpp:49
CNcbiOstream & os
the standard C++ ostream object
vector< TMaskedInterval > TMaskList
A type representing the total of masking information about a sequence.
Definition: mask_writer.hpp:85
CSeqVector –.
Definition: seq_vector.hpp:65
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
@ eCoding_Iupac
Set coding to printable coding (Iupacna or Iupacaa)
TSeqPos size(void) const
Definition: seq_vector.hpp:291
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
int i
USING_SCOPE(objects)
int tolower(Uchar c)
Definition: ncbictype.hpp:72
static Uint4 letter(char c)
Modified on Sun Mar 03 03:15:59 2024 by modify_doxy.py rev. 669887