added submit_def.py with example to run batch of 50
This commit is contained in:
parent
cfe9028a9c
commit
5d6ddb7639
2 changed files with 144 additions and 3 deletions
|
@ -44,7 +44,7 @@ out_url_file = dynamut_temp_dir + '/dynamut_result_url_batch_' + str(batch_no) +
|
|||
|
||||
|
||||
#%% 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") as mutation_list:
|
||||
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'
|
||||
|
@ -57,6 +57,7 @@ with open("/home/tanu/git/Data/streptomycin/input/gid_complex.pdb", "rb") as pdb
|
|||
url_match = re.search('/dynamut/results_prediction/.+(?=")', response.text)
|
||||
url = host + url_match.group()
|
||||
print(url)
|
||||
|
||||
#===============
|
||||
# writing file: result urls
|
||||
#===============
|
||||
|
@ -90,7 +91,31 @@ def request_calculation(pdb_file, mutation_list
|
|||
@param prediction_url: dynamut url for prediction
|
||||
@type string
|
||||
|
||||
@return response object
|
||||
@type object
|
||||
@return txt file containing batch no. of snps processed
|
||||
@type string
|
||||
"""
|
||||
|
||||
with open(pdb_file, "rb") as pdb_file, open (mutation_list) 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()
|
||||
#====================
|
||||
# Submit first batch
|
||||
|
|
116
dynamut/submit_def.py
Normal file
116
dynamut/submit_def.py
Normal file
|
@ -0,0 +1,116 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Wed Aug 19 14:33:51 2020
|
||||
|
||||
@author: tanu
|
||||
"""
|
||||
#%% load packages
|
||||
import os,sys
|
||||
import subprocess
|
||||
import argparse
|
||||
import requests
|
||||
import re
|
||||
import time
|
||||
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)
|
||||
#%%
|
||||
def request_calculation(pdb_file
|
||||
, mutation_list
|
||||
, batch_no
|
||||
, chain
|
||||
, my_email
|
||||
, prediction_url
|
||||
, output_dir
|
||||
#, gene_name
|
||||
#, out_url_file
|
||||
):
|
||||
"""
|
||||
Makes a POST request for a ligand affinity prediction.
|
||||
|
||||
@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 batch_no: batch no so it can be added as a suffix to the the outfile
|
||||
@type int
|
||||
|
||||
@param chain: single-letter(caps)
|
||||
@type chr
|
||||
|
||||
@param prediction_url: dynamut url for prediction
|
||||
@type string
|
||||
|
||||
@param output_dir: output dir
|
||||
@type string
|
||||
|
||||
@param gene_name: name of gene
|
||||
@type string
|
||||
|
||||
#@param out_url_file: name of output file with batch no. as suffix
|
||||
@type string
|
||||
|
||||
@return txt file containing batch no. of snps processed (i.e out_url_file)
|
||||
@type string
|
||||
"""
|
||||
|
||||
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": chain
|
||||
, "email": my_email}
|
||||
|
||||
response = requests.post(prediction_url, files = files, data = body)
|
||||
print(response.status_code)
|
||||
if response.history:
|
||||
print('\nPASS: valid submission. Fetching result url')
|
||||
url_match = re.search('/dynamut/results_prediction/.+(?=")', response.text)
|
||||
url = host + url_match.group()
|
||||
print('\nURL for snp batch no ', str(batch_no), ':', url)
|
||||
|
||||
#===============
|
||||
# writing file: result urls
|
||||
#===============
|
||||
dynamut_temp_dir = outdir + '/dynamut_temp'
|
||||
if not os.path.exists(dynamut_temp_dir):
|
||||
print('\nCreating dynamut_temp in outdir', outdir )
|
||||
os.makedirs(dynamut_temp_dir)
|
||||
|
||||
out_url_file = dynamut_temp_dir + '/dynamut_result_url_batch_' + str(batch_no) + '.txt'
|
||||
print('\nWriting output url file:', out_url_file)
|
||||
myfile = open(out_url_file, 'a')
|
||||
myfile.write(url)
|
||||
myfile.close()
|
||||
#%%globals!?
|
||||
host = 'http://biosig.unimelb.edu.au'
|
||||
#prediction_url = f"{host}/dynamut/prediction_list"
|
||||
#print(prediction_url)
|
||||
|
||||
#gene = 'gid'
|
||||
drug = 'streptomycin'
|
||||
datadir = homedir + '/git/Data'
|
||||
indir = datadir + '/' + drug + '/input'
|
||||
outdir = datadir + '/' + drug + '/output'
|
||||
#outdir = homedir + '/git/LSHTM_analysis/dynamut' # for example
|
||||
|
||||
|
||||
my_pdb_file = homedir + '/git/Data/streptomycin/input/gid_complex.pdb'
|
||||
my_mutation_list = homedir + '/git/Data/streptomycin/output/snp_batches/50/snp_batch_00.txt'
|
||||
my_chain = 'A'
|
||||
my_batch = 1
|
||||
#my_outfile = dynamut_temp_dir + '/dynamut_result_url_batch_' + str(batch_no) + '.txt'
|
||||
# %% call this function
|
||||
request_calculation (pdb_file = my_pdb_file
|
||||
, mutation_list = my_mutation_list
|
||||
, chain = my_chain
|
||||
, my_email = 'tanushree.tunstall@lshtm.ac.uk'
|
||||
, prediction_url = f"{host}/dynamut/prediction_list"
|
||||
, output_dir = outdir
|
||||
, batch_no = my_batch)
|
Loading…
Add table
Add a link
Reference in a new issue