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
47 changes: 46 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,12 @@ df = ms.predict_dataframe(["SIINFEKL"])
df = ms.predict_proteins_dataframe({"TP53": "MEEPQ..."})
```

### Measurement kinds
### Measurement kinds and MHC context

Each `Prediction` has a `kind` string describing what it measures:

The canonical prediction kind strings are defined in `mhctools.pred.Kind`.

| Kind | Meaning |
|---|---|
| `pMHC_affinity` | Peptide-MHC binding affinity |
Expand All @@ -167,6 +169,49 @@ Each `Prediction` has a `kind` string describing what it measures:
| `tap_transport` | TAP transport score (reserved, not yet used) |
| `erap_trimming` | ERAP trimming score (reserved, not yet used) |

Predictors also expose `kind_support()` so downstream code can tell what MHC
context is meaningful for each emitted kind:

```python
support = predictor.kind_support()
support["pMHC_affinity"]
# {"mhc_dependence": "single_allele", "mhc_class": "I"}
```

`mhc_dependence` is one of:

| Value | Meaning |
|---|---|
| `none` | The prediction is MHC-independent; `Prediction.allele` is empty. |
| `single_allele` | The prediction is for one peptide/MHC allele pair; `Prediction.allele` is part of the key. |
| `haplotype` | The prediction uses the requested MHC repertoire jointly; `Prediction.allele` may carry best-allele attribution but is not the prediction key. |

`mhc_class` is one of `none`, `I`, `II`, or `both`.

The allowed metadata values are defined in `mhctools.pred` as
`MHC_DEPENDENCE_VALUES` and `MHC_CLASS_VALUES`.

Examples:

| Predictor | Kind | `mhc_dependence` | `mhc_class` |
|---|---|---|---|
| `NetMHCpan41` | `pMHC_affinity` | `single_allele` | `I` |
| `NetMHCpan41` | `pMHC_presentation` | `single_allele` | `I` |
| `NetMHCIIpan4_EL` | `pMHC_presentation` | `single_allele` | `II` |
| `NetMHCstabpan` | `pMHC_stability` | `single_allele` | `I` |
| `MHCflurry` | `pMHC_affinity` | `single_allele` | `I` |
| `MHCflurry` haplotype mode | `pMHC_presentation` | `haplotype` | `I` |
| `MHCflurry` per-allele panel mode | `pMHC_presentation` | `single_allele` | `I` |
| `Pepsickle` | `proteasome_cleavage` | `none` | `none` |

For MHCflurry presentation, `presentation_allele_mode="haplotype"` treats the
requested alleles as one sample genotype and emits one `pMHC_presentation`
record per peptide. The `allele` field carries MHCflurry's `best_allele`
attribution when available. `presentation_allele_mode="per_allele"` treats each
allele as a separate one-allele synthetic sample and emits one presentation
record per peptide/allele pair. The default `"auto"` mode uses haplotype mode
for up to six alleles and per-allele mode for larger allele panels.

### The Prediction object

Every prediction is a frozen, self-contained `Prediction` dataclass:
Expand Down
15 changes: 13 additions & 2 deletions mhctools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
from .binding_prediction import BindingPrediction
from .binding_prediction_collection import BindingPredictionCollection
from .pred import Prediction, Pred, PeptideResult, PeptidePreds, Kind, preds_from_rows
from .pred import (
Kind,
MHC_CLASS_VALUES,
MHC_DEPENDENCE_VALUES,
PeptidePreds,
PeptideResult,
Pred,
Prediction,
preds_from_rows,
)
from .sample import MultiSample
from .iedb import (
IedbNetMHCcons,
Expand Down Expand Up @@ -63,14 +72,16 @@ def __getattr__(name):
raise AttributeError(
"module %r has no attribute %r" % (__name__, name))

__version__ = "3.13.6"
__version__ = "3.13.7"

__all__ = [
"Prediction",
"Pred", # backward compat alias
"PeptideResult",
"PeptidePreds", # backward compat alias
"Kind",
"MHC_CLASS_VALUES",
"MHC_DEPENDENCE_VALUES",
"preds_from_rows",
"MultiSample",
"BindingPrediction",
Expand Down
21 changes: 20 additions & 1 deletion mhctools/base_predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@

from .unsupported_allele import UnsupportedAllele
from .binding_prediction_collection import BindingPredictionCollection
from .pred import Prediction, Kind, PeptideResult
from .pred import (
Kind,
PeptideResult,
Prediction,
)

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -101,6 +105,7 @@ class BasePredictor(object):
flank_length = 15
n_flank_length = None
c_flank_length = None
mhc_class = "I"

def __init__(
self,
Expand Down Expand Up @@ -331,6 +336,20 @@ def _default_pred_kind(self):
"""Override in subclasses to set the Kind for compat conversion."""
return Kind.pMHC_affinity

def kind_support(self):
"""Predictor-specific MHC context for supported prediction kinds."""
return {
self._default_pred_kind(): {
"mhc_dependence": "single_allele",
"mhc_class": self.mhc_class,
}
}

@property
def supported_kinds(self):
"""Prediction kind strings this predictor can emit."""
return tuple(self.kind_support())

# --- deprecated API (still works) ---

def predict_peptides(self, peptides):
Expand Down
19 changes: 18 additions & 1 deletion mhctools/bigmhc.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@
import pandas as pd
import torch

from .pred import Kind, Prediction, PeptideResult, COLUMNS
from .pred import (
COLUMNS,
Kind,
PeptideResult,
Prediction,
)


def _find_bigmhc_dir(bigmhc_path=None):
Expand Down Expand Up @@ -133,6 +138,18 @@ def _pred_kind(self):
return Kind.immunogenicity
return Kind.pMHC_presentation

def kind_support(self):
return {
self._pred_kind(): {
"mhc_dependence": "single_allele",
"mhc_class": "I",
}
}

@property
def supported_kinds(self):
return tuple(self.kind_support())

def _predictor_name(self):
return "bigmhc_%s" % self.mode

Expand Down
2 changes: 2 additions & 0 deletions mhctools/iedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ def __init__(
IEDB_MHC_CLASS_II_URL = "http://tools-cluster-interface.iedb.org/tools_api/mhcii/"

class IedbNetMHCIIpan(IedbBasePredictor):
mhc_class = "II"

def __init__(
self,
alleles,
Expand Down
Loading
Loading