-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
131 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from pathlib import Path | ||
|
||
from cyvcf2 import VCF | ||
import pandas as pd | ||
|
||
from ..arrays import GenotypeDtype, GenotypeArray | ||
from ..scalars import Variant | ||
|
||
|
||
def from_vcf(filename: str, min_qual: float = 0, drop_filtered: bool = True): | ||
""" | ||
Load genetic data from a VCF or BCF file into a DataFrame | ||
Parameters | ||
---------- | ||
filename: str or Path | ||
vcf, vcf.gz, or bcf file. | ||
min_qual: float (default = 0) | ||
Skip loading variants with less than this quality | ||
drop_filtered: boolean (default = True) | ||
Skip loading variants with a FILTER value other than "PASS" | ||
Returns | ||
------- | ||
DataFrame | ||
Columns correspond to variants (named as {variant_number}_{variant ID}). | ||
Rows correspond to samples and index columns include sample information. | ||
Examples | ||
-------- | ||
""" | ||
genotype_array_list = [] | ||
for vcf_variant in VCF(filename): # or VCF('some.bcf') | ||
# TODO: Should FILTER or QUAL be stored in the GenotypeArray? | ||
|
||
# Skip filtered variants unless drop_filtered is True | ||
if vcf_variant.FILTER is not None and drop_filtered: | ||
continue | ||
|
||
# Skip variants below the minimum quality | ||
if vcf_variant.QUAL < min_qual: | ||
continue | ||
|
||
variant = Variant(chromosome = vcf_variant.CHROM, | ||
position = vcf_variant.start, | ||
id=vcf_variant.ID, | ||
ref=vcf_variant.REF, | ||
alt=vcf_variant.ALT) | ||
|
||
alleles = vcf_variant.gt_bases | ||
print() | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.