-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathped.cpp
More file actions
119 lines (105 loc) · 2.55 KB
/
Copy pathped.cpp
File metadata and controls
119 lines (105 loc) · 2.55 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
// stl
#include <map>
#include <string>
// imports
using std::map;
using std::iterator;
using std::string;
// custom headers
#include "helper.h"
#include "ped.h"
// functions
void Ped::addPerson( Person* p )
{
string uid = makeUniqueId( p->getFid(), p->getIid() ); // build unique id
++personCount; // increment person count. no need to wait until after, it dies if unsuccessful
pair<map<string, unsigned long int>::iterator, bool> result = index.insert( pair<string,unsigned long int>(uid, Ped::personCount));
// try to add to assoc array
if (!result.second)
{
error("Cannot add person [" + p->getFid() + ", " + p->getIid() + "], they already exist in the frame!");
}
// actually push onto the array
samples.push_back( p );
}
// ATTN need to update this to be an unsigned long int passed by reference. would remove the static cast
bool Ped::boolHavePerson( string const& fid, string const& iid, int& i )
{
map<string, unsigned long int>::iterator hashEnd = index.end();
map<string, unsigned long int>::iterator itemIter = index.find( makeUniqueId(fid, iid) ); // ATTN replace with search?
if (itemIter != hashEnd)
{
i = static_cast<int>(itemIter->second);
return true;
}
else { return false; }
}
unsigned long int Ped::findPerson( string const& famID, string const& indID)
{
map<string, unsigned long int>::iterator hashEnd = index.end();
map<string, unsigned long int>::iterator itemIter = index.find( makeUniqueId(famID, indID) ); // ATTN replace with search
if ( itemIter != hashEnd) { return itemIter->second; }
else { error("Unable to find individual with family ID " + famID + " and individual ID " + indID); }
return 0;
}
string Ped::fileGenotypeString( bool hasCall, bool a1, bool a2, Locus& snp )
{
string s(" ");
if (hasCall)
{
if (a1)
{
if (a2)
{
// homozygous allele 2
s += snp.getAllele2();
s += " ";
s += snp.getAllele2();
}
else
{
// heterozygous
if (snp.getAllele1() < snp.getAllele2())
{
s += snp.getAllele1();
s += " ";
s += snp.getAllele2();
}
else
{
s += snp.getAllele2();
s += " ";
s += snp.getAllele1();
}
}
}
else
{
if (a2)
{
// heterozygous
if (snp.getAllele1() < snp.getAllele2())
{
s += snp.getAllele1();
s += " ";
s += snp.getAllele2();
}
else
{
s += snp.getAllele2();
s += " ";
s += snp.getAllele1();
}
}
else
{
// homozygous allele 1
s += snp.getAllele1();
s += " ";
s += snp.getAllele1();
}
}
return s;
}
else { return " 0 0"; }
}