6
6
#include < QFile>
7
7
#include < QTextStream>
8
8
9
+ // TODO: Handle missing variants (check in BAM for depth, check target region if region is contained > use AF if missing?)
9
10
10
11
class ConcreteTool
11
12
: public ToolBase
@@ -103,6 +104,7 @@ class ConcreteTool
103
104
}
104
105
105
106
// iterate over all variants in PRS
107
+ int c_found = 0 ;
106
108
for (int i = 0 ; i < prs_variant_list.count (); ++i)
107
109
{
108
110
const VcfLine& prs_variant = prs_variant_list[i];
@@ -113,7 +115,6 @@ class ConcreteTool
113
115
THROW (FileParseException, " Multi-allelic variants in PRS VCF files are not supported: " + prs_variant.variantToString ());
114
116
}
115
117
116
- int allele_count = 0 ;
117
118
// get all matching variants at this position
118
119
QByteArrayList matching_lines = sample_vcf.getMatchingLines (prs_variant.chr (), prs_variant.start (), prs_variant.end (), true );
119
120
QByteArrayList matching_variants;
@@ -142,6 +143,7 @@ class ConcreteTool
142
143
if (genotype_idx < 0 ) THROW (FileParseException, " Genotype information is missing for sample variant: " + matching_variants[0 ]);
143
144
QByteArray genotype = format_value_items[genotype_idx].trimmed ().replace (" |" , " /" ).replace (" ." , " 0" );
144
145
146
+ int allele_count = 0 ;
145
147
if (genotype == " 0/1" ) allele_count = 1 ;
146
148
else if (genotype == " 1/1" ) allele_count = 2 ;
147
149
else THROW (FileParseException, " Invalid genotype '" + genotype + " ' in sample variant: " + matching_variants[0 ]);
@@ -150,16 +152,22 @@ class ConcreteTool
150
152
double weight = Helper::toDouble (prs_variant.info (" WEIGHT" ), " PRS weight" );
151
153
prs += weight * allele_count;
152
154
155
+ ++c_found;
153
156
}
154
-
155
157
}
158
+
156
159
// compute percentile
157
160
int percentile = -1 ;
158
161
if (percentiles.size () == 100 )
159
162
{
160
- int i = 0 ;
161
- for (i = 0 ; i < percentiles.size (); ++i) if (prs < percentiles[i]) break ;
162
- percentile = i + 1 ;
163
+ for (int i = 0 ; i < percentiles.size (); ++i)
164
+ {
165
+ if (prs < percentiles[i])
166
+ {
167
+ percentile = i + 1 ;
168
+ break ;
169
+ }
170
+ }
163
171
}
164
172
165
173
QByteArray percentile_string = (percentile == -1 ) ? " ." : QByteArray::number (percentile);
@@ -171,7 +179,7 @@ class ConcreteTool
171
179
172
180
173
181
// print final PRS
174
- out << column_entries[" pgs_id" ] << " :\t " << prs << endl;
182
+ out << column_entries[" pgs_id" ] << " : variants_found= " << c_found << " prs= " << prs << " percentile= " << percentile_string << endl;
175
183
}
176
184
177
185
output_tsv->flush ();
0 commit comments