Repository navigation
Read wrapped FASTA and reject malformed input instead of looping forever - #105
Merged
Merged
Conversation
The parser reads each record as one header line plus one sequence line and did not check either. A sequence line shorter than k underflowed its k-mer count (n - k + 1), so compute_minimizer_tuples never terminated and wrote temp files until the disk was full (e.g. for wrapped FASTA, whose lines get paired out of step). Now throw std::runtime_error if - an (unweighted) header line does not start with '>', - a sequence is shorter than k, - the last sequence line is not terminated by a newline (it used to be dropped silently). test_malformed_input caps RLIMIT_FSIZE, so a regression fails with SIGXFSZ instead of filling the disk. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A header at the end of the file without a sequence was silently dropped, and characters such as N were silently encoded as some other base. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A record's sequence now runs until the next '>' header or the end of the file, so wrapped (multi-line) FASTA is accepted instead of rejected. A header followed directly by another header is reported as a record with no sequence. The --check reader in check_from_file.hpp reads records the same way, so it no longer reports false errors on wrapped input. Co-Authored-By: Claude Opus 5.5 <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.
The FASTA parser in
encode_stringsreads each record as one header line plus one sequence line and checks neither (onlyassert(n >= k), which is compiled out in Release builds). Wrapped (multi-line) FASTA is a common input, and with it the lines get paired out of step. Headers are encoded as sequence, and eventually a line shorter than k is taken as a sequence. Thenn - k + 1underflows, the per-sequence loop incompute_minimizer_tuplesruns ~2^64 times, and each full buffer is flushed to a newsshash.tmp.run_*.minimizers.N.binfile. We hit this with a 100-transcript FASTA: about 1.4 TB of temp files in 20 minutes before the disk filled.This PR:
>header or the end of the file, so its lines are joined. Single-line input is parsed as before. This applies to weighted input too, whoseLN:i:length is then checked against the joined sequence;encode_stringsthrow astd::runtime_errorinstead of looping or silently misreading when:>(e.g. FASTQ);Nin DNA. Such characters were silently encoded as some other base or amino acid. The check is one table lookup per character while parsing.The
cf_segformat keeps its one-line-per-segment parsing. The--checkreader intest/check_from_file.hppreads FASTA records the same way, so it doesn't report false errors on wrapped input. Buildingecoli1_k31_ust.fa.gzandwith_weights/ecoli_sakai.ust.k31.fa.gzre-wrapped at 60 columns gives indexes byte-identical to the unwrapped builds, and--checkpasses on both.test/test_malformed_input.cppchecks each rejection and that a wrapped record is read as one sequence. It lowersRLIMIT_FSIZEto 64 MiB, so a regression fails with SIGXFSZ instead of filling the CI runner's disk.