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

Go to the SVN repository for this file.

1 /* $Id: feat_importer.cpp 86362 2019-05-02 15:04:11Z ludwigf $
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: Iterate through file names matching a given glob pattern
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 #include <corelib/ncbifile.hpp>
34 
37 
38 #include "feat_importer_impl.hpp"
40 #include "ftable/gtf_importer.hpp"
41 #include "ftable/gff3_importer.hpp"
42 #include "ftable/bed_importer.hpp"
43 #include "ftable/5col_importer.hpp"
47 #include "annot_import_data.hpp"
48 
49 #include <assert.h>
50 
53 
54 
55 // ============================================================================
58  const string& format,
59  unsigned int flags,
60  CImportMessageHandler& errorHandler
61  )
62 // ============================================================================
63 {
64  if (format == "gtf") {
65  return new CGtfImporter(flags, errorHandler);
66  }
67  if (format == "gff3") {
68  return new CGff3Importer(flags, errorHandler);
69  }
70  if (format == "bed") {
71  return new CBedImporter(flags, errorHandler);
72  }
73  if (format == "5col") {
74  return new C5ColImporter(flags, errorHandler);
75  }
76  return nullptr;
77 };
78 
79 
80 // ============================================================================
82  unsigned int flags,
83  CImportMessageHandler& errorHandler):
84 // ============================================================================
85  mFlags(flags),
86  mpReader(nullptr),
87  mErrorHandler(errorHandler)
88 {
89  bool allIdsAsLocal = (mFlags & CFeatImporter::fAllIdsAsLocal);
90  bool numericIdsAsLocal = (mFlags & CFeatImporter::fNumericIdsAsLocal);
91  SetIdResolver(new CIdResolverCanonical(allIdsAsLocal, numericIdsAsLocal));
92 };
93 
94 
95 // ============================================================================
96 void
98  CIdResolver* pIdResolver)
99 // ============================================================================
100 {
101  mpIdResolver.reset(pIdResolver);
102 }
103 
104 // =============================================================================
105 void
107  CNcbiIstream& istr,
108  CSeq_annot& annot)
109 // =============================================================================
110 {
111  CStreamLineReader lineReader(istr);
112  ReadSeqAnnot(lineReader, annot);
113 }
114 
115 // =============================================================================
116 void
118  CStreamLineReader& lineReader,
119  CSeq_annot& annot)
120 // =============================================================================
121 {
123 
124  //mpReader->SetInputStream(istr);
125  if (mFlags & fReportProgress) {
126  mpReader->SetProgressReportFrequency(5);
127  }
128 
129  mpAssembler->InitializeAnnot(annot);
130 
131  bool terminateNow = false;
132  while (!terminateNow) {
133  try {
134  if (!mpReader->GetNextRecord(lineReader, *mpImportData)) {
135  break;
136  }
137  mpAssembler->ProcessRecord(*mpImportData, annot);
138  }
139  catch(CImportError& err) {
140  if (err.LineNumber() == 0) {
141  err.SetLineNumber(lineReader.GetLineNumber());
142  }
144  switch(err.Severity()) {
145  default:
146  continue;
148  terminateNow = true;
149  break;
150  case CImportError::FATAL:
151  throw;
152  }
153  }
154  }
155  const CAnnotImportData& annotMeta = mpReader->AnnotImportData();
156  mpAssembler->FinalizeAnnot(annotMeta, annot);
157 }
158 
159 
virtual void SetIdResolver(CIdResolver *) override
virtual void ReadSeqAnnot(CStreamLineReader &, CSeq_annot &) override
unique_ptr< CFeatImportData > mpImportData
CImportMessageHandler & mErrorHandler
CFeatImporter_impl(unsigned int, CImportMessageHandler &)
unique_ptr< CFeatAnnotAssembler > mpAssembler
unique_ptr< CFeatLineReader > mpReader
unique_ptr< CIdResolver > mpIdResolver
void ReadSeqAnnot(CNcbiIstream &, CSeq_annot &)
static CFeatImporter * Get(const std::string &, unsigned int, CImportMessageHandler &)
void SetLineNumber(unsigned int lineNumber)
ErrorLevel Severity() const
unsigned int LineNumber() const
virtual void ReportError(const CImportError &)
Simple implementation of ILineReader for i(o)streams.
static uch flags
USING_SCOPE(objects)
USING_NCBI_SCOPE
Uint8 GetLineNumber(void) const
Returns the current line number (counting from 1, not 0).
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
Definition: ncbistre.hpp:146
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
#define nullptr
Definition: ncbimisc.hpp:45
static Format format
Definition: njn_ioutil.cpp:53
#define assert(x)
Definition: srv_diag.hpp:58
Modified on Sat Dec 02 09:22:13 2023 by modify_doxy.py rev. 669887