Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mhctools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __getattr__(name):
raise AttributeError(
"module %r has no attribute %r" % (__name__, name))

__version__ = "3.31.0"
__version__ = "3.31.1"

__all__ = [
"Prediction",
Expand Down
9 changes: 2 additions & 7 deletions mhctools/netmhcstabpan.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,8 @@ def __init__(
length_flag="-l",
allele_flag="-a",
extra_flags=flags,
process_limit=process_limit)

def predict_peptides(self, peptides):
peptide_lengths = set(len(p) for p in peptides)
if len(peptide_lengths) > 1:
raise ValueError("All peptides must be the same length")
return super().predict_peptides(peptides)
process_limit=process_limit,
group_peptides_by_length=True)

def _default_pred_kind(self):
return Kind.pMHC_stability
Expand Down
42 changes: 41 additions & 1 deletion tests/test_netmhc_stabpan.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os

from numpy.testing import assert_allclose
from mhctools import NetMHCstabpan
from mhctools.base_commandline_predictor import BaseCommandlinePredictor
from mhctools.binding_prediction_collection import BindingPredictionCollection


DEFAULT_ALLELE = 'HLA-A*02:01'
Expand Down Expand Up @@ -58,4 +62,40 @@ def test_netmhc_stabpan_accuracy():
# This could be the result of different versions of dependencies or the nature of the ANN itself.
assert_allclose(expected, actual, atol=0.01, err_msg="Peptide %d: expected %f but got %f" % (i, expected, actual))



def test_netmhc_stabpan_groups_mixed_length_peptides(monkeypatch):
def fake_collect(self, commands, input_filenames, temp_dir_list,
sequence_key_mapping=None):
seen_groups = []
for path in input_filenames:
with open(path) as fd:
seen_groups.append([line.strip() for line in fd])
os.remove(path)
for output_file in commands:
output_file.close()
os.remove(output_file.name)
self.seen_groups = seen_groups
return BindingPredictionCollection([])

monkeypatch.setattr(
BaseCommandlinePredictor,
"_determine_supported_alleles",
staticmethod(lambda command, flag: {"HLA-A02:01"}))
monkeypatch.setattr(
NetMHCstabpan,
"_run_commands_and_collect_predictions",
fake_collect)
monkeypatch.setattr(
NetMHCstabpan,
"_check_results",
lambda self, binding_predictions, peptides, alleles: None)

predictor = NetMHCstabpan(alleles=[DEFAULT_ALLELE])
predictor.predict_peptides(["SIINFEKL", "SIINFEKLL", "SIINFEKLQY"])

assert predictor.group_peptides_by_length is True
assert sorted(predictor.seen_groups) == sorted([
["SIINFEKL"],
["SIINFEKLL"],
["SIINFEKLQY"],
])
Loading