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

DKI/convert_to_vcf #21

Merged
merged 2 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
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
29 changes: 29 additions & 0 deletions data_collection/refactoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,32 @@ def from_clinvar_name_to_cdna_position(name):
break

return name[start:end]


def save_lovd_as_vcf(df, save_to):
"""
Gets hg38 variants from LOVD and saves as VCF file.
:param DataFrame df: LOVD DataFrame with data
:param str save_to: path where to save VCF file.
"""

if "VariantOnGenome/DNA/hg38" not in df.columns:
raise ValueError("VariantOnGenome/DNA/hg38 is not in the LOVD DataFrame.")

save_to_dir = os.path.dirname(save_to)
if not os.path.exists(save_to_dir):
os.makedirs(save_to_dir)

with open(save_to, "w", encoding="UTF-8") as f:
header = ("##fileformat=VCFv4.2\n"
"##contig=<ID=6,length=63719980>\n"
"#CHROM POS ID REF ALT QUAL FILTER INFO\n")
f.write(header)
for variant in df.loc[:, "VariantOnGenome/DNA/hg38"]:
if len(variant) != 13 or variant[-2] != '>':
logging.warning("Skipping variant %s", variant)
continue
record = ["6", variant[2:-3], ".", variant[-3], variant[-1], ".", ".", "."]

f.write("\t".join(record))
f.write("\n")
Loading
Loading