This repository has been archived by the owner on Aug 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHaploPattern.cpp
101 lines (90 loc) · 1.85 KB
/
HaploPattern.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
#include "HaploPattern.h"
#include "GenoData.h"
#include "MemLeak.h"
boost::pool<> HaploPattern::m_pool(sizeof(HaploPattern));
////////////////////////////////
//
// class HaploPattern
int HaploPattern::getAlleleIndex(int local_locus) const
{
int index;
if (m_alleles[local_locus].isMissing()) {
index = -1;
}
else {
index = m_genos.getAlleleIndex(m_start+local_locus, m_alleles[local_locus]);
}
return index;
}
void HaploPattern::setPattern(const Allele &a, int start)
{
m_alleles.clear();
m_alleles.push_back(a);
m_start = start;
m_end = m_start + length();
}
void HaploPattern::setPattern(const AlleleSequence &as, int start)
{
AlleleSequence::operator =(as);
m_start = start;
m_end = m_start + length();
}
void HaploPattern::repack()
{
int i, start, len;
vector<Allele> temp;
bool repacked;
start = 0;
repacked = false;
for (i=0; i<length(); i++) {
if (m_alleles[i].isMissing()) {
m_start++;
start++;
repacked = true;
}
else {
break;
}
}
for (i=length()-1; i>=m_start; --i) {
if (m_alleles[i].isMissing()) {
m_end--;
repacked = true;
}
else {
break;
}
}
if (repacked) {
len = m_end - m_start;
temp = m_alleles;
if (len > 0) {
m_alleles.assign(&temp[start], &temp[start+len]);
}
else {
m_alleles.clear();
}
}
}
char *HaploPattern::read(char *buffer, int len)
{
buffer = AlleleSequence::read(NULL, buffer, len);
m_start = 0;
m_end = length();
repack();
return buffer;
}
char *HaploPattern::write(char *buffer, bool long_format) const
{
char *s = buffer;
if (long_format) {
AlleleSequence(m_start).write(NULL, s);
s += strlen(s);
}
AlleleSequence::write(NULL, s);
s += strlen(s);
if (long_format) {
AlleleSequence(m_genos.genotype_len()-m_end).write(NULL, s);
}
return buffer;
}