Try to make last-split faster
authorMartin C. Frith
Wed Mar 11 19:19:09 2020 +0900 (2 months ago)
changeset 105313c4e8b892dc
parent 1052 ba6739cb6e7b
child 1054 8621c8e512ff
Try to make last-split faster
src/split/cbrc_split_aligner.cc
src/split/cbrc_split_aligner.hh
     1.1 --- a/src/split/cbrc_split_aligner.cc	Wed Mar 11 18:35:26 2020 +0900
     1.2 +++ b/src/split/cbrc_split_aligner.cc	Wed Mar 11 19:19:09 2020 +0900
     1.3 @@ -294,7 +294,38 @@
     1.4    newNumInplay = (newEnd - newBeg) + (sortedAlnPos - sortedAlnOldPos);
     1.5  }
     1.6  
     1.7 -long SplitAligner::viterbi() {
     1.8 +long SplitAligner::viterbiSplit() {
     1.9 +  resizeMatrix(Vmat);
    1.10 +  resizeVector(Vvec);
    1.11 +
    1.12 +  unsigned sortedAlnPos = 0;
    1.13 +  unsigned oldNumInplay = 0;
    1.14 +  unsigned newNumInplay = 0;
    1.15 +
    1.16 +  stable_sort(sortedAlnIndices.begin(), sortedAlnIndices.end(),
    1.17 +	      QbegLess(&dpBegs[0], &rnameAndStrandIds[0], &rBegs[0]));
    1.18 +
    1.19 +  for (unsigned i = 0; i < numAlns; ++i) cell(Vmat, i, dpBeg(i)) = INT_MIN/2;
    1.20 +  long maxScore = 0;
    1.21 +
    1.22 +  for (unsigned j = minBeg; j < maxEnd; j++) {
    1.23 +    updateInplayAlnIndicesF(sortedAlnPos, oldNumInplay, newNumInplay, j);
    1.24 +    cell(Vvec, j) = maxScore;
    1.25 +    long scoreFromJump = maxScore + restartScore;
    1.26 +    for (unsigned x = 0; x < newNumInplay; ++x) {
    1.27 +      unsigned i = newInplayAlnIndices[x];
    1.28 +      size_t ij = matrixRowOrigins[i] + j;
    1.29 +      long s = std::max(scoreFromJump, Vmat[ij] + Dmat[ij]) + Amat[ij];
    1.30 +      Vmat[ij + 1] = s;
    1.31 +      maxScore = std::max(maxScore, s);
    1.32 +    }
    1.33 +  }
    1.34 +
    1.35 +  cell(Vvec, maxEnd) = maxScore;
    1.36 +  return maxScore;
    1.37 +}
    1.38 +
    1.39 +long SplitAligner::viterbiSplice() {
    1.40      resizeMatrix(Vmat);
    1.41      resizeVector(Vvec);
    1.42  
    1.43 @@ -324,7 +355,7 @@
    1.44  			   scoreFromSplice(i, j, oldNumInplay, oldInplayPos));
    1.45  	    s += spliceEndScore(ij);
    1.46  	    s = std::max(s, Vmat[ij] + Dmat[ij]);
    1.47 -	    if (restartProb <= 0 && alns[i].qstart == j && s < 0) s = 0;
    1.48 +	    if (alns[i].qstart == j && s < 0) s = 0;
    1.49  	    s += Amat[ij];
    1.50  
    1.51  	    Vmat[ij + 1] = s;
    1.52 @@ -335,7 +366,7 @@
    1.53      }
    1.54  
    1.55      cell(Vvec, maxEnd) = maxScore;
    1.56 -    return (restartProb > 0) ? maxScore : endScore();
    1.57 +    return endScore();
    1.58  }
    1.59  
    1.60  long SplitAligner::endScore() const {
     2.1 --- a/src/split/cbrc_split_aligner.hh	Wed Mar 11 18:35:26 2020 +0900
     2.2 +++ b/src/split/cbrc_split_aligner.hh	Wed Mar 11 19:19:09 2020 +0900
     2.3 @@ -74,7 +74,12 @@
     2.4      // Call this before viterbi/forward/backward, and after layout
     2.5      void initMatricesForOneQuery();
     2.6  
     2.7 -    long viterbi();  // returns the optimal split-alignment score
     2.8 +    long viterbiSplit();
     2.9 +    long viterbiSplice();
    2.10 +
    2.11 +    long viterbi() {  // returns the optimal split-alignment score
    2.12 +      return (restartProb > 0) ? viterbiSplit() : viterbiSplice();
    2.13 +    }
    2.14  
    2.15      // Gets the chunks of an optimal split alignment.
    2.16      // For each chunk, it gets: