Added qPCR Validation design code
[htsworkflow.git] / htswanalysis / src / ValidationDesign / window.cpp
1 #include <iostream>
2 #include <string>
3 #include <sstream>
4 #include <vector>
5
6 #include "window.h"
7 #include "util.h"
8
9 void Window::count_hits() {
10   total = 0;
11   for(vector<unsigned int>::iterator i = counts.begin(); i != counts.end(); ++i) {
12   total += *i;
13   }
14 }
15
16 Window::Window(string name, string chr, int start, int end, double score) { 
17   this->name = name;
18   this->chr = chr; 
19   this->start = start; 
20   this->end = end; 
21   this->score = score;
22   counts.clear();
23   counts.resize(end-start+1,0);
24   this->sequence = "";
25 }
26
27 Window::Window(const Window& r) { 
28   this->name = r.name;
29   this->score= r.score; 
30   this->chr = r.chr; 
31   this->sequence = r.sequence;
32   this->start = r.start; 
33   this->end = r.end; 
34   this->counts = r.counts; 
35 }
36
37 Window& Window::operator=(const Window& r) {
38   this->name = r.name;
39   this->score = r.score; 
40   this->chr = r.chr; 
41   this->sequence = r.sequence;
42   this->start = r.start; 
43   this->end = r.end; 
44   this->counts = r.counts; 
45   return *this;
46 }
47
48 ostream &operator<<( ostream &out, const Window &w ) {
49   out << w.chr.c_str() << "\t" << w.start << "\t" << w.end << "\t" << w.total;
50   return out;
51 }
52
53 bool Window::operator<(const Window& b) const { 
54   if(this->chr == b.chr) { return this->start < b.start; } else { return this->chr < b.chr; } }
55
56
57 Window::Window(string line) {
58         istringstream outStream;
59         
60         vector<string> fields;
61         string delim("\t");
62         split(line,delim,fields);
63
64         this->name = fields[0];
65         this->chr = fields[1];
66         this->start = atoi(fields[2].c_str());
67         this->end = atoi(fields[3].c_str());
68         this->score = strtod(fields[4].c_str(), NULL);
69         this->sequence = "";
70 }
71
72 void Window::reset(unsigned int new_start, unsigned int new_end) {
73   this->start = new_start;
74   this->end = new_end;
75   this->counts.clear();
76   this->counts.resize(end-start+1,0);
77 }
78
79 bool compare_windows(const Window &a, const Window &b) { if(a.chr == b.chr) { return a.start < b.start; } else { return a.chr < b.chr; } }