A library for working with phylogenetic data.
v0.25.0
gff_reader.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_POPULATION_FORMATS_GFF_READER_H_
2 #define GENESIS_POPULATION_FORMATS_GFF_READER_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2020 Lucas Czech
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 
21  Contact:
22  Lucas Czech <lucas.czech@h-its.org>
23  Exelixis Lab, Heidelberg Institute for Theoretical Studies
24  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
25 */
26 
36 
37 #include <string>
38 #include <utility>
39 #include <vector>
40 
41 namespace genesis {
42 namespace population {
43 
44 // =================================================================================================
45 // GFF/GTF Reader
46 // =================================================================================================
47 
55 class GffReader
56 {
57 public:
58 
59  // -------------------------------------------------------------------------
60  // Typedefs and Enums
61  // -------------------------------------------------------------------------
62 
63  using Attribute = std::pair<std::string, std::string>;
64 
68  struct Feature
69  {
70  std::string seqname;
71  std::string source;
72  std::string feature;
73  size_t start;
74  size_t end;
75  double score;
76  char strand;
77  signed char frame;
78  std::vector<Attribute> attributes;
79  };
80 
81  // -------------------------------------------------------------------------
82  // Constructors and Rule of Five
83  // -------------------------------------------------------------------------
84 
85  GffReader() = default;
86  ~GffReader() = default;
87 
88  GffReader( GffReader const& ) = default;
89  GffReader( GffReader&& ) = default;
90 
91  GffReader& operator= ( GffReader const& ) = default;
92  GffReader& operator= ( GffReader&& ) = default;
93 
94  // ---------------------------------------------------------------------
95  // Reading
96  // ---------------------------------------------------------------------
97 
98  std::vector<Feature> read( std::shared_ptr< utils::BaseInputSource > source ) const;
99 
100  // -------------------------------------------------------------------------
101  // Parsing
102  // -------------------------------------------------------------------------
103 
104  bool parse_line(
105  utils::InputStream& input_stream,
106  Feature& feature
107  ) const;
108 
109 };
110 
111 } // namespace population
112 } // namespace genesis
113 
114 #endif // include guard
genesis::utils::InputStream
Stream interface for reading data from an InputSource, that keeps track of line and column counters.
Definition: input_stream.hpp:80
genesis::population::GffReader::Feature::feature
std::string feature
Definition: gff_reader.hpp:72
genesis::population::GffReader::Feature::frame
signed char frame
Definition: gff_reader.hpp:77
genesis::population::GffReader::Feature::source
std::string source
Definition: gff_reader.hpp:71
genesis::population::GffReader::Feature::start
size_t start
Definition: gff_reader.hpp:73
genesis::population::GffReader::parse_line
bool parse_line(utils::InputStream &input_stream, Feature &feature) const
Definition: gff_reader.cpp:61
genesis::population::GffReader::Feature
Definition: gff_reader.hpp:68
genesis::population::GffReader::operator=
GffReader & operator=(GffReader const &)=default
genesis::population::GffReader::Feature::seqname
std::string seqname
Definition: gff_reader.hpp:70
input_source.hpp
genesis::population::GffReader::Feature::attributes
std::vector< Attribute > attributes
Definition: gff_reader.hpp:78
input_stream.hpp
genesis::population::GffReader::read
std::vector< Feature > read(std::shared_ptr< utils::BaseInputSource > source) const
Definition: gff_reader.cpp:48
genesis
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
Definition: placement/formats/edge_color.cpp:42
genesis::population::GffReader::Feature::end
size_t end
Definition: gff_reader.hpp:74
genesis::population::GffReader
Reader for GFF (General Feature Format) and GTF (General Transfer Format) files.
Definition: gff_reader.hpp:55
genesis::population::GffReader::GffReader
GffReader()=default
genesis::population::GffReader::Feature::strand
char strand
Definition: gff_reader.hpp:76
genesis::population::GffReader::~GffReader
~GffReader()=default
genesis::population::GffReader::Attribute
std::pair< std::string, std::string > Attribute
Definition: gff_reader.hpp:63
genesis::population::GffReader::Feature::score
double score
Definition: gff_reader.hpp:75