Skip to content

Skip inter-block header lines in multi-allele NetMHCpan output (fixes #195) - #196

Merged
iskandr merged 1 commit into
masterfrom
fix-195-multi-allele-parsing
Apr 15, 2026
Merged

Skip inter-block header lines in multi-allele NetMHCpan output (fixes #195)#196
iskandr merged 1 commit into
masterfrom
fix-195-multi-allele-parsing

Conversation

@iskandr

@iskandr iskandr commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

Fixes #195.

Summary

When NetMHCpan is run with multiple alleles in one invocation, each per-allele result block is preceded by a line like:

```
HLA-A24:02 : Distance to training data 0.000 (using nearest neighbor HLA-A24:02)
```

For single-allele runs this line appears before the first `---` separator and is already skipped. For multi-allele runs the second-and-subsequent ones appear after a separator, so they passed through `split_stdout_lines` and `parse_stdout` crashed converting `HLA-A24:02` to an integer Pos.

Fix

In `split_stdout_lines`, after the existing comment/separator/header-token filters, also drop any line whose first token isn't an integer. `.lstrip("-").isdigit()` preserves support for NetMHC 4.0's negative positions in peptide-input mode (already explicitly accommodated in that module's comment).

Test plan

  • New regression test `test_multi_allele_netmhcpan41_skips_interblock_headers` in `tests/test_mhc_formats.py` — parses a two-allele NetMHCpan 4.1 output with the offending inter-block "Distance to training data" line, asserts 2 rows come out with both alleles.
  • Reproduced exact error from the issue (`ValueError: invalid literal for int() with base 10: 'HLA-A24:02'`) before the fix; test passes after.
  • Full existing parser-test suite (`test_mhc_formats.py`, `test_class2_allele_formats.py`) still passes — 33 tests.

When NetMHCpan is run with multiple alleles in a single invocation,
each per-allele result block is preceded by a line of the form
"HLA-X : Distance to training data ..." *after* the first `---`
separator. The existing split_stdout_lines filter only dropped
comments, empty lines, dash-separator lines, and lines starting with
a known header token — "Distance to training data" lines slipped
through and the parser crashed trying to convert "HLA-A24:02" to an
int for the Pos column.

Fix: after the other filters, also skip any line whose first token
isn't an integer (possibly negative, to preserve the existing support
for NetMHC 4.0's peptide-mode negative positions).

Regression test parses a two-allele NetMHCpan 4.1 output containing
the offending header line.
@iskandr
iskandr merged commit 6c6ec95 into master Apr 15, 2026
4 checks passed
@iskandr
iskandr deleted the fix-195-multi-allele-parsing branch April 15, 2026 18:05
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.

parse_netmhcpan_stdout crashes on multi-allele NetMHCpan output

1 participant