From e58705b309393c27d3b0879eac2683c8e329bb7a Mon Sep 17 00:00:00 2001 From: sixty-66 Date: Mon, 9 Nov 2026 02:51:28 +0000 Subject: [PATCH] Fix PDB and mmCIF query directories Import the structure parser in the directory branch and stop structure inputs from falling through to FASTA processing. Cover real structure fixtures and mixed directory traversal orders. --- colabfold/input.py | 3 +++ tests/test_input.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 tests/test_input.py diff --git a/colabfold/input.py b/colabfold/input.py index 387f2f99d..bd16ad362 100644 --- a/colabfold/input.py +++ b/colabfold/input.py @@ -338,6 +338,8 @@ def get_queries( logger.warning(f"non-fasta/a3m/pdb/cif file in input directory: {file}") continue if file.suffix.lower() in [".pdb", ".cif"]: + from alphafold.common import protein + header = file.stem if file.suffix.lower() == ".pdb": pdb_string = pdb_to_string(file.read_text()) @@ -351,6 +353,7 @@ def get_queries( continue queries.append((header, sequences, None, None)) + continue else: # file.suffix.lower() in [".a3m", ".fasta", ".faa"] (seqs, header) = parse_fasta(file.read_text()) if len(seqs) == 0: diff --git a/tests/test_input.py b/tests/test_input.py new file mode 100644 index 000000000..48497d879 --- /dev/null +++ b/tests/test_input.py @@ -0,0 +1,43 @@ +import shutil + +import pytest + +from colabfold.input import get_queries + + +STRUCTURE_SEQUENCE = ( + "CPSGWVGFSDNCYQWNSQKLTWSDAREFCNNHEADLVSIHSDLENNFISYQLSPKKQRFWIGTQRKAT" + "GSTEWLWTDGSSFDYENFCQGKLDNWLGNQDCLDIGYTWGSQCSRDTWDDQPCDHQLPFVCK" +) + + +@pytest.mark.parametrize("suffix", [".pdb", ".cif", ".PDB", ".CIF"]) +def test_get_queries_structure_dir(pytestconfig, tmp_path, suffix): + source = pytestconfig.rootpath.joinpath( + f"test-data/ERR550519_2213899_unrelaxed_model_1{suffix.lower()}" + ) + shutil.copyfile(source, tmp_path.joinpath(f"structure{suffix}")) + + queries, is_complex = get_queries(tmp_path) + + assert queries == [("structure", [STRUCTURE_SEQUENCE], None, None)] + assert is_complex + + +@pytest.mark.parametrize("suffix", [".pdb", ".cif"]) +@pytest.mark.parametrize("fasta_first", [True, False]) +def test_get_queries_mixed_structure_dir(pytestconfig, tmp_path, suffix, fasta_first): + source = pytestconfig.rootpath.joinpath( + f"test-data/ERR550519_2213899_unrelaxed_model_1{suffix}" + ) + shutil.copyfile(source, tmp_path.joinpath(f"1_structure{suffix}")) + fasta_name = "0_fasta" if fasta_first else "2_fasta" + tmp_path.joinpath(f"{fasta_name}.fasta").write_text(">query\nACDEFG\n") + + queries, is_complex = get_queries(tmp_path) + + assert queries == [ + (fasta_name, "ACDEFG", None, None), + ("1_structure", [STRUCTURE_SEQUENCE], None, None), + ] + assert is_complex