43 #include <Bpp/Text/StringTokenizer.h> 44 #include <Bpp/Text/TextTools.h> 45 #include <Bpp/Text/KeyvalTools.h> 64 while (TextTools::isEmpty(nextLine_) || nextLine_.size() < 2 || nextLine_[0] ==
'#') {
69 getline(*input_, nextLine_);
75 if (!hasMoreFeature())
76 throw Exception(
"GtfFeatureReader::nextFeature(). No more feature in file.");
79 StringTokenizer st(nextLine_,
"\t");
80 if (st.numberOfRemainingTokens() != 9)
81 throw Exception(
"GtfFeatureReader::nextFeature(). Wrong GTF file format: should have 9 tab delimited columns.");
84 std::string seqId = st.nextToken();
85 std::string source = st.nextToken();
86 std::string type = st.nextToken();
87 unsigned int start = TextTools::to<unsigned int>(st.nextToken()) - 1;
88 unsigned int end = TextTools::to<unsigned int>(st.nextToken());
89 double score = TextTools::to<double>(st.nextToken());
90 std::string strand = st.nextToken();
91 std::string phase = st.nextToken();
92 std::string attrDesc = st.nextToken();
93 std::map<string, string> attributes;
94 bpp::StringTokenizer st1(attrDesc,
";");
95 while (st1.hasMoreToken()) {
96 std::string item(bpp::TextTools::removeSurroundingWhiteSpaces(st1.nextToken()));
97 std::string::size_type idx = item.find_first_of(
' ');
98 std::string key(item.substr(0, idx));
99 std::string value(item.substr(idx));
105 || bpp::TextTools::isWhiteSpaceCharacter(value[0])
108 value.erase(value.begin());
114 value[value.size() - 1] ==
'"' 115 || bpp::TextTools::isWhiteSpaceCharacter(value[value.size() - 1])
118 value.erase(value.end() - 1);
120 attributes[key] = value;
129 phase = bpp::TextTools::removeSurroundingWhiteSpaces(phase);
130 if (phase !=
".") feature.
setAttribute(GTF_PHASE, phase);
133 for (std::map<std::string, std::string>::iterator it = attributes.begin(); it != attributes.end(); ++it) {
static const std::string GTF_TRANSCRIPT_ID
static const std::string GTF_PHASE
static const std::string GTF_GENE_ID
void setAttribute(const std::string &attribute, const std::string &value)
Set the value of an attribute.
const BasicSequenceFeature nextFeature()
A very simple implementation of the SequenceFeature class.