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

Go to the SVN repository for this file.

1 /* $Id: gtf_writer.hpp 99488 2023-04-05 11:57:12Z stakhovv $
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  * Authors: Frank Ludwig
27  *
28  * File Description: Write gtf file
29  *
30  */
31 
32 #ifndef OBJTOOLS_WRITERS___GTF_WRITER__HPP
33 #define OBJTOOLS_WRITERS___GTF_WRITER__HPP
34 
35 #include <corelib/ncbistd.hpp>
37 #include <objmgr/scope.hpp>
43 #include <objmgr/util/feature.hpp>
44 
46 BEGIN_objects_SCOPE
47 
48 class CGtfRecord;
49 
50 // ============================================================================
52 // ============================================================================
53 {
54 public:
56 
57  void Reset()
58  {
60  }
61  string NextId(
62  const string prefix)
63  {
64  auto mapIt = mLastSuffixes.find(prefix);
65  if (mapIt != mLastSuffixes.end()) {
66  ++mapIt->second;
67  return prefix + "_" + NStr::NumericToString(mapIt->second);
68  }
69  mLastSuffixes[prefix] = 1;
70  return prefix + "_1";
71  }
72 
73 private:
75 };
76 
77 // ============================================================================
79  public CGff2Writer
80 // ============================================================================
81 {
82 public:
83  enum {
84  fStructibutes = 1<<16,
85  fNoGeneFeatures = 1<<17,
86  fNoExonNumbers = 1<<18
87  };
88 
89  CGtfWriter(
90  CScope&,
91  CNcbiOstream&,
92  unsigned int = 0 );
93  CGtfWriter(
94  CNcbiOstream&,
95  unsigned int = 0 );
96  ~CGtfWriter();
97 
98  bool WriteHeader() override;
100  const CSeq_annot& annot) override { return CGff2Writer::WriteHeader(annot); };
101 
102 protected:
103  bool x_WriteBioseqHandle(
104  CBioseq_Handle) override;
105 
106  bool xAssignFeatureType(
109  const CMappedFeat&) override;
110 
114  const CMappedFeat&) override;
115 
119  const CMappedFeat&) override;
120  virtual bool xAssignFeatureAttributeGeneId(
121  CGtfRecord&,
123  const CMappedFeat&);
124  virtual bool xAssignFeatureAttributeTranscriptId(
125  CGtfRecord&,
127  const CMappedFeat&);
128  virtual bool xAssignFeatureAttributeTranscriptBiotype(
129  CGtfRecord&,
131  const CMappedFeat&);
135  const CMappedFeat&) override;
139  const CMappedFeat&) override;
143  const CMappedFeat&) override;
144 
145  std::string xGenericGeneId(
146  const CMappedFeat&,
148  std::string xGenericTranscriptId(
149  const CMappedFeat&);
150 
151  bool xWriteRecord(
152  const CGffWriteRecord* );
153 
154  bool xWriteFeature(
156  const CMappedFeat&) override;
157  virtual bool xWriteRecordsGene(
159  const CMappedFeat& );
160  virtual bool xWriteRecordsTranscript(
162  const CMappedFeat&,
163  const string& ="" );
164  virtual bool xWriteRecordsCds(
166  const CMappedFeat&,
167  const string& ="" );
168  virtual bool xWriteFeatureExons(
170  const CMappedFeat&,
171  const string& ="" );
172 
173  virtual bool xAssignFeaturesGene(
174  list<CRef<CGtfRecord>>&,
176  const CMappedFeat&);
177  virtual bool xAssignFeaturesTranscript(
178  list<CRef<CGtfRecord>>&,
180  const CMappedFeat&,
181  const string&); //transcript ID
182  virtual bool xAssignFeaturesCds(
183  list<CRef<CGtfRecord>>&,
185  const CMappedFeat&,
186  const string& = ""); //transcript ID
187 
188 private:
189  using FEAT_ID = string;
192 
195 
196  using GENE_ID = string;
199 
202 
205 };
206 
207 END_objects_SCOPE
209 
210 #endif // OBJTOOLS_WRITERS___GTF_WRITER__HPP
User-defined methods of the data storage class.
CBioseq_Handle –.
CWriterBase implementation that formats Genbank objects as plain GFF files.
Definition: gff_writer.hpp:60
virtual bool xAssignFeatureAttributeNote(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
Definition: gff_writer.hpp:267
virtual bool xAssignFeatureType(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
Definition: gff_writer.cpp:463
virtual bool xAssignFeatureAttributeDbxref(CGffFeatureRecord &, CGffFeatureContext &, const string &label, const CMappedFeat &)
Definition: gff_writer.cpp:613
virtual bool xWriteFeature(CGffFeatureContext &, const CMappedFeat &)
Definition: gff_writer.cpp:290
virtual bool xAssignFeatureMethod(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
Definition: gff_writer.cpp:487
virtual bool xAssignFeatureAttributesQualifiers(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
Definition: gff_writer.hpp:247
bool WriteHeader() override
Write a file header identifying the file content as GFF version 2.
Definition: gff_writer.cpp:335
virtual bool xAssignFeatureAttributesFormatSpecific(CGffFeatureRecord &, CGffFeatureContext &, const CMappedFeat &)
Definition: gff_writer.cpp:572
virtual bool x_WriteBioseqHandle(CBioseq_Handle)
Definition: gff_writer.cpp:208
map< string, int > mLastSuffixes
Definition: gtf_writer.hpp:74
string NextId(const string prefix)
Definition: gtf_writer.hpp:61
map< CMappedFeat, string > mMapFeatToGeneId
Definition: gtf_writer.hpp:203
bool WriteHeader(const CSeq_annot &annot) override
Write a file header, using annotation information.
Definition: gtf_writer.hpp:99
GENE_IDS mUsedGeneIds
Definition: gtf_writer.hpp:200
string GENE_ID
Definition: gtf_writer.hpp:196
CGtfIdGenerator mIdGenerator
Definition: gtf_writer.hpp:204
FEAT_IDS mUsedFeatIds
Definition: gtf_writer.hpp:194
GENE_MAP mGeneMap
Definition: gtf_writer.hpp:201
FEAT_MAP mFeatMap
Definition: gtf_writer.hpp:193
string FEAT_ID
Definition: gtf_writer.hpp:189
CMappedFeat –.
Definition: mapped_feat.hpp:59
CRef –.
Definition: ncbiobj.hpp:618
CScope –.
Definition: scope.hpp:92
const_iterator end() const
Definition: map.hpp:152
void clear()
Definition: map.hpp:169
const_iterator find(const key_type &key) const
Definition: map.hpp:153
Include a standard set of the NCBI C++ Toolkit most basic headers.
string
Definition: cgiapp.hpp:687
#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
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
Definition: ncbistr.hpp:673
#define NCBI_XOBJWRITE_EXPORT
Definition: ncbi_export.h:1347
The Object manager core.
static const char * prefix[]
Definition: pcregrep.c:405
Modified on Tue May 07 08:16:37 2024 by modify_doxy.py rev. 669887