-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrun.py
executable file
·78 lines (67 loc) · 3.86 KB
/
run.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 python
import click
import ImmunoPDB
import ab_haddock_format
from pathlib import Path
from pdbtools import pdb_tidy
def tidy_up(file: Path, where: Path, strict: bool = True) -> Path:
with where.open("w") as f:
new_pdb = pdb_tidy.run(file.open("r"), strict)
for line in new_pdb:
f.write(line)
return where
def process_pdb(pdb_path: Path, output_path: Path, scheme: str, fvonly: bool, rename: bool, splitscfv: bool, chain: str, delete_intermediate: bool) -> Path:
output_path.mkdir(exist_ok=True)
pdb_name = pdb_path.name
# Format the antibody in order to fit the HADDOCK format requirements
print(f"processing pdb {str(pdb_path)}, results will be saved to {output_path}")
annotated_pdb = (output_path / pdb_name.replace(".pdb", f"_{scheme}.pdb")).resolve()
ImmunoPDB.main(inputstructure=str(pdb_path), outfile=str(annotated_pdb), scheme=scheme, fvonly=fvonly, rename=rename, splitscfv=splitscfv)
print(f"pdb annotated as {annotated_pdb}")
haddock_pdb = (output_path / pdb_name.replace(".pdb", f"_HADDOCK.pdb")).resolve()
# file to save active sites
active_sites_file = output_path / pdb_name.replace(".pdb", f"_active.txt")
ab_haddock_format.main(pdb_file=str(annotated_pdb),
out_file=str(haddock_pdb),
chain_id=chain,
active_sites_file=str(active_sites_file)
)
print(f"pdb ported to haddock format and saved as {haddock_pdb}")
print(f"active residues saved as {active_sites_file}")
tidy_pdb = (output_path / pdb_name.replace(".pdb", f"_HADDOCK_tidy.pdb")).resolve()
tidy_up(haddock_pdb, tidy_pdb, True)
if delete_intermediate:
annotated_pdb.unlink(missing_ok=True)
haddock_pdb.unlink(missing_ok=True)
print("intermediate files deleted")
print(f"final pdb saved as {tidy_pdb}")
return tidy_pdb
def process_folder(pdb_path: Path, output_path: Path, scheme: str, fvonly: bool, rename: bool, splitscfv: bool, chain: str, delete_intermediate: bool) -> Path:
print(f"{str(pdb_path)} is folder, processing all subfolders and pdb files inside of it!")
for child in pdb_path.iterdir():
output_subpath = output_path / child.name
if child.is_dir() and not child.is_symlink() and any(child.iterdir()):
output_subpath.mkdir(exist_ok=True)
process_folder(child, output_subpath, scheme, fvonly, rename, splitscfv, chain, delete_intermediate)
elif child.is_file() and "pdb" in child.suffix:
process_pdb(child, output_subpath, scheme, fvonly, rename, splitscfv, chain, delete_intermediate)
return output_path
@click.command()
@click.option('--pdb', type=click.Path(exists=True), help='pdb file or a folder with pdb files to run protocol at, for example 4G6K.pdb (file) or my_antibodies (folder)')
@click.option('--output', default="output", help='output folder to store results')
@click.option('--scheme', default="c", help="numbering scheme")
@click.option('--fvonly', default=True, help="use only fv region")
@click.option('--rename', default=True, help="renaming")
@click.option('--splitscfv', default=True, help="splitscfv")
@click.option('--chain', default="A", help="chain to extract active regions from")
@click.option('--delete_intermediate', default=False, help="Delete intermediate files")
def cli(pdb: str, output: str, scheme: str, fvonly: bool, rename: bool, splitscfv: bool, chain: str, delete_intermediate: bool):
output_path = Path(output).resolve()
output_path.mkdir(exist_ok=True)
pdb_path = Path(pdb).resolve()
if pdb_path.is_dir():
process_folder(pdb_path, output_path, scheme, fvonly, rename, splitscfv, chain, delete_intermediate)
else:
process_pdb(pdb_path, output_path, scheme, fvonly, rename, splitscfv, chain, delete_intermediate)
if __name__ == '__main__':
cli()