-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmarker.cc
88 lines (73 loc) · 2.47 KB
/
marker.cc
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
#include <stdio.h>
#include <string.h>
#include <vector>
#include <assert.h>
#include "marker.h"
using namespace std;
////////////////////////////////////////////////////////////////////////////////
// initialize static members
vector<Marker *> Marker::_allMarkers;
int Marker::_firstMarkerNum[LAST_CHROM + 1] = { 0 };
void Marker::readMarkerFile(char *markerFile) {
FILE *in;
char markerName[256];
int chrom;
Marker *prevMarker = NULL;
double mapPos;
int physPos;
char alleles[2];
assert(_allMarkers.size() == 0); // shouldn't have any markers yet
_allMarkers.reserve(600000); // allocate space for 600k markers
int numMarkersCurChrom = 0;
in = fopen(markerFile, "r");
// Note: I assume the map positions are in Morgans.
while (fscanf(in, "%s %d %lf %d %c %c", markerName, &chrom, &mapPos, &physPos,
&alleles[0], &alleles[1]) == 6) {
Marker *m = new Marker(markerName, chrom, mapPos, physPos, alleles);
if (prevMarker != NULL) {
int prevChrom = prevMarker->_chrom;
if (chrom == prevChrom) {
assert(mapPos >= prevMarker->_mapPos && physPos > prevMarker->_physPos);
}
else { // Have a valid prev chrom? Update marker counts
assert(chrom > prevChrom);
numMarkersCurChrom = 0; // reset
// about to append the first marker for this chrom to this index:
_firstMarkerNum[chrom] = _allMarkers.size();
}
}
_allMarkers.push_back(m);
numMarkersCurChrom++;
prevMarker = m;
}
fclose(in);
}
Marker::Marker(char *markerName, int chrom, double mapPos, int physPos,
char alleles[2]) {
_name = new char[strlen(markerName)+1];
strcpy(_name, markerName);
_chrom = chrom;
_mapPos = mapPos;
_physPos = physPos;
_alleles[0] = alleles[0];
_alleles[1] = alleles[1];
// No longer necessary:
// These values are calculated as the genotypes are read in, using the method
// Marker::addMarkerGenotype()
// _majAlleleCount = _totalAlleles = 0;
}
// No longer necessary:
//void Marker::addMarkerGenotype(int markerNum, int genotype) {
// if (genotype != 9) { // as long as it's not missing data:
// // note: a value of 0 is two major alleles, and a genotype of 2 is 0 major
// // alleles
// Marker *theMarker = _allMarkers[markerNum];
// theMarker->_majAlleleCount += 2 - genotype;
// theMarker->_totalAlleles += 2;
// }
//}
//
//double Marker::getAlleleFreq(int markerNum) {
// Marker *theMarker = _allMarkers[markerNum];
// return (double) theMarker->_majAlleleCount / theMarker->_totalAlleles;
//}