bpp-seq-omics  2.4.1
GffFeatureReader.h
Go to the documentation of this file.
1 //
2 // File: GffFeatureReader.h
3 // Created by: Julien Dutheil
4 // Created on: Mon Nov 21 2011
5 //
6 
7 /*
8 Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
9 
10 This software is a computer program whose purpose is to provide classes
11 for sequences analysis.
12 
13 This software is governed by the CeCILL license under French law and
14 abiding by the rules of distribution of free software. You can use,
15 modify and/ or redistribute the software under the terms of the CeCILL
16 license as circulated by CEA, CNRS and INRIA at the following URL
17 "http://www.cecill.info".
18 
19 As a counterpart to the access to the source code and rights to copy,
20 modify and redistribute granted by the license, users are provided only
21 with a limited warranty and the software's author, the holder of the
22 economic rights, and the successive licensors have only limited
23 liability.
24 
25 In this respect, the user's attention is drawn to the risks associated
26 with loading, using, modifying and/or developing or reproducing the
27 software by the user in light of its specific status of free software,
28 that may mean that it is complicated to manipulate, and that also
29 therefore means that it is reserved for developers and experienced
30 professionals having in-depth computer knowledge. Users are therefore
31 encouraged to load and test the software's suitability as regards their
32 requirements in conditions enabling the security of their systems and/or
33 data to be ensured and, more generally, to use and operate it in the
34 same conditions as regards security.
35 
36 The fact that you are presently reading this means that you have had
37 knowledge of the CeCILL license and that you accept its terms.
38 */
39 
40 #ifndef _GFFFEATUREREADER_H_
41 #define _GFFFEATUREREADER_H_
42 
43 #include "../SequenceFeature.h"
44 #include "../FeatureReader.h"
45 
46 //From bpp-core:
47 #include <Bpp/Exceptions.h>
48 
49 //From the STL:
50 #include <string>
51 #include <vector>
52 
53 namespace bpp {
54 
67  public virtual FeatureReader
68 {
69  public:
70  static const std::string GFF_STRAND;
71  static const std::string GFF_PHASE;
72  static const std::string GFF_NAME;
73  static const std::string GFF_ALIAS;
74  static const std::string GFF_PARENT;
75  static const std::string GFF_TARGET;
76  static const std::string GFF_GAP;
77  static const std::string GFF_DERIVES_FROM;
78  static const std::string GFF_NOTE;
79  static const std::string GFF_DBXREF;
80  static const std::string GFF_ONTOLOGY_TERM;
81  static const std::string GFF_IS_CIRCULAR;
82 
83  private:
84  std::istream& input_;
85  std::string nextLine_;
86 
87  public:
88  GffFeatureReader(std::istream& input):
89  input_(input), nextLine_()
90  {
91  getNextLine_();
92  }
93 
94  public:
95  bool hasMoreFeature() const { return nextLine_ != ""; }
97 
99  while (hasMoreFeature()) {
100  features.addFeature(nextFeature());
101  }
102  }
103  void getFeaturesOfType(const std::string& type, SequenceFeatureSet& features) {
104  while (hasMoreFeature()) {
105  BasicSequenceFeature feature = nextFeature();
106  if (feature.getType() == type)
107  features.addFeature(feature);
108  }
109  }
110  void getFeaturesOfSequence(const std::string& seqId, SequenceFeatureSet& features) {
111  while (hasMoreFeature()) {
112  BasicSequenceFeature feature = nextFeature();
113  if (feature.getSequenceId() == seqId)
114  features.addFeature(feature);
115  }
116  }
117 
122  static std::string toString(const bpp::SequenceFeature& f);
123 
132  static void toString(const bpp::SequenceFeature& f, std::ostream& out) {
133  out << toString(f) << std::endl;
134  }
135 
136  static void toString(const bpp::SequenceFeatureSet& fs, std::ostream& out) {
137  for (unsigned int i = 0; i < fs.getNumberOfFeatures(); ++i) {
138  toString(fs[i], out);
139  }
140  }
141 
142  private:
143  void getNextLine_();
144 
145 };
146 
147 } //end of namespace bpp
148 
149 #endif //_GFFFEATUREREADER_H_
150 
A very simple implementation of the SequenceFeature class.
const std::string & getSequenceId() const
const std::string & getType() const
Interface for feature readers.
Definition: FeatureReader.h:60
A simple reader implementing the Gene Finding Feature format.
static const std::string GFF_DBXREF
static const std::string GFF_STRAND
static const std::string GFF_ALIAS
void getFeaturesOfSequence(const std::string &seqId, SequenceFeatureSet &features)
static std::string toString(const bpp::SequenceFeature &f)
static const std::string GFF_NOTE
void getFeaturesOfType(const std::string &type, SequenceFeatureSet &features)
static const std::string GFF_PHASE
static const std::string GFF_DERIVES_FROM
static const std::string GFF_TARGET
static const std::string GFF_ONTOLOGY_TERM
static const std::string GFF_IS_CIRCULAR
static const std::string GFF_GAP
void getAllFeatures(SequenceFeatureSet &features)
static void toString(const bpp::SequenceFeatureSet &fs, std::ostream &out)
bool hasMoreFeature() const
static const std::string GFF_PARENT
static const std::string GFF_NAME
const BasicSequenceFeature nextFeature()
GffFeatureReader(std::istream &input)
static void toString(const bpp::SequenceFeature &f, std::ostream &out)
Out put a string description of a feature to a stream.
A simple ensemble of sequence features.
void addFeature(const SequenceFeature &feature)
Add a feature to the container. The feature will be copied and the copy owned by the container.
size_t getNumberOfFeatures() const
The base interface for sequence features.