-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsave_domains_from_info.py
executable file
·88 lines (66 loc) · 2.32 KB
/
save_domains_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
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python3
# # -*- coding: utf-8 -*-
"""
@Authors Max Tong & Huy Bui
@Require ChimeraX
"""
import sys,os,time
from shutil import which
from datetime import datetime
script_dir=os.path.dirname(os.path.realpath(__file__))
import subprocess, multiprocessing
import pandas as pd
def execute(cmd):
print(f'start {cmd}', datetime.now())
return subprocess.call(cmd,shell=True)
def print_usage ():
print("usage: python save_domains_from_info.py inputDirPDB inputDirDomainInfo outputDir minLength maxLength noProcessor")
sys.exit()
if __name__ == "__main__":
if len(sys.argv) < 2 :
print_usage()
else:
logs=[]
input_dir1 = sys.argv[1] # PDB
input_dir2 = sys.argv[2] # Domain info
output_dir = sys.argv[3]
threads = 10
if len(sys.argv) < 4:
min_length = '50'
else:
min_length = sys.argv[4]
if len(sys.argv) < 5:
max_length = '1000'
else:
max_length = sys.argv[5]
if len(sys.argv) == 7:
threads = int(sys.argv[6])
# Check operating system
useMacOs = 0
print("Platform: " + sys.platform)
os.makedirs(output_dir, exist_ok=True)
if sys.platform == 'darwin': #MacOS
useMacOs = 1
print ("No capability to generate picture on MacOS!!!")
chimerax_path = "chimerax"
if useMacOs == 1:
chimerax_path = "/Applications/ChimeraX-1.5.app/Contents/MacOS/ChimeraX"
if os.path.exists(chimerax_path) == 0 and which(chimerax_path) is None:
print(f"The file '{chimerax_path}' does not exist.")
print("Modify the script for the path of ChimeraX version from 1.5 and above.")
exit(0)
print('Saving chains between ' + min_length + ' and ' + max_length + ' aa')
log_file = output_dir + '/domain_logs.txt'
log = open(log_file, "w")
log.write("#{}\n".format(datetime.now().strftime("%m/%d/%Y, %H:%M:%S")))
log.write("\nUniprotId,Domain,NoResidues\n")
log.close()
list = os.listdir(input_dir1)
cmds=[]
for cif in os.listdir(input_dir1):
if cif.endswith((".cif", ".pdb")) & os.path.exists(os.path.join(input_dir2, f"{cif[:-4]}.domains")):
# Add them to the command list
uniprotID = cif[:-4]
cmds.append(f'{chimerax_path} --nogui --offscreen --cmd \"runscript {script_dir}/save_domain_single_from_info.py {input_dir1}/{cif} {input_dir2}/{uniprotID}.domains {output_dir} {min_length} {max_length}" --exit')
with multiprocessing.Pool(processes=threads) as pool:
results = pool.map(execute, cmds)