Пример #1
0
  /**
   * Returns a list of {@code this.nCopies()} sampled haplotype pairs for the specified parent
   * ({@code sampleA}) and offspring ({@code sampleB}). Haplotype pairs are sampled conditional on
   * the HMM with transition probabilities determined by {@code this.dag()} and emission
   * probabilities determined by {@code this.gl()}. Posterior genotype probabilities for the parent
   * and offspring are written to {@code gtProbsA} and {@code gtProbsB} respectively. The posterior
   * probability of the {@code j}-th genotype for the {@code k}-th marker is stored at index {@code
   * gl.markers().sumGenotypes(k) + j} in the {@code gtProbsA} and {@code gtProbsB} arrays. The
   * contract for this method is unspecified if no parent haplotype pairs or no offspring haplotype
   * pairs are consistent with the HMM.
   *
   * @param sampleA the sample index of the parent.
   * @param sampleB the sample index of the offspring.
   * @param gtProbsA an array to which posterior genotype probabilities for the parent will be
   *     written.
   * @param gtProbsB an array to which posterior genotype probabilities for the offspring will be
   *     written.
   * @return a list of {@code this.nCopies()} sampled haplotype pairs for the specified individuals.
   * @throws IndexOutOfBoundsException if {@code sampleA<0 || sampleA>=this.gl().nSamples()}
   * @throws IndexOutOfBoundsException if {@code sampleB<0 || sampleB>=this.gl().nSamples()}
   * @throws IllegalArgumentException if {@code gtProbsA.length!=this.gl().markers().sumGenotypes()}
   * @throws IllegalArgumentException if {@code gtProbsB.length!=this.gl().markers().sumGenotypes()}
   * @throws NullPointerException if {@code gtProbsA==null || gtProbsB==null}
   */
  public List<HapPair> sample(int sampleA, int sampleB, double[] gtProbsA, double[] gtProbsB) {
    checkGprobs(gtProbsA, gtProbsB);
    forwardAlgorithm(sampleA, sampleB);

    initSampleAlleles(currentLevel(), sampleA, sampleB);
    currentLevel().setInitialBackwardValues(bwdNodes);
    setGprobs(currentLevel(), gtProbsA, gtProbsB);

    for (int j = nMarkers - 2; j >= 0; --j) {
      DuoBaumLevel level = previousLevel(sampleA, sampleB);
      sampleAlleles(level, sampleA, sampleB);
      level.setBackwardValues(bwdNodes);
      setGprobs(level, gtProbsA, gtProbsB);
    }
    return hapList(sampleA, sampleB);
  }