Skip to content

Commit 5e121aa

Browse files
Merge pull request #347 from uclahs-cds/sfitz-fix-plot-vaf
fix divide by zero VAF calculation error
2 parents a483c91 + 2e7b469 commit 5e121aa

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818

1919
### Changed
2020

21+
- Avoid VAF divide by zero error
2122
- Switch to generalized resource handling
2223
- Update NFTest paths
2324
- Fix single tool run logic

script/prepare-VAFs.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ def get_vaf_strelka2(variant: dict, sample: str) -> Tuple[int, int]:
103103
alt_reads = max([int(variant.samples[sample_index][allele.sequence + 'U'][0]) \
104104
for allele in variant.ALT])
105105
total_reads = ref_reads + alt_reads
106+
if total_reads == 0:
107+
return 0
106108
return alt_reads/total_reads
107109

108110
def get_vaf_somaticsniper(variant: dict, sample: str) -> Tuple[int, int]:
@@ -114,6 +116,8 @@ def get_vaf_somaticsniper(variant: dict, sample: str) -> Tuple[int, int]:
114116
alt_reads = int(variant.samples[sample_index]["DP4"][2]) \
115117
+ int(variant.samples[sample_index]["DP4"][3])
116118
total_reads = ref_reads + alt_reads
119+
if total_reads == 0:
120+
return 0
117121
return alt_reads/total_reads
118122

119123
def get_vaf_mutect2(variant: dict, sample: str) -> Tuple[int, int]:
@@ -122,7 +126,8 @@ def get_vaf_mutect2(variant: dict, sample: str) -> Tuple[int, int]:
122126
ref_reads = int(variant.samples[sample_index]["AD"][0])
123127
alt_reads = int(variant.samples[sample_index]["AD"][1])
124128
total_reads = ref_reads + alt_reads
125-
129+
if total_reads == 0:
130+
return 0
126131
return alt_reads/total_reads
127132

128133
def does_variant_pass(variant: dict) -> bool:

0 commit comments

Comments
 (0)