Ejemplo n.º 1
0
 /**
  * Constructs a new {@code GprobsStatistics} instance from the specified scaled genotype
  * probabilities.
  *
  * @param gv scaled sample posterior genotype probabilities.
  * @param marker a marker index
  * @throws IndexOutOfBoundsException if {@code marker<0 || marker>=gv.nMarkers()}
  */
 public GprobsStatistics(GenotypeValues gv, int marker) {
   int nAlleles = gv.marker(marker).nAlleles();
   this.marker = gv.marker(marker);
   this.nSamples = gv.nSamples();
   this.alleleFreq = new float[nAlleles];
   float[] gtProbs = new float[3];
   for (int j = 0; j < this.nSamples; ++j) {
     setProbs(gv, marker, j, gtProbs, alleleFreq);
     int call = maxIndex(gtProbs, random);
     float exp = (gtProbs[1] + 2 * gtProbs[2]);
     float expSquare = (gtProbs[1] + 4 * gtProbs[2]);
     sumCall += call;
     sumSquareCall += call * call;
     sumExpected += exp;
     sumExpectedSquare += expSquare;
     sumSquareExpected += (exp * exp);
     sumCallExpected += (call * exp);
   }
   divideBySum(alleleFreq);
 }
Ejemplo n.º 2
0
  private static void setProbs(
      GenotypeValues gv, int marker, int sample, float[] gtProbs, float[] alleleFreq) {
    Arrays.fill(gtProbs, 0.0f);
    int nGt = gv.marker(marker).nGenotypes();
    float sum = 0.0f;
    for (int gt = 0; gt < nGt; ++gt) {
      sum += gv.value(marker, sample, gt);
    }

    int gt = -1;
    for (int a2 = 0; a2 < alleleFreq.length; ++a2) {
      for (int a1 = 0; a1 < a2; ++a1) {
        float gprob = gv.value(marker, sample, ++gt) / sum;
        alleleFreq[a1] += gprob;
        alleleFreq[a2] += gprob;
        gtProbs[(a1 == 0) ? 1 : 2] += gprob;
      }
      float gprob = gv.value(marker, sample, ++gt) / sum;
      alleleFreq[a2] += 2 * gprob;
      gtProbs[(a2 == 0) ? 0 : 2] += gprob;
    }
  }