Spaces:
Sleeping
Sleeping
Commit
·
993c0d3
1
Parent(s):
1ca7fde
Delete code/add_sasa_alphafold.py
Browse files- code/add_sasa_alphafold.py +0 -129
code/add_sasa_alphafold.py
DELETED
|
@@ -1,129 +0,0 @@
|
|
| 1 |
-
import glob
|
| 2 |
-
import ssbio.utils
|
| 3 |
-
import subprocess
|
| 4 |
-
import ssbio
|
| 5 |
-
import os.path as op
|
| 6 |
-
from add_3Dalignment import *
|
| 7 |
-
import os
|
| 8 |
-
from pathlib import Path
|
| 9 |
-
import gzip
|
| 10 |
-
import shutil
|
| 11 |
-
import streamlit as st
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
def run_freesasa(infile, outfile, include_hetatms=True, outdir=None, force_rerun=False, file_type = 'gzip'):
|
| 15 |
-
if not outdir:
|
| 16 |
-
outdir = ''
|
| 17 |
-
outfile = op.join(outdir, outfile)
|
| 18 |
-
if file_type == 'pdb':
|
| 19 |
-
if ssbio.utils.force_rerun(flag=force_rerun, outfile=outfile):
|
| 20 |
-
if include_hetatms:
|
| 21 |
-
shell_command = 'freesasa --format=rsa --hetatm {} -o {}'.format(infile, outfile)
|
| 22 |
-
else:
|
| 23 |
-
shell_command = 'freesasa --format=rsa {} -o {}'.format(infile, outfile)
|
| 24 |
-
command = subprocess.Popen(shell_command,
|
| 25 |
-
stdout=subprocess.PIPE,
|
| 26 |
-
stderr=subprocess.PIPE,
|
| 27 |
-
shell=True)
|
| 28 |
-
out, err = command.communicate()
|
| 29 |
-
elif file_type == 'gzip':
|
| 30 |
-
with gzip.open(infile, 'rb') as f_in:
|
| 31 |
-
with open('file_temp.pdb', 'wb') as f_out:
|
| 32 |
-
shutil.copyfileobj(f_in, f_out)
|
| 33 |
-
|
| 34 |
-
infile = 'file_temp.pdb'
|
| 35 |
-
|
| 36 |
-
if ssbio.utils.force_rerun(flag=force_rerun, outfile=outfile):
|
| 37 |
-
if include_hetatms:
|
| 38 |
-
shell_command = 'freesasa --format=rsa --hetatm {} -o {}'.format(infile, outfile)
|
| 39 |
-
else:
|
| 40 |
-
shell_command = 'freesasa --format=rsa {} -o {}'.format(infile, outfile)
|
| 41 |
-
command = subprocess.Popen(shell_command,
|
| 42 |
-
stdout=subprocess.PIPE,
|
| 43 |
-
stderr=subprocess.PIPE,
|
| 44 |
-
shell=True)
|
| 45 |
-
out, err = command.communicate()
|
| 46 |
-
return outfile
|
| 47 |
-
|
| 48 |
-
def calculate_freesasa(ID, model_num, existing_free_sasa, path_to_input,path_to_output_files, file_type = 'gzip'):
|
| 49 |
-
print('Calculating surface area...\n')
|
| 50 |
-
file_base = str(Path(path_to_input / '*'))
|
| 51 |
-
file_str = glob.glob(file_base)[0].split('-')[-1].split('.')[0]
|
| 52 |
-
if file_type == 'gzip':
|
| 53 |
-
if ID not in existing_free_sasa:
|
| 54 |
-
fullID = f'AF-{ID}-F{model_num}-{file_str }.pdb.gz'
|
| 55 |
-
run_freesasa(Path(path_to_input / fullID),
|
| 56 |
-
Path(path_to_output_files / f'freesasa_files/{fullID}.txt'), include_hetatms=True,
|
| 57 |
-
outdir=None, force_rerun=False)
|
| 58 |
-
elif file_type == 'pdb':
|
| 59 |
-
if ID not in existing_free_sasa:
|
| 60 |
-
fullID = f'AF-{ID}-F{model_num}-model_v1.pdb'
|
| 61 |
-
run_freesasa(Path(path_to_input / fullID),
|
| 62 |
-
Path(path_to_output_files / f'freesasa_files/{fullID}.txt'), include_hetatms=True,
|
| 63 |
-
outdir=None, force_rerun=False)
|
| 64 |
-
|
| 65 |
-
def sasa(source, pdbID, uniprotID, sasa_pos, wt, mode, path_to_output_files,file_type = 'gzip'):
|
| 66 |
-
if mode == 1:
|
| 67 |
-
sasa = 'nan'
|
| 68 |
-
for filename in list(Path(path_to_output_files / 'freesasa_files').glob("*")):
|
| 69 |
-
if source == 'PDB':
|
| 70 |
-
fname = str(filename).split('.')[0].split('/')[-1].upper()
|
| 71 |
-
elif source == 'MODBASE':
|
| 72 |
-
fname = str(filename).split('.')[0].split('/')[-1]
|
| 73 |
-
elif source == 'SWISSSMODEL':
|
| 74 |
-
fname = str(filename).split('_')[2]
|
| 75 |
-
if pdbID == fname:
|
| 76 |
-
files = open(filename, 'r')
|
| 77 |
-
file = files.readlines()
|
| 78 |
-
for k in file:
|
| 79 |
-
|
| 80 |
-
if k.strip()[10:13] == sasa_pos:
|
| 81 |
-
residue = str(k[4:7].strip())
|
| 82 |
-
if wt == threeToOne(residue):
|
| 83 |
-
sasa = str(k[22:28]).strip('\n')
|
| 84 |
-
return (sasa)
|
| 85 |
-
elif wt != threeToOne(residue):
|
| 86 |
-
sasa = str(k[22:28]).strip('\n') + '*'
|
| 87 |
-
return (sasa)
|
| 88 |
-
else:
|
| 89 |
-
return 'nan' #######
|
| 90 |
-
|
| 91 |
-
if mode == 2:
|
| 92 |
-
if sasa_pos != np.NaN:
|
| 93 |
-
sasa = 'nan'
|
| 94 |
-
if file_type == 'pdb':
|
| 95 |
-
for filename in list(Path(path_to_output_files / 'freesasa_files').glob("*")):
|
| 96 |
-
fname = list(filter(None, filename.split('.'))).split('/')[-1].upper()
|
| 97 |
-
if uniprotID == fname:
|
| 98 |
-
files = open(filename, 'r')
|
| 99 |
-
file = files.readlines()
|
| 100 |
-
for k in file:
|
| 101 |
-
if k.strip()[10:13] == sasa_pos:
|
| 102 |
-
residue = str(k[4:7].strip())
|
| 103 |
-
if wt == threeToOne(residue):
|
| 104 |
-
sasa = str(k[22:28]).strip('\n')
|
| 105 |
-
elif wt != threeToOne(residue):
|
| 106 |
-
sasa = str(k[22:28]).strip('\n') + '*'
|
| 107 |
-
|
| 108 |
-
return sasa
|
| 109 |
-
elif file_type == 'gzip':
|
| 110 |
-
for filename in list(Path(path_to_output_files / 'freesasa_files').glob("*")):
|
| 111 |
-
fname = list(filter(None, str(filename).split('.')))[0].split('/')[-1].split('-')[1].upper()
|
| 112 |
-
|
| 113 |
-
if uniprotID == fname:
|
| 114 |
-
files = open(filename, 'r')
|
| 115 |
-
file = files.readlines()
|
| 116 |
-
for k in file:
|
| 117 |
-
if str(k.strip()[10:13]) == str(sasa_pos):
|
| 118 |
-
residue = str(k[4:7].strip())
|
| 119 |
-
if wt == threeToOne(residue):
|
| 120 |
-
sasa = str(k[22:28]).strip('\n')
|
| 121 |
-
elif wt != threeToOne(residue):
|
| 122 |
-
sasa = str(k[22:28]).strip('\n') + '*'
|
| 123 |
-
else:
|
| 124 |
-
sasa = 'nan'
|
| 125 |
-
|
| 126 |
-
return sasa
|
| 127 |
-
else:
|
| 128 |
-
sasa = 'nan'
|
| 129 |
-
return sasa
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|