forked from sgusev/GERMLINE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chromosome.cpp
65 lines (52 loc) · 1.64 KB
/
Chromosome.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Chromosome.cpp.haplotyped markers for a chromosome
#include "Chromosome.h"
#include <iostream>
using namespace std;
// Chromosome(): default constructor
Chromosome::Chromosome()
{}
// returns a pointer to a marker set?
MarkerSet * Chromosome::getMarkerSet()
{
// if (DEBUG) cout << "Chromosome.getMarkerSet() called without params; position_ms is " << position_ms << endl;
return chromosome[position_ms];
}
MarkerSet * Chromosome::getMarkerSet(unsigned int pos)
{
return chromosome[pos];
}
void Chromosome::clear()
{
for ( size_t i = 0 ; i < chromosome.size() ; i++ ) { delete chromosome[i]; }
chromosome.clear();
}
// addMarkerSet(): adds a MarkerSet
void Chromosome::addMarkerSet(MarkerSet * marker_set)
{
if (DEBUG) cout << "Chromosome.addMarkerSet called" << endl;
chromosome.push_back(marker_set);
}
void Chromosome::print_snps(ostream& out, unsigned int start, unsigned int end)
{
unsigned int p_ms = position_ms;
unsigned int ms_start = start / MARKER_SET_SIZE;
unsigned int ms_end = end / MARKER_SET_SIZE;
if( start % MARKER_SET_SIZE != 0 ) { position_ms = ms_start; chromosome[ms_start++]->print(out,start % MARKER_SET_SIZE,MARKER_SET_SIZE); out << ' '; }
print(out,ms_start,ms_end);
if( end % MARKER_SET_SIZE != 0 ) { out << ' '; chromosome[ms_end]->print(out,0,end % MARKER_SET_SIZE); }
position_ms = p_ms;
}
void Chromosome::print(ostream& out,unsigned int start,unsigned int end)
{
for(position_ms=start;position_ms<end;position_ms++)
{
if( position_ms > start ) out << ' ';
chromosome[position_ms]->print(out);
}
}
ostream& operator<<(ostream &fout, Chromosome& c)
{
fout << c.getMarkerSet();
return fout;
}
// end Chromosome.cpp