Repository navigation
map: quantification score with an end fit for reads without a poly(A) tail, and antisense evidence - #39
Merged
Conversation
… tail Every hit gets a second score, the quantification score (`qscore`): the mapping score plus `--end-fit` points (5) for the candidates whose annotated 3' end a read without a poly(A) tail reaches, when at least two hits lie within the tie-break margin and their 3' ends lie farther apart than `--end-fit-tol` (4 compressed bases). Without a tail, isoforms that differ only in their 3' end and antisense transcripts on opposite strands tie, and a quantifier tends to give their reads to the transcript with more unique reads; the quantification score tilts them toward the candidates the read fits. The mapping score, ranks, best set, primary hit and orientation are unchanged, so mapping output is the same as in 0.2.1; only the score a quantifier weighs hits by differs. The read end is measured from the alignment of the read's right end, or, in the drna preset (spans not extended), from each candidate's chain (`--end-fit-chain`; `--no-end-fit-chain` aligns). Off in the -fast presets. Output: TSV column `qscore`, PAF tag `qs:f`, optional RAD alignment tag `qscore` (file tag `quant_scores`), `Hit::quant_score`, and in Python `Hit.quant_score` and `Mapper.tsv_header`; all left out when the end fit is off. New docs page "Mapping and quantification scores"; CHANGELOG entry under 0.3.0 (unreleased). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…orient-same-exact) When the best hits of a read's two orientations are one sequence on opposite strands under the chains (a short antisense isoform contained in a longer one, a pseudogene antisense in a host gene), the two orientations were reported tied, and only the poly(A) tail term could separate them. The read often holds more than the shared sequence: bases one transcript has of its own (a short isoform's first bases), and a tail the detector missed because the read kept its primer and sequencing adapter after it. Such a mirrored pair is now compared by exact local alignments of the whole read against both hits, as orient_exact compares other near-tied orientations. The shared sequence scores the same in both, whatever the chains, so the difference is what the read holds beyond it. Three rules go with it: - The alignments are skipped where the two transcripts are one sequence under the whole read's projection as well: both would score the same. - A read end earns the end bonus in them only where both transcripts, projected through their hits, reach it (orient_same_end_cut). A read that ends at one transcript's end, with a junk base or two after it, reaches its end in the other only through those bases aligned into its continuation, which is no evidence for it; end_bonus_cut applies the same rule within an orientation. - The pair stands at the better of the two chain scores, whichever orientation the alignments favour: it is one sequence, and the lower chain is seed luck. The orientation comparison's tail term (orient_tail) also accepts a poly(A) tail followed by more than TAIL_AFTER read bases, up to orient_tail_after, where the A-run starts at the hit transcript's 3' end (within the tie-break's end tolerance). cDNA reads that kept their adapters carry that much after the tail. An A-run that far from the read's end anywhere else is mostly the transcript's own sequence, so the old limit stands there; the tie-break's own tail search and tail-first are unchanged. `local_band_ends` is `local_band` with a bonus of its own for each read end; `local_band` is unchanged. Settings `orient_same_exact` (`--orient-same-exact` / `--no-orient-same-exact`), `orient_same_end_cut` (`--orient-same-end-cut` / `--no-orient-same-end-cut`) and `orient_tail_after` (`--orient-tail-after`, 120), on in every preset except the three -fast ones, which keep 0.1.0's hits and scores. Options recorded without them deserialize to the old behaviour. `--no-orient-same-exact --orient-tail-after=80` maps as before. Rebased onto the end fit (the quantification score): the end fit's check that a read has no tail keeps the TAIL_AFTER limit, so it fires on the same reads as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013PdRfyfQgt9mi8eYLo2VqT
…e only (--orient-quant) The two orientation rules of the previous commit, the exact comparison of mirrored pairs (orient_same_exact) and the longer adapter after a tail at the transcript end (orient_tail_after), now act through the quantification score by default. The orientation, the reported hits, their ranks and their mapping scores are decided as without them, and each hit's quantification score moves by what the two would have moved its mapping score. The evidence they add is sound where it fires: a poly(A) that starts at the short isoform's 3' end, or bases the short isoform has of its own. But what it changes is how a read's weight is split between two transcripts that are one sequence under the read, which is the quantifier's call. Kept out of the mapping score, it leaves the mapping output, best sets included, exactly as with the end fit alone, while a quantifier that reads qscore weighs the read by it as before. ranked_tops gives the best score rank_orientations leaves each orientation; the difference between the two leads (with and without the rules) is added to the end fit's adjustment of each hit. The exact alignments of orient_exact are computed once for both leads. Setting orient_quant (--orient-quant / --no-orient-quant), on in every preset except the -fast ones; recorded options without it deserialize to off. quant_scores() is also on when it has something to route, so a qscore is written with --end-fit 0 unless --no-orient-quant is given too. --no-orient-quant maps exactly as the previous commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013PdRfyfQgt9mi8eYLo2VqT
Both changes add entries to the 0.3.0 (unreleased) changelog section; both are kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013PdRfyfQgt9mi8eYLo2VqT
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.
What
A candidate for 0.3.0. Every hit gets a second score, the quantification score (
qscore). It adds an end fit for reads without a poly(A) tail. Mapping output is unchanged; only the weights a quantifier gives a read's hits change.The poly(A) tail is spearfish's only evidence for:
--tail-bonusfor the candidate whose annotated 3' end lies where the tail starts;--orient-tail.Without a tail (poly(A)-trimmed reads, or reads that lost their tail), two kinds of transcripts tie:
The EM then tends to give such reads to whichever transcript has more unique reads, and the shorter or antisense transcript can drop to about zero.
Rule. The quantification score is the mapping score plus
--end-fitpoints (default 5) for the candidates whose annotated 3' end the read reaches. It applies only when all of these hold:--end-fit-tol(4 compressed bases), so ends that can't be told apart get no relative adjustment.Why a separate score. A first version broke ties with this evidence in the mapper. It lowered top-1 accuracy on simulated reads: reads truncated at a sibling's end, and reads whose measured end was shifted by indels, were sent to the wrong isoform. Read by read that is ambiguous; across reads, the quantifier can resolve it. So the mapping score, and with it the ranks, best set, primary hit and orientation, stays exactly as in 0.2.1. The evidence only reaches the quantifier, as a soft preference: about 12 to 1 in oarfish's weights at the default scale.
How the read end is measured
drnapreset: its spans are not extended, so aligning would be done for this alone. It takes each candidate's chain, continued without gaps from its last anchor, instead (--end-fit-chain).--no-end-fit-chainaligns instead, at a higher mapping cost.--extend-ends) implies alignment, unless--end-fit-chainis given.Settings
ont,drna,hifi)-fastpresetsend_fit--end-fit SCOREend_fit_tol--end-fit-tol BASESend_fit_chain--end-fit-chain/--no-end-fit-chainAll three are also in the library (
MapOptions) and Python (Mapper(..., end_fit=..., end_fit_tol=..., end_fit_chain=...)).Output
Each addition below appears only when the end fit is on, and is backward compatible:
qscore, named in the header. Columns 1–14 are unchanged.qs:f.AS:iandsc:fstay the mapping score.qscore(f32), with the file tagquant_scores = 1. Readers that don't know it skip it.Hit::quant_scoreandMapper::quant_scores().Hit.quant_score, aquant_scorecolumn inhit_columns()/to_pandas(), andMapper.tsv_header.With
--end-fit 0or a-fastpreset, every output is byte-identical to 0.2.1.Effect
Measured on internal benchmarks.
Unchanged by construction, and checked:
-fastpresets: byte-identical.Poly(A)-trimmed real spike-in data: much of the isoform accuracy lost to trimming comes back on two recent ONT PCR cDNA runs. Reads with tails are about the same.
Quantification on simulated reads (full ONT cDNA set, hard sets at several error rates, identity sweep, other simulated ONT and HiFi sets): better, with fewer reads on unexpressed transcripts.
Real data against short-read quantification: union Spearman improves. Expressed-transcript Spearman is neutral at the default score denominator and slightly lower at a wider one.
Spike-ins on older runs: direct RNA improves, PacBio is unchanged, and cDNA is mixed but small.
Instruction counts:
--no-end-fit-chainA wall-time comparison on a quiet machine is still to be run before this merges.
Implementation notes
end_fitandright_reachincrates/map/src/lib.rs. Candidates whose 3' end is out of reach are aligned only when a bound from the band says the result could matter.crates/spearfish/src/settings.rs, CLI flags incrates/spearfish-cli, output incrates/spearfish/src/output.rs, RAD tag incrates/rad(long-read-rad), Python incrates/py-spearfish.website/src/content/docs/concepts/scores.md). The output guide documents the new column and tags.0.3.0 (unreleased). The version number is open.qscore, in process and from RAD, and exposes the three settings. It will follow once this is released.Checks
See the PR checks; the same steps were run locally first.
Second change: antisense pairs told apart through the quantification score
Two further commits (
--orient-same-exact, then--orient-quant) build on the end fit. In short: when a read's two orientations tie on a short antisense isoform contained in a longer one, the read's own evidence beyond the shared sequence now moves the quantification score, again leaving the mapping output unchanged.What
When the best hits of a read's two orientations are one sequence on opposite strands (a short antisense isoform contained in a longer one, a pseudogene antisense in a host gene), spearfish reports the two orientations tied, and only the poly(A) tail term can separate them. The read often holds more than the shared sequence:
The first commit scores that evidence in the orientation decision (as drafted earlier for 0.2.1):
--orient-same-exact). The shared sequence scores the same in both, so the difference is exactly what the read holds beyond it. Where the two transcripts are one sequence under the whole read, the alignments are skipped.--orient-same-end-cut): in those alignments a read end earns the end bonus only where both transcripts reach it, as--end-bonus-cutdoes within an orientation.--orient-tail-after, 120): in every orientation comparison, a poly(A) followed by up to 120 read bases counts where the A-run starts at the hit transcript's 3' end. Elsewhere the 80-base limit stands.The second commit routes that evidence through the quantification score by default (
--orient-quant). The orientation, the reported hits, their ranks and their mapping scores are decided as onend-fit-qscore. Each hit'sqscoremoves by what the rules above would have moved its mapping score.Why through the quantification score. Applied to the mapping score, the rules decide a few close calls on simulated reads the wrong way: random bases at a read's end align by chance a point or two into the longer transcript's continuation. That lowers tie-aware top-1 slightly (by 1 and 24 reads on two simulated sets). Weighed across reads by the quantifier, the same evidence keeps its whole effect on quantification. The mapping output, best sets included, stays exactly as with the end fit alone.
--no-orient-quantapplies the rules to the mapping score instead.Settings
-fastpresetsorient_same_exact--orient-same-exact/--no-orient-same-exactorient_same_end_cut--orient-same-end-cut/--no-orient-same-end-cutorient_tail_after--orient-tail-after=<BASES>orient_quant--orient-quant/--no-orient-quantMapSettings(builder, JSON, Python keyword arguments), the CLI, the mapping guide, the scores page and the changelog.-fastpresets are byte-identical to 0.2.1.orient_quanthas something to change. With--end-fit 0alone aqscoreis still written.--end-fit 0 --no-orient-quantgives the old formats.--no-orient-same-exact --orient-tail-after=80maps exactly asend-fit-qscore.Effect
Measured on internal benchmarks, against
end-fit-qscore.end-fit-qscorein columns 1-14 by construction (checked on spike-in reads). Top-1, in-set and best sets on the simulated ONT and HiFi sets are identical.The long isoforms that lose reads were credited with them through the tie.
end-fit-qscore; +0.0% direct RNA and +0.1% HiFi.Tests
a_mirrored_pair_is_told_apart_by_what_lies_beyond_the_shared_sequencea_mirrored_pair_earns_the_end_bonus_only_where_both_transcripts_reach_the_read_enda_long_adapter_after_the_tail_counts_only_at_the_transcript_enda_mirrored_pair_stands_at_the_better_chain_scorethe_quantification_score_takes_the_orientation_scores_the_rules_would_give:ranked_topsagrees withrank_orientationsover leads, orders and levels.local_band_endsagainst the naive definition and the full-matrix recurrence.settings_override_and_validate: preset defaults and each setting off on its own.every_setting_has_a_flagcovers the new flags.qscoreoutput with the orientation evidence on and off.cargo fmt --check,clippy --workspace --all-targets -D warnings,cargo test --workspace, the toy fixture, the docs build, the package step, the Python job, the allocator stress and shadow tests and the MSRV check pass locally. The Miri job could not build its sysroot locally (a permission error).🤖 Generated with Claude Code
https://claude.ai/code/session_013PdRfyfQgt9mi8eYLo2VqT