-
Notifications
You must be signed in to change notification settings - Fork 0
/
psiblast.py
53 lines (44 loc) · 1.4 KB
/
psiblast.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import multiprocessing
import os
import shutil
import subprocess
import tempfile
import pandas
def _read_pssm(pssm_dir):
column_names = ['idx'] + 'A R N D C Q E G H I L K M F P S T W Y V'.split()
pssm_table = pandas.read_csv(
os.path.join(pssm_dir, 'pssm.txt'),
engine='python',
sep='\s+',
usecols=[0] + list(range(2, 22)), # skip column with the sequence
names=column_names,
index_col=0,
skiprows=3,
skipfooter=5,
)
return pssm_table.as_matrix()
def pssm(sequence=None, filename=None):
pssm_dir = tempfile.mkdtemp(prefix='pssm_psiblast__')
if sequence is not None:
filename = os.path.join(pssm_dir, 'tmp.fasta')
with open(filename, 'w') as fasta_file:
fasta_file.write('>Seq\n')
fasta_file.write(sequence)
filename = os.path.join(pssm_dir, 'tmp.fasta')
subprocess.check_call([
'psiblast',
'-db', 'blastdb/pdbseqres',
'-evalue', '0.01',
'-query', filename,
'-out_ascii_pssm', pssm_dir + '/pssm.txt',
'-num_iterations', '3',
'-out', 'output.txt',
'-comp_based_stats', '0',
'-num_threads', str(multiprocessing.cpu_count()),
])
pssm = _read_pssm(pssm_dir)
try:
shutil.rmtree(pssm_dir)
except OSError:
print('Could not remove pssm dir ' + pssm_dir)
return pssm