@@ -84,8 +84,12 @@ def extract(cls, var_allele_idx, genotype, alleles, caller_id):
8484 )
8585 # Format numerical depths
8686 depths = [i if i != "." and i is not None else 0 for i in new_gt ["AD" ]]
87- # Set other tags
88- new_gt ["GT" ] = genotype ["GT" ]
87+ # require all genotype alleles be definite or none should be
88+ if all (genotype ["GT" ]):
89+ new_gt ["GT" ] = genotype ["GT" ]
90+ else :
91+ new_gt ["GT" ] = None
92+ # copy depth as-is
8993 new_gt ["DP" ] = dp
9094 return new_gt , depths
9195
@@ -125,7 +129,7 @@ def _dispatch_extractor(cls, var_allele_idx, genotype, alleles, caller_id):
125129 if caller_id == variant_callers .SVABA_SOMATIC :
126130 depths , dp = cls ._extract_svaba_somatic (genotype )
127131 if caller_id == variant_callers .STRELKA_SOMATIC :
128- depths , dp = cls ._extract_strelka_somatic (genotype )
132+ depths , dp = cls ._extract_strelka_somatic (var_allele_idx , genotype , alleles )
129133 # if caller_id == variant_callers.VARDICT:
130134 # self.extract_legacy(cls, var_allele_idx, genotype, alleles)
131135 return depths , dp
@@ -263,24 +267,66 @@ def _extract_sanger_pindel(cls, genotype):
263267 def _extract_svaba_somatic (cls , genotype ):
264268 """
265269 SvABA only reports the depth of the alt allele in 'AD' and reports
266- total depth in 'DP' so we infer the ref allele depth from these.
270+ total depth in 'DP'. However, SvABA vcfs should have had their format
271+ adjusted upstream by the filtration workflow to comply with standards.
272+ Thus we can simply grab these values from the relevant tags.
267273 """
268- total_depth = genotype ["DP" ]
269- alt_depth = genotype ["AD" ][0 ]
270- ref_depth = total_depth - alt_depth
271- allele_depths = [ref_depth , alt_depth ]
272- dp = total_depth
274+ dp = genotype ["DP" ]
275+ allele_depths = genotype ["AD" ]
273276 return (allele_depths , dp )
274277
275278 @classmethod
276- def _extract_strelka_somatic (cls , genotype ):
279+ def _extract_strelka_somatic (cls , var_allele_idx , genotype , alleles ):
277280 """
278- NOT YET IMPLEMENTED
279- There are two subtypes we have to deal with
280-
281- Strelka reports total depth in DP
281+ Strelka independently calls Indels and SNVs then both are combined
282+ into one vcf with two styles of calls.
283+
284+ For SNVs
285+ Strelka reports per-nucleotide counts, the nucleotide corresponding
286+ to ref and alt alleles must be used to extract these counts and
287+ construct needed values.
288+
289+ For Indels
290+ Strelka VCF headers are in direct conflict with documentation, but
291+ the documentation seems to make the most sense.
292+
293+ from: https://github.com/Illumina/strelka/blob/v2.9.x/docs/userGuide/README.md#vcf-files
294+ tier1RefCounts = First comma-delimited value from FORMAT/TAR
295+ tier1AltCounts = First comma-delimited value from FORMAT/TIR
296+ Somatic allele freqeuncy is $tier1AltCounts / ($tier1AltCounts + $tier1RefCounts)
282297 """
283- return ([], 0 )
298+
299+ indel_format_key_set = {
300+ "DP2" ,
301+ "TAR" ,
302+ "TIR" ,
303+ "TOR" ,
304+ "DP50" ,
305+ "FDP50" ,
306+ "SUBDP50" ,
307+ "BCN50" ,
308+ }
309+ snv_format_key_set = {"FDP" , "SDP" , "SUBDP" , "AU" , "CU" , "GU" , "TU" }
310+ common_format_key_set = {"GT" , "DP" }
311+ allele_depths = ()
312+ dp = 0
313+ if set (genotype .keys ()) - indel_format_key_set == common_format_key_set :
314+ # Indel case
315+ ref_count = genotype ["TAR" ][0 ]
316+ alt_count = genotype ["TIR" ][0 ]
317+ dp = ref_count + alt_count
318+ allele_depths = ref_count , alt_count
319+ if set (genotype .keys ()) - snv_format_key_set == common_format_key_set :
320+ # SNV case
321+ alt_allele = alleles [var_allele_idx ]
322+ alt_count_name = f"{ alt_allele } U"
323+ alt_count = genotype [alt_count_name ][0 ]
324+ ref_allele = [al for al in alleles if al != alt_allele ][0 ]
325+ ref_count_name = f"{ ref_allele } U"
326+ ref_count = genotype [ref_count_name ][0 ]
327+ dp = alt_count + ref_count
328+ allele_depths = ref_count , alt_count
329+ return (allele_depths , dp )
284330
285331 def extract_legacy (cls , var_allele_idx , genotype , alleles ):
286332 """
0 commit comments