bpp-seq-omics  2.2.0
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  private:
96  GffFeatureReader& operator=(const GffFeatureReader& reader) { return *this; }
97 
98  public:
99  bool hasMoreFeature() const { return nextLine_ != ""; }
100  const BasicSequenceFeature nextFeature() throw (Exception);
101 
103  while (hasMoreFeature()) {
104  features.addFeature(nextFeature());
105  }
106  }
107  void getFeaturesOfType(const std::string& type, SequenceFeatureSet& features) {
108  while (hasMoreFeature()) {
109  BasicSequenceFeature feature = nextFeature();
110  if (feature.getType() == type)
111  features.addFeature(feature);
112  }
113  }
114  void getFeaturesOfSequence(const std::string& seqId, SequenceFeatureSet& features) {
115  while (hasMoreFeature()) {
116  BasicSequenceFeature feature = nextFeature();
117  if (feature.getSequenceId() == seqId)
118  features.addFeature(feature);
119  }
120  }
121 
126  static std::string toString(const bpp::SequenceFeature& f);
127 
136  static void toString(const bpp::SequenceFeature& f, std::ostream& out) {
137  out << toString(f) << std::endl;
138  }
139 
140  static void toString(const bpp::SequenceFeatureSet& fs, std::ostream& out) {
141  for (unsigned int i = 0; i < fs.getNumberOfFeatures(); ++i) {
142  toString(fs[i], out);
143  }
144  }
145 
146  private:
147  void getNextLine_();
148 
149 };
150 
151 } //end of namespace bpp
152 
153 #endif //_GFFFEATUREREADER_H_
154 
static const std::string GFF_PARENT
static const std::string GFF_ALIAS
const std::string & getType() const
static const std::string GFF_PHASE
void addFeature(const SequenceFeature &feature)
Add a feature to the container. The feature will be copied and the copy owned by the container...
A simple reader implementing the Gene Finding Feature format.
static const std::string GFF_TARGET
GffFeatureReader & operator=(const GffFeatureReader &reader)
static const std::string GFF_GAP
GffFeatureReader(const GffFeatureReader &reader)
bool hasMoreFeature() const
Interface for feature readers.
Definition: FeatureReader.h:59
void getFeaturesOfType(const std::string &type, SequenceFeatureSet &features)
static const std::string GFF_NAME
static const std::string GFF_STRAND
void getAllFeatures(SequenceFeatureSet &features)
static const std::string GFF_ONTOLOGY_TERM
static void toString(const bpp::SequenceFeature &f, std::ostream &out)
Out put a string description of a feature to a stream.
size_t getNumberOfFeatures() const
static const std::string GFF_IS_CIRCULAR
static const std::string GFF_DBXREF
static void toString(const bpp::SequenceFeatureSet &fs, std::ostream &out)
void getFeaturesOfSequence(const std::string &seqId, SequenceFeatureSet &features)
static std::string toString(const bpp::SequenceFeature &f)
GffFeatureReader(std::istream &input)
static const std::string GFF_NOTE
The base interface for sequence features.
const std::string & getSequenceId() const
const BasicSequenceFeature nextFeature()
static const std::string GFF_DERIVES_FROM
A very simple implementation of the SequenceFeature class.
A simple ensemble of sequence features.