88 lines
2.8 KiB
Python
Executable file
88 lines
2.8 KiB
Python
Executable file
#!/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
|
|
#%%
|
|
host = 'http://biosig.unimelb.edu.au'
|
|
prediction_url = f"{host}/dynamut/prediction_list"
|
|
print(prediction_url)
|
|
|
|
#%%
|
|
#def format_data(data_file):
|
|
|
|
#%% request calculation (no def)
|
|
output_dir = "/home/tanu/git/LSHTM_analysis/dynamut"
|
|
gene_name = 'gid'
|
|
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:
|
|
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 = output_dir + '/' + gene_name.lower() + '_snp_batch' + '_result_url.txt'
|
|
print(out_url_file)
|
|
myfile = open(out_url_file, 'a')
|
|
myfile.write(url + '\n')
|
|
myfile.close()
|
|
else:
|
|
print('ERROR: invalid mutation! Wild-type residue doesn\'t match pdb file.'
|
|
, '\nSkipping to the next mutation in file...')
|
|
#===============
|
|
# writing file: invalid mutations
|
|
#===============
|
|
out_error_file = output_dir + '/' + gene_name.lower() + '_errors.txt'
|
|
failed_muts = open(out_error_file, 'a')
|
|
failed_muts.write(mutation_list + '\n')
|
|
failed_muts.close()
|
|
|
|
#%%
|
|
def request_calculation(pdb_file, mutation_list
|
|
, chain
|
|
, my_email
|
|
, prediction_url
|
|
, output_dir
|
|
, gene_name
|
|
, 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 chain: single-letter(caps)
|
|
@type chr
|
|
|
|
@param prediction_url: dynamut url for prediction
|
|
@type string
|
|
|
|
@return response object
|
|
@type object
|
|
"""
|
|
#====================
|