Skip to content

Commit

Permalink
Merge pull request #10 from NCIP/devel
Browse files Browse the repository at this point in the history
COSMIC pulling CANCER snps in cancer.vcf
  • Loading branch information
asmariyaz23 authored Jan 23, 2019
2 parents d54ee6b + ff35eb3 commit d74442a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
46 changes: 23 additions & 23 deletions src/annotate_with_cravat.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import os
import requests
import time
import urllib
import urllib.request

# Constants
str_response_job_id = "jobid"
Expand Down Expand Up @@ -55,7 +55,7 @@ def func_check_job(str_json_id):

# Send file over to service
response_check_job = requests.get("http://www.cravat.us/CRAVAT/rest/service/status", params={ str_response_job_id: str_json_id })
return response_check_job.json()
return(response_check_job.json())

def func_download_cravat_result(str_cravat_url, str_download_location):
"""
Expand All @@ -69,11 +69,11 @@ def func_download_cravat_result(str_cravat_url, str_download_location):

# Download Cravat result
try:
urllib.urlretrieve(str_cravat_url, str_download_location)
return True
urllib.request.urlretrieve(str_cravat_url, str_download_location)
return(True)
except IOError:
print "annotate_with_cravat::Error in retrieving results. " + str(IOError)
return False
print("annotate_with_cravat::Error in retrieving results. " + str(IOError))
return(False)

def func_get_cravat_response(str_json_id, i_max_attempts, i_wait):
"""
Expand All @@ -87,26 +87,26 @@ def func_get_cravat_response(str_json_id, i_max_attempts, i_wait):
: int
"""

for x_attempt in xrange(i_max_attempts):
print "annotate_with_cravat::Attempting to get CRAVAT response. Attempt " + str(x_attempt + 1)
for x_attempt in range(i_max_attempts):
print("annotate_with_cravat::Attempting to get CRAVAT response. Attempt " + str(x_attempt + 1))
time.sleep(i_wait)
response_json = func_check_job(str_json_id)
if not response_json:
print "annotate_with_cravat::Error did not get a response from CRAVAT"
print("annotate_with_cravat::Error did not get a response from CRAVAT")
return(None)
str_success = str(response_json.get(str_response_status, None))
if (not str_success) or (str_success in lstr_response_fail):
print " ".join(["annotate_with_cravat::Error was not successful in getting info from CRAVAT.",
print (" ".join(["annotate_with_cravat::Error was not successful in getting info from CRAVAT.",
"Job id =" + str(str_json_id) + ".",
"Success =" + str(str_success) + ".",
response_json.get(str_response_log, "")])
response_json.get(str_response_log, "")]))
return(None)
if str_success == str_response_pass:
print "annotate_with_cravat:: Reponse URL on success: " + str(response_json)
print("annotate_with_cravat:: Reponse URL on success: " + str(response_json))
return response_json.get(str_response_url, None)
print " ".join(["annotate_with_cravat::Error gave up on CRAVAT after " + str(i_max_attempts * i_wait) + " seconds.",
print(" ".join(["annotate_with_cravat::Error gave up on CRAVAT after " + str(i_max_attempts * i_wait) + " seconds.",
"Job id =" + str(str_json_id) + ".",
"Success =" + str(str_success) + "."])
"Success =" + str(str_success) + "."]))
return(None)


Expand Down Expand Up @@ -140,10 +140,10 @@ def func_request_cravat_service(str_vcf_path, str_analysis,
response_cravat = requests.post("http://cravat.us/CRAVAT/rest/service/submit",
files={"inputfile": open(str_vcf_path)},
data=pyld_request)
print response_cravat
print(response_cravat)
json_response = response_cravat.json()
# Get return (job id)
return json_response.get(str_response_job_id, None)
return(json_response.get(str_response_job_id, None))

# Ensure the extention to the output directory is zip
if not os.path.splitext(args_call.str_output_dir)[1] == ".zip":
Expand All @@ -156,29 +156,29 @@ def func_request_cravat_service(str_vcf_path, str_analysis,
args_call.f_hg_19,
args_call.str_email)
if not str_job_id:
print " ".join(["annotate_with_cravat::Error Job id not found.",
"Job id =" + str(str_job_id)])
print(" ".join(["annotate_with_cravat::Error Job id not found.",
"Job id =" + str(str_job_id)]))
exit(100)

# Wait for result
str_download_url = func_get_cravat_response(str_job_id,
args_call.i_max_attempts,
args_call.i_wait)
if not str_download_url:
print " ".join(["annotate_with_cravat::Error did no",
print(" ".join(["annotate_with_cravat::Error did no",
"recieve valid URL download.",
"Job id =" + str(str_job_id) + ".",
"URL =" + str(str_download_url) + "."])
"URL =" + str(str_download_url) + "."]))
exit(101)

# Get zip file
f_success = func_download_cravat_result(str_download_url,
args_call.str_output_dir)
print "annotate_with_cravat:: Success = " + str(f_success)
print("annotate_with_cravat:: Success = " + str(f_success))
if not f_success:
print " ".join(["annotate_with_cravat::Error,",
print(" ".join(["annotate_with_cravat::Error,",
"could not download data in URL.",
"Job id =" + str(str_job_id) + ".",
"URL =" + str(str_download_url) + ".",
"Download =" + str(args_call.str_output_dir) + "."])
"Download =" + str(args_call.str_output_dir) + "."]))
exit(102)
2 changes: 1 addition & 1 deletion src/filter_vcf_for_cancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def func_split_token(str_token):

# Get handle
str_input_ext = os.path.splitext(args.str_input_file)[1]
hndl_vcf = gzip.open(args.str_input_file, "rb") if str_input_ext == ".gz" else open(args.str_input_file, "rb")
hndl_vcf = gzip.open(args.str_input_file, "rt") if str_input_ext == ".gz" else open(args.str_input_file, "r")

# Read in vcf file
if args.str_input_file:
Expand Down
4 changes: 2 additions & 2 deletions src/filter_vcf_for_predictions.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def func_split_token(str_token):

# Get handle
str_input_ext = os.path.splitext(args.str_input_file)[1]
hndl_vcf = gzip.open(args.str_input_file, "rb") if str_input_ext == ".gz" else open(args.str_input_file, "rb")
hndl_vcf = gzip.open(args.str_input_file, "rt") if str_input_ext == ".gz" else open(args.str_input_file, "rb")

# Read in vcf file
if args.str_input_file:
Expand All @@ -74,7 +74,7 @@ def func_split_token(str_token):
# Parse INFO tokens
dict_info_tokens = dict([func_split_token(str_token) for str_token
in lstr_line[I_INFO_INDEX].split(CHR_INFO_DELIMITER)])
print dict_info_tokens
print(dict_info_tokens)
# Keep everything that is a COSMIC ID at this point.
# Otherwise require CRAVAT or VEST to have an annotation.
if STR_CHASM_FDR in dict_info_tokens:
Expand Down

0 comments on commit d74442a

Please sign in to comment.