annotate SMART/Java/Python/Cpp/genomicInterval.hpp @ 18:94ab73e8a190

Uploaded
author m-zytnicki
date Mon, 29 Apr 2013 03:20:15 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
1 #ifndef GENOMIC_INTERVAL_HPP
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
2 #define GENOMIC_INTERVAL_HPP
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
3
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
4 #include "interval.hpp"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
5 #include <stdio.h>
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
6 #include <stdlib.h>
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
7 #include <string>
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
8 #include <sstream>
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
9
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
10 class GenomicInterval: public Interval {
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
11
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
12 public:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
13 string chromosome;
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
14
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
15 GenomicInterval(string chromosome = "", unsigned int start = 0, unsigned int end = 0): Interval(start, end), chromosome(chromosome) { }
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
16
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
17 bool onSameChromosome(const GenomicInterval &i) const {
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
18 return (chromosome == i.chromosome);
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
19 }
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
20
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
21 // friend bool operator==(const GenomicInterval &i1, const GenomicInterval &i2) {
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
22 // return ((i1.onSameChromosome(i2)) && (Interval::i1 == Interval::i2));
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
23 // }
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
24
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
25 // friend bool operator<(const GenomicInterval &i1, const GenomicInterval &i2) {
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
26 // return ((i1.onSameChromosome(i2)) && (Interval::i1 < Interval::i2));
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
27 // }
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
28
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
29 friend ofstream& operator<<(ofstream &stream, const GenomicInterval &i) {
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
30 stream << i.chromosome << '\t' << i.start << '\t' << i.end << '\n';
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
31 return stream;
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
32 }
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
33
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
34 void parseFromLine(string &line) {
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
35 string strStart, strEnd;
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
36 istringstream iss(line);
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
37 getline(iss, chromosome, '\t');
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
38 getline(iss, strStart, '\t');
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
39 getline(iss, strEnd, '\t');
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
40 start = atoi(strStart.c_str());
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
41 end = atoi(strEnd.c_str());
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
42 //cout << "read " << chromosome << ":" << start << ".." << end << endl;
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
43 }
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
44
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
45 };
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
46
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
47 #endif