Make info file offsets refer to the original read - #894
Open
cindykrafft wants to merge 1 commit into
Open
Conversation
When bases were removed from a read before adapter trimming (--cut, --quality-cutoff, --nextseq-trim), the adapter match coordinates refer to the shortened read, but the info file sliced the original read at those coordinates: the offsets in columns 3-4 were too small by the number of bases removed from the 5' end and columns 5-7 (and 9-11) showed the wrong sequences. ModificationInfo now records how many bases these modifiers removed from either end, and InfoFileWriter computes the records relative to the read the adapters were searched in and adds the removed bases back to the first record, so that the offsets and columns 5-7 refer to the original read as documented. Fixes marcelm#518 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TaHntBDKuZJpMAAMenkC44
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.
Fixes #518.
When bases are removed from a read before adapter trimming (
--cut,--quality-cutoff,--nextseq-trim), the adapter match coordinates refer to the shortened read, butInfoFileWriterslicedinfo.original_readat those coordinates. With-u 5 -a GATTACAonAAAAACCCCCCCCCCCGATTACAGGGG, the info file reported the match at 11–18 and showedCCCCCGAas the matched sequence instead of 16–23 andGATTACA; the same happens with 5' quality trimming.The fix records in
ModificationInfohow many basesUnconditionalCutter,QualityTrimmerandNextseqQualityTrimmerremoved from either end (removed_front,removed_back).InfoFileWritercomputes the records relative to the read the adapters were actually searched in (which also keeps--timesand linked-adapter rows correct) and adds the removed bases back to the first record, so that the offsets in columns 3–4 and the sequences in columns 5–7 (qualities in 9–11) refer to the original read, as the documentation says. With--revcompthe removed prefix and suffix swap roles.On your suggestion that all read modifications could result in a
MatchobjectThat is the more general fix, and it would also give #281 somewhere to live and make the row
count in #586 well defined. I did not take it here because
info.matchescurrently means"adapter matches" to four other places, and all of them would change behaviour:
DiscardUntrimmed.testisnot info.matches(predicates.py:153), so--discard-untrimmedand
--untrimmed-outputwould treat every read as trimmed as soon as-uor-qis in use;IsTrimmedinverts the same test;PrefixSuffixAdderandRenamerresolve{name},{adapter_name}and{match_sequence}from
info.matches[-1](modifiers.py:584,:775-777), which would become the cutter ratherthan the adapter;
Each of those is solvable, with a separate list or a type check at those four sites, but it is a
larger change than I wanted to make unasked and it settles the info-file format along the way.
This PR keeps the current format and only corrects the coordinates. If you would rather have the
Match-object version, I am glad to rework it that way.Tests:
test_info_file_offsets_after_cut_or_quality_trim(-u 5,-u -3,-q 20,20,--nextseq-trim 20,-u 5 --revcomp),test_info_file_offsets_after_cut_reverse_complemented(read actually reverse-complemented, with-u -3 -q 20,0) andtest_info_file_offsets_after_cut_times(--times 2, FASTA); the two modifier tests assert the new counters. Five of the info-file cases and both modifier tests fail onmain. The full suite passes (710 passed;test_run_cutadapt_processfails in my environment only becausecutadaptis not onPATH).black --check(22.3.0),flake8andmypy src/are clean. A changelog entry and a sentence in the info-file format reference are included.Found while working through open issues in Mytochondria, a volunteer project that verifies fixes for the software behind published results (methods and harnesses: https://github.com/cindykrafft/mytochondria/tree/main/audits/cutadapt)
Generated by Claude Code