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

Go to the SVN repository for this file.

1 /* $Id: seq_masker_ostat_ascii.cpp 98105 2022-09-29 00:28:26Z morgulis $
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  * Implementation of CSeqMaskerUStatAscii class.
30  *
31  */
32 
33 #include <ncbi_pch.hpp>
34 
35 #include <corelib/ncbistd.hpp>
36 
38 
40 
41 #define STAT_FMT_COMPONENT_NAME "windowmasker-statistics-format-version"
42 #define STAT_FMT_VER_MAJOR 1
43 #define STAT_FMT_VER_MINOR 1
44 #define STAT_FMT_VER_PATCH 0
45 #define STAT_FMT_VER_PFX "ascii "
46 
47 //------------------------------------------------------------------------------
54 );
55 
56 //------------------------------------------------------------------------------
57 const char *
59 {
60  switch( GetErrCode() )
61  {
62  case eBadOrder: return "bad unit order";
63  default: return CException::GetErrCodeString();
64  }
65 }
66 
67 //------------------------------------------------------------------------------
69  const string & name, string const & metadata )
70  : CSeqMaskerOstat(
71  name.empty() ?
72  static_cast<CNcbiOstream&>(NcbiCout) :
73  static_cast<CNcbiOstream&>(*new CNcbiOfstream( name.c_str() )),
74  name.empty() ? false : true, metadata )
75 {}
76 
77 //------------------------------------------------------------------------------
79  CNcbiOstream & os, string const & metadata )
80  : CSeqMaskerOstat( os, false, metadata )
81 {}
82 
83 //------------------------------------------------------------------------------
85 {
86 }
87 
88 //------------------------------------------------------------------------------
90 {
91  static Uint4 punit = 0;
92 
93  if( unit != 0 && unit <= punit )
94  {
95  CNcbiOstrstream ostr;
96  ostr << "current unit " << hex << unit << "; "
97  << "previous unit " << hex << punit;
98  string s = CNcbiOstrstreamToString(ostr);
100  }
101 
102  counts.push_back( std::make_pair( unit, count ) );
103  punit = unit;
104 }
105 
106 //------------------------------------------------------------------------------
108 {
109  comments.push_back( msg );
110 }
111 
112 //------------------------------------------------------------------------------
115  out_stream << (Uint4)unit_size << endl;
116 
117  for( size_t i( 0 ); i < counts.size(); ++i ) {
118  out_stream << hex << counts[i].first << ' '
119  << dec << counts[i].second << '\n';
120  }
121 
122  out_stream << '\n';
123 
124  for( size_t i( 0 ); i < comments.size(); ++i ) {
125  out_stream << '#' << comments[i] << '\n';
126  }
127 
128  out_stream << '\n';
129  out_stream << '>' << PARAMS[0] << ' ' << pvalues[0] << '\n';
130  out_stream << '>' << PARAMS[1] << ' ' << pvalues[1] << '\n';
131  out_stream << '>' << PARAMS[2] << ' ' << pvalues[2] << '\n';
132  out_stream << '>' << PARAMS[3] << ' ' << pvalues[3] << '\n';
133  out_stream << endl;
134 }
135 
136 END_NCBI_SCOPE
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
Definition: ncbistre.hpp:802
Exceptions that CSeqMaskerOstatAscii might throw.
virtual const char * GetErrCodeString() const override
Get a description string for this exception.
@ eBadOrder
Unit information is not added in ascending order of units.
std::vector< std::string > comments
Set of comments to print in the end of the stats file.
virtual void doFinalize()
Write data to output file.
virtual ~CSeqMaskerOstatAscii()
Object destructor.
virtual void doSetComment(const string &msg)
Prints msg as a comment line in the output file.
static CSeqMaskerVersion FormatVersion
Format version.
CSeqMaskerOstatAscii(const string &name, string const &metadat)
Object constructor.
virtual void doSetUnitCount(Uint4 unit, Uint4 count)
Output a line with information about the given unit count.
Base class for computing and saving unit counts data.
Uint1 unit_size
unit size
string metadata
metadata string
vector< pair< Uint4, Uint4 > > counts
Unit counts.
CNcbiOstream & out_stream
Refers to the C++ stream that should be used to write out the unit counts data.
string FormatMetaData() const
Combine version data and metadata into a single string.
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define true
Definition: bool.h:35
#define false
Definition: bool.h:36
TErrCode GetErrCode(void) const
Get error code.
Definition: ncbiexpt.cpp:453
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
virtual const char * GetErrCodeString(void) const
Get error code interpreted as text.
Definition: ncbiexpt.cpp:444
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
IO_PREFIX::ofstream CNcbiOfstream
Portable alias for ofstream.
Definition: ncbistre.hpp:500
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
#define NcbiCout
Definition: ncbistre.hpp:543
int i
yy_size_t n
static void hex(unsigned char c)
Definition: mdb_dump.c:56
constexpr bool empty(list< Ts... >) noexcept
#define count
#define STAT_FMT_COMPONENT_NAME
#define STAT_FMT_VER_MAJOR
#define STAT_FMT_VER_PFX
#define STAT_FMT_VER_PATCH
#define STAT_FMT_VER_MINOR
static SLJIT_INLINE sljit_ins msg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
Modified on Fri Sep 20 14:57:39 2024 by modify_doxy.py rev. 669887