Initial check in of c++ short read programming library. These classes give functional...
[htsworkflow.git] / htswanalysis / src / SRLib / read.cpp
1 /*
2  * Read.cpp:
3  * 
4  * Implementation of Read class. Since the class consists of public variables (more of a struct, really) there is not much 
5  * here.
6  *
7  * compare_reads: function to compare two reads, first be chromosome, then by position. Useful to sort a vector of reads.
8  */
9
10 #include <string>
11 #include <iostream>
12
13 #include "Read.h"
14
15 Read::Read(string chr, unsigned int pos, bool strand, string seq) : Loci(chr,pos) { 
16   this->strand = strand; 
17   this->seq = seq; 
18 }
19
20 Read::Read(const Read& r) : Loci(r) { 
21   this->strand = strand; 
22   this->seq = r.seq; 
23 }
24
25 Read& Read::operator=(const Read& r) { 
26   if(this == &r) return *this;
27
28   Loci::operator=(r);
29   this->strand = r.strand; 
30   this->seq = r.seq; 
31   return *this;
32 }
33
34 unsigned int Read::length() const {
35   return seq.length();
36 }
37
38 //Errors if the offset exceeds the length of the read
39 char Read::operator[](size_t off) const {
40   if(off >= this->length()) { 
41     cerr << "Error: index " << off << " out of bounds for read of length " << this->length() << endl;
42   }
43
44   return this->seq[off]; 
45 }