Skip to content

Commit

Permalink
Merge pull request #58 from dufeiyu/bugfix
Browse files Browse the repository at this point in the history
Replace empty string with 0 for AD, DP, AF
  • Loading branch information
dufeiyu authored Nov 7, 2017
2 parents 98d904b + 87d8cdf commit f75bf1c
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions add_bam_readcount_to_vcf_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def calculate_coverage(ref, var):
return ref + var

def calculate_vaf(var, depth):
return (var / int(depth)) * 100
return format((var / int(depth)) * 100, '.3f')

def parse_to_bam_readcount(start, reference, alt):
if len(alt) != len(reference):
Expand Down Expand Up @@ -114,9 +114,9 @@ def parse_to_bam_readcount(start, reference, alt):
if ref_base in brct:
depth = read_counts[sample][chromosome][bam_readcount_position][ref_base]['depth']
else:
depth = ''
depth = 0
else:
depth = ''
depth = 0
entry.call_for_sample[sample].data['DP'] = depth

#AF - variant allele frequencies
Expand All @@ -135,9 +135,9 @@ def parse_to_bam_readcount(start, reference, alt):
if var_base in brct:
vafs.append(calculate_vaf(int(brct[var_base]), depth))
else:
vafs.append('')
vafs.append(0)
else:
vafs.append('')
vafs.append(0)
entry.call_for_sample[sample].data['AF'] = vafs

#AD - ref, var1..varN counts
Expand All @@ -154,9 +154,9 @@ def parse_to_bam_readcount(start, reference, alt):
if ref_base in brct:
ads.append(brct[ref_base])
else:
ads.append('')
ads.append(0)
else:
ads.append('')
ads.append(0)
for alt in alts:
if type(alt) is not str:
alt = alt.serialize()
Expand All @@ -170,9 +170,9 @@ def parse_to_bam_readcount(start, reference, alt):
if var_base in brct:
ads.append(brct[var_base])
else:
ads.append('')
ads.append(0)
else:
ads.append('')
ads.append(0)
entry.call_for_sample[sample].data['AD'] = ads

vcf_writer.write_record(entry)
Expand Down

0 comments on commit f75bf1c

Please sign in to comment.