Add files via upload

This commit is contained in:
HarshitGupta11 2019-08-23 15:25:59 +05:30 committed by GitHub
parent 647b2c9140
commit 855c89df56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,19 +3,14 @@ import requests
import progressbar
import sys
def update_protein(gene_seq,gene):
t=0
while(t!=2):
try:
server = "https://rest.ensembl.org"
ext = "/sequence/id/" + \
str(gene) + "?type=protein;multiple_sequences=1"
ext = "/sequence/id/"+str(gene)+"?type=protein;multiple_sequences=1"
r = requests.get(
server + ext,
headers={
"Content-Type": "application/json"})
r = requests.get(server+ext, headers={ "Content-Type" : "application/json"})
if not r.ok:
r.raise_for_status()
@ -36,16 +31,15 @@ def update_protein(gene_seq, gene):
r=dict(r[maxi])
gene_seq[gene]=str(r["seq"])
return
except BaseException:
except :
t+=1
#print("\nError:",e)
continue
gene_seq[gene]=""
def update_rest_protein(data):
def update_rest_protein(data,fname):
gids={}
with open("processed/not_found.json", "r") as file:
with open("processed/not_found_"+fname+".json","r") as file:
gids=dict(json.load(file))
gids=list(gids.keys())
@ -54,19 +48,13 @@ def update_rest_protein(data):
server = "https://rest.ensembl.org"
ext = "/sequence/id?type=protein"
headers = {
"Content-Type": "application/json",
"Accept": "application/json"}
headers={ "Content-Type" : "application/json", "Accept" : "application/json"}
for i in progressbar.progressbar(range(0,len(gids)-50,50)):
ids=dict(ids=list(gids[i:i+50]))
while(1):
try:
r = requests.post(
server + ext,
headers=headers,
data=str(
json.dumps(ids)))
r = requests.post(server+ext, headers=headers, data=str(json.dumps(ids)))
if not r.ok:
r.raise_for_status()
gs=r.json()
@ -83,26 +71,21 @@ def update_rest_protein(data):
for genes in gids:
try:
_=data[genes]
except BaseException:
except:
print(genes)
update_protein(data,genes)
print("Gene Sequences Updated Successfully")
print("Protein Sequences Updated Successfully")
return data
def update(gene_seq,gene):
t=0
while(t!=2):
try:
server = "https://rest.ensembl.org"
ext = "/sequence/id/" + \
str(gene) + "?type=cds;multiple_sequences=1"
ext = "/sequence/id/"+str(gene)+"?type=cds;multiple_sequences=1"
r = requests.get(
server + ext,
headers={
"Content-Type": "application/json"})
r = requests.get(server+ext, headers={ "Content-Type" : "application/json"})
if not r.ok:
r.raise_for_status()
@ -123,13 +106,12 @@ def update(gene_seq, gene):
r=dict(r[maxi])
gene_seq[gene]=str(r["seq"])
return
except BaseException:
except Exception as e:
t+=1
#print("\nError:",e)
continue
gene_seq[gene]=""
def update_rest(data,fname):
gids={}
with open("processed/not_found_"+fname+".json","r") as file:
@ -141,19 +123,13 @@ def update_rest(data, fname):
server = "https://rest.ensembl.org"
ext = "/sequence/id?type=cds"
headers = {
"Content-Type": "application/json",
"Accept": "application/json"}
headers={ "Content-Type" : "application/json", "Accept" : "application/json"}
for i in progressbar.progressbar(range(0,len(gids)-50,50)):
ids=dict(ids=list(gids[i:i+50]))
while(1):
try:
r = requests.post(
server + ext,
headers=headers,
data=str(
json.dumps(ids)))
r = requests.post(server+ext, headers=headers, data=str(json.dumps(ids)))
if not r.ok:
r.raise_for_status()
gs=r.json()
@ -170,7 +146,7 @@ def update_rest(data, fname):
for genes in gids:
try:
_=data[genes]
except BaseException:
except:
print(genes)
update(data,genes)