43 #include <Bpp/Text/StringTokenizer.h> 44 #include <Bpp/Text/TextTools.h> 45 #include <Bpp/Text/KeyvalTools.h> 46 #include <Bpp/Numeric/VectorTools.h> 70 while (TextTools::isEmpty(nextLine_) || nextLine_.size() < 2 || nextLine_[0] ==
'#') {
75 getline(*input_, nextLine_);
81 if (!hasMoreFeature())
82 throw Exception(
"GffFeatureReader::nextFeature(). No more feature in file.");
85 StringTokenizer st(nextLine_,
"\t");
86 if (st.numberOfRemainingTokens() != 9)
87 throw Exception(
"GffFeatureReader::nextFeature(). Wrong GFF3 file format: should have 9 tab delimited columns.");
90 string seqId = st.nextToken();
91 string source = st.nextToken();
92 string type = st.nextToken();
93 unsigned int start = TextTools::to<unsigned int>(st.nextToken()) - 1;
94 unsigned int end = TextTools::to<unsigned int>(st.nextToken());
95 double score = TextTools::to<double>(st.nextToken());
96 string strand = st.nextToken();
97 string phase = st.nextToken();
98 string attrDesc = st.nextToken();
99 map<string, string> attributes;
100 KeyvalTools::multipleKeyvals(attrDesc, attributes,
";",
false);
101 string id = attributes[
"ID"];
105 if (phase !=
".") feature.
setAttribute(GFF_PHASE, phase);
108 for (map<string, string>::iterator it = attributes.begin(); it != attributes.end(); ++it) {
109 if (it->first !=
"ID")
120 std::vector< std::string > v;
121 std::vector< std::string > attr;
126 v.push_back(bpp::TextTools::toString(f.
getStart() + 1));
127 v.push_back(bpp::TextTools::toString(f.
getEnd()));
128 v.push_back(bpp::TextTools::toString(f.
getScore()));
144 if (f.
getId() !=
"") {
145 attr.push_back(
"ID=" + f.
getId());
147 for (std::set< std::string >::iterator it = attrNames.begin() ; it != attrNames.end() ; it++) {
150 v.push_back(bpp::VectorTools::paste(attr,
";"));
151 return bpp::VectorTools::paste(v,
"\t");
static const std::string GFF_PARENT
static const std::string GFF_ALIAS
virtual const double & getScore() const =0
static const std::string GFF_PHASE
virtual const size_t getStart() const =0
static const std::string GFF_TARGET
static const std::string GFF_GAP
virtual std::set< std::string > getAttributeList() const =0
virtual const std::string & getType() const =0
virtual const size_t getEnd() const =0
static const std::string GFF_NAME
static const std::string GFF_ONTOLOGY_TERM
static const std::string GFF_IS_CIRCULAR
static const std::string GFF_DBXREF
virtual const std::string & getSource() const =0
virtual const std::string & getSequenceId() const =0
virtual bool isNegativeStrand() const =0
void setAttribute(const std::string &attribute, const std::string &value)
Set the value of an attribute.
static std::string toString(const bpp::SequenceFeature &f)
static const std::string GFF_NOTE
The base interface for sequence features.
virtual const std::string & getAttribute(const std::string &attribute) const =0
const BasicSequenceFeature nextFeature()
static const std::string GFF_DERIVES_FROM
virtual bool isStranded() const =0
A very simple implementation of the SequenceFeature class.
virtual const std::string & getId() const =0