forked from sgusev/GERMLINE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MatchesBuilder.cpp
100 lines (82 loc) · 2.35 KB
/
MatchesBuilder.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
// MatchesBuilder.cpp: builds matches from individuals
#include "MatchesBuilder.h"
unsigned int position_ms;
unsigned int num_sets;
int ALLOWED_MASKED;
// MatchesBuilder(): default constructor
MatchesBuilder::MatchesBuilder( PolymorphicIndividualsExtractor * pie )
{
individualsP = & ALL_SAMPLES;
pieP = pie;
}
// buildMatches(): builds matches from individuals
void MatchesBuilder::buildMatches()
{
if ( !SILENT ) cout << "Read Markers" << endl;
ms_start = 0; ms_end = num_sets;
readAllMarkers();
if ( !SILENT ) cout << "Match Markers" << endl;
matchAllMarkers();
}
void MatchesBuilder::printHaplotypes(string fout_name)
{
ofstream fout( fout_name.c_str() );
for(individualsP->begin();individualsP->more();)
{
individualsP->next()->print(fout,0,num_sets);
}
fout.close();
}
// matchAllMarkers(): builds matches for individuals considering all markers
void MatchesBuilder::matchAllMarkers()
{
for (position_ms = ms_start; position_ms < ms_end - 1; position_ms++)
{
if ( !SILENT ) cerr << "\rMatching Markers - " << (position_ms*100) / (ms_end - 1) << "%" << flush;
matchMarkerSet();
}
if ( !SILENT ) cerr << '\r' << "Matching Markers Complete" << endl;
}
void MatchesBuilder::readAllMarkers()
{
for (position_ms = ms_start; position_ms < ms_end; position_ms++)
{
if ( !SILENT ) cerr << "\rReading Markers - " << position_ms*100/ms_end << "%" << flush;
if ( HAPLOID ) readHaploidMarkerSet(); else readMarkerSet();
}
if ( !SILENT ) cerr << '\r' << "Reading Markers Complete" << endl;
}
void MatchesBuilder::readHaploidMarkerSet()
{
// Read the individuals two at a time
Individual * i[2];
for(individualsP->begin();individualsP->more();)
{
i[0] = individualsP->next();
i[1] = individualsP->next();
pieP->getCompleteMarkerSet( i[0] , i[1] );
}
}
void MatchesBuilder::readMarkerSet()
{
Individual * i;
for(individualsP->begin();individualsP->more();)
{
i = individualsP->next();
pieP->getCompleteMarkerSet(i);
}
}
// matchMarkerSet(): builds matches for individuals considering markers in marker set.
void MatchesBuilder::matchMarkerSet()
{
// Match:
for(individualsP->begin();individualsP->more();)
matchFactory.hash( individualsP->next() );
// Verify:
matchFactory.assertShares();
// Extend:
for(individualsP->begin();individualsP->more();)
individualsP->next()->assertShares();
matchFactory.initialize();
}
// end MatchesBuilder.cpp