Skip to content

Commit

Permalink
improve prints
Browse files Browse the repository at this point in the history
  • Loading branch information
jethror1 committed Sep 20, 2024
1 parent 88e58a2 commit 48eed12
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/vcf_qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ def get_het_hom_counts(vcf) -> dict:
'x_hom': []
}

variants = autosomes = x_variants = 0

for record in vcf_handle.fetch():
sample_fields = record.samples[sample]

Expand All @@ -122,6 +124,8 @@ def get_het_hom_counts(vcf) -> dict:
if sample_fields['GT'] == (0, 0):
continue

variants += 1

# using the sum of all allele depths instead of the format AD
# field to be the informative read depths supporting each allele
informative_total_depth = sum(sample_fields['AD'])
Expand All @@ -132,16 +136,20 @@ def get_het_hom_counts(vcf) -> dict:
if len(set(sample_fields['GT'])) == 1:
# homozygous variant
if is_autosome(record.chrom):
autosomes += 1
counts['hom'].append(non_ref_aaf)

if re.match(r'(chr)?x', record.chrom, re.IGNORECASE):
x_variants += 1
counts['x_hom'].append(non_ref_aaf)
else:
# heterozygous variant
if is_autosome(record.chrom):
autosomes += 1
counts['het'].append(non_ref_aaf)

if re.match(r'(chr)?x', record.chrom, re.IGNORECASE):
x_variants += 1
counts['x_het'].append(non_ref_aaf)

# handy print for the logs for sense checking
Expand All @@ -152,6 +160,11 @@ def get_het_hom_counts(vcf) -> dict:
f"\tAAF: {non_ref_aaf}"
)

print(
f"\nTotal variants: {variants}\nTotal autosome variants: {autosomes}\n"
f"Total X variants: {x_variants}\n"
)

return {k: sorted(v) for k, v in counts.items()}


Expand Down Expand Up @@ -199,7 +212,7 @@ def calculate_ratios(counts) -> dict:
)

for field, value in ratios.items():
print(f"{field}\t{value}")
print(f"{field}:\t{value}")

return ratios

Expand Down Expand Up @@ -254,7 +267,7 @@ def upload_output_file(outfile) -> None:
outfile : str
name of file to upload
"""
print(f"Uploading {outfile}")
print(f"\nUploading {outfile}")

url_file = dxpy.upload_local_file(
filename=outfile,
Expand Down

0 comments on commit 48eed12

Please sign in to comment.