-
Notifications
You must be signed in to change notification settings - Fork 7
/
Chromosome.cpp
107 lines (87 loc) · 3 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Chromosome.cpp.haplotyped markers for a chromosome
#include "Chromosome.h"
#include <iostream>
using namespace std;
// Chromosome(): default constructor
Chromosome::Chromosome()
{mem_chromosome+= sizeof(Chromosome);}
Chromosome::~Chromosome()
{mem_chromosome-= sizeof(Chromosome);}
MarkerSet * Chromosome::getMarkerSet()
{
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++ )
{
mem_markers -= (sizeof(MarkerSet) + (chromosome[i]->getMarkerBits().num_blocks() * sizeof(unsigned long)));
delete chromosome[i];
}
mem_bufferchr-= ceil((float)buffer_chromosome.size()/8);
chromosome.clear();
buffer_chromosome.clear();
}
// addMarkerSet(): adds a MarkerSet
void Chromosome::addMarkerSet(MarkerSet * ms)
{
chromosome.push_back(ms);
}
//overloaded addMarkerSet() : loads the entire marker data into a buffer chromosome
void Chromosome::addMarkers(vector<bool>* markers)
{
buffer_chromosome = *markers;
mem_bufferchr+= ceil((float)buffer_chromosome.size()/8);
}
//TODO: update to use WIndowSize instead of MARKER_SET_SIZE
void Chromosome::print_snps(ostream& out, unsigned int start, unsigned int end)
{
int p_ms = position_ms;
int ms_start = start / MARKER_SET_SIZE;
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;
}
//TODO: update to use WIndowSize instead of MARKER_SET_SIZE
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);
}
}
//TODO: update to use WIndowSize instead of MARKER_SET_SIZE
ostream& operator<<(ostream &fout, Chromosome& c)
{
fout << c.getMarkerSet();
return fout;
}
/////////////////////////////////////////////////////////////////////////////
void Chromosome::updateMarkerSet(unsigned int start, unsigned int end)
{
MarkerSet* ms = new MarkerSet(true);
for(unsigned int i = start; i<end; i++)
{
ms->pushback(buffer_chromosome.at(i));
}
chromosome.push_back(ms);
mem_markers+= (sizeof(MarkerSet) + (ms->getMarkerBits().num_blocks() * sizeof(unsigned long)));
}
void Chromosome::appendMarkerSet(unsigned int end,int num_markers)
{
mem_markers-= (sizeof(MarkerSet) + (chromosome.back()->getMarkerBits().num_blocks() * sizeof(unsigned long)));
while(num_markers>0)
{
chromosome.back()->pushback(buffer_chromosome.at(end-num_markers));
num_markers--;
}
mem_markers+= (sizeof(MarkerSet) + (chromosome.back()->getMarkerBits().num_blocks() * sizeof(unsigned long)));
}
// end Chromosome.cpp