Added qPCR Validation design code
[htsworkflow.git] / htswanalysis / src / ValidationDesign / peak.cpp
1 /*
2  *  peak.cpp
3  *  PeakLocator
4  *
5  *  Created by Alan You on 8/11/08.
6  *  Copyright 2008 Hudson Alpha. All rights reserved.
7  *
8  */
9
10 #include <vector>
11 #include <string>
12
13 #include "peak.h"
14 #include "util.h"
15
16 using namespace std;
17
18 Peak::Peak()
19 {
20         this->startBP = 0;
21         this->endBP = 0;
22         this->length = 0;
23         this->chrom = "";
24         this->score = 0;        
25         this->sequence = "";
26 }
27
28 Peak::Peak(string line)
29 {
30         istringstream outStream;
31         
32         vector<string> fields;
33         string delim("\t");
34         split(line,delim,fields);
35
36         this->chrom = fields[0];
37         this->startBP = atoi(fields[1].c_str());
38         this->endBP = atoi(fields[2].c_str());
39         this->score = strtod(fields[3].c_str(), NULL);
40         this->length = this->endBP - this->startBP;
41         this->sequence = "";
42 }
43
44 Peak::Peak(const Peak& p)
45 {
46         this->startBP = p.startBP;
47         this->endBP = p.endBP;
48         this->length = p.length;
49         this->chrom = p.chrom;
50         this->score = p.score;
51         this->sequence = p.sequence;
52 }
53
54 Peak::~Peak()
55 {
56 ;
57 }
58
59 void Peak::print()
60 {
61         cout << "Chromosome:\t\t" << this->chrom.c_str() << endl;
62         cout << "Starting Base Pair:\t" << this->startBP << endl;
63         cout << "Ending Base Pair:\t" << this->endBP << endl;
64         cout << "Sequence Length:\t" << this->length << endl;
65         cout << "Sequence Score:\t\t" << this->score << endl;
66         cout << "Sequence:\t\t" << this->sequence << endl;
67 }
68
69 void Peak::printToFile(ofstream &outputFile)
70 {
71         outputFile << "Chromosome:\t\t" << this->chrom.c_str() << endl;
72         outputFile << "Starting Base Pair:\t" << this->startBP << endl;
73         outputFile << "Ending Base Pair:\t" << this->endBP << endl;
74         outputFile << "Sequence Length:\t" << this->length << endl;
75         outputFile << "Sequence Score:\t\t" << this->score << endl;
76         outputFile << "Sequence:\t\t" << this->sequence << endl;
77         outputFile << endl;
78 }
79
80 bool Peak::operator<(const Peak& that) const
81 {
82         if (this->chrom == that.chrom) { return(this->startBP < that.startBP);
83         } else { return(this->chrom < that.chrom); }
84 }
85
86 bool Peak::operator>(const Peak& that) const
87 {
88         if (this->chrom == that.chrom) { return(this->startBP > that.startBP);
89         } else { return(this->chrom > that.chrom); }
90         
91 }
92
93 Peak& Peak:: operator=(const Peak& that)
94 {
95         if (this != &that)
96         {
97                 this->chrom = that.chrom;
98                 this->startBP = that.startBP;
99                 this->endBP = that.endBP;
100                 this->length = that.length;
101                 this->score = that.score;
102                 this->sequence = that.sequence;
103         }
104         
105         return *this;
106 }