private double[] oneDprob(final EvidenceInterface evidence) { final Code code = mSubHypotheses.code(); final double[] probs = new double[mSubHypotheses.size()]; for (int i = 0; i < probs.length; i++) { final double a = Math.max(0, evidence.probability(code.a(i))); final double b = Math.max(0, evidence.probability(code.bc(i))); probs[i] = 0.5 * (a + b); } // System.err.println(probs.length + " :" + Arrays.toString(probs)); return probs; }
/** * @param diseaseHyp haploid disease hypothesis that starts with NONE and includes rest of * nucleotides (see <code>HypothesesDisease</code>). * @param genome selects family member with father starting at 0. * @return true iff the disease hypothesis is consistent with the disease status of this family * member (aka genome). Assumes disease is dominant. */ private boolean q(final int diseaseHyp, final int genome) { final int hyp = mCurrentHypotheses[genome]; final boolean contains; final Code code = mIndividualHypotheses.code(); final int dis = diseaseHyp - 1; // TODO implement recessive version controlled by flag. if (code.homozygous(hyp)) { contains = code.a(hyp) == dis; } else { contains = code.a(hyp) == dis || code.b(hyp) == dis; } return contains == mFamily.isDiseased(genome); }
@Override public void increment(final EvidenceInterface evidence) { // System.err.println(evidence); incrementStatistics(evidence); if (ambiguityShortCircuit(evidence)) { return; } final double r = evidence.mapError(); final double rc = 1.0 - r; // Avoid case where mapq is 0 which gives a NaN if (rc <= 0.0) { return; } final double[] probs = oneDprob(evidence); final double pE = evidence.pe(); final double pEr = r * pE; final Code code = hypotheses().code(); for (int i = 0; i < size(); i++) { final int a = code.a(i); final int b = code.bc(i); // The cross-product is normal x cancer final double prob = probs[a] * mContamination + probs[b] * mContaminationM; // Phred scores of 0 can result in 0 probability, just skip them if (prob <= 0.0) { return; } // Adjust for mapQ - see theory in scoring.tex final double pr = prob * rc + pEr; final double np = arithmetic().multiply(mPosteriors[i], arithmetic().prob2Poss(pr)); assert arithmetic() .isValidPoss( np); // : System.err.println("np=" + np + " mPosteriors[i]=" + mPosteriors[i] + " i=" // + i + " pr=" + pr + " prob=" + prob + " rc=" + rc + " r=" + r + " pE=" + pE); mPosteriors[i] = np; } }