Commit 4ec5bcc9 authored by Enza Colonna's avatar Enza Colonna
Browse files

safety before lunch ;)

parent 7a177575
This diff is collapsed.
import requests, sys, json , argparse
listOfDict=[]
listOfrsid=["rs10494366", "rs1060501114", "rs1060501127", "rs1060501130"]
server = "https://rest.ensembl.org"
ext = "/vep/human/id"
headers={ "Content-Type" : "application/json", "Accept" : "application/json"}
strOfDataDictionary=json.dumps({"ids" : listOfrsid })
res = requests.post(server+ext, headers=headers, data=strOfDataDictionary)
#return json.loads(res.text)
decoded = res.json() # a python dictionary
for elem in decoded:
#freq_dict={}
for var in elem["colocated_variants"]:
if 'frequencies' in var:#freq_dict=var["frequencies"]
listOfDict.append(var["frequencies"] )
return listOfDict
#print (len(decoded) )
#print(json.dumps(decoded, indent=2))
......@@ -19,18 +19,23 @@ def compareFreq (dictionary, threshold):
def getfreqfromVEPbulck (listOfrsid):
freq_dict={}
listOfDict=[]
server = "https://rest.ensembl.org"
ext = "/vep/human/id"
headers={ "Content-Type" : "application/json", "Accept" : "application/json"}
strOfDataDictionary=json.dumps({"ids" : listOfrsid })
res = requests.post(server+ext, headers=headers, data=strOfDataDictionary)
#return json.loads(res.text)
decoded = res.json() # a python dictionary
for elem in decoded:
rsid=elem["input"]
freq_dict={}
for var in elem["colocated_variants"]:
#rsid=var["id"]
if 'frequencies' in var: freq_dict=var["frequencies"]
listOfDict.append((rsid, freq_dict))
return listOfDict
#decoded = res.json()
#for var in decoded[0]["colocated_variants"] :
#if "frequencies" in var: freq_dict=var["frequencies"]
#return freq_dict
def getfreqfromVEP (rsid):
freq_dict={}
......@@ -46,7 +51,7 @@ def getfreqfromVEP (rsid):
return freq_dict
def get_rsID (line):
linesp=line.rstrip().split("\"")
linesp=line.rstrip().split()
myrs=[ i for i in linesp if "rs" in i]
return myrs[0]
......@@ -56,16 +61,13 @@ def main():
parser.add_argument("-t", help="threshold for filtering allele frequencies ", type=float,required=True)
args = parser.parse_args()
allrsId=[]
for line in open(args.f, 'r'):
if "\"rs" in line:
#rselem = get_rsID(line )
allrsId.append(get_rsID(line ))
with open(args.f) as myf:
allrsId = myf.readlines()
#thislist=["rs12720452", "rs1060501130"]
print (allrsId[1:5])
result = getfreqfromVEPbulck(allrsId[1:100])
#print(json.dumps(result, indent=2))
print (result)
print(json.dumps(result, indent=2))
#print (result)
#mydict = getfreqfromVEP(rselem)
#if not any(mydict): print (rselem) #, mydict , "RARE")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment