code: public int getAlignedChar(int iMinusOne,boolean preferHigherIndices)
      {
          // internally to this package, strings are indexed 1...N, so
          // we need to convert from the usual 0...N-1 Java convention
          int i = iMinusOne+1;
  
          int bestJ = -1;
          double bestScore = -Double.MAX_VALUE;
          for (int j=mat.getFirstStoredEntryInRow(i); j<=mat.getLastStoredEntryInRow(i); j++) {
              if (mat.outOfRange(i,j)) log.error("out of range: "+i+","+j);
              double score = mat.get(i,j);
              if ((score>bestScore) || (score==bestScore && preferHigherIndices)) {
                  bestScore = score; bestJ = j;
              }
          }
          // convert back to the usual 0...N-1 Java convention
          return bestJ-1;
      }
docs: Find a character in the first string, s, that can be aligned
  with the i-th character in the second string, t.