Don't save range in meta.json for features. Save PAE.png shorter to avoid too long names

This commit is contained in:
Dima Molodenskiy
2024-10-22 15:25:12 +02:00
parent 572087025f
commit cdc5253223
4 changed files with 95 additions and 45 deletions

View File

@@ -598,7 +598,7 @@ class AlphaFoldBackend(FoldingBackend):
for idx, model_name in enumerate(ranked_order):
prediction_result = prediction_results[model_name]
figure_name = os.path.join(
output_dir, f"{multimeric_object.description}_PAE_plot_ranked_{idx}.png")
output_dir, f"pae_plot_ranked_{idx}.png")
plot_pae_from_matrix(
seqs=prediction_result['seqs'],
pae_matrix=prediction_result['predicted_aligned_error'],

View File

@@ -224,12 +224,20 @@ def pre_modelling_setup(
if flags.use_ap_style:
output_dir = join(output_dir, object_to_model.description)
if len(output_dir) > 100:
raise ValueError(f"Output directory path is too long: {output_dir}."
"Please use a shorter path with --output_directory.")
makedirs(output_dir, exist_ok=True)
# Copy features metadata to output directory
for interactor in interactors:
for feature_dir in flags.features_directory:
# meta.json is named the same way as the pickle file
if isinstance(interactor, ChoppedObject):
description = interactor.description.split('_')[0]
elif isinstance(interactor, MonomericObject):
description = interactor.description
meta_json = glob.glob(
join(feature_dir, f"{interactor.description}_feature_metadata_*.json")
join(feature_dir, f"{description}_feature_metadata_*.json")
)
if meta_json:
feature_json = meta_json[0]

View File

@@ -42,7 +42,8 @@ class _TestBase(parameterized.TestCase):
# Get path of the alphapulldown module
alphapulldown_path = alphapulldown.__path__[0]
# Join the path with the script name
self.script_path = os.path.join(alphapulldown_path, "scripts/run_multimer_jobs.py")
self.script_path1 = os.path.join(alphapulldown_path, "scripts/run_multimer_jobs.py")
self.script_path2 = os.path.join(alphapulldown_path, "scripts/run_structure_prediction.py")
def _runCommonTests(self, result, multimer_mode, dirname=None):
print(result.stdout)
@@ -104,52 +105,92 @@ class _TestBase(parameterized.TestCase):
class TestRunModes(_TestBase):
def setUp(self) -> None:
super().setUp()
self.args = [
sys.executable,
self.script_path,
"--num_cycle=1",
"--num_predictions_per_model=1",
f"--data_dir={self.data_dir}",
f"--monomer_objects_dir={self.test_features_dir}",
"--job_index=1"
]
def tearDown(self) -> None:
# Remove the temporary directory
# shutil.rmtree(self.output_dir)
pass
def _build_args(self, protein_list, mode, script):
if script == 'run_multimer_jobs.py':
args = [
sys.executable,
self.script_path1,
"--num_cycle=1",
"--num_predictions_per_model=1",
f"--data_dir={self.data_dir}",
f"--monomer_objects_dir={self.test_features_dir}",
"--job_index=1",
f"--output_path={self.output_dir}",
]
# Set appropriate flag based on mode
flag = "--oligomer_state_file" if mode == "homo-oligomer" else "--protein_lists"
# Construct full path to protein list
protein_list_path = os.path.join(self.test_protein_lists_dir, protein_list)
# Extend arguments with mode and protein list
args.extend([
f"--mode={mode}",
f"{flag}={protein_list_path}",
])
elif script == 'run_structure_prediction.py':
args = [
sys.executable,
self.script_path2,
"--input=A0A075B6L2:10:1-3:4-5:6-7:7-8",
f"--output_directory={self.output_dir}",
"--num_cycle=1",
"--num_predictions_per_model=1",
f"--data_directory={self.data_dir}",
f"--features_directory={self.test_features_dir}",
]
return args
@parameterized.named_parameters(
{'testcase_name': 'monomer', 'protein_list': 'test_monomer.txt', 'mode': 'custom'},
{'testcase_name': 'dimer', 'protein_list': 'test_dimer.txt', 'mode': 'custom'},
{'testcase_name': 'trimer', 'protein_list': 'test_trimer.txt', 'mode': 'custom'},
{'testcase_name': 'homo_oligomer', 'protein_list': "test_homooligomer.txt", 'mode': 'homo-oligomer'},
{'testcase_name': 'chopped_dimer', 'protein_list': 'test_dimer_chopped.txt', 'mode': 'custom'}
{
'testcase_name': 'monomer',
'protein_list': 'test_monomer.txt',
'mode': 'custom',
'script': 'run_multimer_jobs.py',
},
{
'testcase_name': 'dimer',
'protein_list': 'test_dimer.txt',
'mode': 'custom',
'script': 'run_multimer_jobs.py',
},
{
'testcase_name': 'trimer',
'protein_list': 'test_trimer.txt',
'mode': 'custom',
'script': 'run_multimer_jobs.py',
},
{
'testcase_name': 'homo_oligomer',
'protein_list': "test_homooligomer.txt",
'mode': 'homo-oligomer',
'script': 'run_multimer_jobs.py',
},
{
'testcase_name': 'chopped_dimer',
'protein_list': 'test_dimer_chopped.txt',
'mode': 'custom',
'script': 'run_multimer_jobs.py',
},
{
'testcase_name': 'long_name',
'protein_list': 'test_long_name.txt',
'mode': 'custom',
'script': 'run_structure_prediction.py',
},
)
def test_(self, protein_list, mode):
"""Test run monomer structure prediction"""
#self.output_dir = f"{self.test_modelling_dir}" #Debug
self.args.append(f"--output_path={self.output_dir}")
flag = "--protein_lists"
if mode == "homo-oligomer":
flag = "--oligomer_state_file"
if "monomer" in protein_list:
multimer_mode = False
else:
multimer_mode = True
protein_list = os.path.join(self.test_protein_lists_dir, protein_list)
self.args.extend([
f"--mode={mode}",
f"{flag}={protein_list}",
])
def test_(self, protein_list, mode, script):
"""Test run monomer structure prediction."""
# Determine if multimer mode is enabled
multimer_mode = "monomer" not in protein_list
# Build arguments based on the script parameter
self.args = self._build_args(protein_list, mode, script)
# Execute the subprocess with the given arguments
result = subprocess.run(self.args, capture_output=True, text=True)
self._runCommonTests(result, multimer_mode)
class TestResume(_TestBase):
def setUp(self) -> None:
super().setUp()

View File

@@ -96,15 +96,16 @@ pytest -s test/check_predict_structure.py::{class_name}::{test_name}
subprocess.run(command, check=True)
@parameterized.named_parameters(
{"testcase_name": "monomer", "i": 1, "class_name": "TestRunModes", "test_name": "test__monomer"},
{"testcase_name": "dimer", "i": 2, "class_name": "TestRunModes", "test_name": "test__dimer"},
{"testcase_name": "trimer", "i": 3, "class_name": "TestRunModes", "test_name": "test__trimer"},
{"testcase_name": "monomer", "i": 0, "class_name": "TestRunModes", "test_name": "test__monomer"},
{"testcase_name": "dimer", "i": 1, "class_name": "TestRunModes", "test_name": "test__dimer"},
{"testcase_name": "trimer", "i": 2, "class_name": "TestRunModes", "test_name": "test__trimer"},
{"testcase_name": "chopped_dimer", "i": 3, "class_name": "TestRunModes", "test_name": "test__chopped_dimer"},
{"testcase_name": "homo_oligomer", "i": 4, "class_name": "TestRunModes", "test_name": "test__homo_oligomer"},
{"testcase_name": "no_relax", "i": 5, "class_name": "TestResume", "test_name": "test__no_relax"},
{"testcase_name": "relax_all", "i": 6, "class_name": "TestResume", "test_name": "test__relax_all"},
{"testcase_name": "continue_relax", "i": 7, "class_name": "TestResume", "test_name": "test__continue_relax"},
{"testcase_name": "continue_prediction", "i": 8, "class_name": "TestResume", "test_name": "test__continue_prediction"},
{"testcase_name": "long_name", "i": 9, "class_name": "TestRunModes", "test_name": "test__long_name"},
)
def test_predict_structure(self, i: int, class_name: str, test_name: str):
conda_env = os.environ.get('CONDA_DEFAULT_ENV')