Ejemplo n.º 1
0
  private void saveCluster(File file, Experiment experiment, IData data, int[] rows)
      throws Exception {
    PrintWriter out = new PrintWriter(new FileOutputStream(file));
    String[] fieldNames = data.getFieldNames();
    out.print("Original row");
    out.print("\t");
    for (int i = 0; i < fieldNames.length; i++) {
      out.print(fieldNames[i]);
      // if (i < fieldNames.length - 1) {
      out.print("\t");
      // }
    }
    for (int i = 0; i < geneGroupMeans[0].length; i++) {
      out.print("Group" + (i + 1) + " mean\t");
      out.print("Group" + (i + 1) + " std.dev.\t");
    }
    // out.print("\t");
    out.print("F ratio");
    out.print("\t");
    out.print("SS(Groups)\t");
    out.print("SS(Error)\t");
    out.print("df (Groups)\t");
    out.print("df (Error)\t");
    out.print("raw p value\t");
    out.print("adj p value");

    // out.print("UniqueID\tName");
    for (int i = 0; i < experiment.getNumberOfSamples(); i++) {
      out.print("\t");
      out.print(data.getFullSampleName(experiment.getSampleIndex(i)));
    }
    out.print("\n");
    for (int i = 0; i < rows.length; i++) {
      out.print(Integer.toString(experiment.getGeneIndexMappedToData(rows[i]) + 1));
      // out.print(data.getUniqueId(rows[i]));
      out.print("\t");
      // out.print(data.getGeneName(rows[i]));
      for (int k = 0; k < fieldNames.length; k++) {
        out.print(data.getElementAttribute(experiment.getGeneIndexMappedToData(rows[i]), k));
        // if (k < fieldNames.length - 1) {
        out.print("\t");
        // }
      }
      for (int j = 0; j < geneGroupMeans[rows[i]].length; j++) {
        out.print(geneGroupMeans[rows[i]][j] + "\t");
        out.print(geneGroupSDs[rows[i]][j] + "\t");
      }
      // out.print("\t");
      out.print("" + ((Float) fValues.get(rows[i])).floatValue());
      out.print("\t");
      out.print("" + ((Float) ssGroups.get(rows[i])).floatValue());
      out.print("\t");
      out.print("" + ((Float) ssError.get(rows[i])).floatValue());
      out.print("\t");
      out.print("" + ((Float) dfNumValues.get(rows[i])).floatValue());
      out.print("\t");
      out.print("" + ((Float) dfDenomValues.get(rows[i])).floatValue());
      out.print("\t");
      out.print("" + ((Float) rawPValues.get(rows[i])).floatValue());
      out.print("\t");
      out.print("" + ((Float) adjPValues.get(rows[i])).floatValue());
      for (int j = 0; j < experiment.getNumberOfSamples(); j++) {
        out.print("\t");
        out.print(Float.toString(experiment.get(rows[i], j)));
      }
      out.print("\n");
    }
    out.flush();
    out.close();
  }
Ejemplo n.º 2
0
  /**
   * Gathers data for a set of genes
   *
   * @param geneIndices
   */
  private void getChartData(int[] geneIndices, int multigeneIndex) {
    try {
      lowerOutliers[multigeneIndex] = new float[clusterCount][];
      upperOutliers[multigeneIndex] = new float[clusterCount][];
      expressionSDs[multigeneIndex] = new float[clusterCount];
      expressionAverages[multigeneIndex] = new float[clusterCount];
      expressionMedian[multigeneIndex] = new float[clusterCount];
      expressionQ1[multigeneIndex] = new float[clusterCount];
      expressionQ3[multigeneIndex] = new float[clusterCount];
      expressionIQR[multigeneIndex] = new float[clusterCount];
      expressionLowerWhisker[multigeneIndex] = new float[clusterCount];
      expressionUpperWhisker[multigeneIndex] = new float[clusterCount];
      for (int i = 0; i < clusterCount; i++) {
        float average = 0;
        float sum = 0;
        int membership = 0;
        for (int j = 0; j < clusters[i].length; j++) {
          for (int k = 0; k < geneIndices.length; k++) {
            average = average + experiment.get(geneIndices[k], clusters[i][j]);
            membership++;
          }
        }
        average = average / (float) membership;
        expressionAverages[multigeneIndex][i] = average;
        for (int j = 0; j < clusters[i].length; j++) {
          for (int k = 0; k < geneIndices.length; k++) {
            sum =
                sum + (float) Math.pow(experiment.get(geneIndices[k], clusters[i][j]) - average, 2);
          }
        }
        sum = sum / (float) membership;
        expressionSDs[multigeneIndex][i] = (float) Math.sqrt(sum);

        // get box plot stuff
        float[] expression = new float[clusters[i].length * geneIndices.length];
        int expindex = 0;
        for (int j = 0; j < clusters[i].length; j++) {
          for (int k = 0; k < geneIndices.length; k++) {
            expression[expindex++] = (experiment.get(geneIndices[k], clusters[i][j]));
          }
        }
        Arrays.sort(expression);
        expressionMedian[multigeneIndex][i] = getMedian(expression);

        float[] lower = new float[expression.length / 2];
        float[] upper = new float[expression.length / 2];
        for (int j = 0; j < lower.length; j++) {
          lower[j] = expression[j];
          upper[upper.length - 1 - j] = expression[expression.length - 1 - j];
        }
        expressionQ1[multigeneIndex][i] = getMedian(lower);
        expressionQ3[multigeneIndex][i] = getMedian(upper);
        expressionIQR[multigeneIndex][i] =
            expressionQ3[multigeneIndex][i] - expressionQ1[multigeneIndex][i];
        expressionLowerWhisker[multigeneIndex][i] =
            expressionQ1[multigeneIndex][i] - 1.5f * expressionIQR[multigeneIndex][i];
        expressionUpperWhisker[multigeneIndex][i] =
            expressionQ3[multigeneIndex][i] + 1.5f * expressionIQR[multigeneIndex][i];

        int upperCount = 0;
        int lowerCount = 0;
        for (int index = 0; index < expression.length; index++) {
          if (expression[index] < expressionLowerWhisker[multigeneIndex][i]) lowerCount++;
          if (expression[index] > expressionUpperWhisker[multigeneIndex][i]) upperCount++;
        }
        lowerOutliers[multigeneIndex][i] = new float[lowerCount];
        upperOutliers[multigeneIndex][i] = new float[upperCount];
        for (int j = 0; j < lowerOutliers[multigeneIndex][i].length; j++) {
          lowerOutliers[multigeneIndex][i][j] = expression[j];
        }
        for (int j = 0; j < upperOutliers[multigeneIndex][i].length; j++) {
          upperOutliers[multigeneIndex][i][j] = expression[expression.length - 1 - j];
        }
      }
    } catch (Exception e) {
      System.out.println("data problem");
      e.printStackTrace();
      for (int i = 0; i < clusterCount; i++) {
        expressionAverages[multigeneIndex][i] = (float) Math.random();
        expressionSDs[multigeneIndex][i] = (float) Math.random() / 10f;
      }
    }
  }