Beispiel #1
0
  /**
   * Creates a new {@code DuoBaum} instance.
   *
   * @param dag the directed acyclic graph that determines the transition probabilities.
   * @param gl the emission probabilities.
   * @param seed the initial random seed.
   * @param nCopies the number of haplotype pairs that will be sampled for each individual in a
   *     parent-offspring duo.
   * @throws IllegalArgumentException if {@code nCopies<1 ||
   *     dag.markers().equals(gl.markers())==false}
   * @throws NullPointerException if {@code dag==null || gl==null}
   */
  public DuoBaum(Dag dag, GL gl, long seed, int nCopies) {
    if (dag.markers().equals(gl.markers()) == false) {
      throw new IllegalArgumentException("inconsistent markers");
    }
    if (nCopies < 1) {
      throw new IllegalArgumentException("nCopies<1: " + nCopies);
    }
    this.dag = dag;
    this.gl = gl;
    this.nMarkers = dag.nMarkers();
    this.nCopies = nCopies;
    this.seed = seed;
    this.random = new Random(seed);

    this.nodeAB1 = new int[nCopies];
    this.nodeA2 = new int[nCopies];
    this.nodeB2 = new int[nCopies];
    this.nodeValue = new double[nCopies];
    this.allelesAB1 = new byte[nCopies][gl.nMarkers()];
    this.allelesA2 = new byte[nCopies][gl.nMarkers()];
    this.allelesB2 = new byte[nCopies][gl.nMarkers()];

    int size = (int) Math.ceil(Math.sqrt(1 + 8 * dag.nMarkers()) / 2.0) + 1;
    this.levels = new DuoBaumLevel[size];
    for (int j = 0; j < levels.length; ++j) {
      levels[j] = new DuoBaumLevel(dag, gl);
    }
    this.fwdNodes = new DuoNodes();
    this.bwdNodes = new DuoNodes();
  }
Beispiel #2
0
 private double parentSum(DuoBaumLevel level, int sampleA, int sampleB, int state) {
   int marker = level.marker();
   double fwdValue = level.forwardValuesSum() * level.forwardValue(state);
   int edgeAB1 = level.edgeAB1(state);
   int edgeA2 = level.edgeA2(state);
   int edgeB2 = level.edgeB2(state);
   double tpAB1 = dag.condEdgeProb(marker, edgeAB1);
   double tpA2 = dag.condEdgeProb(marker, edgeA2);
   double tpB2 = dag.condEdgeProb(marker, edgeB2);
   byte symbolAB1 = dag.symbol(marker, edgeAB1);
   byte symbolA2 = dag.symbol(marker, edgeA2);
   byte symbolB2 = dag.symbol(marker, edgeB2);
   double epA = gl.gl(marker, sampleA, symbolAB1, symbolA2);
   double epB = gl.gl(marker, sampleB, symbolAB1, symbolB2);
   return fwdValue / ((epA * epB) * (tpAB1 * tpA2 * tpB2));
 }