Skip to content

Commit

Permalink
allow wrong program name to be FileNotFoundError in test
Browse files Browse the repository at this point in the history
  • Loading branch information
iskandr committed Mar 15, 2024
1 parent 4ac19e4 commit c24b598
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 38 deletions.
30 changes: 11 additions & 19 deletions tests/test_known_class1_epitopes.py
Expand Up @@ -13,19 +13,10 @@
"""
Make sure all class I binding predictors give a high IC50 and percentile rank.
"""
import pytest
import mhctools
from .predictor_classes import mhc1_predictor_classes

mhc_classes = [
mhctools.NetMHCcons,
mhctools.NetMHCpan,
mhctools.NetMHC,
mhctools.NetMHC3,
mhctools.NetMHC4,
mhctools.IedbNetMHCcons,
mhctools.IedbNetMHCpan,
mhctools.IedbSMM,
mhctools.IedbSMM_PMBEC,
]

# Tests assume that a netMHC-3.4 binary exists, and that netMHC is 4.0.
program_name_overrides = {mhctools.NetMHC3: "netMHC-3.4"}
Expand All @@ -41,18 +32,19 @@ def make_mhc_model(mhc_class, alleles):
kwargs.update({"program_name": program_name_overrides[mhc_class]})
return mhc_class(**kwargs)

def test_MAGE_epitope():

@pytest.mark.parametrize("mhc_class", mhc1_predictor_classes)
def test_MAGE_epitope(mhc_class):
# Test the A1 MAGE epitope ESDPIVAQY from
# Identification of a Titin-Derived HLA-A1-Presented Peptide
# as a Cross-Reactive Target for Engineered MAGE A3-Directed
# T Cells
for mhc_class in mhc_classes:
mhc_model = make_mhc_model(mhc_class, "HLA-A*01:01")
expect_binder(mhc_model, "ESDPIVAQY")
mhc_model = make_mhc_model(mhc_class, "HLA-A*01:01")
expect_binder(mhc_model, "ESDPIVAQY")

def test_HIV_epitope():
@pytest.mark.parametrize("mhc_class", mhc1_predictor_classes)
def test_HIV_epitope(mhc_class):
# Test the A2 HIV epitope SLYNTVATL from
# The HIV-1 HLA-A2-SLYNTVATL Is a Help-Independent CTL Epitope
for mhc_class in mhc_classes:
mhc_model = make_mhc_model(mhc_class, "HLA-A*02:01")
expect_binder(mhc_model, "SLYNTVATL")
mhc_model = make_mhc_model(mhc_class, "HLA-A*02:01")
expect_binder(mhc_model, "SLYNTVATL")
16 changes: 7 additions & 9 deletions tests/test_known_class2_epitopes.py
Expand Up @@ -13,12 +13,9 @@
"""
Make sure all class II binding predictors give a high IC50 and percentile rank.
"""
import mhctools
import pytest
from .predictor_classes import mhc2_predictor_classes

mhc_classes = [
mhctools.NetMHCIIpan,
mhctools.IedbNetMHCIIpan,
]

def expect_binder(mhc_model, peptide):
prediction = mhc_model.predict(peptide)[0]
Expand All @@ -29,11 +26,12 @@ def expect_binder(mhc_model, peptide):
assert prediction.percentile_rank < 5, "Expected %s to have percent rank < 3, got %s" % (
peptide, prediction)

def test_Gag_epitope():

@pytest.mark.parametrize("mhc_class", mhc2_predictor_classes)
def test_Gag_epitope(mhc_class):
# Test the DRB1*04:01 HIV epitope LERFAVNPGLLETSE from
# Dendritic Cell Mediated Delivery of Plasmid DNA Encoding LAMP/HIV-1 Gag
# Fusion Immunogen Enhances T Cell Epitope Responses in HLA DR4
# Transgenic Mice
for mhc_class in mhc_classes:
mhc_model = mhc_class("HLA-DRB1*04:01", default_peptide_lengths=15)
expect_binder(mhc_model, "LERFAVNPGLLETSE")
mhc_model = mhc_class("HLA-DRB1*04:01", default_peptide_lengths=15)
expect_binder(mhc_model, "LERFAVNPGLLETSE")
4 changes: 3 additions & 1 deletion tests/test_netchop.py
Expand Up @@ -10,9 +10,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import pytest
from numpy import testing

from mhctools import NetChop
from .arch import apple_silicon

# Peptides from http://tools.iedb.org/netchop/example/
peptides = """
Expand All @@ -22,6 +23,7 @@
""".strip().split()


@pytest.mark.skipif(apple_silicon, "Can't run netChop on arm64 architecture")
def test_simple():
obj = NetChop()
result = obj.predict(peptides)
Expand Down
11 changes: 7 additions & 4 deletions tests/test_netmhc_cons.py
Expand Up @@ -11,12 +11,16 @@
# limitations under the License.


import pytest

from mhctools import NetMHCcons
from mhcnames import normalize_allele_name

from .arch import apple_silicon

DEFAULT_ALLELE = 'HLA-A*02:01'

