-
Notifications
You must be signed in to change notification settings - Fork 1
/
save_domain_single_from_info.py
executable file
·78 lines (59 loc) · 2 KB
/
save_domain_single_from_info.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python3
# # -*- coding: utf-8 -*-
"""
@Authors Max Tong & Huy Bui
@Require ChimeraX
Note: if the .domains not exist, save the entire file
"""
from chimerax.core.commands import run
import os.path
import sys,os
import pandas as pd
input_cif = sys.argv[1]
input_domain = sys.argv[2]
output_dir = sys.argv[3]
if len(sys.argv) < 4:
min_length = 50
else:
min_length = int(sys.argv[4])
if len(sys.argv) < 5:
max_length = 1000
else:
max_length = int(sys.argv[5])
model = run(session, 'open %s' % input_cif)[0]
if input_cif.endswith('cif'):
model_basename = os.path.basename(input_cif).replace('.cif','')
else:
model_basename = os.path.basename(input_cif).replace('.pdb','')
print('Saving chains between ' + str(min_length) + ' and ' + str(max_length) + ' aa')
# Check operating system
useMacOs = 0
if sys.platform == 'darwin': #MacOS
useMacOs = 1
log_file = output_dir + '/domain_logs.txt'
log = open(log_file, "a")
df = pd.read_csv(f"{input_domain}", sep="\t", header=None)
domain_names = df[0]
domain_ranges = df[1]
for chainNo in range(len(domain_names)):
noResidues = 0
if ',' in domain_ranges[chainNo]:
ranges = [x for x in domain_ranges[chainNo].split(',') if x.strip()]
for x in ranges:
r = [int(x) for x in x.split('-') if x.strip()]
noResidues += r[1] - r[0]
else:
ranges = [int(x) for x in domain_ranges[chainNo].split('-') if x.strip()]
noResidues = ranges[1] - ranges[0]
log.write('%s,%s,%d\n' % (model_basename, domain_names[chainNo], noResidues))
if noResidues < min_length or noResidues > max_length:
print('--> Skip due to length')
continue
print('Saving chain ' + domain_names[chainNo])
run(session, f"sel #1:{domain_ranges[chainNo]}")
output = output_dir + '/' + model_basename + '_' + domain_names[chainNo] + '.pdb'
run(session, 'save %s selectedOnly true models #%d' % (output, 1))
if useMacOs == 0 : #MacOS
output_png = output_dir + '/' + model_basename + '_' + domain_names[chainNo] + '.png'
run(session, 'save %s width 1000 super 3' % output_png)
log.close()