ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/gclib/tophat_cpp/reads.h
Revision: 29
Committed: Tue Aug 2 21:24:54 2011 UTC (9 years, 7 months ago) by gpertea
File size: 3465 byte(s)
Log Message:
adding tophat source work

Line User Rev File contents
1 gpertea 29 #ifndef READS_H
2     #define READS_H
3     /*
4     * reads.h
5     * TopHat
6     *
7     * Created by Cole Trapnell on 9/2/08.
8     * Copyright 2008 Cole Trapnell. All rights reserved.
9     *
10     */
11    
12     #include <string>
13     #include <sstream>
14     #include <seqan/sequence.h>
15     #include "common.h"
16    
17     using std::string;
18    
19     static const int max_read_bp = 64;
20    
21     // Note: qualities are not currently used by TopHat
22     struct Read
23     {
24     Read()
25     {
26     seq.reserve(max_read_bp);
27     qual.reserve(max_read_bp);
28     }
29    
30     string name;
31     string seq;
32     string alt_name;
33     string qual;
34    
35     bool lengths_equal() { return seq.length() == qual.length(); }
36     void clear()
37     {
38     name.clear();
39     seq.clear();
40     qual.clear();
41     alt_name.clear();
42     }
43     };
44    
45     void reverse_complement(string& seq);
46     string convert_color_to_bp(const string& color);
47     seqan::String<char> convert_color_to_bp(char base, const seqan::String<char>& color);
48    
49     string convert_bp_to_color(const string& bp, bool remove_primer = false);
50     seqan::String<char> convert_bp_to_color(const seqan::String<char>& bp, bool remove_primer = false);
51    
52     /*
53     This is a dynamic programming to decode a colorspace read, which is from BWA paper.
54    
55     Heng Li and Richard Durbin
56     Fast and accurate short read alignment with Burrows-Wheeler transform
57     */
58     void BWA_decode(const string& color, const string& qual, const string& ref, string& decode);
59    
60    
61     template <class Type>
62     string DnaString_to_string(const Type& dnaString)
63     {
64     std::string result;
65     std::stringstream ss(std::stringstream::in | std::stringstream::out);
66     ss << dnaString >> result;
67     return result;
68     }
69    
70     class ReadTable;
71    
72     bool get_read_from_stream(uint64_t insert_id,
73     FILE* reads_file,
74     ReadFormat reads_format,
75     bool strip_slash,
76     char read_name [],
77     char read_seq [],
78     char read_alt_name [],
79     char read_qual []);
80    
81     class FLineReader { //simple text line reader class, buffering last line read
82     int len;
83     int allocated;
84     char* buf;
85     bool isEOF;
86     FILE* file;
87     bool is_pipe;
88     bool pushed; //pushed back
89     int lcount; //counting all lines read by the object
90     public:
91     char* chars() { return buf; }
92     char* line() { return buf; }
93     int readcount() { return lcount; } //number of lines read
94     int length() { return len; } //length of the last line read
95     bool isEof() {return isEOF; }
96     char* nextLine();
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     FLineReader(FILE* stream=NULL) {
101     len=0;
102     isEOF=false;
103     is_pipe=false;
104     allocated=512;
105     buf=(char*)malloc(allocated);
106     lcount=0;
107     buf[0]=0;
108     file=stream;
109     pushed=false;
110     }
111    
112     FLineReader(FZPipe& fzpipe) {
113     len=0;
114     isEOF=false;
115     allocated=512;
116     buf=(char*)malloc(allocated);
117     lcount=0;
118     buf[0]=0;
119     file=fzpipe.file;
120     is_pipe=!fzpipe.pipecmd.empty();
121     pushed=false;
122     }
123     void close() {
124     if (file==NULL) return;
125     if (is_pipe) pclose(file);
126     else fclose(file);
127     }
128     ~FLineReader() {
129     free(buf); //does not call close() -- we might reuse the file handle
130     }
131     };
132    
133     void skip_lines(FLineReader& fr);
134     bool next_fasta_record(FLineReader& fr, string& defline, string& seq, ReadFormat reads_format);
135     bool next_fastq_record(FLineReader& fr, const string& seq, string& alt_name, string& qual, ReadFormat reads_format);
136     bool next_fastx_read(FLineReader& fr, Read& read, ReadFormat reads_format,
137     FLineReader* frq=NULL);
138    
139     #endif