Detect swapped arguments, harden error reporting, and add NO_COLOR support#80
Open
mmokrejs wants to merge 2 commits into
Open
Detect swapped arguments, harden error reporting, and add NO_COLOR support#80mmokrejs wants to merge 2 commits into
mmokrejs wants to merge 2 commits into
Conversation
When the query file contains DNA instead of protein sequences (>80%
A/C/G/T/N residues), miniprot now emits a clear error message and
returns exit code 1. Previously, swapping the <ref.fa> and <query.faa>
arguments would cause miniprot to silently run to completion with exit
code 0, producing no useful output.
The check is performed once on the first batch of query sequences.
If the composition is >80% nucleotide characters, the mapping is
aborted immediately with:
[ERROR] query file appears to contain DNA, not protein sequences.
Did you swap the arguments? Usage: miniprot <ref.fa> <query.faa>
This makes it straightforward for wrapper scripts to detect the
failure via subprocess return code.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 27 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
9893016 to
c9b3e4b
Compare
Build on the DNA-in-protein detection from the previous commit: - Unrecognized options now exit non-zero (previously continued silently with exit 0, dangerous for pipeline callers) - Missing query/reference file arguments produce specific error messages instead of just dumping usage - Index load and mapping failures include the filename in the error - Deprecated -s option is a hard error instead of a silent no-op - ALL atoi()/atof() calls are now validated: passing invalid values like --outs=abc is caught with a clear error message and exit code 1 - Respect NO_COLOR (https://no-color.org/): ANSI color escapes are suppressed when NO_COLOR is set or stderr is not a terminal. All hardcoded \033[1;31m escapes across main.c, map.c, bseq.c, and options.c are replaced with MP_COLOR_RED/MP_COLOR_RESET macros. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR improves miniprot's error handling for pipeline callers that rely on exit codes and stderr messages.
Commit 1: Detect DNA queries and exit with non-zero code
When the query file contains DNA instead of protein sequences (>80% A/C/G/T/N residues), miniprot now emits a clear error message and returns exit code 1. Previously, swapping the
<ref.fa>and<query.faa>arguments would cause miniprot to silently run to completion with exit code 0, producing no useful output.Commit 2: Harden argument validation, error reporting, and NO_COLOR support
[ERROR] missing query protein fileor[ERROR] missing argumentsbefore the usage.-s→ hard error: Was silently ignored; now exits with a clear deprecation message.atoi()/atof()calls: Passing invalid values like--outs=abcnow produces[ERROR] invalid numeric value 'abc' for --outsinstead of silently setting the value to 0.\033[1;31mANSI escapes acrossmain.c,map.c,bseq.c, andoptions.care replaced withMP_COLOR_RED/MP_COLOR_RESETmacros that respect theNO_COLORenvironment variable andisatty(stderr).Motivation
When miniprot is called from a bioinformatics pipeline (e.g., via
subprocess.run(..., check=True)in Python), the caller relies on the exit code to detect failures. The current behavior of returning exit 0 on swapped arguments, unrecognized options, or invalid numeric values makes it impossible to reliably detect misconfigurations.Testing
Verified with 9 functional tests covering all error paths and normal operation.