HInt-ppi 0.9.2__tar.gz → 0.9.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/HInt/File_proteins.py +1 -1
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/HInt/HInt.py +23 -32
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/HInt/Scoring_HInt.py +20 -2
- hint_ppi-0.9.4/HInt/Send_to_database.py +240 -0
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/HInt/Utils_HInt.py +25 -10
- hint_ppi-0.9.4/HInt/build_local_species_db.py +205 -0
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/HInt_ppi.egg-info/PKG-INFO +1 -1
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/HInt_ppi.egg-info/SOURCES.txt +2 -0
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/PKG-INFO +1 -1
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/README.md +7 -4
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/setup.py +1 -1
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/HInt/__init__.py +0 -0
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/HInt/get_good_inter_pae.py +0 -0
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/HInt/script_pi_score/__init__.py +0 -0
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/HInt/script_pi_score/calculate_mpdockq.py +0 -0
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/HInt/script_pi_score/clean_pdb.py +0 -0
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/HInt/script_pi_score/interface_assess.py +0 -0
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/HInt/script_pi_score/pi_score_utils.py +0 -0
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/HInt/script_pi_score/pisa_utils.py +0 -0
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/HInt/script_pi_score/run_piscore_wc.py +0 -0
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/HInt/script_pi_score/sc_utils.py +0 -0
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/HInt/script_pi_score/svm_model/__init__.py +0 -0
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/HInt/script_pi_score/svm_model/finalized_model_A.sav +0 -0
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/HInt/script_pi_score/svm_model/finalized_model_B.sav +0 -0
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/HInt/script_pi_score/svm_model/finalized_model_wc.sav +0 -0
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/HInt/script_pi_score/svm_model/scaler_model_A.sav +0 -0
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/HInt/script_pi_score/svm_model/scaler_model_B.sav +0 -0
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/HInt/script_pi_score/svm_model/scaler_model_wc.sav +0 -0
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/HInt_ppi.egg-info/dependency_links.txt +0 -0
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/HInt_ppi.egg-info/entry_points.txt +0 -0
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/HInt_ppi.egg-info/requires.txt +0 -0
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/HInt_ppi.egg-info/top_level.txt +0 -0
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/LICENSE +0 -0
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/MANIFEST.in +0 -0
- {hint_ppi-0.9.2 → hint_ppi-0.9.4}/setup.cfg +0 -0
|
@@ -446,7 +446,7 @@ class File_proteins() :
|
|
|
446
446
|
scrap_name = new_name
|
|
447
447
|
break
|
|
448
448
|
new_fasta += ">" + scrap_name + "\n"
|
|
449
|
-
|
|
449
|
+
elif line[0] == ">" and "[protein_id=" in line or "[locus_tag=" in line or "[gbkey=" in line : #clean ncbi file
|
|
450
450
|
scrap_name = line.split(" ")[1].split("=")[1][0:len(line.split(" ")[1].split("=")[1])-1].replace("(","").replace(")","").replace("-","_")
|
|
451
451
|
if scrap_name in list_new_prot_name :
|
|
452
452
|
for i in range(1,100) :
|
|
@@ -59,6 +59,7 @@ def add_arguments(parser) :
|
|
|
59
59
|
parser.add_argument("--cpu", help="Number of CPUs available for computation (default: half of the CPUs)", required=False, default=default_cpu, type=int)
|
|
60
60
|
parser.add_argument("--multi_job_per_gpu", help="Allow multiple jobs to run on the same GPU if VRAM allows it (default: True)", required=False, default="True")
|
|
61
61
|
parser.add_argument("--multi_scoring", help="Score all models of each interaction (default: False) and make a mean score.", required=False, default="False")
|
|
62
|
+
parser.add_argument("--send_to_database", help="Publish models to the public QSProteome database (https://qsproteome.org/). All, Negative or None", required=False, default="None")
|
|
62
63
|
|
|
63
64
|
# ------------------------------------------------------------------
|
|
64
65
|
# Main execution
|
|
@@ -80,6 +81,9 @@ def main() :
|
|
|
80
81
|
multi_scoring = args.multi_scoring
|
|
81
82
|
if multi_scoring not in ["True", "False"] :
|
|
82
83
|
raise ValueError("Invalid value for --multi_scoring. Need True or False.")
|
|
84
|
+
send_to_database = args.send_to_database
|
|
85
|
+
if send_to_database not in ["All", "Negative", "None"] :
|
|
86
|
+
raise ValueError("Invalid value for --send_to_database. Need All, Negative or None.")
|
|
83
87
|
Informations_dict = Define_informations()
|
|
84
88
|
|
|
85
89
|
# --------------------------------------------------------------
|
|
@@ -92,6 +96,7 @@ def main() :
|
|
|
92
96
|
logger.info(f"Multi-job per GPU set to: {multi_job_per_gpu}")
|
|
93
97
|
logger.info(f"Number of CPUs set to: {CPU}")
|
|
94
98
|
logger.info(f"AlphaFold version set to: {Informations_dict['AlphaFold']}")
|
|
99
|
+
logger.info(f"Send to database option set to: {send_to_database}")
|
|
95
100
|
|
|
96
101
|
time_dict = HInt_object.get_time_dict()
|
|
97
102
|
time_dict["Summarize_info"] = [Informations_dict["Interact_with"], Informations_dict["DeepLoc"], Informations_dict["Signal_peptide"], Informations_dict["Min_protein_length"], Informations_dict["Max_protein_length"], Informations_dict["Homo-oligomer"],str(len(HInt_object.get_possible_prey())),Informations_dict["Organism"]]
|
|
@@ -181,10 +186,6 @@ def main() :
|
|
|
181
186
|
if os.path.exists("log_file/shallow_MSA.txt") :
|
|
182
187
|
os.remove("log_file/shallow_MSA.txt")
|
|
183
188
|
|
|
184
|
-
# --------------------------------------------------------------
|
|
185
|
-
# Feature generation (MSA + pickle files)
|
|
186
|
-
# --------------------------------------------------------------
|
|
187
|
-
|
|
188
189
|
|
|
189
190
|
#Create batch just for loop on
|
|
190
191
|
job_with_vram_length = []
|
|
@@ -204,32 +205,25 @@ def main() :
|
|
|
204
205
|
Make_all_MSA_coverage(HInt_object, Informations_dict["Path_Pickle_Feature"], Informations_dict["Interact_with"], []) # Just for bait prot
|
|
205
206
|
HInt_object.Make_save_dict()
|
|
206
207
|
prio_list_MSA = []
|
|
207
|
-
if First_batch
|
|
208
|
+
if First_batch is not None :
|
|
208
209
|
prio_list_MSA = prioritize_by_vram_fit(job_with_vram_length, First_batch, GPU)
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
new_prio_list = []
|
|
213
|
-
for prot in batch :
|
|
214
|
-
if prot in need_pkl :
|
|
215
|
-
new_prio_list.append(prot)
|
|
216
|
-
if new_prio_list != [] :
|
|
217
|
-
batch_MSA.append(new_prio_list)
|
|
210
|
+
need_pkl_set = set(need_pkl)
|
|
211
|
+
# One flat list in priority order: proteins that still need a pkl, without duplicates
|
|
212
|
+
new_prio_list_MSA = list(dict.fromkeys(prot for batch in prio_list_MSA for prot in batch if prot in need_pkl_set))
|
|
218
213
|
start_PPI = time.time()
|
|
219
214
|
if HInt_object.get_compounds() != {} :
|
|
220
|
-
gpu_thread = threading.Thread(target=Generate_3D_model, args=(HInt_object, CPU, multi_scoring, Informations_dict, "Compounds", job_with_vram_length, GPU, multi_job_per_gpu))
|
|
215
|
+
gpu_thread = threading.Thread(target=Generate_3D_model, args=(HInt_object, CPU, multi_scoring, send_to_database, Informations_dict, "Compounds", job_with_vram_length, GPU, multi_job_per_gpu))
|
|
221
216
|
gpu_thread.start()
|
|
222
217
|
gpu_thread.join()
|
|
223
218
|
else :
|
|
224
|
-
gpu_thread = threading.Thread(target=Generate_3D_model, args=(HInt_object, CPU, multi_scoring, Informations_dict, "PPI_int", job_with_vram_length, GPU, multi_job_per_gpu))
|
|
219
|
+
gpu_thread = threading.Thread(target=Generate_3D_model, args=(HInt_object, CPU, multi_scoring, send_to_database, Informations_dict, "PPI_int", job_with_vram_length, GPU, multi_job_per_gpu))
|
|
225
220
|
gpu_thread.start()
|
|
226
|
-
|
|
227
|
-
create_feature(HInt_object, Informations_dict, GPU, CPU, [], batch)
|
|
221
|
+
create_feature(HInt_object, Informations_dict, GPU, CPU, [], new_prio_list_MSA)
|
|
228
222
|
Make_all_MSA_coverage(HInt_object, Informations_dict["Path_Pickle_Feature"], Informations_dict["Interact_with"], HInt_object.get_possible_prey()) # For preys
|
|
229
223
|
gpu_thread.join()
|
|
230
224
|
time_PPI = format_time(time.time() - start_PPI)
|
|
231
225
|
time_dict["PPI"] = [len(job_with_vram_length), time_PPI]
|
|
232
|
-
Score_interaction(HInt_object, Informations_dict, CPU, "PPI_int", "", multi_scoring, bait) #if score is not done in Generate_3D_model, do it here
|
|
226
|
+
Score_interaction(HInt_object, Informations_dict, CPU, "PPI_int", send_to_database, "", multi_scoring, bait) #if score is not done in Generate_3D_model, do it here
|
|
233
227
|
HInt_object.Make_save_dict()
|
|
234
228
|
|
|
235
229
|
|
|
@@ -250,24 +244,21 @@ def main() :
|
|
|
250
244
|
prio_list_MSA = []
|
|
251
245
|
if First_batch != None :
|
|
252
246
|
prio_list_MSA = prioritize_by_vram_fit(job_with_vram_length, First_batch, GPU)
|
|
253
|
-
|
|
254
|
-
if
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
batch_MSA.append(new_prio_list)
|
|
262
|
-
gpu_thread = threading.Thread(target=Generate_3D_model, args=(HInt_object, CPU, multi_scoring, Informations_dict, "homo_int", job_with_vram_length, GPU, multi_job_per_gpu))
|
|
247
|
+
prio_list_MSA = []
|
|
248
|
+
if First_batch is not None :
|
|
249
|
+
prio_list_MSA = prioritize_by_vram_fit(job_with_vram_length, First_batch, GPU)
|
|
250
|
+
need_pkl_set = set(need_pkl)
|
|
251
|
+
# One flat list in priority order: proteins that still need a pkl, without duplicates
|
|
252
|
+
new_prio_list_MSA = list(dict.fromkeys(prot for batch in prio_list_MSA for prot in batch if prot in need_pkl_set))
|
|
253
|
+
|
|
254
|
+
gpu_thread = threading.Thread(target=Generate_3D_model, args=(HInt_object, CPU, multi_scoring, send_to_database, Informations_dict, "homo_int", job_with_vram_length, GPU, multi_job_per_gpu))
|
|
263
255
|
gpu_thread.start()
|
|
264
|
-
|
|
265
|
-
create_feature(HInt_object, Informations_dict, GPU, CPU, [], batch)
|
|
256
|
+
create_feature(HInt_object, Informations_dict, GPU, CPU, [], new_prio_list_MSA)
|
|
266
257
|
Make_all_MSA_coverage(HInt_object, Informations_dict["Path_Pickle_Feature"], Informations_dict["Interact_with"], HInt_object.get_possible_prey())
|
|
267
258
|
gpu_thread.join()
|
|
268
259
|
Score_interaction(HInt_object, Informations_dict, CPU, "homo_int", "", multi_scoring)
|
|
269
260
|
else :
|
|
270
|
-
Generate_3D_model(HInt_object, CPU, multi_scoring, Informations_dict, "homo_int", job_with_vram_length, GPU, multi_job_per_gpu)
|
|
261
|
+
Generate_3D_model(HInt_object, CPU, multi_scoring, send_to_database, Informations_dict, "homo_int", job_with_vram_length, GPU, multi_job_per_gpu)
|
|
271
262
|
Score_interaction(HInt_object, Informations_dict, CPU, "homo_int", "", multi_scoring)
|
|
272
263
|
HInt_object.Make_save_dict()
|
|
273
264
|
|
|
@@ -6,7 +6,7 @@ import os
|
|
|
6
6
|
import csv
|
|
7
7
|
import logging
|
|
8
8
|
import multiprocessing
|
|
9
|
-
import HInt.get_good_inter_pae
|
|
9
|
+
import HInt.get_good_inter_pae, HInt.Send_to_database
|
|
10
10
|
import gc
|
|
11
11
|
import pandas as pd
|
|
12
12
|
import json
|
|
@@ -37,7 +37,7 @@ logging.basicConfig(
|
|
|
37
37
|
|
|
38
38
|
logger = logging.getLogger()
|
|
39
39
|
|
|
40
|
-
def Score_interaction (file, Informations_dict, CPU, Interaction, job="", multi_scoring="False", bait="") :
|
|
40
|
+
def Score_interaction (file, Informations_dict, CPU, Interaction, send_to_database, job="", multi_scoring="False", bait="") :
|
|
41
41
|
"""
|
|
42
42
|
Compute interaction scores (PPI or homo-oligomer) from AlphaFold predictions, aggregate them into meaningful metrics (iQ_score / hiQ_score), and update the list of valid prey proteins accordingly.
|
|
43
43
|
|
|
@@ -55,6 +55,7 @@ def Score_interaction (file, Informations_dict, CPU, Interaction, job="", multi_
|
|
|
55
55
|
Interaction type ("PPI_int" or "homo_int")
|
|
56
56
|
job : str
|
|
57
57
|
multi_scoring : str
|
|
58
|
+
send_to_database : str
|
|
58
59
|
bait : str
|
|
59
60
|
|
|
60
61
|
"""
|
|
@@ -220,10 +221,16 @@ def Score_interaction (file, Informations_dict, CPU, Interaction, job="", multi_
|
|
|
220
221
|
mean_iQ_score[prey_name].append(iQ_score)
|
|
221
222
|
int_score[prey_name][f"iQ_score_vs_{bait_name}"] = iQ_score
|
|
222
223
|
result_dict[prey_name][f"iQ_score_vs_{bait_name}"] = iQ_score
|
|
224
|
+
if send_to_database == "All" :
|
|
225
|
+
zip_path = HInt.Send_to_database.HInt_to_QSProteome(f"./result_{Interaction}/{just_name}", AF_version)
|
|
226
|
+
HInt.Send_to_database.send_to_QSproteome(zip_path)
|
|
227
|
+
|
|
228
|
+
|
|
223
229
|
if prey_name not in new_possible_prey :
|
|
224
230
|
new_possible_prey.append(prey_name)
|
|
225
231
|
if "ranked_0" in job :
|
|
226
232
|
all_lines = all_lines + line
|
|
233
|
+
|
|
227
234
|
for protein in possible_prey :
|
|
228
235
|
if multi_scoring == True and protein in mean_iQ_score.keys() :
|
|
229
236
|
scores = mean_iQ_score[protein]
|
|
@@ -236,6 +243,16 @@ def Score_interaction (file, Informations_dict, CPU, Interaction, job="", multi_
|
|
|
236
243
|
int_score[protein][f"iQ_score_vs_{bait_name}"] = 0
|
|
237
244
|
result_dict[protein][f"iQ_score_vs_{bait_name}"] = 0 #if prey don't have interaction, set iQ_score to 0
|
|
238
245
|
result_dict[protein]["Reason_for_filtering"] = f"Bad interactions with {bait_name} : inter PAE > 10 A"
|
|
246
|
+
if send_to_database == "All" or send_to_database == "Negative" :
|
|
247
|
+
dir_path = Path(f"./result_{Interaction}/{bait_name}_and_{protein}")
|
|
248
|
+
inv_dir = Path(f"./result_{Interaction}/{protein}_and_{bait_name}")
|
|
249
|
+
if dir_path.exists() and dir_path.is_dir() :
|
|
250
|
+
job = dir_path
|
|
251
|
+
elif inv_dir.exists() and inv_dir.is_dir() :
|
|
252
|
+
job = inv_dir
|
|
253
|
+
zip_path = HInt.Send_to_database.HInt_to_QSProteome(job, AF_version)
|
|
254
|
+
HInt.Send_to_database.send_to_QSproteome(zip_path)
|
|
255
|
+
|
|
239
256
|
#For homo-oligomer
|
|
240
257
|
if Interaction == "homo_int" : #score homo-oligomer
|
|
241
258
|
all_homo = dict()
|
|
@@ -286,6 +303,7 @@ def Score_interaction (file, Informations_dict, CPU, Interaction, job="", multi_
|
|
|
286
303
|
file.set_int_score(int_score)
|
|
287
304
|
file.set_result_dict(result_dict)
|
|
288
305
|
file.set_possible_prey(new_possible_prey)
|
|
306
|
+
file.Make_save_dict()
|
|
289
307
|
else :
|
|
290
308
|
logger.info(f"result_{Interaction}/ don't exist")
|
|
291
309
|
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import zipfile
|
|
5
|
+
import hashlib
|
|
6
|
+
import io
|
|
7
|
+
import os
|
|
8
|
+
import time
|
|
9
|
+
from collections import defaultdict, Counter
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
import matplotlib
|
|
12
|
+
matplotlib.use("Agg")
|
|
13
|
+
import matplotlib.pyplot as plt
|
|
14
|
+
import requests
|
|
15
|
+
import logging
|
|
16
|
+
import pickle
|
|
17
|
+
import gzip
|
|
18
|
+
|
|
19
|
+
# Configure global logger
|
|
20
|
+
logging.basicConfig(
|
|
21
|
+
filename="./log_file/HInt.log", # Log file name
|
|
22
|
+
level=logging.INFO, # Log level
|
|
23
|
+
format="%(asctime)s - %(levelname)s - %(message)s" # Log format
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
# Use the logger configuration from HInt.py
|
|
27
|
+
logger = logging.getLogger()
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def HInt_to_QSProteome (ppi, AF_version) :
|
|
31
|
+
"""
|
|
32
|
+
Create a Zip file to send to the database.
|
|
33
|
+
|
|
34
|
+
Parameters :
|
|
35
|
+
----------
|
|
36
|
+
ppi : str
|
|
37
|
+
AF_version : str
|
|
38
|
+
|
|
39
|
+
"""
|
|
40
|
+
folder = Path(ppi)
|
|
41
|
+
name = folder.name
|
|
42
|
+
zip_path = folder / f"{name}_qsproteome_upload.zip"
|
|
43
|
+
|
|
44
|
+
if AF_version == "3" :
|
|
45
|
+
AF_version = "3.0.2"
|
|
46
|
+
num_recycles = 10
|
|
47
|
+
|
|
48
|
+
RENAME = {
|
|
49
|
+
"_model.cif": "_model_0.cif",
|
|
50
|
+
"_summary_confidences.json": "_summary_confidences_0.json",
|
|
51
|
+
"_confidences.json": "_full_data_0.json",
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zf :
|
|
55
|
+
for old, new in RENAME.items() :
|
|
56
|
+
zf.write(folder / f"{name}{old}", f"{name}/{name}{new}")
|
|
57
|
+
|
|
58
|
+
data = json.loads((folder / f"{name}_data.json").read_text())
|
|
59
|
+
chains = [
|
|
60
|
+
{"proteinChain": {"sequence": s["protein"]["sequence"], "count": len(s["protein"]["id"]) if isinstance(s["protein"]["id"], list) else 1}}
|
|
61
|
+
for s in data["sequences"] if "protein" in s
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
job = [{"name": name, "modelSeeds": [str(x) for x in data["modelSeeds"]], "sequences": chains, "dialect": "alphafold3", "version": AF_version, "num_recycles": num_recycles}]
|
|
65
|
+
zf.writestr(f"{name}/{name}_job_request.json", json.dumps(job))
|
|
66
|
+
|
|
67
|
+
if AF_version == "2" :
|
|
68
|
+
AF_version = "2.3.2"
|
|
69
|
+
num_recycles = 3
|
|
70
|
+
AA3 = {"ALA": "A", "ARG": "R", "ASN": "N", "ASP": "D", "CYS": "C", "GLN": "Q", "GLU": "E", "GLY": "G",
|
|
71
|
+
"HIS": "H", "ILE": "I", "LEU": "L", "LYS": "K", "MET": "M", "PHE": "F", "PRO": "P", "SER": "S",
|
|
72
|
+
"THR": "T", "TRP": "W", "TYR": "Y", "VAL": "V"}
|
|
73
|
+
# AF2 has no summary/confidences/data json: build them from ranked_0.pdb and the best result_*.pkl
|
|
74
|
+
best = json.loads((folder / "ranking_debug.json").read_text())["order"][0]
|
|
75
|
+
|
|
76
|
+
pkl = folder / f"result_{best}.pkl"
|
|
77
|
+
with (open(pkl, "rb") if pkl.exists() else gzip.open(f"{pkl}.gz", "rb")) as f :
|
|
78
|
+
result = pickle.load(f)
|
|
79
|
+
num_recycles = int(result.get("num_recycles", num_recycles))
|
|
80
|
+
|
|
81
|
+
pdb = (folder / "ranked_0.pdb").read_text()
|
|
82
|
+
atoms = [l for l in pdb.splitlines() if l.startswith("ATOM")]
|
|
83
|
+
residues = list(dict.fromkeys((l[21], int(l[22:26]), l[17:20]) for l in atoms))
|
|
84
|
+
seqs = {}
|
|
85
|
+
for chain, _, res in residues :
|
|
86
|
+
seqs[chain] = seqs.get(chain, "") + AA3.get(res, "X")
|
|
87
|
+
|
|
88
|
+
summary = {"iptm": float(result["iptm"]) if "iptm" in result else None, "ptm": float(result["ptm"]),
|
|
89
|
+
"ranking_score": float(result["ranking_confidence"]), "num_recycles": num_recycles}
|
|
90
|
+
full_data = {"atom_chain_ids": [l[21] for l in atoms], "atom_plddts": [float(l[60:66]) for l in atoms],
|
|
91
|
+
"pae": result["predicted_aligned_error"].round(2).tolist(),
|
|
92
|
+
"token_chain_ids": [c for c, _, _ in residues], "token_res_ids": [r for _, r, _ in residues]}
|
|
93
|
+
|
|
94
|
+
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zf :
|
|
95
|
+
zf.writestr(f"{name}/{name}_model_0.pdb", pdb)
|
|
96
|
+
zf.writestr(f"{name}/{name}_summary_confidences_0.json", json.dumps(summary))
|
|
97
|
+
zf.writestr(f"{name}/{name}_full_data_0.json", json.dumps(full_data))
|
|
98
|
+
|
|
99
|
+
chains = [{"proteinChain": {"sequence": s, "count": n}} for s, n in Counter(seqs.values()).items()]
|
|
100
|
+
|
|
101
|
+
job = [{"name": name, "modelSeeds": [], "sequences": chains, "dialect": "alphafold2", "version": AF_version, "num_recycles": num_recycles}]
|
|
102
|
+
zf.writestr(f"{name}/{name}_job_request.json", json.dumps(job))
|
|
103
|
+
return zip_path
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def screenshot(model_bytes) :
|
|
107
|
+
"""
|
|
108
|
+
Simple PNG of the Calpha trace, coloured by chain (the database requires an image)
|
|
109
|
+
|
|
110
|
+
Parameters :
|
|
111
|
+
----------
|
|
112
|
+
model_bytes : bytes
|
|
113
|
+
CIF or PDB file data
|
|
114
|
+
|
|
115
|
+
Returns :
|
|
116
|
+
-------
|
|
117
|
+
bytes : PNG image data
|
|
118
|
+
|
|
119
|
+
"""
|
|
120
|
+
cols, chains = [], defaultdict(list)
|
|
121
|
+
for line in model_bytes.decode().splitlines() :
|
|
122
|
+
if line.startswith("_atom_site.") :
|
|
123
|
+
cols.append(line.split(".")[1].strip())
|
|
124
|
+
elif line.startswith("ATOM") and cols : # mmCIF (AF3)
|
|
125
|
+
f = dict(zip(cols, line.split()))
|
|
126
|
+
if f["label_atom_id"] == "CA" :
|
|
127
|
+
chains[f["label_asym_id"]].append((float(f["Cartn_x"]), float(f["Cartn_y"])))
|
|
128
|
+
elif line.startswith("ATOM") and line[12:16].strip() == "CA" : # PDB (AF2)
|
|
129
|
+
chains[line[21]].append((float(line[30:38]), float(line[38:46])))
|
|
130
|
+
fig, ax = plt.subplots(figsize=(4, 4))
|
|
131
|
+
for xy in chains.values() :
|
|
132
|
+
ax.plot(*zip(*xy), lw=1.5)
|
|
133
|
+
ax.set_aspect("equal")
|
|
134
|
+
ax.axis("off")
|
|
135
|
+
buf = io.BytesIO()
|
|
136
|
+
fig.savefig(buf, format="png", dpi=100)
|
|
137
|
+
plt.close(fig)
|
|
138
|
+
return buf.getvalue()
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def content_type (name) :
|
|
142
|
+
"""
|
|
143
|
+
Determine the content type based on the file extension.
|
|
144
|
+
|
|
145
|
+
Parameters :
|
|
146
|
+
----------
|
|
147
|
+
name : str
|
|
148
|
+
|
|
149
|
+
Returns :
|
|
150
|
+
-------
|
|
151
|
+
str : Content type
|
|
152
|
+
|
|
153
|
+
"""
|
|
154
|
+
if name.endswith(".json"):
|
|
155
|
+
return "application/json"
|
|
156
|
+
if name.endswith(".cif"):
|
|
157
|
+
return "application/cif"
|
|
158
|
+
if name.endswith(".pdb"):
|
|
159
|
+
return "chemical/x-pdb"
|
|
160
|
+
return "application/octet-stream"
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def upload_run (s, run_id, files, credits) :
|
|
164
|
+
"""
|
|
165
|
+
Upload a single run to the QSProteome database.
|
|
166
|
+
|
|
167
|
+
Parameters :
|
|
168
|
+
----------
|
|
169
|
+
s : requests.Session
|
|
170
|
+
run_id : str
|
|
171
|
+
files : dict
|
|
172
|
+
credits : dict
|
|
173
|
+
|
|
174
|
+
"""
|
|
175
|
+
TIMEOUT = 40
|
|
176
|
+
BASE = os.environ.get("QSPROTEOME_URL", "https://qsproteome.org")
|
|
177
|
+
model_name = next(n for n in files if "model_0" in n)
|
|
178
|
+
model = files[model_name]
|
|
179
|
+
|
|
180
|
+
digest = hashlib.sha256(model).hexdigest()
|
|
181
|
+
if s.post(f"{BASE}/api/rds/check-structure-hash", json={"hash": digest}, timeout=TIMEOUT).json().get("exists") :
|
|
182
|
+
logger.info(f"[{run_id}] already in database, skipping upload")
|
|
183
|
+
return
|
|
184
|
+
|
|
185
|
+
job_id = f"af3ws_{int(time.time() * 1000)}_{run_id}"
|
|
186
|
+
urls = {}
|
|
187
|
+
for name, blob, ctype in [("screenshot.png", screenshot(model), "image/png")] + \
|
|
188
|
+
[(n, b, content_type(n)) for n, b in files.items()]:
|
|
189
|
+
key = f"{job_id}/{name}"
|
|
190
|
+
r = s.get(f"{BASE}/api/s3/get-presigned-url", params={"fileName": key, "fileType": ctype}, timeout=TIMEOUT)
|
|
191
|
+
r.raise_for_status()
|
|
192
|
+
requests.put(r.json()["url"], data=blob, headers={"Content-Type": ctype}, timeout=TIMEOUT).raise_for_status()
|
|
193
|
+
urls[name] = f"https://qsproteome.s3.us-west-1.amazonaws.com/uploads/{key}"
|
|
194
|
+
|
|
195
|
+
def url(k) :
|
|
196
|
+
return next((u for n, u in urls.items() if k in n), None)
|
|
197
|
+
|
|
198
|
+
s.post(f"{BASE}/api/rds/complex-data/upload", json={
|
|
199
|
+
"complex_id": job_id,
|
|
200
|
+
"structure_file": url("model_0"),
|
|
201
|
+
"config_file": url("job_request"),
|
|
202
|
+
"metrics_file": url("full_data_0"),
|
|
203
|
+
"summary_file": url("summary_confidences_0"),
|
|
204
|
+
"image_file": url("screenshot.png"),
|
|
205
|
+
"credits": credits,
|
|
206
|
+
}, timeout=TIMEOUT).raise_for_status()
|
|
207
|
+
logger.info(f"[{run_id}] send -> {BASE}/structure/{job_id}")
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def send_to_QSproteome (zip_file) :
|
|
211
|
+
"""
|
|
212
|
+
Upload a zip file containing AlphaFold predictions to the QSProteome database, then remove it.
|
|
213
|
+
|
|
214
|
+
Parameters :
|
|
215
|
+
----------
|
|
216
|
+
zip_file : str
|
|
217
|
+
|
|
218
|
+
"""
|
|
219
|
+
BASE = os.environ.get("QSPROTEOME_URL", "https://qsproteome.org")
|
|
220
|
+
KEYS = ["model_0", "summary_confidences_0", "full_data_0", "job_request"]
|
|
221
|
+
credits = {"firstName": "HInt", "lastName": "PPI", "affiliation": "University of Rennes", "publicationLink": ""}
|
|
222
|
+
|
|
223
|
+
try :
|
|
224
|
+
requests.get(BASE, timeout=10).raise_for_status()
|
|
225
|
+
except requests.RequestException as e :
|
|
226
|
+
logger.error(f"QSProteome unreachable, upload skipped ({e}). Zip kept : {zip_file}")
|
|
227
|
+
return
|
|
228
|
+
|
|
229
|
+
runs = defaultdict(dict) # one run per top-level folder, as on the site
|
|
230
|
+
with zipfile.ZipFile(zip_file) as z :
|
|
231
|
+
for name in z.namelist() :
|
|
232
|
+
if any(k in name for k in KEYS) :
|
|
233
|
+
runs[name.split("/")[0]][name] = z.read(name)
|
|
234
|
+
|
|
235
|
+
with requests.Session() as s :
|
|
236
|
+
for run_id, files in runs.items() :
|
|
237
|
+
upload_run(s, run_id, files, credits)
|
|
238
|
+
|
|
239
|
+
Path(zip_file).unlink(missing_ok=True)
|
|
240
|
+
|
|
@@ -138,6 +138,8 @@ def Define_informations () :
|
|
|
138
138
|
name_prot = prot.split("(")[0]
|
|
139
139
|
new_baits_list.append(name_prot.strip())
|
|
140
140
|
regions_dict[name_prot.strip()] = prot.split("(")[1].strip(")")
|
|
141
|
+
if regions_dict[name_prot.strip()].split("-")[0] == "0" or regions_dict[name_prot.strip()].split("-")[1] == "0" :
|
|
142
|
+
raise ValueError(f"HInt don't support region with 0 for protein bait : {name_prot.strip()}")
|
|
141
143
|
for i,multimer in enumerate(Informations_dict["Multimer_bait"]) :
|
|
142
144
|
if prot in multimer :
|
|
143
145
|
new_multimer = multimer.replace(prot,name_prot.strip())
|
|
@@ -310,11 +312,11 @@ def run_SP (file, Informations_dict, need_SP, need_msa) :
|
|
|
310
312
|
with open(f"log_file/{file_signalp}","r") as fh :
|
|
311
313
|
for line in fh :
|
|
312
314
|
new_line = line.split("\t")
|
|
313
|
-
if new_line[1] != "OTHER" and new_line[0][0] != "#" :
|
|
315
|
+
if new_line[1] != "OTHER" and new_line[0][0] != "#" and "-" in new_line :
|
|
314
316
|
prot_SP_len[new_line[0]] = new_line[len(new_line)-1].split("-")[1].split(".")[0]
|
|
315
317
|
result_dict[new_line[0]]["Signal_peptide"] = "Yes"
|
|
316
318
|
if_prot_SP[new_line[0]] = "Yes"
|
|
317
|
-
elif new_line[
|
|
319
|
+
elif new_line[0][0] != "#" :
|
|
318
320
|
result_dict[new_line[0]]["Signal_peptide"] = "No"
|
|
319
321
|
if_prot_SP[new_line[0]] = "No"
|
|
320
322
|
with open(f"log_file/{fasta_file}", "r") as fa_file :
|
|
@@ -415,7 +417,12 @@ def create_feature (file, Informations_dict, GPU, CPU, need_msa, need_pkl) :
|
|
|
415
417
|
logger.info(f"{len(need_pkl)} proteins need pkl files")
|
|
416
418
|
if os.path.exists(Path_Pickle_Feature) == False :
|
|
417
419
|
os.system(f"mkdir {Path_Pickle_Feature}")
|
|
418
|
-
|
|
420
|
+
|
|
421
|
+
os.environ.setdefault("ALPHAPULLDOWN_SPECIES_CACHE", os.path.abspath(f"{Path_Pickle_Feature}/uniprot_species_cache.sqlite")) #Shared UniProt accession -> taxid cache for every create_individual_features.py process
|
|
422
|
+
local_species_db = os.path.join(Path_Database, "uniref30_2302_species.sqlite")
|
|
423
|
+
if os.path.exists(local_species_db) :
|
|
424
|
+
os.environ.setdefault("ALPHAPULLDOWN_LOCAL_SPECIES_DB", os.path.abspath(local_species_db))
|
|
425
|
+
|
|
419
426
|
def AFDB_msa_search(Path_Pickle_Feature,prot_SP,prot_no_SP,generated_msa) :
|
|
420
427
|
retry_queue = list() #list of protein to retry if error during MSA search in AFdb (too many request on server)
|
|
421
428
|
with ThreadPoolExecutor(max_workers=max_workers_mafft) as executor :
|
|
@@ -1110,7 +1117,7 @@ def prioritize_by_vram_fit (jobs, first_batch, GPU, max_per_batch=3) :
|
|
|
1110
1117
|
all_batches.append(pending)
|
|
1111
1118
|
return all_batches
|
|
1112
1119
|
|
|
1113
|
-
def Generate_3D_model (HInt_object, CPU, multi_scoring, Informations_dict, interaction_type, job_with_vram_length, GPU, multi_job_per_gpu, seq_bait={}, compounds_dict={}) :
|
|
1120
|
+
def Generate_3D_model (HInt_object, CPU, multi_scoring, send_to_database, Informations_dict, interaction_type, job_with_vram_length, GPU, multi_job_per_gpu, seq_bait={}, compounds_dict={}) :
|
|
1114
1121
|
"""
|
|
1115
1122
|
Generate 3D models using multiple GPUs and multiprocessing.
|
|
1116
1123
|
|
|
@@ -1118,7 +1125,8 @@ def Generate_3D_model (HInt_object, CPU, multi_scoring, Informations_dict, inter
|
|
|
1118
1125
|
----------
|
|
1119
1126
|
HInt_object : HInt object
|
|
1120
1127
|
CPU : int
|
|
1121
|
-
multi_scoring :
|
|
1128
|
+
multi_scoring : str
|
|
1129
|
+
send_to_database : str
|
|
1122
1130
|
Informations_dict : dict
|
|
1123
1131
|
interaction_files : str
|
|
1124
1132
|
job_with_vram_length : list of tuple
|
|
@@ -1151,6 +1159,7 @@ def Generate_3D_model (HInt_object, CPU, multi_scoring, Informations_dict, inter
|
|
|
1151
1159
|
HInt_object=HInt_object,
|
|
1152
1160
|
CPU=CPU,
|
|
1153
1161
|
multi_scoring=multi_scoring,
|
|
1162
|
+
send_to_database=send_to_database,
|
|
1154
1163
|
Informations_dict=Informations_dict,
|
|
1155
1164
|
GPU=GPU,
|
|
1156
1165
|
max_vram=max_vram,
|
|
@@ -1163,7 +1172,7 @@ def Generate_3D_model (HInt_object, CPU, multi_scoring, Informations_dict, inter
|
|
|
1163
1172
|
stop_flag.set()
|
|
1164
1173
|
monitor.join()
|
|
1165
1174
|
|
|
1166
|
-
def manager (jobs_pending, HInt_object, CPU, multi_scoring, Informations_dict, GPU, max_vram, interaction_type, multi_job_per_gpu, seq_bait, compounds_dict) :
|
|
1175
|
+
def manager (jobs_pending, HInt_object, CPU, multi_scoring, send_to_database, Informations_dict, GPU, max_vram, interaction_type, multi_job_per_gpu, seq_bait, compounds_dict) :
|
|
1167
1176
|
"""
|
|
1168
1177
|
Manage repartition of jobs on GPUs, monitor VRAM usage, and handle job completion.
|
|
1169
1178
|
|
|
@@ -1173,6 +1182,7 @@ def manager (jobs_pending, HInt_object, CPU, multi_scoring, Informations_dict, G
|
|
|
1173
1182
|
HInt_object : HInt object
|
|
1174
1183
|
CPU : int
|
|
1175
1184
|
multi_scoring : str
|
|
1185
|
+
send_to_database : str
|
|
1176
1186
|
Informations_dict : dict
|
|
1177
1187
|
GPU : list
|
|
1178
1188
|
max_vram : float
|
|
@@ -1199,6 +1209,9 @@ def manager (jobs_pending, HInt_object, CPU, multi_scoring, Informations_dict, G
|
|
|
1199
1209
|
gpu_vram_used = {gpu: 0.0 for gpu in GPU}
|
|
1200
1210
|
jobs_running = {gpu: [] for gpu in GPU} # {gpu_id: {job_str: process}}
|
|
1201
1211
|
|
|
1212
|
+
scoring_pool = ThreadPoolExecutor(max_workers=1) #scoring in background, one at a time
|
|
1213
|
+
scoring_futures = []
|
|
1214
|
+
|
|
1202
1215
|
while jobs_pending or any(jobs_running.values()) :
|
|
1203
1216
|
|
|
1204
1217
|
while not result_queue.empty() :
|
|
@@ -1208,12 +1221,14 @@ def manager (jobs_pending, HInt_object, CPU, multi_scoring, Informations_dict, G
|
|
|
1208
1221
|
if j == job :
|
|
1209
1222
|
p.join()
|
|
1210
1223
|
jobs_running[gpu_id].pop(i)
|
|
1224
|
+
|
|
1211
1225
|
if status == "done" :
|
|
1212
|
-
Score_interaction
|
|
1213
|
-
|
|
1226
|
+
scoring_futures.append(scoring_pool.submit(Score_interaction, HInt_object, Informations_dict, CPU, interaction_type, send_to_database, job, multi_scoring, ""))
|
|
1227
|
+
|
|
1214
1228
|
elif status == "error" :
|
|
1215
1229
|
logger.error(f"Error {job}, put on the waiting list")
|
|
1216
1230
|
jobs_pending.append((job, v))
|
|
1231
|
+
|
|
1217
1232
|
break
|
|
1218
1233
|
|
|
1219
1234
|
launched = False
|
|
@@ -1242,7 +1257,7 @@ def manager (jobs_pending, HInt_object, CPU, multi_scoring, Informations_dict, G
|
|
|
1242
1257
|
|
|
1243
1258
|
free = max_vram - gpu_vram_used[gpu_id]
|
|
1244
1259
|
if job_vram <= free and (multi_job_per_gpu or len(jobs_running[gpu_id]) == 0) :
|
|
1245
|
-
|
|
1260
|
+
logger.info(f"[GPU {gpu_id}] VRAM available for scheduling: "
|
|
1246
1261
|
f"{free:.2f} GB"
|
|
1247
1262
|
)
|
|
1248
1263
|
|
|
@@ -1267,7 +1282,7 @@ def manager (jobs_pending, HInt_object, CPU, multi_scoring, Informations_dict, G
|
|
|
1267
1282
|
gpu_vram_used[gpu_id] += job_vram
|
|
1268
1283
|
jobs_running[gpu_id].append((interaction, p, job_vram))
|
|
1269
1284
|
jobs_pending.remove((interaction, job_vram))
|
|
1270
|
-
|
|
1285
|
+
logger.info(
|
|
1271
1286
|
f"[GPU {gpu_id}] Job started: '{interaction.strip()}' | "
|
|
1272
1287
|
f"PID: {p.pid} | "
|
|
1273
1288
|
f"Predicted VRAM: {job_vram:.2f} GB | "
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Build the local accession -> taxid database read instead of UniProt.
|
|
3
|
+
|
|
4
|
+
ColabFold ships, next to uniref30_2302, the taxonomy it uses to pair MSAs:
|
|
5
|
+
<db>_seq_h (+ .index) internal key -> header "UniRef100_<accession> ..."
|
|
6
|
+
<db>_mapping internal key -> NCBI taxid (binary MMseqs2 "TAXM")
|
|
7
|
+
Joining both gives accession -> taxid for the same UniRef release as the MSAs,
|
|
8
|
+
including accessions deleted from UniProt since then. The mapping taxid is
|
|
9
|
+
used; the header "TaxID=" is the fallback.
|
|
10
|
+
|
|
11
|
+
Run once (20 to 90 min, ~14 GB, plus as much temporary space next to --out):
|
|
12
|
+
build_local_species_db.py --colabfold-db-dir /path/to/database \
|
|
13
|
+
--out /path/to/database/uniref30_2302_species.sqlite
|
|
14
|
+
then point AlphaPulldown to it:
|
|
15
|
+
export ALPHAPULLDOWN_LOCAL_SPECIES_DB=/path/to/database/uniref30_2302_species.sqlite
|
|
16
|
+
|
|
17
|
+
Nothing in the ColabFold database directory is modified.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
import argparse
|
|
23
|
+
import mmap
|
|
24
|
+
import os
|
|
25
|
+
import sqlite3
|
|
26
|
+
import sys
|
|
27
|
+
import time
|
|
28
|
+
|
|
29
|
+
import numpy as np
|
|
30
|
+
|
|
31
|
+
# Must match alphapulldown/utils/mmseqs_species_identifiers.py.
|
|
32
|
+
LOCAL_SPECIES_DB_TABLE = "local_species_ids"
|
|
33
|
+
TAXM_MAGIC = 0x0C170013
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def log(message: str) -> None:
|
|
37
|
+
print(time.strftime("%H:%M:%S"), message, flush=True)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def open_taxonomy_mapping(path: str) -> tuple[np.ndarray, np.ndarray]:
|
|
41
|
+
"""Memory-map an MMseqs2 binary taxonomy mapping as (keys, taxids)."""
|
|
42
|
+
size = os.path.getsize(path)
|
|
43
|
+
with open(path, "rb") as handle:
|
|
44
|
+
head = handle.read(64)
|
|
45
|
+
if int.from_bytes(head[:4], "little") != TAXM_MAGIC:
|
|
46
|
+
raise ValueError(f"{path}: not a binary MMseqs2 taxonomy mapping")
|
|
47
|
+
# The (key, taxid) pairs follow a short header; keys read 0, 1, 2, ...
|
|
48
|
+
for offset in range(4, 17):
|
|
49
|
+
chunk = head[offset:offset + 24] # first three (key, taxid) pairs
|
|
50
|
+
if len(chunk) < 24 or (size - offset) % 8:
|
|
51
|
+
continue
|
|
52
|
+
pairs = np.frombuffer(chunk, dtype="<u4")
|
|
53
|
+
if list(pairs[0::2]) == [0, 1, 2]:
|
|
54
|
+
break
|
|
55
|
+
else:
|
|
56
|
+
raise ValueError(f"{path}: cannot locate the (key, taxid) pairs")
|
|
57
|
+
data = np.memmap(path, dtype="<u4", mode="r", offset=offset).reshape(-1, 2)
|
|
58
|
+
keys = data[:, 0]
|
|
59
|
+
sample = keys[:: max(1, len(keys) // 100000)].astype(np.int64)
|
|
60
|
+
if not np.all(np.diff(sample) > 0):
|
|
61
|
+
raise ValueError(f"{path}: keys are not sorted")
|
|
62
|
+
return keys, data[:, 1]
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def header_taxid(header: bytes) -> int:
|
|
66
|
+
start = header.find(b"TaxID=")
|
|
67
|
+
if start < 0:
|
|
68
|
+
return 0
|
|
69
|
+
start += 6
|
|
70
|
+
end = start
|
|
71
|
+
while end < len(header) and 48 <= header[end] <= 57:
|
|
72
|
+
end += 1
|
|
73
|
+
return int(header[start:end]) if end > start else 0
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def build_local_species_db(
|
|
77
|
+
colabfold_db_dir: str,
|
|
78
|
+
out_path: str,
|
|
79
|
+
*,
|
|
80
|
+
db_name: str = "uniref30_2302_db",
|
|
81
|
+
progress_every: int = 20_000_000,
|
|
82
|
+
) -> int:
|
|
83
|
+
"""Build the accession -> taxid SQLite database; return its row count."""
|
|
84
|
+
prefix = os.path.join(colabfold_db_dir, db_name)
|
|
85
|
+
for suffix in ("_seq_h", "_seq_h.index", "_mapping"):
|
|
86
|
+
if not os.path.exists(prefix + suffix):
|
|
87
|
+
raise FileNotFoundError(prefix + suffix)
|
|
88
|
+
keys, taxids = open_taxonomy_mapping(prefix + "_mapping")
|
|
89
|
+
log(f"taxonomy mapping: {len(keys):,} entries")
|
|
90
|
+
direct = len(keys) > 0 and int(keys[-1]) == len(keys) - 1
|
|
91
|
+
|
|
92
|
+
def mapped_taxid(key: int) -> int:
|
|
93
|
+
if direct:
|
|
94
|
+
return int(taxids[key]) if key < len(keys) else 0
|
|
95
|
+
row = int(np.searchsorted(keys, key))
|
|
96
|
+
return int(taxids[row]) if row < len(keys) and keys[row] == key else 0
|
|
97
|
+
|
|
98
|
+
out_path = os.path.abspath(os.path.expanduser(out_path))
|
|
99
|
+
out_dir = os.path.dirname(out_path)
|
|
100
|
+
os.makedirs(out_dir, exist_ok=True)
|
|
101
|
+
temp_path = out_path + ".building"
|
|
102
|
+
for leftover in (temp_path, temp_path + "-journal"):
|
|
103
|
+
if os.path.exists(leftover):
|
|
104
|
+
os.remove(leftover)
|
|
105
|
+
# Sorting for the index needs temporary space: keep it next to the output
|
|
106
|
+
# rather than in /tmp, which is often small on clusters.
|
|
107
|
+
os.environ.setdefault("SQLITE_TMPDIR", out_dir)
|
|
108
|
+
connection = sqlite3.connect(temp_path)
|
|
109
|
+
connection.execute("PRAGMA journal_mode=OFF")
|
|
110
|
+
connection.execute("PRAGMA synchronous=OFF")
|
|
111
|
+
connection.execute(
|
|
112
|
+
f"CREATE TABLE {LOCAL_SPECIES_DB_TABLE} "
|
|
113
|
+
"(accession TEXT NOT NULL, taxid INTEGER NOT NULL)"
|
|
114
|
+
)
|
|
115
|
+
insert = f"INSERT INTO {LOCAL_SPECIES_DB_TABLE} VALUES (?, ?)"
|
|
116
|
+
rows: list[tuple[str, int]] = []
|
|
117
|
+
count = scanned = 0
|
|
118
|
+
started = time.time()
|
|
119
|
+
with open(prefix + "_seq_h", "rb") as data_file, \
|
|
120
|
+
open(prefix + "_seq_h.index", "rb") as index_file:
|
|
121
|
+
data = mmap.mmap(data_file.fileno(), 0, access=mmap.ACCESS_READ)
|
|
122
|
+
try:
|
|
123
|
+
for line in index_file:
|
|
124
|
+
scanned += 1
|
|
125
|
+
key, offset, length = line.split(b"\t")
|
|
126
|
+
start = int(offset)
|
|
127
|
+
header = data[start:start + int(length)]
|
|
128
|
+
space = header.find(b" ")
|
|
129
|
+
name = header[: space if space > 0 else len(header)].rstrip(b"\x00\n")
|
|
130
|
+
if name.startswith(b"UniRef100_"):
|
|
131
|
+
name = name[10:]
|
|
132
|
+
taxid = mapped_taxid(int(key)) or header_taxid(header)
|
|
133
|
+
if taxid:
|
|
134
|
+
rows.append((name.decode(), taxid))
|
|
135
|
+
count += 1
|
|
136
|
+
if len(rows) >= 200_000:
|
|
137
|
+
connection.executemany(insert, rows)
|
|
138
|
+
rows.clear()
|
|
139
|
+
if progress_every and scanned % progress_every == 0:
|
|
140
|
+
log(f"{scanned:,} headers read, {count:,} rows "
|
|
141
|
+
f"({(time.time() - started) / 60:.0f} min)")
|
|
142
|
+
finally:
|
|
143
|
+
data.close()
|
|
144
|
+
if rows:
|
|
145
|
+
connection.executemany(insert, rows)
|
|
146
|
+
connection.commit()
|
|
147
|
+
log(f"indexing {count:,} rows ...")
|
|
148
|
+
connection.execute(
|
|
149
|
+
f"CREATE INDEX {LOCAL_SPECIES_DB_TABLE}_accession "
|
|
150
|
+
f"ON {LOCAL_SPECIES_DB_TABLE}(accession)"
|
|
151
|
+
)
|
|
152
|
+
connection.commit()
|
|
153
|
+
connection.close()
|
|
154
|
+
os.replace(temp_path, out_path)
|
|
155
|
+
log(f"local species database written: {out_path} "
|
|
156
|
+
f"({count:,} rows, {(time.time() - started) / 60:.0f} min)")
|
|
157
|
+
return count
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def check(out_path: str) -> bool:
|
|
161
|
+
"""Compare a few entries with the taxids UniProt gives."""
|
|
162
|
+
expected = {"Q96UW3": "5270", "A0A2K6Q9X5": "61622"}
|
|
163
|
+
connection = sqlite3.connect(f"file:{out_path}?mode=ro", uri=True)
|
|
164
|
+
ok = True
|
|
165
|
+
for accession, taxid in expected.items():
|
|
166
|
+
row = connection.execute(
|
|
167
|
+
f"SELECT taxid FROM {LOCAL_SPECIES_DB_TABLE} WHERE accession = ?",
|
|
168
|
+
(accession,),
|
|
169
|
+
).fetchone()
|
|
170
|
+
found = str(row[0]) if row else None
|
|
171
|
+
ok &= found == taxid
|
|
172
|
+
log(f"check {accession}: {found} "
|
|
173
|
+
+ ("OK" if found == taxid else f"unexpected (UniProt says {taxid})"))
|
|
174
|
+
connection.close()
|
|
175
|
+
return ok
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def main(argv: list[str] | None = None) -> int:
|
|
179
|
+
parser = argparse.ArgumentParser(
|
|
180
|
+
description=__doc__.split("\n\n")[0],
|
|
181
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
182
|
+
epilog=__doc__.split("\n\n", 1)[1],
|
|
183
|
+
)
|
|
184
|
+
parser.add_argument("--colabfold-db-dir", required=True,
|
|
185
|
+
help="folder holding uniref30_2302_db_seq_h and uniref30_2302_db_mapping")
|
|
186
|
+
parser.add_argument("--out", required=True, help="SQLite file to create")
|
|
187
|
+
parser.add_argument("--db-name", default="uniref30_2302_db")
|
|
188
|
+
parser.add_argument("--force", action="store_true",
|
|
189
|
+
help="rebuild even if --out already exists")
|
|
190
|
+
args = parser.parse_args(argv)
|
|
191
|
+
|
|
192
|
+
out_path = os.path.abspath(os.path.expanduser(args.out))
|
|
193
|
+
if os.path.exists(out_path) and not args.force:
|
|
194
|
+
log(f"{out_path} already exists (use --force to rebuild)")
|
|
195
|
+
return 0
|
|
196
|
+
try:
|
|
197
|
+
build_local_species_db(args.colabfold_db_dir, out_path, db_name=args.db_name)
|
|
198
|
+
except (FileNotFoundError, ValueError) as exc:
|
|
199
|
+
log(f"error: {exc}")
|
|
200
|
+
return 1
|
|
201
|
+
return 0
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
if __name__ == "__main__":
|
|
205
|
+
sys.exit(main())
|
|
@@ -5,8 +5,10 @@ setup.py
|
|
|
5
5
|
HInt/File_proteins.py
|
|
6
6
|
HInt/HInt.py
|
|
7
7
|
HInt/Scoring_HInt.py
|
|
8
|
+
HInt/Send_to_database.py
|
|
8
9
|
HInt/Utils_HInt.py
|
|
9
10
|
HInt/__init__.py
|
|
11
|
+
HInt/build_local_species_db.py
|
|
10
12
|
HInt/get_good_inter_pae.py
|
|
11
13
|
HInt/script_pi_score/__init__.py
|
|
12
14
|
HInt/script_pi_score/calculate_mpdockq.py
|
|
@@ -47,6 +47,7 @@ tar xvzf ccp4-9-setup.tar.gz
|
|
|
47
47
|
For optimal performance, store MMseqs2 database and MSAs on SSD storage rather than HDDs.<br>
|
|
48
48
|
|
|
49
49
|
```bash
|
|
50
|
+
conda activate HInt
|
|
50
51
|
wget https://raw.githubusercontent.com/Qrouger/HInt/main/setup_databases.sh
|
|
51
52
|
chmod +x setup_databases.sh
|
|
52
53
|
GPU=1 ./setup_databases.sh <DB_DIR>
|
|
@@ -113,17 +114,16 @@ HInt currently does not support multiple regions for bait proteins.
|
|
|
113
114
|
|
|
114
115
|
### Paths
|
|
115
116
|
|
|
116
|
-
- **
|
|
117
|
+
- **Path_Database** : Path to the HInt database (string).
|
|
117
118
|
|
|
118
119
|
- **Path_ccp4** : Path of CCP4 package (string). Default set on /opt/xtal/ccp4-9.
|
|
119
120
|
|
|
120
|
-
- **Path_MMseqs2_Data** : Path of GPU-indexed MMseqs2 database (string).
|
|
121
121
|
>[!NOTE]
|
|
122
122
|
>This path is not mandatory. If not set also MMseqs2-GPU will not be used.
|
|
123
123
|
|
|
124
124
|
- **Path_Uniprot_ID** : Path to the protein sequence file (string).
|
|
125
125
|
|
|
126
|
-
- **Path_Pickle_Feature** : Path where MSA files will be saved (string).
|
|
126
|
+
- **Path_Pickle_Feature** : Path where MSA and pkl files will be saved (string).
|
|
127
127
|
|
|
128
128
|
<br>
|
|
129
129
|
|
|
@@ -173,7 +173,7 @@ MNEVYVIAGGEWLRNNLNAIAAFMGTWTWDSIEKIALTLSVLAVAVMWVQRHNVMDLLGWVAVFVLISLLVNVRTSVQII
|
|
|
173
173
|
You need to be in the directory containing the HInt.txt file and activate the HInt Conda environment.
|
|
174
174
|
|
|
175
175
|
```bash
|
|
176
|
-
HInt --cpu <Integer> --gpu <Integer(s)> --multi_job_per_gpu <Boolean>
|
|
176
|
+
HInt --cpu <Integer> --gpu <Integer(s)> --multi_job_per_gpu <Boolean> --send_to_database <All,Negative,None>
|
|
177
177
|
```
|
|
178
178
|
<details>
|
|
179
179
|
<summary>Flag descriptions </summary>
|
|
@@ -187,6 +187,9 @@ HInt --cpu <Integer> --gpu <Integer(s)> --multi_job_per_gpu <Boolean>
|
|
|
187
187
|
|
|
188
188
|
# Allows multiple jobs to run on a single GPU, reducing time of modeling. By default set on True.
|
|
189
189
|
--multi_job_per_gpu : Boolean
|
|
190
|
+
|
|
191
|
+
# Allows to sending interaction generated in a public database (https://qsproteome.org/). All PPI, only negative PPI or none. By default set on None.
|
|
192
|
+
--send_to_database : All, Negative or None.
|
|
190
193
|
```
|
|
191
194
|
</details>
|
|
192
195
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|