1 // -*-mode:c++; c-style:k&r; c-basic-offset:4;-*-
2 //
3 // Copyright 2010, Julian Catchen <jcatchen@uoregon.edu>
4 //
5 // This file is part of Stacks.
6 //
7 // Stacks is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // Stacks is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with Stacks. If not, see <http://www.gnu.org/licenses/>.
19 //
20
21 //
22 // Code to parse the internal (and tempoary) data format. This format is created for
23 // reads that have been aligned to a reference genome. It takes the tab-separated form:
24 //
25 // <chromosome> <base pair> <sequence> <phred quality score>
26 //
27 // One record per line.
28 //
29 #ifndef __TSV_H__
30 #define __TSV_H__
31
32 #include "input.h"
33
34 class Tsv: public Input {
35
36 public:
Tsv(const char * path)37 Tsv(const char *path) : Input(path) {};
~Tsv()38 ~Tsv() {};
39 Seq *next_seq();
40 int next_seq(Seq &);
41 };
42
next_seq()43 Seq *Tsv::next_seq() {
44 Seq* s = new Seq();
45 if(next_seq(*s) != 1) {
46 delete s;
47 s = NULL;
48 }
49 return s;
50 }
51
next_seq(Seq & s)52 int Tsv::next_seq(Seq& s) {
53 vector<string> parts;
54
55 this->fh.getline(this->line, max_len);
56
57 if (!this->fh.good()) {
58 return 0;
59 }
60
61 parse_tsv(this->line, parts);
62
63 string id = parts[0] + "_" + parts[1];
64
65 s = Seq(id.c_str(), parts[2].c_str(), parts[3].c_str(), parts[0].c_str(), atoi(parts[1].c_str()), strand_plus);
66
67 return 1;
68 }
69
70 #endif // __TSV_H__
71