Ejemplo n.º 1
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);
  }
Ejemplo n.º 2
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);
  }