From 4f993e8dbef64036269a05d0de3a8199d4b50c79 Mon Sep 17 00:00:00 2001
From: Valentin Ruano-Rubio In order to save CPU time the indices contained in this array (not the array itself) is
+ * lazily initialized by invoking {@link #readIndexBySampleIndex(int)}.
- * The matrix is indexed by allele and the by read index.
- *
- *
- * result[a][r] == lnLk(Read_r | Allele_a)
- *
- *
- * The matrix is live and changes to it update the likelihood in the collection, please use with care. - *
- * - * @param sampleIndex the sample index. - * - * @return never {@code null}. - */ - /* package */ double[][] sampleValues(final int sampleIndex) { - checkSampleIndex(sampleIndex); - return valuesBySampleIndex[sampleIndex]; - } - - /** * Returns a read vs allele likelihood matrix corresponding to a sample. * @@ -441,7 +337,7 @@ public class ReadLikelihoods implements Cloneable { if (maximumLikelihoodDifferenceCap == Double.NEGATIVE_INFINITY && !bestToZero) return; - final int alleleCount = alleles.length; + final int alleleCount = alleles.alleleCount(); if (alleleCount == 0) // trivial case there is no alleles. return; else if (alleleCount == 1 && !bestToZero) @@ -469,19 +365,20 @@ public class ReadLikelihoods implements Cloneable { final double bestAbsoluteLikelihood = Math.max(bestAlternativeAllele.likelihood,referenceLikelihood); + final int alleleCount = alleles.alleleCount(); if (bestToZero) { if (bestAbsoluteLikelihood == Double.NEGATIVE_INFINITY) - for (int a = 0; a < alleles.length; a++) + for (int a = 0; a < alleleCount; a++) sampleValues[a][readIndex] = 0; else if (worstLikelihoodCap != Double.NEGATIVE_INFINITY) - for (int a = 0; a < alleles.length; a++) + for (int a = 0; a < alleleCount; a++) sampleValues[a][readIndex] = (sampleValues[a][readIndex] < worstLikelihoodCap ? worstLikelihoodCap : sampleValues[a][readIndex]) - bestAbsoluteLikelihood; else - for (int a = 0; a < alleles.length; a++) + for (int a = 0; a < alleleCount; a++) sampleValues[a][readIndex] -= bestAbsoluteLikelihood; } else // else if (maximumReferenceLikelihoodFall != Double.NEGATIVE_INFINITY ) { // - // Guarantee to be the case by enclosing code. - for (int a = 0; a < alleles.length; a++) + // Guarantee to be the case by enclosing code. + for (int a = 0; a < alleleCount; a++) if (sampleValues[a][readIndex] < worstLikelihoodCap) sampleValues[a][readIndex] = worstLikelihoodCap; } @@ -499,9 +396,8 @@ public class ReadLikelihoods implements Cloneable { * @return never {@code null}. */ public List- * If not, it throws an exception. - *
- * @param alleleIndex the target sample index. - * - * @throws IllegalArgumentException if {@code alleleIndex} is invalid, i.e. outside the range [0,{@link #sampleCount}). - */ - private void checkAlleleIndex(final int alleleIndex) { - if (alleleIndex < 0 || alleleIndex >= alleles.length) - throw new IllegalArgumentException("invalid allele index: " + alleleIndex); - } } \ No newline at end of file