Skip to content

Commit 10574e9

Browse files
author
James Parkhurst
authored
Merge branch 'alan-turing-institute:main' into main
2 parents b566fd4 + 896b9f3 commit 10574e9

File tree

3 files changed

+162
-365
lines changed

3 files changed

+162
-365
lines changed

_tests/test_io.py

Lines changed: 45 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -158,60 +158,52 @@ def test_command_line_main(tmpdir, test_id):
158158
assert os.path.exists(filename)
159159

160160

161-
def get_cleave_ids():
162-
test_id_map = {
163-
"alphafold": ["P0A855_cleaved_1to21", "P21170_cleaved_none"],
164-
"pdb": ["P0A855_1c5k_cleaved_1to21", "P21170_3nzq_cleaved_none"],
165-
}
166-
for source, test_id_list in test_id_map.items():
167-
for test_id in test_id_list:
168-
yield source, test_id
161+
@pytest.mark.parametrize(
162+
"signal_peptides, hydrogens, water, hetatoms, expected_filename_suffix",
163+
[
164+
(True, True, True, True, "nosignal1to25_nohydrogens_nowater_nohetatm"),
165+
(False, True, True, True, "nohydrogens_nowater_nohetatm"),
166+
(True, False, True, True, "nosignal1to25_nowater_nohetatm"),
167+
(True, True, False, True, "nosignal1to25_nohydrogens_nohetatm"),
168+
(True, True, True, False, "nosignal1to25_nohydrogens_nowater"),
169+
(
170+
False,
171+
False,
172+
False,
173+
False,
174+
"unmodified",
175+
),
176+
],
177+
)
178+
def test_fetcher_remove_stuff(
179+
tmpdir,
180+
signal_peptides,
181+
hydrogens,
182+
water,
183+
hetatoms,
184+
expected_filename_suffix,
185+
):
186+
fetcher = Fetcher()
187+
fetcher.set_directory(str(tmpdir))
169188

189+
# Fetch the file
190+
fetcher.get_file(
191+
uniprot_id="P45523", filetype="pdb", filesave=True, db="pdb"
192+
)
170193

171-
def remove_suffixes(ids):
172-
# Define patterns to match "_none" and "_1to21" at the end of the string
173-
patterns = [r"_cleaved_none$", r"_cleaved_1to21$"]
174-
# Apply each pattern and remove matching suffixes
175-
for pattern in patterns:
176-
ids = re.sub(pattern, "", ids)
177-
return ids
194+
# Remove elements based on the test parameters
195+
fetcher.remove(
196+
"P45523",
197+
signal_peptides=signal_peptides,
198+
hydrogens=hydrogens,
199+
water=water,
200+
hetatoms=hetatoms,
201+
)
178202

203+
# Construct the expected filename
204+
expected_filename = os.path.join(
205+
str(tmpdir), f"p45523_1q6u_{expected_filename_suffix}.pdb"
206+
)
179207

180-
@pytest.mark.parametrize("test_id", get_cleave_ids())
181-
def test_fetcher_cleave_off_signal_peptides_pdb(tmpdir, test_id):
182-
source, pdb_id_signals = test_id
183-
pdb_id = remove_suffixes(pdb_id_signals)
184-
fetcher = Fetcher(source)
185-
fetcher.set_directory(str(tmpdir))
186-
if source == "pdb":
187-
pdb_id = pdb_id[:-5]
188-
fetcher.get_file(
189-
uniprot_id=pdb_id, filetype="pdb", filesave=True, db=source
190-
)
191-
fetcher.cleave_off_signal_peptides(pdb_id)
192-
else:
193-
fetcher.get_file(
194-
uniprot_id=pdb_id, filetype="pdb", filesave=True, db=source
195-
)
196-
fetcher.cleave_off_signal_peptides(pdb_id)
197-
assert os.path.exists(str(tmpdir) + "/" + pdb_id_signals.lower() + ".pdb")
198-
199-
200-
@pytest.mark.parametrize("test_id", get_cleave_ids())
201-
def test_fetcher_cleave_off_signal_peptides_cif(tmpdir, test_id):
202-
source, pdb_id_signals = test_id
203-
pdb_id = remove_suffixes(pdb_id_signals)
204-
fetcher = Fetcher(source)
205-
fetcher.set_directory(str(tmpdir))
206-
if source == "pdb":
207-
pdb_id = pdb_id[:-5]
208-
fetcher.get_file(
209-
uniprot_id=pdb_id, filetype="cif", filesave=True, db=source
210-
)
211-
fetcher.cleave_off_signal_peptides(pdb_id)
212-
else:
213-
fetcher.get_file(
214-
uniprot_id=pdb_id, filetype="cif", filesave=True, db=source
215-
)
216-
fetcher.cleave_off_signal_peptides(pdb_id)
217-
assert os.path.exists(str(tmpdir) + "/" + pdb_id_signals.lower() + ".cif")
208+
# Assert that the expected file exists
209+
assert os.path.exists(expected_filename)

0 commit comments

Comments
 (0)