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

Go to the SVN repository for this file.

1 
2 /* $Id: psl_writer.cpp 94178 2021-07-02 14:10:03Z ludwigf $
3  * ===========================================================================
4  *
5  * PUBLIC DOMAIN NOTICE
6  * National Center for Biotechnology Information
7  *
8  * This software/database is a "United States Government Work" under the
9  * terms of the United States Copyright Act. It was written as part of
10  * the author's official duties as a United States Government employee and
11  * thus cannot be copyrighted. This software/database is freely available
12  * to the public for use. The National Library of Medicine and the U.S.
13  * Government have not placed any restriction on its use or reproduction.
14  *
15  * Although all reasonable efforts have been taken to ensure the accuracy
16  * and reliability of the software and data, the NLM and the U.S.
17  * Government do not and cannot warrant the performance or results that
18  * may be obtained by using this software or data. The NLM and the U.S.
19  * Government disclaim all warranties, express or implied, including
20  * warranties of performance, merchantability or fitness for any particular
21  * purpose.
22  *
23  * Please cite the author in any work or product based on this material.
24  *
25  * ===========================================================================
26  *
27  * Authors: Frank Ludwig
28  *
29  * File Description: Write alignment
30  *
31  */
32 
33 #include <ncbi_pch.hpp>
34 
47 
48 #include <objmgr/scope.hpp>
49 #include <objmgr/bioseq_handle.hpp>
50 #include <objmgr/seq_vector.hpp>
51 #include <objmgr/util/sequence.hpp>
52 
58 #include "psl_record.hpp"
59 #include "psl_formatter.hpp"
60 
62 
65 
66 // ----------------------------------------------------------------------------
68  CScope& scope,
69  CNcbiOstream& ostr,
70  unsigned int uFlags) :
71 // ----------------------------------------------------------------------------
72  CWriterBase(ostr, uFlags),
73  mRecordCounter(0)
74 {
75  m_pScope.Reset(&scope);
76 };
77 
78 
79 // ----------------------------------------------------------------------------
81  CNcbiOstream& ostr,
82  unsigned int uFlags) :
83  CPslWriter(*(new CScope(*CObjectManager::GetInstance())), ostr, uFlags)
84 // ----------------------------------------------------------------------------
85 {
86 };
87 
88 
89 // ----------------------------------------------------------------------------
91  const CSeq_annot& annot,
92  const string& name,
93  const string& descr)
94 // ----------------------------------------------------------------------------
95 {
96  if (!annot.IsAlign()) {
97  return CWriterBase::WriteAnnot(annot, name, descr);
98  }
99  for (const auto& pAlign: annot.GetData().GetAlign()) {
100  if (!WriteAlign(*pAlign, name, descr)) {
101  return false;
102  }
103  }
104  return true;
105 }
106 
107 // ----------------------------------------------------------------------------
109  const CSeq_align& align,
110  const string& name,
111  const string& descr)
112 // ----------------------------------------------------------------------------
113 {
114  if (IsCanceled()) {
115  NCBI_THROW(
117  eInterrupted,
118  "Processing terminated by user");
119  }
120 
121  ++mRecordCounter;
122  try {
124  auto segType = align.GetSegs().Which();
125  switch (segType) {
126 
127  default:
128  throw CWriterMessage(
129  "Input alignment type not supported", eDiag_Error);
130 
132  record.Initialize(*m_pScope, align.GetSegs().GetSpliced());
133  break;
134 
136  record.Initialize(*m_pScope, align.GetSegs().GetDenseg());
137  if (align.CanGetScore()) {
138  record.Initialize(*m_pScope, align.GetScore());
139  }
140  break;
141 
143  const auto& data = align.GetSegs().GetDisc().Get();
144  for (const auto& pAlign: data) {
145  WriteAlign(*pAlign);
146  }
147  return true;
148  }
149  record.Finalize();
150 
151  CPslFormatter formatter(m_Os);
152  formatter.Format(record);
153  }
154  catch(CWriterMessage& writerMessage) {
155  switch(writerMessage.GetSeverity()) {
156  case eDiag_Fatal:
157  throw;
158  default:
159  PutMessage(writerMessage);
160  break;
161  }
162  }
163  catch(CException& e) {
164  throw CWriterMessage("Exception thrown: " + e.GetMsg(), eDiag_Error);
165  }
166  return true;
167 }
168 
170 
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
bool IsCanceled() const
Definition: writer.hpp:62
CObjectManager –.
virtual EDiagSev GetSeverity(void) const
Definition: message.cpp:96
void Format(const CPslRecord &record)
void Initialize(CScope &scope, const CSpliced_seg &splicedSeg)
Definition: psl_record.cpp:337
void Finalize()
Definition: psl_record.cpp:375
bool WriteAlign(const CSeq_align &align, const string &name="", const string &descr="") override
Write a raw Seq-align to the internal output stream.
Definition: psl_writer.cpp:108
CRef< CScope > m_pScope
Definition: psl_writer.hpp:76
int mRecordCounter
Definition: psl_writer.hpp:77
bool WriteAnnot(const CSeq_annot &annot, const string &name="", const string &descr="") override
Write a raw Seq-annot to the internal output stream.
Definition: psl_writer.cpp:90
CPslWriter(CScope &scope, CNcbiOstream &ostr, unsigned int uFlags)
Definition: psl_writer.cpp:67
CScope –.
Definition: scope.hpp:92
bool IsAlign(void) const
Definition: Seq_annot.cpp:182
Defines and provides stubs for a general interface to a variety of file formatters.
Definition: writer.hpp:81
virtual bool WriteAnnot(const CSeq_annot &, const string &="", const string &="")
Write a raw Seq-annot to the internal output stream.
Definition: writer.hpp:116
CWriterListener * mpMessageListener
Definition: writer.hpp:271
virtual void PutMessage(const CWriterMessage &message)
Definition: writer.hpp:238
CNcbiOstream & m_Os
Definition: writer.hpp:267
char data[12]
Definition: iconv.c:80
@ eDiag_Error
Error message.
Definition: ncbidiag.hpp:653
@ eDiag_Fatal
Fatal error – guarantees exit(or abort)
Definition: ncbidiag.hpp:655
#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
const string & GetMsg(void) const
Get message string.
Definition: ncbiexpt.cpp:461
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
const TDenseg & GetDenseg(void) const
Get the variant data.
Definition: Seq_align_.cpp:153
E_Choice Which(void) const
Which variant is currently selected.
Definition: Seq_align_.hpp:691
bool CanGetScore(void) const
Check if it is safe to call GetScore method.
Definition: Seq_align_.hpp:890
const TSpliced & GetSpliced(void) const
Get the variant data.
Definition: Seq_align_.cpp:219
const TScore & GetScore(void) const
Get the Score member data.
Definition: Seq_align_.hpp:896
const TDisc & GetDisc(void) const
Get the variant data.
Definition: Seq_align_.cpp:197
const Tdata & Get(void) const
Get the member data.
const TSegs & GetSegs(void) const
Get the Segs member data.
Definition: Seq_align_.hpp:921
const TAlign & GetAlign(void) const
Get the variant data.
Definition: Seq_annot_.hpp:641
const TData & GetData(void) const
Get the Data member data.
Definition: Seq_annot_.hpp:873
USING_SCOPE(objects)
Modified on Wed Apr 17 13:09:51 2024 by modify_doxy.py rev. 669887