forked from BioinfoMachineLearning/EnQA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculate_lddt.py
68 lines (47 loc) · 2.04 KB
/
calculate_lddt.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
import os
import logging
from tqdm import tqdm
from pathlib import Path
from typing import List
PATH_TO_LDDT = Path('lddt-linux/lddt') # path to lddt
PATH_TO_TARGET = Path('reindex_anbase') # path to reindexed anbase structures ПРИБИТО ГВОЗДЯМИ
PATH_TO_PRED = Path('reindex_pred') # path to reindexed predictions
PATH_TO_SAVE_LDDT = Path('lddt_results')
def get_structures_names(path: Path) -> List:
"""
Get structures name for lddt calculation
@param path: path to structures
@return: list of structures names
"""
return os.listdir(path)
def calculate_save_lddt(name: str, path_to_lddt: Path, target_struct: str, pred_struct: str, path_to_save: Path, index: str) -> None:
"""
Calculate lddt and save to file.
@param name: structure name
@param path_to_lddt: path to lddt script
@param target_struct: target structure
@param pred_struct: predicted structure
@param path_to_save: where to save lddt
@return: None
"""
if not os.path.isdir(path_to_save):
os.makedirs(path_to_save)
filename = name + '_' + index + '.csv'
try:
os.system(f"{path_to_lddt} {target_struct} {pred_struct} >> {path_to_save / filename}")
except Exception as e:
logging.exception(e)
if __name__ == '__main__':
logging.basicConfig(format='%(asctime)s %(levelname)s - %(message)s', filename='logging_lddt.txt', level=logging.DEBUG)
structure_names = get_structures_names(PATH_TO_TARGET)
for name in tqdm(structure_names):
logging.info(f"Structure name: {name}")
path_to_target = PATH_TO_TARGET / name
path_to_pred = PATH_TO_PRED / name
target_struct = path_to_target / f"{name}.pdb"
index = 1
for file in os.listdir(path_to_pred):
pred_struct = path_to_pred / file
calculate_save_lddt(name=name, path_to_lddt=PATH_TO_LDDT, target_struct=target_struct,
pred_struct=pred_struct, path_to_save=PATH_TO_SAVE_LDDT / name, index=str(index))
index += 1