Exemplo n.º 1
0
  /**
   * Deprecated.
   *
   * @param rankarray double[]
   * @return double[]
   */
  private double[] getRanks(double[] rankarray) {

    double[] sortdata = new double[data.length];
    System.arraycopy(data, 0, sortdata, 0, data.length);
    Arrays.sort(sortdata);

    int neg = 0;
    while ((neg < sortdata.length) && (sortdata[neg] < 0)) {
      neg++;
    }

    int ct = 0;
    if (neg > 0) {
      for (int i = neg; i > 0; i--) {
        rankarray[ct] = -1 * i;
        ct++;
      }
    }

    for (int i = 1; ct < rankarray.length; i++) {
      rankarray[ct] = i;
      ct++;
    }

    double[] orig_ranks = new double[(int) (segInfo.getEnd() - segInfo.getStart())];
    int count = 0;

    for (int i = (int) segInfo.getStart(); i < segInfo.getEnd(); i++) {
      int index = Arrays.binarySearch(sortdata, (data[i]));
      orig_ranks[count] = rankarray[index];
      count++;
    }

    return orig_ranks;
  }
Exemplo n.º 2
0
  /** Performs sign significance test. */
  public void runSignTest() {
    // System.out.println("In SigTestThread runSignTest()");
    float thresh = getThreshhold(data);
    int totalbeats = 0;
    int overbeats = 0;
    int underbeats = 0;

    float pval_over = 1;
    float pval_under = 1;

    // System.out.println("thresh: " + thresh + ", data.length: " + data.length +
    // ", segInfo.getStart():" + segInfo.getStart() + ", segInfo.getEnd(): " + segInfo.getEnd());
    for (int i = (int) segInfo.getStart(); i <= (int) segInfo.getEnd(); i++) {

      if (data[i] > thresh) {
        totalbeats++;
        overbeats++;
      }
      if (data[i] < -1 * thresh) {
        totalbeats++;
        underbeats++;
      }
    }

    if (totalbeats > 15) {
      pval_over =
          1
              - Statistics.getNormalCDF(
                  (2 * overbeats - totalbeats) / (float) Math.pow(totalbeats, .5));
      pval_under =
          1
              - Statistics.getNormalCDF(
                  (2 * underbeats - totalbeats) / (float) Math.pow(totalbeats, .5));
    } else if (totalbeats > 0) {
      pval_over = (float) (1 - Statistics.getBinomialCDF(overbeats, totalbeats));
      pval_under = (float) (1 - Statistics.getBinomialCDF(underbeats, totalbeats));
    } else {
      pval_over = pval_under = 1;
    }

    segInfo.setStatistic(new String("Sign pos"), pval_over);
    segInfo.setStatistic(new String("Sign neg"), pval_under);

    // System.out.println("SegmentInfo ["+start+" , "+end+"]: sign p-values: over = "+pval_over+",
    // under = "+pval_under);

    // put pvalues into chromosomes for storage here?
  }
