separated defs and calls and added a separate script to test examples
This commit is contained in:
parent
6c458f8883
commit
deb0aa8e58
13 changed files with 281 additions and 517 deletions
106
dynamut/submit.py
Executable file → Normal file
106
dynamut/submit.py
Executable file → Normal file
|
@ -16,106 +16,72 @@ from bs4 import BeautifulSoup
|
|||
import pandas as pd
|
||||
from pandas.api.types import is_string_dtype
|
||||
from pandas.api.types import is_numeric_dtype
|
||||
#%% homedir
|
||||
homedir = os.path.expanduser('~')
|
||||
print('My homedir is:', homedir)
|
||||
|
||||
#%%
|
||||
host = 'http://biosig.unimelb.edu.au'
|
||||
prediction_url = f"{host}/dynamut/prediction_list"
|
||||
print(prediction_url)
|
||||
|
||||
#%% example params
|
||||
gene_name = 'gid'
|
||||
drug = 'streptomycin'
|
||||
datadir = homedir + '/git/Data'
|
||||
indir = datadir + '/' + drug + '/input'
|
||||
#outdir = datadir + '/' + drug + '/output'
|
||||
outdir = homedir + '/git/LSHTM_analysis/dynamut' # for example
|
||||
|
||||
dynamut_temp_dir = outdir + '/dynamut_temp'
|
||||
|
||||
if not os.path.exists(dynamut_temp_dir):
|
||||
print('Creating dynamut_temp in outdir', outdir )
|
||||
os.makedirs(dynamut_temp_dir)
|
||||
|
||||
batch_no = 1
|
||||
out_url_file = dynamut_temp_dir + '/dynamut_result_url_batch_' + str(batch_no) + '.txt'
|
||||
|
||||
|
||||
#%% request calculation (no def)
|
||||
with open("/home/tanu/git/Data/streptomycin/input/gid_complex.pdb", "rb") as pdb_file, open ("/home/tanu/git/LSHTM_analysis/dynamut/snp_test2.csv", "rb") as mutation_list:
|
||||
files = {"wild": pdb_file
|
||||
, "mutation_list": mutation_list}
|
||||
body = {"chain": 'A'
|
||||
, "email": 'tanushree.tunstall@lshtm.ac.uk'}
|
||||
|
||||
response = requests.post(prediction_url, files = files, data = body)
|
||||
print(response.status_code)
|
||||
if response.history:
|
||||
print('PASS: valid mutation submitted. Fetching result url')
|
||||
url_match = re.search('/dynamut/results_prediction/.+(?=")', response.text)
|
||||
url = host + url_match.group()
|
||||
print(url)
|
||||
|
||||
#===============
|
||||
# writing file: result urls
|
||||
#===============
|
||||
out_url_file = dynamut_temp_dir + '/dynamut_result_url_batch_' + str(batch_no) + '.txt'
|
||||
print('Writing output url file:', out_url_file)
|
||||
myfile = open(out_url_file, 'a')
|
||||
myfile.write(url)
|
||||
myfile.close()
|
||||
|
||||
#%%
|
||||
def request_calculation(pdb_file, mutation_list
|
||||
#%%#####################################################################
|
||||
def submit_dynamut(host_url
|
||||
, pdb_file
|
||||
, mutation_list
|
||||
, chain
|
||||
, my_email
|
||||
, email_address
|
||||
, prediction_url
|
||||
, output_dir
|
||||
, gene_name
|
||||
, batch_no
|
||||
, out_url_file):
|
||||
, outfile_suffix
|
||||
):
|
||||
"""
|
||||
Makes a POST request for a ligand affinity prediction.
|
||||
Makes a POST request for dynamut predictions.
|
||||
|
||||
@param host_url: valid host url for submitting the job
|
||||
@type string
|
||||
|
||||
@param pdb_file: valid path to pdb structure
|
||||
@type string
|
||||
|
||||
@param mutation_list: list of mutations (1 per line) of the format: {WT}<POS>{Mut}
|
||||
@type string
|
||||
|
||||
|
||||
@param chain: single-letter(caps)
|
||||
@type chr
|
||||
|
||||
@param prediction_url: dynamut url for prediction
|
||||
@type string
|
||||
|
||||
@return txt file containing batch no. of snps processed
|
||||
@param output_dir: output dir
|
||||
@type string
|
||||
|
||||
@param outfile_suffix: outfile_suffix
|
||||
@type string, default is batch no.
|
||||
|
||||
@param outfile_suffix: to append to outfile
|
||||
@type string
|
||||
|
||||
@return writes a .txt file containing url for the snps processed with user provided suffix in filename
|
||||
@type string
|
||||
"""
|
||||
|
||||
with open(pdb_file, "rb") as pdb_file, open (mutation_list) as mutation_list:
|
||||
with open(pdb_file, "rb") as pdb_file, open (mutation_list, "rb") as mutation_list:
|
||||
files = {"wild": pdb_file
|
||||
, "mutation_list": mutation_list}
|
||||
body = {"chain": 'A'
|
||||
, "email": 'tanushree.tunstall@lshtm.ac.uk'}
|
||||
body = {"chain": chain
|
||||
, "email": email_address}
|
||||
|
||||
response = requests.post(prediction_url, files = files, data = body)
|
||||
print(response.status_code)
|
||||
if response.history:
|
||||
print('PASS: valid mutation submitted. Fetching result url')
|
||||
print('\nPASS: valid submission. Fetching result url')
|
||||
url_match = re.search('/dynamut/results_prediction/.+(?=")', response.text)
|
||||
url = host + url_match.group()
|
||||
print(url)
|
||||
url = host_url + url_match.group()
|
||||
print('\nURL for snp batch no ', str(outfile_suffix), ':', url)
|
||||
|
||||
#===============
|
||||
# writing file: result urls
|
||||
#===============
|
||||
out_url_file = dynamut_temp_dir + '/dynamut_result_url_batch_' + str(batch_no) + '.txt'
|
||||
print('Writing output url file:', out_url_file)
|
||||
dynamut_temp_dir = output_dir + '/dynamut_temp' # creates a temp dir within output_dir
|
||||
if not os.path.exists(dynamut_temp_dir):
|
||||
print('\nCreating dynamut_temp in output_dir', output_dir )
|
||||
os.makedirs(dynamut_temp_dir)
|
||||
|
||||
out_url_file = dynamut_temp_dir + '/dynamut_result_url_' + str(outfile_suffix) + '.txt'
|
||||
print('\nWriting output url file:', out_url_file)
|
||||
myfile = open(out_url_file, 'a')
|
||||
myfile.write(url)
|
||||
myfile.close()
|
||||
#====================
|
||||
# Submit first batch
|
||||
#%%#####################################################################
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue