ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/gclib/tophat_cpp/reads.h
(Generate patch)
# Line 11 | Line 11
11  
12   #include <string>
13   #include <sstream>
14 + #include <queue>
15 + #include <limits>
16   #include <seqan/sequence.h>
17   #include "common.h"
18 < #include <queue>
18 >
19  
20   using std::string;
21  
# Line 69 | Line 71
71   }
72  
73   class ReadTable;
72 /*
73 bool get_read_from_stream(uint64_t insert_id,
74                          FILE* reads_file,
75                          ReadFormat reads_format,
76                          bool strip_slash,
77                          char read_name [],
78                          char read_seq  [],
79                          char read_alt_name [],
80                          char read_qual [],
81                          FILE* um_out=NULL); //unmapped reads output
82 */
83 bool get_read_from_stream(uint64_t insert_id,
84        FILE* reads_file,
85        ReadFormat reads_format,
86        bool strip_slash,
87        Read& read,
88        FILE* um_out=NULL, //unmapped reads output
89        bool um_write_found=false);
74  
75   class FLineReader { //simple text line reader class, buffering last line read
76    int len;
# Line 97 | Line 81
81    bool is_pipe;
82    bool pushed; //pushed back
83    int lcount; //counting all lines read by the object
84 +
85 + public:
86 +  // daehwan - this is not a good place to store the last read ...
87 +  Read last_read;
88 +  bool pushed_read;
89 +  
90   public:
91    char* chars() { return buf; }
92    char* line() { return buf; }
# Line 107 | Line 97
97    FILE* fhandle() { return file; }
98    void pushBack() { if (lcount>0) pushed=true; } // "undo" the last getLine request
99             // so the next call will in fact return the same line
100 +  void pushBack_read() { if(!last_read.name.empty()) pushed_read=true;}
101    FLineReader(FILE* stream=NULL) {
102      len=0;
103      isEOF=false;
# Line 117 | Line 108
108      buf[0]=0;
109      file=stream;
110      pushed=false;
111 +    pushed_read=false;
112      }
121
113    FLineReader(FZPipe& fzpipe) {
114      len=0;
115      isEOF=false;
# Line 129 | Line 120
120      file=fzpipe.file;
121      is_pipe=!fzpipe.pipecmd.empty();
122      pushed=false;
123 +    pushed_read=false;
124      }
125    void close() {
126      if (file==NULL) return;
127      if (is_pipe) pclose(file);
128              else fclose(file);
129      }
130 +
131    ~FLineReader() {
132      free(buf); //does not call close() -- we might reuse the file handle
133      }
134   };
135  
136 + bool get_read_from_stream(uint64_t insert_id,
137 +                          FLineReader& fr,
138 +                          ReadFormat reads_format,
139 +                          bool strip_slash,
140 +                          Read& read,
141 +                          FILE* um_out=NULL, //unmapped reads output
142 +                          bool um_write_found=false);
143  
144   void skip_lines(FLineReader& fr);
145   bool next_fasta_record(FLineReader& fr, string& defline, string& seq, ReadFormat reads_format);
# Line 147 | Line 147
147   bool next_fastx_read(FLineReader& fr, Read& read, ReadFormat reads_format=FASTQ,
148                          FLineReader* frq=NULL);
149  
150
151
150   class ReadStream {
151    protected:
152      struct ReadOrdering
# Line 169 | Line 167
167    public:
168      ReadStream():fstream(), read_pq(), last_id(0), r_eof(false) {   }
169  
170 <    ReadStream(string& fname):fstream(fname, false),
170 >    ReadStream(const string& fname):fstream(fname, false),
171         read_pq(), last_id(0), r_eof(false) {   }
172  
173      void init(string& fname) {
# Line 180 | Line 178
178          }
179      //read_ids must ALWAYS be requested in increasing order
180      bool getRead(uint64_t read_id, Read& read,
181 <        ReadFormat read_format=FASTQ,
182 <        bool strip_slash=false,
183 <        FILE* um_out=NULL, //unmapped reads output
184 <        bool um_write_found=false);
181 >                 ReadFormat read_format=FASTQ,
182 >                 bool strip_slash=false,
183 >                 FILE* um_out=NULL, //unmapped reads output
184 >                 bool um_write_found=false,
185 >                 uint64_t begin_id = 0,
186 >                 uint64_t end_id=std::numeric_limits<uint64_t>::max());
187  
188      void rewind() {
189        fstream.rewind();
190        clear();
191        }
192 +    void seek(int64_t offset) {
193 +      clear();
194 +      fstream.seek(offset);
195 +    }
196      FILE* file() {
197        return fstream.file;
198        }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines