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

Go to the SVN repository for this file.

1 /* $Id: reader_base.cpp 101956 2024-03-08 17:00:41Z gotvyans $
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: Frank Ludwig
27  *
28  * File Description:
29  * Basic reader interface.
30  *
31  */
32 
33 #include <ncbi_pch.hpp>
34 #include <corelib/ncbistd.hpp>
35 #include <corelib/ncbiapp.hpp>
36 #include <corelib/ncbithr.hpp>
37 #include <corelib/ncbiutil.hpp>
38 #include <corelib/ncbiexpt.hpp>
39 #include <corelib/stream_utils.hpp>
40 
41 #include <util/static_map.hpp>
42 #include <util/line_reader.hpp>
43 
44 #include <serial/iterator.hpp>
45 #include <serial/objistrasn.hpp>
46 
47 // Objects includes
53 
58 
65 
82 
101 #include <objtools/error_codes.hpp>
103 
104 #include <algorithm>
105 #include <ctime>
106 
107 #include "reader_data.hpp"
109 
110 #define NCBI_USE_ERRCODE_X Objtools_Rd_RepMask
111 
113 BEGIN_objects_SCOPE // namespace ncbi::objects::
114 
115 // ----------------------------------------------------------------------------
120  CReaderListener* pRL )
121 // ----------------------------------------------------------------------------
122 {
123  switch ( format ) {
124  default:
125  return 0;
126  case CFormatGuess::eBed:
127  return new CBedReader(flags);
129  return new CMicroArrayReader(flags, pRL);
131  return new CWiggleReader(flags);
132  case CFormatGuess::eGtf:
134  return new CGtfReader(flags);
136  return new CGff3Reader(flags);
137  case CFormatGuess::eGvf:
138  return new CGvfReader(flags);
139  case CFormatGuess::eVcf:
140  return new CVcfReader(flags, pRL);
141  case CFormatGuess::eRmo:
142  return new CRepeatMaskerReader(flags);
144  return new CFastaReader(flags);
146  return new CFeature_table_reader(flags);
148  return new CUCSCRegionReader(flags);
149  case CFormatGuess::ePsl:
150  return new CPslReader(flags, pRL);
151  }
152 }
153 
154 // ----------------------------------------------------------------------------
157  const string& annotName,
158  const string& annotTitle,
159  SeqIdResolver seqidresolver,
160  CReaderListener* pListener) :
161 // ----------------------------------------------------------------------------
162  m_uLineNumber(0),
163  m_uProgressReportInterval(0),
164  m_uNextProgressReport(0),
165  m_iFlags(flags),
166  m_AnnotName(annotName),
167  m_AnnotTitle(annotTitle),
168  m_pTrackDefaults(new CTrackData),
169  m_pReader(nullptr),
170  m_pCanceler(nullptr),
171  mSeqIdResolve(seqidresolver),
172  m_pMessageHandler(new CReaderMessageHandler(pListener))
173 {
174 }
175 
176 
177 // ----------------------------------------------------------------------------
179 // ----------------------------------------------------------------------------
180 {
181 }
182 
183 // ----------------------------------------------------------------------------
186  CNcbiIstream& istr,
187  ILineErrorListener* pMessageListener )
188 // ----------------------------------------------------------------------------
189 {
190  CStreamLineReader lr( istr );
191  return ReadObject( lr, pMessageListener );
192 }
193 
194 // ----------------------------------------------------------------------------
197  ILineReader& lr,
198  ILineErrorListener* pMessageListener )
199 // ----------------------------------------------------------------------------
200 {
201  CRef<CSerialObject> object(
202  ReadSeqAnnot( lr, pMessageListener ).ReleaseOrNull() );
203  return object;
204 }
205 
206 // ----------------------------------------------------------------------------
209  CNcbiIstream& istr,
210  ILineErrorListener* pMessageListener )
211 // ----------------------------------------------------------------------------
212 {
213  CStreamLineReader lr( istr );
214  return ReadSeqAnnot( lr, pMessageListener );
215 }
216 
217 // ----------------------------------------------------------------------------
220  ILineReader& lr,
221  ILineErrorListener* pEL)
222 // ----------------------------------------------------------------------------
223 {
224  xProgressInit(lr);
225 
226  m_uDataCount = 0;
228 
229  TReaderData readerData;
230  xGuardedGetData(lr, readerData, pEL);
231  if (readerData.empty()) {
232  pAnnot.Reset();
233  return pAnnot;
234  }
235  while (!readerData.empty()) {
236  if (IsCanceled()) {
237  CReaderMessage cancelled(
238  eDiag_Fatal,
240  "Data import interrupted by user.");
241  xProcessReaderMessage(cancelled, pEL);
242  }
243  xReportProgress();
244 
245  xGuardedProcessData(readerData, *pAnnot, pEL);
246  xGuardedGetData(lr, readerData, pEL);
247  }
248  xValidateAnnot(*pAnnot);
249  xPostProcessAnnot(*pAnnot);
250  return pAnnot;
251 }
252 
253 // ----------------------------------------------------------------------------
256 // ----------------------------------------------------------------------------
257 {
258  CRef<CSeq_annot> pAnnot(new CSeq_annot);
259  if (!m_AnnotName.empty()) {
260  pAnnot->SetNameDesc(m_AnnotName);
261  }
262  if (!m_AnnotTitle.empty()) {
263  pAnnot->SetTitleDesc(m_AnnotTitle);
264  }
265  return pAnnot;
266 }
267 
268 // ----------------------------------------------------------------------------
269 void
271  ILineReader& lr,
272  TReaderData& readerData,
273  ILineErrorListener* pEL)
274 // ----------------------------------------------------------------------------
275 {
276  try {
277  xGetData(lr, readerData);
278  }
279  catch (CReaderMessage& err) {
280  xProcessReaderMessage(err, pEL);
281  }
282  catch (ILineError& err) {
283  xProcessLineError(err, pEL);
284  }
285  catch (CException& err) {
287  }
288 }
289 
290 // ----------------------------------------------------------------------------
291 void
293  const TReaderData& readerData,
294  CSeq_annot& annot,
295  ILineErrorListener* pEL)
296 // ----------------------------------------------------------------------------
297 {
298  try {
299  xProcessData(readerData, annot);
300  }
301  catch (CReaderMessage& err) {
302  xProcessReaderMessage(err, pEL);
303  }
304  catch (ILineError& err) {
305  xProcessLineError(err, pEL);
306  }
307  catch (CException& err) {
309  }
310 }
311 
312 // ----------------------------------------------------------------------------
313 void
315  ILineReader& lr,
316  TReaderData& readerData)
317 // ----------------------------------------------------------------------------
318 {
319  readerData.clear();
320  string line;
321  if (xGetLine(lr, line)) {
322  readerData.push_back(TReaderLine{m_uLineNumber, line});
323  }
324  ++m_uDataCount;
325 }
326 
327 // ----------------------------------------------------------------------------
328 void
330  const TReaderData& /*readerData*/,
331  CSeq_annot& /*annot*/)
332 // ----------------------------------------------------------------------------
333 {
334 }
335 
336 // ---------------------------------------------------------------------------
337 void
339  TAnnots& annots,
340  CNcbiIstream& istr,
341  ILineErrorListener* pMessageListener )
342 // ---------------------------------------------------------------------------
343 {
344  CStreamLineReader lr( istr );
345  ReadSeqAnnots( annots, lr, pMessageListener );
346 }
347 
348 // ---------------------------------------------------------------------------
349 void
351  TAnnots& annots,
352  ILineReader& lr,
353  ILineErrorListener* pMessageListener )
354 // ----------------------------------------------------------------------------
355 {
356  xReadInit();
357  xProgressInit(lr);
358  CRef<CSeq_annot> annot = ReadSeqAnnot(lr, pMessageListener);
359  while (annot) {
360  annots.push_back(annot);
361  annot = ReadSeqAnnot(lr, pMessageListener);
362  }
363 }
364 
365 // ----------------------------------------------------------------------------
368  CNcbiIstream& istr,
369  ILineErrorListener* pMessageListener )
370 // ----------------------------------------------------------------------------
371 {
372  CStreamLineReader lr( istr );
373  CRef<CSeq_entry> pResult = ReadSeqEntry( lr, pMessageListener );
374  return pResult;
375 }
376 
377 // ----------------------------------------------------------------------------
380  ILineReader& lr,
382 // ----------------------------------------------------------------------------
383 {
384  xProgressInit(lr);
385  return CRef<CSeq_entry>();
386 }
387 
388 // ----------------------------------------------------------------------------
389 void
392  ILineErrorListener* pContainer )
393 // ----------------------------------------------------------------------------
394 {
396  if (!pContainer) {
397  err.Throw();
398  }
399  if (!pContainer->PutError(err)) {
403  0,
404  "Error allowance exceeded",
406  pErr->Throw();
407  }
408 }
409 
410 // ----------------------------------------------------------------------------
411 void
414  ILineErrorListener* pContainer )
415 // ----------------------------------------------------------------------------
416 {
418  if (!pContainer) {
419  cerr << m_uLineNumber << ": " << err.SeverityStr() << err.Message()
420  << endl;
421  return;
422  }
423  if (!pContainer->PutError(err)) {
424  err.Throw();
425  }
426 }
427 
428 // ----------------------------------------------------------------------------
429 void
431  CLineError& err,
432  ILineErrorListener* pContainer )
433 // ----------------------------------------------------------------------------
434 {
435  if (!pContainer || !pContainer->PutError(err)) {
436  err.Throw();
437  }
438  }
439 
440 // ----------------------------------------------------------------------------
441 void
443  CLineError& err,
444  ILineErrorListener* pContainer )
445 // ----------------------------------------------------------------------------
446 {
447  if (!pContainer) {
448  cerr << m_uLineNumber << ": " << err.SeverityStr() << err.Message()
449  << endl;
450  return;
451  }
452  if (!pContainer->PutError(err)) {
453  err.Throw();
454  }
455  }
456 
457 // ----------------------------------------------------------------------------
458 void
460  const list<string>& stringFlags,
461  const map<string, TReaderFlags> flagMap,
462  TReaderFlags& baseFlags)
463 // ----------------------------------------------------------------------------
464 {
465  for (auto stringFlag: stringFlags) {
466  auto flagEntry = flagMap.find(stringFlag);
467  if (flagEntry == flagMap.end()) {
468  string message = "Unrecognized FASTA flag : " + stringFlag;
469  NCBI_THROW(CException, eUnknown, message);
470  }
471  baseFlags |= flagEntry->second;
472  }
473 };
474 
475 
476 // ----------------------------------------------------------------------------
478  const string& strRaw,
479  CAnnot_descr& desc)
480 // ----------------------------------------------------------------------------
481 {
483  eDiag_Error,
485  "Bad browser line: cannot parse browser position.");
486 
488 
489  string strChrom;
490  string strInterval;
491  if ( ! NStr::SplitInTwo( strRaw, ":", strChrom, strInterval ) ) {
492  throw error;
493  }
494  CRef<CSeq_id> id( new CSeq_id( CSeq_id::e_Local, strChrom ) );
495 
496  if (NStr::Compare(strInterval, "start-stop") == 0 )
497  {
498  location->SetWhole(*id);
499  }
500  else
501  {
502  string strFrom;
503  string strTo;
504  if ( ! NStr::SplitInTwo( strInterval, "-", strFrom, strTo ) ) {
505  throw error;
506  }
507  try
508  {
509  int n_from,n_to;
510 
511  n_from = NStr::StringToInt(strFrom, NStr::fAllowCommas);
512  n_to = NStr::StringToInt(strTo, NStr::fAllowCommas);
513 
514  CSeq_interval& interval = location->SetInt();
515  interval.SetFrom(n_from-1);
516  interval.SetTo(n_to-1);
517  interval.SetStrand( eNa_strand_unknown );
518  location->SetId( *id );
519 
520  }
521  catch (const CStringException&) {
522  location.Reset();
523  throw error;
524  }
525  }
526 
527  if (location.NotEmpty())
528  {
529  CRef<CAnnotdesc> region( new CAnnotdesc() );
530  region->SetRegion( *location );
531  desc.Set().push_back( region );
532  }
533 }
534 
535 // ----------------------------------------------------------------------------
537  const string& strLine,
538  CSeq_annot& annot)
539 // ----------------------------------------------------------------------------
540 {
542  eDiag_Error,
544  "Bad browser line: incomplete position directive.");
545 
546  if ( ! NStr::StartsWith( strLine, "browser" ) ) {
547  return false;
548  }
549  CAnnot_descr& desc = annot.SetDesc();
550 
551  vector<string> fields;
553  for ( vector<string>::iterator it = fields.begin(); it != fields.end(); ++it ) {
554  if ( *it == "position" ) {
555  ++it;
556  if ( it == fields.end() ) {
557  throw error;
558  }
559  xSetBrowserRegion(*it, desc);
560  }
561  }
562  return true;
563 }
564 
565 // ----------------------------------------------------------------------------
567  CSeq_annot& annot )
568 // ----------------------------------------------------------------------------
569 {
570  if (!m_AnnotName.empty()) {
571  annot.SetNameDesc(m_AnnotName);
572  }
573  if (!m_AnnotTitle.empty()) {
574  annot.SetTitleDesc(m_AnnotTitle);
575  }
576  m_pTrackDefaults->WriteToAnnot(annot);
577 }
578 
579 // ----------------------------------------------------------------------------
581  const string& strLine)
582 // ----------------------------------------------------------------------------
583 {
584  vector<string> parts;
585  CReadUtil::Tokenize( strLine, " \t", parts );
586  if ( !CTrackData::IsTrackData( parts ) ) {
587  return false;
588  }
589  m_pTrackDefaults->ParseLine( parts );
590  return true;
591 }
592 
593 // ----------------------------------------------------------------------------
595  const CTempString& record,
596  CRef<CSeq_annot>& /*annot*/ )
597 // ----------------------------------------------------------------------------
598 {
599  if (NStr::StartsWith(record, "#")) {
600  return true;
601  }
602  return false;
603 }
604 
605 // ----------------------------------------------------------------------------
607  CSeq_annot&)
608 // ----------------------------------------------------------------------------
609 {
610 }
611 
612 // ----------------------------------------------------------------------------
614  CSeq_annot& annot,
615  ILineErrorListener* pML)
616 // ----------------------------------------------------------------------------
617 {
618  size_t countInfos = m_pMessageHandler->LevelCount(eDiag_Info);
619  size_t countWarnings = m_pMessageHandler->LevelCount(eDiag_Warning);
620  size_t countErrors = m_pMessageHandler->LevelCount(eDiag_Error);
621  size_t countCritical = m_pMessageHandler->LevelCount(eDiag_Critical);
622  if (pML) {
623  countCritical += pML->LevelCount(eDiag_Critical);
624  countErrors += pML->LevelCount(eDiag_Error);
625  countWarnings += pML->LevelCount(eDiag_Warning);
626  countInfos += pML->LevelCount(eDiag_Info);
627  }
628  if (countInfos + countWarnings + countErrors + countCritical == 0) {
629  return;
630  }
631  CRef<CUser_object> conversioninfo(new CUser_object());
632  conversioninfo->SetType().SetStr("Conversion Info");
633  conversioninfo->AddField( "critical errors", static_cast<int>(countCritical));
634  conversioninfo->AddField( "errors", static_cast<int>(countErrors));
635  conversioninfo->AddField( "warnings", static_cast<int>(countWarnings));
636  conversioninfo->AddField( "notes", static_cast<int>(countInfos));
637 
638  CRef<CAnnotdesc> user(new CAnnotdesc());
639  user->SetUser(*conversioninfo);
640  annot.SetDesc().Set().push_back(user);
641 }
642 
643 // ----------------------------------------------------------------------------
645  unsigned int intv)
646 // ----------------------------------------------------------------------------
647 {
649  m_uNextProgressReport = (unsigned int)time(0) + intv;
650 }
651 
652 // ----------------------------------------------------------------------------
654 // ----------------------------------------------------------------------------
655 {
656  if (0 == m_uProgressReportInterval) {
657  return false;
658  }
659  if (0 == m_pReader) {
660  return false;
661  }
662  return true;
663 }
664 
665 // ----------------------------------------------------------------------------
667  ILineErrorListener* /*pProgress*/)
668 // ----------------------------------------------------------------------------
669 {
670  if (!xIsReportingProgress()) { // progress reports disabled
671  return;
672  }
673  unsigned int uCurrentTime = (unsigned int)time(0);
674  if (uCurrentTime < m_uNextProgressReport) { // not time yet
675  return;
676  }
677 
678  // report something
679  int curPos = static_cast<int>(m_pReader->GetPosition());
680  m_pMessageHandler->Progress(CReaderProgress(curPos, 0));
682 }
683 
684 // ============================================================================
686 // ============================================================================
687 {
688  return true;
689 }
690 
691 // ============================================================================
693  ILineReader& lr)
694 // ============================================================================
695 {
696  if (0 == m_uProgressReportInterval) {
697  return true;
698  }
699  m_pReader = &lr;
700  return true;
701 }
702 
703 // ============================================================================
705  ICanceled* pCanceler)
706 // ============================================================================
707 {
708  m_pCanceler = pCanceler;
709 }
710 
711 // ============================================================================
713 // ============================================================================
714 {
715  if (!m_pCanceler) {
716  return false;
717  }
718  return m_pCanceler->IsCanceled();
719 }
720 
721 // ----------------------------------------------------------------------------
723  const CTempString& strLine)
724 // ----------------------------------------------------------------------------
725 {
726  if (strLine.empty()) {
727  return true;
728  }
729  return (strLine[0] == '#' && strLine[1] != '#');
730 }
731 
732 // ----------------------------------------------------------------------------
734  const CTempString& strLine)
735 // ----------------------------------------------------------------------------
736 {
737  if (strLine == "track") {
738  return true;
739  }
740  if (NStr::StartsWith(strLine, "track ")) {
741  return true;
742  }
743  return NStr::StartsWith(strLine, "track\t");
744 }
745 
746 // ----------------------------------------------------------------------------
748  const CTempString& strLine)
749 // ----------------------------------------------------------------------------
750 {
751  auto line = NStr::TruncateSpaces_Unsafe(strLine);
752  return (line == "###");
753 }
754 
755 // ----------------------------------------------------------------------------
757  const CTempString& strLine)
758 // ----------------------------------------------------------------------------
759 {
760  return NStr::StartsWith(strLine, "browser ");
761 }
762 
763 // ----------------------------------------------------------------------------
765  ILineReader& lr,
766  string& line)
767 // ----------------------------------------------------------------------------
768 {
769  if (!m_PendingLine.empty()) {
770  line = m_PendingLine;
771  m_PendingLine.clear();
772  return true;
773  }
774  CTempString temp;
775  while (!lr.AtEOF()) {
776  temp = *++lr;
777  ++m_uLineNumber;
778  temp = NStr::TruncateSpaces_Unsafe(temp);
779  if (!xIsCommentLine(temp)) {
780  line = temp;
781  return true;
782  }
783  }
784  return false;
785 }
786 
787 // ----------------------------------------------------------------------------
789  ILineReader& lr)
790 // ----------------------------------------------------------------------------
791 {
792  lr.UngetLine();
793  --m_uLineNumber;
794  return true;
795 }
796 
797 // ----------------------------------------------------------------------------
798 void
800  CReaderMessage& readerMessage,
801  ILineErrorListener* pEL)
802 //
803 // Strategy:
804 // (0) Above all, don't swallow FATAl errors as they are guaranteed to stop
805 // the program on the spot.
806 // (1) Give readerMessage to internal message handler. If configured properly
807 // it will handle readerMessage.Otherwise, it will emit an ILineError.
808 // (2) If an ILineError is emitted and we have an actual ILineErrorListener
809 // then give it a shot.
810 // (3) If we don't have an ILineErrorListener or it the ILineErrorListener
811 // does not want the ILineError then rethrow the ILineError and hope for
812 // the best.
813 // ----------------------------------------------------------------------------
814 {
815  readerMessage.SetLineNumber(m_uLineNumber);
816  try {
817  m_pMessageHandler->Report(readerMessage);
818  if (readerMessage.Severity() == eDiag_Fatal) {
819  throw;
820  }
821  }
822  catch(ILineError& lineError) {
823  xProcessLineError(lineError, pEL);
824  }
825 };
826 
827 // ----------------------------------------------------------------------------
828 void
830  const ILineError& lineError,
831  ILineErrorListener* pEL)
832 //
833 // This is to deal with legacy format readers that may throw ILIneError instead
834 // of the preferred CReaderMessage.
835 //
836 // Strategy:
837 // (1) If pEL is good, then give the lineError to pEL.
838 // (2) If pEL doesn't accept the lineError then throw it (and hope some upper
839 // layer knows what to do with it).
840 // ----------------------------------------------------------------------------
841 {
842  if (!pEL || !pEL->PutMessage(lineError)) {
843  throw;
844  }
845 }
846 
847 // ----------------------------------------------------------------------------
848 void
850  const CException& error)
851 //
852 // If we get errors outside of the established type system then there is no way
853 // of knowing what happened, how it happened, how much data is bad, or even
854 // whether there is any way of continuing at all.
855 // We therefore turn all such errors into a FATAL CReaderMessage and rethrow
856 // it.
857 // ----------------------------------------------------------------------------
858 {
860  eDiag_Fatal,
862  "Exception: " + error.GetMsg());
863  throw(terminator);
864 }
865 
866 END_objects_SCOPE
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.
AutoPtr –.
Definition: ncbimisc.hpp:401
CAnnot_descr –.
Definition: Annot_descr.hpp:66
CAnnotdesc –.
Definition: Annotdesc.hpp:66
CReaderBase implementation that reads BED data files, either a single object or all objects found.
Definition: bed_reader.hpp:109
Base class for reading FASTA sequences.
Definition: fasta.hpp:80
EFormat
The formats are checked in the same order as declared here.
@ eFiveColFeatureTable
Five-column feature table.
@ eVcf
VCF, CVcfReader.
@ eBed
UCSC BED file format, CBedReader.
@ eGtf
New GTF, CGtfReader.
@ eGvf
GVF, CGvfReader.
@ eGff3
GFF3, CGff3Reader.
@ eGtf_POISENED
Old and Dead GFF/GTF style annotations.
@ eFasta
FASTA format sequence record, CFastaReader.
@ eRmo
RepeatMasker Output.
@ eUCSCRegion
USCS Region file format.
@ ePsl
PSL alignment format.
@ eBed15
UCSC BED15 or microarray format.
@ eWiggle
UCSC WIGGLE file format.
void Throw(void) const
copy constructor is protected so please use this function to throw the object.
Definition: line_error.cpp:68
void SetLineNumber(unsigned int uLineNumber)
Definition: line_error.hpp:672
void Throw(void) const
this function to throw this object.
Definition: line_error.cpp:221
static CObjReaderLineException * Create(EDiagSev eSeverity, unsigned int uLine, const std::string &strMessage, EProblem eProblem=eProblem_GeneralParsingError, const std::string &strSeqId=string(""), const std::string &strFeatureName=string(""), const std::string &strQualifierName=string(""), const std::string &strQualifierValue=string(""), CObjReaderLineException::EErrCode eErrCode=eFormat, const TVecOfLines &vecOfOtherLines=TVecOfLines())
Please use this instead of the constructor because the ctor is protected.
Definition: line_error.cpp:194
std::string Message() const
Definition: line_error.hpp:664
static void Tokenize(const string &instr, const string &delim, vector< string > &tokens)
Tokenize a given string, respecting quoted substrings an atomic units.
Definition: read_util.cpp:47
Defines and provides stubs for a general interface to a variety of file readers.
Definition: reader_base.hpp:63
unique_ptr< CReaderMessageHandler > m_pMessageHandler
void xProcessLineError(const ILineError &, ILineErrorListener *)
string m_PendingLine
virtual void xSetBrowserRegion(const string &, CAnnot_descr &)
void xGuardedGetData(ILineReader &, TReaderData &, ILineErrorListener *)
virtual CRef< CSerialObject > ReadObject(CNcbiIstream &istr, ILineErrorListener *pErrors=nullptr)
Read an object from a given input stream, render it as the most appropriate Genbank object.
virtual void xValidateAnnot(const CSeq_annot &)
virtual void xProcessData(const TReaderData &, CSeq_annot &)
long TReaderFlags
Definition: reader_base.hpp:84
bool xIsReportingProgress() const
void SetProgressReportInterval(unsigned int intv)
virtual void ReadSeqAnnots(TAnnots &annots, CNcbiIstream &istr, ILineErrorListener *pErrors=nullptr)
Read all objects from given insput stream, returning them as a vector of Seq-annots.
virtual bool xUngetLine(ILineReader &)
virtual bool xIsCommentLine(const CTempString &)
virtual CRef< CSeq_annot > xCreateSeqAnnot()
unsigned int m_uDataCount
virtual CRef< CSeq_entry > ReadSeqEntry(CNcbiIstream &istr, ILineErrorListener *pErrors=nullptr)
Read an object from a given input stream, render it as a single Seq-entry, if possible.
unsigned int m_uLineNumber
void xProcessReaderMessage(CReaderMessage &, ILineErrorListener *)
static CReaderBase * GetReader(CFormatGuess::EFormat format, TReaderFlags flags=0, CReaderListener *=nullptr)
Allocate a CReaderBase derived reader object based on the given file format.
string m_AnnotTitle
unique_ptr< CTrackData > m_pTrackDefaults
virtual bool xParseBrowserLine(const string &, CSeq_annot &)
CReaderBase(TReaderFlags flags=0, const string &name="", const string &title="", SeqIdResolver seqresolver=CReadUtil::AsSeqId, CReaderListener *pListener=nullptr)
Protected constructor. Use GetReader() to get an actual reader object.
bool xIsOperationCanceled() const
unsigned int m_uProgressReportInterval
unsigned int m_uNextProgressReport
virtual void xPostProcessAnnot(CSeq_annot &)
virtual bool xProgressInit(ILineReader &istr)
void ProcessError(CObjReaderLineException &, ILineErrorListener *)
vector< TReaderLine > TReaderData
Definition: reader_base.hpp:70
ICanceled * m_pCanceler
virtual bool xGetLine(ILineReader &, string &)
virtual ~CReaderBase()
TAnnotList TAnnots
Definition: reader_base.hpp:91
virtual void xAddConversionInfo(CSeq_annot &, ILineErrorListener *)
virtual void xGuardedProcessData(const TReaderData &, CSeq_annot &, ILineErrorListener *)
bool xParseComment(const CTempString &, CRef< CSeq_annot > &)
virtual bool xIsBrowserLine(const CTempString &)
string m_AnnotName
ILineReader * m_pReader
virtual bool xParseTrackLine(const string &)
void xReportProgress(ILineErrorListener *=nullptr)
virtual bool xReadInit()
virtual void xAssignTrackData(CSeq_annot &)
void SetCanceler(ICanceled *=nullptr)
void xProcessUnknownException(const CException &)
virtual void xGetData(ILineReader &, TReaderData &)
virtual CRef< CSeq_annot > ReadSeqAnnot(CNcbiIstream &istr, ILineErrorListener *pErrors=nullptr)
Read an object from a given input stream, render it as a single Seq-annot.
struct SReaderLine { SReaderLine(unsigned int line, string data):mLine(line), mData(data) {} TReaderLine
Definition: reader_base.hpp:66
static void xAddStringFlagsWithMap(const list< string > &stringFlags, const map< string, TReaderFlags > flagMap, TReaderFlags &baseFlags)
bool IsCanceled() const
void ProcessWarning(CObjReaderLineException &, ILineErrorListener *)
virtual bool xIsTrackTerminator(const CTempString &)
virtual bool xIsTrackLine(const CTempString &)
void SetLineNumber(int lineNumber)
virtual EDiagSev Severity() const
CRef –.
Definition: ncbiobj.hpp:618
Implements a concrete class for reading RepeatMasker output from tabular form and rendering it as ASN...
Definition: rm_reader.hpp:690
void SetNameDesc(const string &name)
Definition: Seq_annot.cpp:66
void SetTitleDesc(const string &title)
Definition: Seq_annot.cpp:96
Simple implementation of ILineReader for i(o)streams.
CStringException –.
Definition: ncbistr.hpp:4506
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
static bool IsTrackData(const LineData &)
Definition: track_data.cpp:59
CUser_object & AddField(const string &label, const string &value, EParseField parse=eParse_String)
add a data field to the user object that holds a given value
Interface for testing cancellation request in a long lasting operation.
Definition: icanceled.hpp:51
virtual bool PutError(const ILineError &)=0
Store error in the container, and return true if error was stored fine, and return false if the calle...
virtual size_t LevelCount(EDiagSev)=0
Returns the number of errors seen so far at the given severity.
bool PutMessage(const IObjtoolsMessage &message) override
@ eProblem_GeneralParsingError
Definition: line_error.hpp:106
std::string SeverityStr(void) const
Definition: line_error.hpp:168
virtual std::string Message(void) const
Definition: line_error.hpp:143
Abstract base class for lightweight line-by-line reading.
Definition: line_reader.hpp:54
const_iterator end() const
Definition: map.hpp:152
const_iterator find(const key_type &key) const
Definition: map.hpp:153
Definition: map.hpp:338
Include a standard set of the NCBI C++ Toolkit most basic headers.
static uch flags
Operators to edit gaps in sequences.
static const char location[]
Definition: config.c:97
@ eDiag_Info
Informational message.
Definition: ncbidiag.hpp:651
@ eDiag_Error
Error message.
Definition: ncbidiag.hpp:653
@ eDiag_Warning
Warning message.
Definition: ncbidiag.hpp:652
@ eDiag_Fatal
Fatal error – guarantees exit(or abort)
Definition: ncbidiag.hpp:655
@ eDiag_Critical
Critical error message.
Definition: ncbidiag.hpp:654
#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 void UngetLine(void)=0
Unget current line, which must be valid.
virtual bool AtEOF(void) const =0
Indicates (negatively) whether there is any more input.
virtual CT_POS_TYPE GetPosition(void) const =0
Return the current (absolute) position.
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
virtual bool IsCanceled(void) const =0
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
Definition: ncbistre.hpp:146
static CTempString TruncateSpaces_Unsafe(const CTempString str, ETrunc where=eTrunc_Both)
Truncate spaces in a string.
Definition: ncbistr.cpp:3191
static int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
Definition: ncbistr.cpp:630
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
Definition: ncbistr.cpp:3461
bool empty(void) const
Return true if the represented string is empty (i.e., the length is zero)
Definition: tempstr.hpp:334
static int Compare(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2, ECase use_case=eCase)
Compare of a substring with another string.
Definition: ncbistr.hpp:5297
static bool StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
Definition: ncbistr.hpp:5412
static bool SplitInTwo(const CTempString str, const CTempString delim, string &str1, string &str2, TSplitFlags flags=0)
Split a string into two pieces using the specified delimiters.
Definition: ncbistr.cpp:3554
@ fAllowCommas
Allow commas. See 'ENumToStringFlags::fWithCommas'.
Definition: ncbistr.hpp:293
@ fSplit_Truncate
Definition: ncbistr.hpp:2501
@ fSplit_MergeDelimiters
Merge adjacent delimiters.
Definition: ncbistr.hpp:2498
void SetType(TType &value)
Assign a value to Type data member.
void SetTo(TTo value)
Assign a value to To data member.
void SetFrom(TFrom value)
Assign a value to From data member.
void SetStrand(TStrand value)
Assign a value to Strand data member.
@ eNa_strand_unknown
Definition: Na_strand_.hpp:65
@ e_Local
local use
Definition: Seq_id_.hpp:95
Tdata & Set(void)
Assign a value to data member.
void SetDesc(TDesc &value)
Assign a value to Desc data member.
Definition: Seq_annot_.cpp:223
TUser & SetUser(void)
Select the variant.
Definition: Annotdesc_.cpp:190
TRegion & SetRegion(void)
Select the variant.
Definition: Annotdesc_.cpp:300
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
Definition of all error codes used in objtools libraries.
Lightweight interface for getting lines of data with minimal memory copying.
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
Defines NCBI C++ exception handling.
#define nullptr
Definition: ncbimisc.hpp:45
Multi-threading – classes, functions, and features.
Useful/utility classes and methods.
static char terminator
Definition: njn_ioutil.cpp:56
static Format format
Definition: njn_ioutil.cpp:53
#define const
Definition: zconf.h:232
Modified on Wed Apr 17 13:08:45 2024 by modify_doxy.py rev. 669887