Skip to content

Make alleles optional in command-line predictors (default None) - #265

Merged
iskandr merged 1 commit into
masterfrom
optional-alleles
Jul 11, 2026
Merged

Make alleles optional in command-line predictors (default None)#265
iskandr merged 1 commit into
masterfrom
optional-alleles

Conversation

@iskandr

@iskandr iskandr commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Motivation

A predictor built only to score explicit (peptide, allele) pairs via predict_pairs() still had to be handed a placeholder allele at construction — and for predictors that validate against the tool's -listMHC list, a valid one, because the constructor resolves alleles eagerly and raises UnsupportedAllele. In practice that forced awkward calls like NetMHCstabpan(alleles=[]).

Change

Default alleles=None (normalized to []) across the command-line predictors and their factories (NetMHCpan, NetMHC, NetMHCIIpan), so:

NetMHCstabpan().predict_pairs_dataframe(peptides, alleles, skip_unsupported=True)  # no placeholder
NetMHCpan().predict_pairs(pairs)

both work with no constructor alleles. Passing alleles still works unchanged.

The classic predict() / predict_peptides() path scores against self.alleles, and _allele_groups returns [] on empty — so with no alleles it would silently return nothing. A fail-loud _require_alleles() guard now raises there instead, preserving the loud failure the old required-argument gave for the forgot-the-alleles mistake:

ValueError: NetMHCpan42 was constructed without alleles; pass alleles=[...] to the
constructor, or use predict_pairs(peptides, alleles) to score explicit (peptide, allele) pairs.

NetMHCIIpanBase and BaseCommandlinePredictor stay required — they are internal bases that always receive alleles by keyword from their subclasses/factories, and each has a required positional (parse_output_fn) after alleles.

Scope is the command-line (BaseCommandlinePredictor) predictors, where the eager -listMHC validation makes the placeholder especially painful. BasePredictor gains the None → [] normalization (shared) but BigMHC / PRIME / MixMHC* signatures are left required for now — they take a different predict path without the shared guard.

Tests

New CI-safe cases (stub predictor, no binary): BasePredictor normalizes None/omitted/str alleles; predict_pairs works with empty constructor alleles; predict/predict_peptides raise ValueError (not silent-empty) with none. Full suite: 672 passed, 51 skipped, 2 xfailed. Also verified against the real binaries here (NetMHCstabpan() / NetMHCpan() construct, pair-score, and guard).

https://claude.ai/code/session_01SZZUQruWNznzAJSN4FpDGs

A predictor built only to score explicit (peptide, allele) pairs via
predict_pairs() still had to be given a placeholder allele at construction --
and for predictors that validate against the tool's -listMHC list, a *valid*
one, since the constructor resolves alleles eagerly and raises on an
unsupported name. That forced awkward calls like NetMHCstabpan(alleles=[]).

Default alleles=None (normalized to []) across the command-line predictors and
their factories, so NetMHCpan() / NetMHCstabpan() construct and predict_pairs()
works with no constructor alleles. The classic predict()/predict_peptides() path
scores against self.alleles, and _allele_groups returns [] on empty, so it would
silently return nothing; a fail-loud guard now raises there instead, preserving
the old loud failure for the forgot-the-alleles mistake.

NetMHCIIpanBase and BaseCommandlinePredictor stay required: they are internal
bases that always receive alleles by keyword from their subclasses/factories.

Claude-Session: https://claude.ai/code/session_01SZZUQruWNznzAJSN4FpDGs
@iskandr
iskandr merged commit 5024484 into master Jul 11, 2026
5 checks passed
@iskandr
iskandr deleted the optional-alleles branch July 11, 2026 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant