Skip to content

Commit 023f6cc

Browse files
authored
Route predict_peptides_dataframe through canonical schema (fixes #193) (#197)
predict_peptides_dataframe (deprecated) returned the legacy BindingPrediction schema — missing predictor_version, kind, value, and using prediction_method_name instead of predictor_name. Meanwhile predict_proteins_dataframe / predict_dataframe emit the canonical mhctools.pred.COLUMNS schema. The asymmetry forced downstream consumers that treat predictions from either path uniformly (e.g. topiary's CachedPredictor design) to None-fill the missing identity columns. Fix: predict_peptides_dataframe now delegates to predict_dataframe, so both batch-dataframe paths emit the same columns. This is a schema change on an already-deprecated method. Callers that relied on the old legacy columns (affinity, prediction_method_name, length) should migrate to the canonical names (value, predictor_name) and add predictor_version / kind.
1 parent 206fd55 commit 023f6cc

2 files changed

Lines changed: 57 additions & 2 deletions

File tree

mhctools/base_predictor.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,17 @@ def predict_peptides(self, peptides):
197197
"%s must implement predict_peptides" % (self.__class__.__name__,))
198198

199199
def predict_peptides_dataframe(self, peptides):
200-
"""Deprecated: use predict_dataframe() instead."""
201-
return self.predict_peptides(peptides).to_dataframe()
200+
"""Deprecated: use predict_dataframe() instead.
201+
202+
Emits the canonical prediction schema (see ``mhctools.pred.COLUMNS``)
203+
for parity with ``predict_proteins_dataframe`` / ``predict_dataframe``.
204+
Previously this returned the legacy BindingPrediction schema
205+
(``source_sequence_name, offset, peptide, allele, score, affinity,
206+
percentile_rank, prediction_method_name, length``). That schema lacked
207+
``predictor_version``, ``kind``, ``value`` and used
208+
``prediction_method_name`` instead of ``predictor_name`` — see #193.
209+
"""
210+
return self.predict_dataframe(peptides)
202211

203212
def _check_peptide_lengths(self, peptide_lengths=None):
204213
"""
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License");
2+
# you may not use this file except in compliance with the License.
3+
# You may obtain a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
7+
"""Regression test for openvax/mhctools#193.
8+
9+
predict_peptides_dataframe (legacy/deprecated) and predict_proteins_dataframe
10+
(current) must emit the same canonical column schema so downstream code can
11+
treat rows from either path uniformly.
12+
"""
13+
14+
from mhctools import RandomBindingPredictor
15+
from mhctools.pred import COLUMNS
16+
17+
18+
def test_peptides_and_proteins_dataframes_share_schema():
19+
p = RandomBindingPredictor(
20+
alleles=["HLA-A*02:01"], default_peptide_lengths=[9],
21+
)
22+
df_peptides = p.predict_peptides_dataframe(["SIINFEKLA"])
23+
df_proteins = p.predict_proteins_dataframe({"src": "MASIINFEKLA"})
24+
25+
assert list(df_peptides.columns) == list(COLUMNS), (
26+
"predict_peptides_dataframe must emit canonical COLUMNS schema "
27+
"(was previously missing predictor_version, kind, value and used "
28+
"prediction_method_name; see #193)"
29+
)
30+
assert list(df_proteins.columns) == list(COLUMNS)
31+
assert list(df_peptides.columns) == list(df_proteins.columns)
32+
33+
34+
def test_peptides_dataframe_has_predictor_identity_columns():
35+
"""Downstream (e.g. topiary CachedPredictor) needs a stable
36+
(predictor_name, predictor_version) identity on every row."""
37+
p = RandomBindingPredictor(alleles=["HLA-A*02:01"], default_peptide_lengths=[9])
38+
df = p.predict_peptides_dataframe(["SIINFEKLA"])
39+
assert "predictor_name" in df.columns
40+
assert "predictor_version" in df.columns
41+
assert "kind" in df.columns
42+
assert "value" in df.columns
43+
# legacy name must not reappear
44+
assert "prediction_method_name" not in df.columns
45+
# canonical name is populated (RandomBindingPredictor sets it)
46+
assert df["predictor_name"].iloc[0] != ""

0 commit comments

Comments
 (0)