-
Notifications
You must be signed in to change notification settings - Fork 0
/
complementTools.pyx
55 lines (40 loc) · 1.67 KB
/
complementTools.pyx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from pathlib import Path
import pandas as pd
import wget
def download_url(url :str, output_directory : str) ->Path:
"""
This function downloads url and saves the file in the provided output directory.
Args:
url: <str> The url link of the ncbi website.
output_directory: <str> Path of output directory.
Returns:
vcf_file: <Path> Path of the downloaded file.
"""
vcf_file : Path = wget.download(url, out=output_directory)
return vcf_file
def extract_clinical_data(vcf_data: pd.DataFrame) -> (pd.DataFrame, pd.DataFrame):
"""
This function extracts data from dataframe of clinical variations and returns two dataframes with specific fields.
Args:
vcf_data: <dataframe> A dataframe containing data of clinical variations in vcf file format.
Returns:
nods_data: <dataframe> A dataframe containing informations of variant.
links_data: <dataframe> A dataframe containing position start and end of variant.
"""
# Create dataframes for nods and links data
nods_data = pd.DataFrame(columns=["CHROM","POS","ID","REF","ALT","AF_ESP","AF_EXAC","AF_TGP","ALLELEID"])
links_data = pd.DataFrame(columns=["_from","_to"])
# Extract clinical variations
nods_data["CHROM"] = vcf_data["CHROM"]
nods_data["POS"] = vcf_data["POS"]
nods_data["ID"] = vcf_data["ID"]
nods_data["REF"] = vcf_data["REF"]
nods_data["ALT"] = vcf_data["ALT_1"]
nods_data["AF_ESP"] = vcf_data["AF_ESP"]
nods_data["AF_EXAC"] = vcf_data["AF_EXAC"]
nods_data["AF_TGP"] = vcf_data["AF_TGP"]
nods_data["ALLELEID"] = vcf_data["ALLELEID"]
# Extract links between clinvar IDs (ID) and dbsnp IDs (RS)
links_data["_from"] = vcf_data["ID"]
links_data["_to"] = vcf_data["RS"]
return nods_data, links_data