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

Go to the SVN repository for this file.

1 #ifndef OBJTOOLS_FORMAT___SAM_FORMATTER__HPP
2 #define OBJTOOLS_FORMAT___SAM_FORMATTER__HPP
3 
4 /* $Id: sam_formatter.hpp 69724 2015-11-10 20:29:29Z grichenk $
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: Aaron Ucko, Aleksey Grichenko
30  *
31  */
32 
33 /// @file sam_formatter.hpp
34 /// Flat formatter for Sequence Alignment/Map (SAM).
35 
36 
37 #include <corelib/ncbistre.hpp>
41 #include <objmgr/scope.hpp>
42 #include <list>
43 
44 
45 /** @addtogroup Miscellaneous
46  *
47  * @{
48  */
49 
50 
53 
55 {
56 public:
57  enum EFlags {
58  fSAM_AlignmentScore = 1 << 0, ///< Generate AS tags
59  fSAM_ExpectationValue = 1 << 1, ///< Generate EV tags
60  fSAM_NumNucDiff = 1 << 2, ///< Generate NM tags
61  fSAM_PercentageIdentity = 1 << 3, ///< Generate PI tags
62  fSAM_BitScore = 1 << 4, ///< Generate BS tags
63  fSAM_PlainSeqIds = 1 << 5, ///< Drop type prefix in seq-ids
64  fSAM_SeqData = 1 << 6, ///< Print sequence data
65  fSAM_ForceGISeqIds = 1 << 7, ///< Force using GI ids
66 
67  //? Include all tags by default
68  fSAM_Default = fSAM_AlignmentScore |
69  fSAM_ExpectationValue |
70  fSAM_NumNucDiff |
71  fSAM_PercentageIdentity |
72  fSAM_BitScore
73  };
74  typedef int TFlags; ///< bitwise OR of EFlags
75 
77  CScope& scope,
78  TFlags flags = fSAM_Default);
79  ~CSAM_Formatter(void);
80 
81  void SetOutputStream(CNcbiOstream& out) { m_Out = &out; }
82  void SetScope(CScope& scope) { m_Scope.Reset(&scope); }
83  void SetFlags (TFlags flags) { m_Flags = flags; }
84  void SetFlag (EFlags flag) { m_Flags |= flag; }
85  void UnsetFlag(EFlags flag) { m_Flags &= ~flag; }
86 
87  /// @PG tag fields
88  struct SProgramInfo {
89  SProgramInfo(const string& id = kEmptyStr,
90  const string& ver = kEmptyStr,
91  const string& cmd = kEmptyStr)
92  : m_Id(id), m_Version(ver), m_CmdLine(cmd) {}
93 
94  string m_Id; ///< ID - program id
95  string m_Version; ///< VN - version
96  string m_CmdLine; ///< CL - command line
97  string m_Desc; ///< DS - description
98  string m_Name; ///< PN - program name
99  };
100 
101  void SetProgram(const SProgramInfo& pg) { m_ProgramInfo = pg; }
102  SProgramInfo& SetProgram(void) { return m_ProgramInfo; }
103  const SProgramInfo& GetProgram(void) const { return m_ProgramInfo; }
104 
105  enum ESortOrder {
106  eSO_Skip, ///< Do not print SO tag (default)
107  eSO_Unsorted, ///< SO:unsorted
108  eSO_QueryName, ///< SO:queryname
109  eSO_Coordinate, ///< SO:coordinate
110  eSO_User ///< User-provided string
111  };
112 
113  /// Set SO tag value.
114  /// @param so
115  /// Predefined SO tag value.
116  /// @param so_value
117  /// User-defined SO tag value. Used only if 'so' is set to eSO_User.
118  void SetSortOrder(ESortOrder so, const string& so_value = kEmptyStr)
119  {
120  m_SO = so;
121  m_SO_Value = so_value;
122  }
123 
124  enum EGroupOrder {
125  eGO_Skip, ///< Do not print GO tag
126  eGO_None, ///< GO:none
127  eGO_Query, ///< GO:query (default)
128  eGO_Reference, ///< GO:reference
129  eGO_User ///< User-provided string
130  };
131 
132  /// Set GO tag value.
133  /// @param go
134  /// Predefined GO tag value.
135  /// @param go_value
136  /// User-defined GO tag value. Used only if 'go' is set to eGO_User.
137  void SetGroupOrder(EGroupOrder go, const string& go_value = kEmptyStr)
138  {
139  m_GO = go;
140  m_GO_Value = go_value;
141  }
142 
143  CSAM_Formatter& Print(const CSeq_align& aln,
144  const CSeq_id& query_id);
145  CSAM_Formatter& Print(const CSeq_align& aln,
146  CSeq_align::TDim query_row);
147  CSAM_Formatter& Print(const CSeq_align_set& aln,
148  const CSeq_id& query_id);
149  CSAM_Formatter& Print(const CSeq_align_set& aln,
150  CSeq_align::TDim query_row);
151 
152  // Write all data to the output, start a new file.
153  void Flush(void);
154 
155 private:
161  string m_SO_Value;
163  string m_GO_Value;
164 
165  void x_PrintSOTag(void) const;
166  void x_PrintGOTag(void) const;
167 
168  friend class CSAM_CIGAR_Formatter;
169 
170  typedef list<string> TLines;
171 
173  {
174  public:
175  CSAM_Headers(void) {}
176  void AddSequence(CSeq_id_Handle id, const string& line);
177  typedef list<pair<CSeq_id_Handle, string> > TData;
179  };
180 
183 };
184 
185 
188 
189 
190 /* @} */
191 
192 #endif /* OBJTOOLS_FORMAT___SAM_FORMATTER__HPP */
static CRef< CScope > m_Scope
CScope –.
Definition: scope.hpp:92
void Print(const CCompactSAMApplication::AlignInfo &ai)
static uch flags
std::ofstream out("events_result.xml")
main entry point for tests
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
void UnsetFlag(EFlags flag)
void SetGroupOrder(EGroupOrder go, const string &go_value=kEmptyStr)
Set GO tag value.
string m_Id
ID - program id.
string m_CmdLine
CL - command line.
SProgramInfo(const string &id=kEmptyStr, const string &ver=kEmptyStr, const string &cmd=kEmptyStr)
void SetOutputStream(CNcbiOstream &out)
list< string > TLines
CNcbiOstream * m_Out
list< pair< CSeq_id_Handle, string > > TData
CRef< CScope > m_Scope
string m_Name
PN - program name.
void SetFlags(TFlags flags)
int TFlags
bitwise OR of EFlags
SProgramInfo & SetProgram(void)
const SProgramInfo & GetProgram(void) const
void SetScope(CScope &scope)
void SetProgram(const SProgramInfo &pg)
string m_Version
VN - version.
void SetFlag(EFlags flag)
CSAM_Headers m_Header
void SetSortOrder(ESortOrder so, const string &so_value=kEmptyStr)
Set SO tag value.
string m_Desc
DS - description.
EGroupOrder m_GO
SProgramInfo m_ProgramInfo
@ eSO_Skip
Do not print SO tag (default)
@ eSO_Unsorted
SO:unsorted.
@ eSO_QueryName
SO:queryname.
@ eSO_Coordinate
SO:coordinate.
@ eGO_Reference
GO:reference.
@ eGO_None
GO:none.
@ eGO_Query
GO:query (default)
@ eGO_Skip
Do not print GO tag.
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
#define kEmptyStr
Definition: ncbistr.hpp:123
#define NCBI_FORMAT_EXPORT
Definition: ncbi_export.h:496
NCBI C++ stream class wrappers for triggering between "new" and "old" C++ stream libraries.
Modified on Wed May 08 12:09:43 2024 by modify_doxy.py rev. 669887