41 #include <Bpp/Text/TextTools.h> 42 #include <Bpp/Text/StringTokenizer.h> 54 return nextSequence(input, seq, pos);
61 throw IOException (
"PhredPhd::read: fail to open stream");
65 std::string name, sequence =
"";
66 std::vector<int> q, p;
68 flag = parseFile_(input, name, sequence, q, p);
71 throw Exception(
"PhredPhd::read: sequence without name!");
73 seq.setContent(sequence);
84 bool PhredPhd::parseFile_(std::istream& input, std::string& name, std::string& sequence, std::vector<int>& qual, std::vector<int>& pos)
const {
85 bool readSeqFlag =
false;
89 while (!input.eof()) {
90 std::getline(input, temp,
'\n');
91 StringTokenizer st(temp,
" ");
92 if (st.hasMoreToken()) {
93 if (st.getToken(0) ==
"BEGIN_SEQUENCE") {
94 name = st.getToken(1);
96 std::string flag = st.getToken(0);
97 while (flag !=
"END_SEQUENCE" && !input.eof()) {
98 getline(input, temp,
'\n');
99 StringTokenizer st2(temp,
" ");
100 if (st2.hasMoreToken()) {
101 flag = st2.getToken(0);
103 if (flag ==
"BEGIN_DNA") {
104 readSeqFlag =
parseDNA_(input, sequence, qual, pos);
115 bool PhredPhd::parseDNA_(std::istream& input, std::string& sequence, std::vector<int>& qual, std::vector<int>& pos)
const {
116 bool readSeqFlag =
false;
117 std::string line_buffer;
122 while (flag !=
"END_DNA" && !input.eof()) {
123 std::getline(input, line_buffer,
'\n');
124 StringTokenizer st(line_buffer,
" ");
125 if (st.hasMoreToken()) {
126 flag = TextTools::toUpper(st.getToken(0));
127 if (st.numberOfRemainingTokens() == 3) {
129 qual.push_back(TextTools::toInt(st.getToken(1)));
130 pos.push_back(TextTools::toInt(st.getToken(2)));
This alphabet is used to deal NumericAlphabet.
A SequenceWithAnnotation class with quality scores attached.
bool nextSequence(std::istream &input, Sequence &seq) const
Read sequence from stream.
bool parseFile_(std::istream &input, std::string &name, std::string &sequence, std::vector< int > &qual, std::vector< int > &pos) const
Global file parser.
void setQualities(const std::vector< int > &quality)
Set the whole quality scores.
bool parseDNA_(std::istream &input, std::string &sequence, std::vector< int > &qual, std::vector< int > &pos) const
Parse the DNA part of the file.