Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update vcf file processing #124

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions software/metax/genotype/CYVCF2Genotype.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

def vcf_file_geno_lines(path, mode="genotyped", variant_mapping=None, whitelist=None, skip_palindromic=False, liftover_conversion=None):
logging.log(9, "Processing vcf %s", path)
vcf_reader = VCF(path)
vcf_reader = VCF(path, gts012=True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does gts012 represent?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From cyvcf2.VCF documentation:
gts012 (bool) – if True, then gt_types will be 0=HOM_REF, 1=HET, 2=HOM_ALT, 3=UNKNOWN. If False, 3, 2 are flipped.


is_dict_mapping = variant_mapping is not None and type(variant_mapping) == dict

Expand Down Expand Up @@ -40,12 +40,12 @@ def vcf_file_geno_lines(path, mode="genotyped", variant_mapping=None, whitelist=
for sample in variant.genotypes:
d_ = (sample[0] == a+1) + (sample[1] == a+1)
d.append(d_)
f = numpy.mean(numpy.array(d,dtype=numpy.int32))/2
f = numpy.nanmean(numpy.array(d,dtype=numpy.int32))/2
yield (variant_id, chr, pos, ref, alt, f) + tuple(d)

elif mode == "imputed":
if len(alts) > 1:
logging.log("VCF imputed mode doesn't support multiple ALTs, skipping %s", variant_id)
if (len(ref)) | (len(alts[0])) > 1:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The genotype contains indels too?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and they could be coded as either REF or ALT.

logging.log(8, "VCF imputed mode doesn't support multiple REFs or ALTs, skipping %s", variant_id)
continue

alt = alts[0]
Expand All @@ -60,7 +60,7 @@ def vcf_file_geno_lines(path, mode="genotyped", variant_mapping=None, whitelist=

try:
d = numpy.apply_along_axis(lambda x: x[0], 1, variant.format("DS"))
f = numpy.mean(numpy.array(d)) / 2
f = numpy.nanmean(numpy.array(d)) / 2
yield (variant_id, chr, pos, ref, alt, f) + tuple(d)
except KeyError:
yield RuntimeError("Missing DS field when vcf mode is imputed")
Expand Down