@pytest.mark.skipif(apple_silicon, "Can't run netMHCcons on arm64 architecture")
def test_netmhc_cons():
alleles = [normalize_allele_name(DEFAULT_ALLELE)]
cons_predictor = NetMHCcons(
Expand All @@ -32,13 +36,15 @@ def test_netmhc_cons():
assert len(binding_predictions) == 4, \
"Expected 4 epitopes from %s" % (binding_predictions,)

@pytest.mark.skipif(apple_silicon, "Can't run netMHCcons on arm64 architecture")
def test_netmhc_cons_multiple_lengths():
cons_predictor = NetMHCcons(alleles=["A6801"])
binding_predictions = cons_predictor.predict_peptides(
["A" * 8, "A" * 9, "A" * 10, "A" * 11])
assert len(binding_predictions) == 4, \
"Expected 4 epitopes from %s" % (binding_predictions,)

@pytest.mark.skipif(apple_silicon, "Can't run netMHCcons on arm64 architecture")
def test_netmhc_cons_multiple_alleles():
alleles = 'A*02:01,B*35:02'
cons_predictor = NetMHCcons(
Expand All @@ -53,6 +59,7 @@ def test_netmhc_cons_multiple_alleles():
assert len(binding_predictions) == 8, \
"Expected 4 binding predictions from %s" % (binding_predictions,)

@pytest.mark.skipif(apple_silicon, "Can't run netMHCcons on arm64 architecture")
def test_netmhc_cons_process_limits():
alleles = [normalize_allele_name(DEFAULT_ALLELE)]
sequence_dict = {
Expand Down Expand Up @@ -84,7 +91,3 @@ def test_netmhc_cons_process_limits():
("Expected each fasta key to appear twice, once for "
"each length, but saw %s %d time(s)" % (
fasta_key, fasta_count))

if __name__ == "__main__":
test_netmhc_cons()
test_netmhc_cons_process_limits()
24 changes: 22 additions & 2 deletions tests/test_netmhc_pan.py
Expand Up @@ -15,8 +15,6 @@
from mhctools import NetMHCpan




DEFAULT_ALLELE = 'HLA-A*02:01'

protein_sequence_dict = {
Expand Down Expand Up @@ -67,3 +65,25 @@ def check_netmhc_pan(program_name, fail_if_no_such_program=True):
eq_(expected_peptide, x.peptide,
"Peptide mismatch: expected %s but got %s in binding prediction '%s'" % (
expected_peptide, x.peptide, x,))


def test_netmhc_pan_multiple_lengths():
predictor = NetMHCpan(alleles=["A6801"])
binding_predictions = predictor.predict_peptides(
["A" * 8, "A" * 9, "A" * 10, "A" * 11])
assert len(binding_predictions) == 4, \
"Expected 4 epitopes from %s" % (binding_predictions,)

def test_netmhc_pan_multiple_alleles():
alleles = 'A*02:01,B*35:02'
predictor = NetMHCpan(
alleles=alleles,
default_peptide_lengths=[9])
sequence_dict = {
"SMAD4-001": "ASIINFKELA",
"TP53-001": "ASILLLVFYW"
}
binding_predictions = predictor.predict_subsequences(
sequence_dict=sequence_dict)
assert len(binding_predictions) == 8, \
"Expected 4 binding predictions from %s" % (binding_predictions,)
13 changes: 10 additions & 3 deletions tests/test_netmhc_version.py
@@ -1,7 +1,8 @@

import pytest
from mhctools import NetMHC, NetMHC3, NetMHC4
from mhcnames import normalize_allele_name
from .common import raises, eq_
from .arch import apple_silicon


def run_class_with_executable(mhc_class, mhc_executable):
Expand All @@ -21,30 +22,36 @@ def run_class_with_executable(mhc_class, mhc_executable):
def test_executable_mismatch_3_4():
run_class_with_executable(NetMHC3, "netMHC")

@pytest.mark.skipif(apple_silicon, "Can't run netMHC-3.4 on arm64 architecture")
@raises(SystemError)
def test_executable_mismatch_4_3():
run_class_with_executable(NetMHC4, "netMHC-3.4")

def test_wrapper_function():
def test_wrapper_function_netMHC4():
alleles = [normalize_allele_name("HLA-A*02:01")]
wrapped_4 = NetMHC(
alleles=alleles,
default_peptide_lengths=[9],
program_name="netMHC")
eq_(type(wrapped_4), NetMHC4)

@pytest.mark.skipif(apple_silicon, "Can't run netMHC-3.4 on arm64 architecture")
def test_wrapper_function_netMHC3():
alleles = [normalize_allele_name("HLA-A*02:01")]
wrapped_3 = NetMHC(
alleles=alleles,
default_peptide_lengths=[9],
program_name="netMHC-3.4")
eq_(type(wrapped_3), NetMHC3)

@raises(SystemError, OSError)
@raises(SystemError, OSError, FileNotFoundError)
def test_wrapper_failure():
alleles = [normalize_allele_name("HLA-A*02:01")]
NetMHC(alleles=alleles,
default_peptide_lengths=[9],
program_name="netMHC-none")

@pytest.mark.skipif(apple_silicon, "Can't run netMHC-3.4 on arm64 architecture")
def test_multiple_lengths_netmhc3():
alleles = [normalize_allele_name("H-2-Kb")]
predictor = NetMHC3(alleles=alleles,
Expand Down

0 comments on commit c24b598

Please sign in to comment.