0
|
1 /*****************************************************************************
|
|
2 tabFile.h
|
|
3
|
|
4 (c) 2009 - Aaron Quinlan
|
|
5 Hall Laboratory
|
|
6 Department of Biochemistry and Molecular Genetics
|
|
7 University of Virginia
|
|
8 aaronquinlan@gmail.com
|
|
9
|
|
10 Licensed under the GNU General Public License 2.0 license.
|
|
11 ******************************************************************************/
|
|
12 #ifndef TABFILE_H
|
|
13 #define TABFILE_H
|
|
14
|
|
15 #include "gzstream.h"
|
|
16 #include <vector>
|
|
17 #include <string>
|
|
18 #include <iostream>
|
|
19
|
|
20 using namespace std;
|
|
21
|
|
22 // enum to flag the state of a given line in a TAB file.
|
|
23 enum TabLineStatus
|
|
24 {
|
|
25 TAB_INVALID = -1,
|
|
26 TAB_HEADER = 0,
|
|
27 TAB_BLANK = 1,
|
|
28 TAB_VALID = 2
|
|
29 };
|
|
30
|
|
31 typedef vector<string> TAB_FIELDS;
|
|
32
|
|
33 //************************************************
|
|
34 // TabFile Class methods and elements
|
|
35 //************************************************
|
|
36 class TabFile {
|
|
37
|
|
38 public:
|
|
39
|
|
40 // Constructor
|
|
41 TabFile(const string &tabFile);
|
|
42
|
|
43 // Destructor
|
|
44 ~TabFile(void);
|
|
45
|
|
46 // Open a TAB file for reading (creates an istream pointer)
|
|
47 void Open(void);
|
|
48
|
|
49 // Close an opened TAB file.
|
|
50 void Close(void);
|
|
51
|
|
52 // Get the next TAB entry in an opened TAB file.
|
|
53 TabLineStatus GetNextTabLine (TAB_FIELDS &tab, int &lineNum);
|
|
54
|
|
55 private:
|
|
56
|
|
57 // data
|
|
58 istream *_tabStream;
|
|
59 string _tabFile;
|
|
60
|
|
61 // methods
|
|
62 inline TabLineStatus parseTabLine (const vector<string> &lineVector, int &lineNum) {
|
|
63 // bail out if we have a blank line
|
|
64 if (lineVector.size() == 0)
|
|
65 return TAB_BLANK;
|
|
66 // real line with data
|
|
67 if (lineVector[0][0] != '#') {
|
|
68 return TAB_VALID;
|
|
69 }
|
|
70 // comment or header line
|
|
71 else {
|
|
72 lineNum--;
|
|
73 return TAB_HEADER;
|
|
74 }
|
|
75 // default
|
|
76 return TAB_INVALID;
|
|
77 }
|
|
78 };
|
|
79
|
|
80 #endif /* TABFILE_H */
|