forked from pkrusche/vt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
genotyping_record.cpp
205 lines (186 loc) · 4.76 KB
/
genotyping_record.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/* The MIT License
Copyright (c) 2014 Adrian Tan <atks@umich.edu>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include "genotyping_record.h"
/**
* Constructor.
* @v - VCF record.
*/
GenotypingRecord::GenotypingRecord(bcf_hdr_t *h, bcf1_t *v, int32_t vtype)
{
clear();
this->h = h;
this->v = v;
rid = bcf_get_rid(v);
pos1 = bcf_get_pos1(v);
this->vtype = vtype;
int32_t n_allele = bcf_get_n_allele(v);
if (vtype==VT_SNP && n_allele==2)
{
rid = bcf_get_rid(v);
beg1 = bcf_get_pos1(v);
end1 = beg1;
}
else if (vtype==VT_INDEL && bcf_get_n_allele(v)==2)
{
rid = bcf_get_rid(v);
char** alleles = bcf_get_allele(v);
dlen = strlen(alleles[1])-strlen(alleles[0]);
len = abs(dlen);
int32_t *flanks = NULL;
int32_t n = 0;
if (bcf_get_info_int32(h, v, "FLANKS", &flanks, &n)>0)
{
lend1 = flanks[0];
rbeg1 = flanks[1];
free(flanks);
}
else
{
lend1 = bcf_get_pos1(v) - 1;
rbeg1 = bcf_get_end_pos1(v) + 1;
}
int32_t *fuzzy_flanks = NULL;
n = 0;
if (bcf_get_info_int32(h, v, "FZ_FLANKS", &fuzzy_flanks, &n)>0)
{
fuzzy_lend1 = fuzzy_flanks[0];
fuzzy_rbeg1 = fuzzy_flanks[1];
free(fuzzy_flanks);
}
else
{
fuzzy_lend1 = bcf_get_pos1(v) - 1;
fuzzy_rbeg1 = bcf_get_end_pos1(v) + 1;
}
beg1 = std::min(lend1-2, fuzzy_lend1-2);
end1 = std::max(rbeg1+2, fuzzy_rbeg1+2);
//construct alleles
//get reference sequence
// char* ref_seq = NULL;
// int32_t ref_len = 0;
//// ref_seq = faidx_fetch_seq(fai, bcf_get_chrom(h,v), lend1+1-1, rbeg1-1-1, &ref_len);
//
// for (uint32_t i=0; i<n_allele; ++i)
// {
//
// }
// for ()
// {
// }
//
if (dlen>0)
{
indel.append(&alleles[1][1]);
}
else
{
indel.append(&alleles[0][1]);
}
}
else if (vtype==VT_VNTR)
{
rid = bcf_get_rid(v);
beg1 = bcf_get_pos1(v) - 1;
end1 = bcf_get_end_pos1(v) + 1;
char *motif = NULL;
int32_t n = 0;
if (bcf_get_info_string(h, v, "MOTIF", &motif, &n)>0)
{
this->motif.assign(motif);
free(motif);
}
}
}
/**
* Translates from descriptive allele to integer encoding.
*/
int32_t GenotypingRecord::dallele2allele(char dallele)
{
if (dallele=='0')
{
return 0;
}
else if (dallele=='~')
{
return -1;
}
else if ('A'<=dallele && dallele<='Z')
{
return dallele - 64;
}
else if ('a'<=dallele && dallele<='z')
{
return ((int32_t)dallele) - 99;
}
else if (dallele=='*')
{
return -101;
}
else if (dallele=='-')
{
return -102;
}
else if (dallele=='+')
{
return -103;
}
else if (dallele=='?')
{
return -104;
}
else if (dallele=='.')
{
return -105;
}
else if (dallele=='!')
{
return -127;
}
else return 128;
}
/**
* Clears this record.
*/
void GenotypingRecord::clear()
{
v =NULL;
vtype = -1;
no_nonref = 0;
bqs.clear();
aqs.clear();
mqs.clear();
sts.clear();
als.clear();
dls.clear();
cys.clear();
nms.clear();
allele_depth_fwd.resize(2,0);
allele_depth_rev.resize(2,0);
depth = 0;
depth_fwd = 0;
depth_rev = 0;
base_qualities_sum = 0;
}
/**
* Destructor.
*/
GenotypingRecord::~GenotypingRecord()
{
if (v) bcf_destroy(v);
}