Repository navigation
Score all sequence pairs without building alignments (GLOBAL, LOCAL): 27-286x faster getAllPairsScores - #1161
Open
mikepapadim wants to merge 1 commit into
Open
mikepapadim wants to merge 1 commit into
mikepapadim wants to merge 1 commit into
Conversation
Alignments.getAllPairsScores, and the pairwise stage of getMultipleSequenceAlignment, built a full NeedlemanWunsch or SmithWaterman alignment for every pair, with a traceback matrix of objects per cell, only to read its score. For GLOBAL and LOCAL scoring the score needs only the last row of the dynamic programming matrix. AllPairsScores scores each pair in linear memory on primitive arrays, with the recurrences of AlignerHelper (linear and affine gap penalties), so the scores are exactly the aligners'. The scorers it returns for the guide tree have the aligners' maximum and minimum scores, hence the same distances and the same multiple alignment. Pairs run on the ConcurrencyTools pool, one task per query sequence. Other scorer types, a single sequence, an empty sequence or mixed compound sets take the existing path. AllPairsScoresTest checks scores, maximum, minimum, distance and similarity of every pair against the aligners for random and related proteins, rare compounds, very different lengths, DNA, six gap penalties and three matrices, and the multiple alignment for GLOBAL and LOCAL. SmithWaterman with a linear gap penalty throws for a pair with no positive substitution score (ArrayIndexOutOfBoundsException in its traceback), and getListFromFutures drops that pair's score, so runPairwiseScorers returns fewer scores than pairs. The local score of such a pair is 0, which is what the new path returns; noPositiveLocalCell documents the case.
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.
Follow-up to #1158, proposal (1): a CPU-only fast path, no new dependencies.
What
Alignments.getAllPairsScoresbuilt a fullNeedlemanWunsch/SmithWatermanalignment for every pair, with a traceback matrix of objects per cell, only to read its score. So did the pairwise stage ofgetMultipleSequenceAlignment. ForGLOBALandLOCALscoring the score needs only the last row of the dynamic-programming matrix.The new package-private
AllPairsScoresscores each pair in linear memory on primitive arrays:AlignerHelper, linear and affine, so the scores are exactly the aligners'.ConcurrencyToolspool, one task per query sequence, soConcurrencyTools.setThreadPoolSizestill applies.Other scorer types (
*_IDENTITIES,*_SIMILARITIES,KMERS,WU_MANBER), fewer than two sequences, an empty sequence or mixed compound sets take the existing path unchanged. No public API changes.Speed
getAllPairsScores, BLOSUM62, gaps 10/1, best of 3 after 2 warm-ups. i9-13900K (32 threads), JDK 21,ConcurrencyToolsdefault pool. The machine was also running other jobs, so read the ratios rather than the absolute times. The checksum of all scores is identical on both branches.masterOn PF00104,
masteris dominated by allocating and collecting the per-cell traceback objects of long sequences.Tests
AllPairsScoresTest(8 tests). For every pair it compares score, max, min, distance and similarity againstgetAllPairsScorers+ the aligners. Inputs:X B Z U *);It also checks that
getMultipleSequenceAlignmentgives the same profile as before forGLOBALandLOCAL.The whole
biojava-alignmentsuite passes: 135 tests, 0 failures.A bug this found in the existing path
SmithWatermanwith a linear gap penalty throwsArrayIndexOutOfBoundsExceptionfor a pair that has no positive substitution score, e.g.WvsMKwith BLOSUM62. The exception is in its traceback.getListFromFutureslogs and drops the failed future, sorunPairwiseScorersreturns fewer scores than pairs, and every later score sits at the wrong index. The local score of such a pair is 0. That is whatSmithWatermanreturns with an affine penalty, and what this PR returns for both.noPositiveLocalCelldocuments it. I leftSmithWatermanitself alone; happy to fix it in a separate PR if you like.How to run
To time it yourself, a minimal program (run it against
masterand this branch):