Exemplo n.º 3
0
  /** Deprecated. */
  public void runPermuteTestOld() {

    int mean_beats = 0;

    int windowsize = (int) (segInfo.getEnd() - segInfo.getStart() + 1);

    // gets statistics of the actual segInfo
    float realmean = Statistics.getMean(data, (int) segInfo.getStart(), (int) segInfo.getEnd());
    orig_mean = realmean;

    // copies the data into an array that will be randomized
    float[] random_data = new float[data.length];

    System.arraycopy(data, 0, random_data, 0, data.length);

    boolean precision_reached = false;
    segInfo.setNumPermutations(0);

    permuteloop:
    for (curr_permutation = 0;
        (curr_permutation < NUM_PERMUTATIONS && !precision_reached);
        curr_permutation++) {

      if (stop) {
        break permuteloop;
      }

      // shuffle the array of randomly ordered genes, and ranks if needed
      for (int j = random_data.length - 1; j > 0; j--) {
        int random_index = (int) (Math.random() * j);
        float temp = random_data[random_index];
        random_data[random_index] = random_data[j];
        random_data[j] = temp;
      }

      boolean meanbeat = false;
      int curr_start = 0;

      while ((curr_start < data.length - windowsize) && !meanbeat) {

        // sets random statistics ---------------------------
        double random_mean = Statistics.getMean(random_data, curr_start, (curr_start + windowsize));

        // checks to see if statistics are beat by random--------
        if ((!meanbeat)
            && (((realmean > 0) && (random_mean > realmean))
                || ((realmean < 0) && (random_mean < realmean)))) {
          mean_beats++;
          meanbeat = true;
        }

        curr_start++;
      }

      if (mean_beats > PRECISION_THRESH) {
        precision_reached = true;
        curr_permutation = NUM_PERMUTATIONS;
      }

      segInfo.setNumPermutations(segInfo.getNumPermutations() + 1);
    }

    int num_permutations_performed = segInfo.getNumPermutations();

    segInfo.setStatistic(
        new String("Mean"), (float) mean_beats / (float) num_permutations_performed);

    segInfo.setDataMean(orig_mean);
  }
Exemplo n.º 4
0
  /** Actually runs permutation test- for threaded run, use start(). */
  public void runPermuteTest() {
    // System.out.println("In SigTestThread runPermuteTest()");
    float realmean = Statistics.getMean(data, (int) segInfo.getStart(), (int) segInfo.getEnd());
    orig_mean = realmean;
    int windowsize = (int) (segInfo.getEnd() - segInfo.getStart() + 1);

    float[] random_data = new float[data.length];
    System.arraycopy(data, 0, random_data, 0, data.length);

    float[] random_maxmeans = new float[this.NUM_PERMUTATIONS];
    boolean precision_reached = false;
    segInfo.setNumPermutations(0);

    int mean_beats = 0;

    permuteloop:
    for (curr_permutation = 0;
        (curr_permutation < NUM_PERMUTATIONS && !precision_reached);
        curr_permutation++) {

      if (stop) {
        break permuteloop;
      }

      // shuffle the array of randomly ordered genes, and ranks if needed
      for (int j = random_data.length - 1; j > 0; j--) {
        int random_index = (int) (Math.random() * j);
        float temp = random_data[random_index];
        random_data[random_index] = random_data[j];
        random_data[j] = temp;
      }

      int curr_start = 0;
      float curr_mean = Statistics.getMean(random_data, curr_start, (curr_start + windowsize));
      float rand_max = 0;

      while ((curr_start < Math.min(data.length - windowsize, this.MAX_PERMUTE_VAL))) {

        curr_mean -= random_data[curr_start] / windowsize;
        curr_mean += random_data[curr_start + windowsize] / windowsize;
        if (curr_mean < 0 && curr_mean < rand_max) rand_max = curr_mean;
        else if (curr_mean > 0 && curr_mean > rand_max) rand_max = curr_mean;

        curr_start++;
      }

      random_maxmeans[curr_permutation] = rand_max;

      if (((realmean > 0) && (rand_max > realmean)) || ((realmean < 0) && (rand_max < realmean)))
        mean_beats++;

      if (mean_beats > PRECISION_THRESH) precision_reached = true;
    }

    segInfo.setNumPermutations(curr_permutation);
    segInfo.setDataMean(orig_mean);

    float maxMean = Statistics.getMean(random_maxmeans, 0, curr_permutation - 1);
    float maxVar = Statistics.getVariance(random_maxmeans, 0, curr_permutation - 1, maxMean);

    float pvalue = 1;
    if (realmean > 0)
      pvalue = 1 - Statistics.getNormalCDF((realmean - maxMean) / (float) Math.pow(maxVar, .5));
    else pvalue = Statistics.getNormalCDF((realmean - maxMean) / (float) Math.pow(maxVar, .5));

    segInfo.setStatistic(new String("Mean"), pvalue);
  }