Example #1
0
  public void executeFoldChange() {

    int[] cols = dataset.getColumnIndexesByVariableValue(className, classValues.get(0));
    DoubleMatrix sample1 = dataset.getSubMatrixByColumns(cols);

    cols = dataset.getColumnIndexesByVariableValue(className, classValues.get(1));
    DoubleMatrix sample2 = dataset.getSubMatrixByColumns(cols);

    try {

      Dataset subDataset = dataset.getSubDataset(className, classValues);

      FoldChangeTest foldChange = new FoldChangeTest();
      double[] logRes = foldChange.logFoldChange(sample1, sample2);
      double[] diffRes = foldChange.diffFoldChange(sample1, sample2);

      updateJobStatus("80", "saving results");

      setFoldChangeResults(subDataset, "log", "Log", logRes, className);
      setFoldChangeResults(subDataset, "diff", "Diff", diffRes, className);

      //			String test, testLabel;
      //			DataFrame dataFrame;
      //			FeatureData featureData;
      //			File file;
      //
      //			int[] columnOrder;
      //			int[] rowOrder;
      //			Canvas heatmap;
      //			String heatmapFilename;
      //
      //			// log fold change
      //			//
      //			test = "log";
      //			testLabel = "Log";
      //
      //			columnOrder =
      // ListUtils.order(subDataset.getVariables().getByName(className).getValues());
      //			rowOrder = ListUtils.order(ArrayUtils.toList(logRes), true);
      //
      //			dataFrame = new DataFrame(subDataset.getFeatureNames().size(), 0);
      //			dataFrame.addColumn(test, ListUtils.ordered(ArrayUtils.toStringList(logRes), rowOrder));
      //			dataFrame.setRowNames(ListUtils.ordered(subDataset.getFeatureNames(), rowOrder));
      //			featureData = new FeatureData(dataFrame);
      //			file = new File(outdir + "/" + test + "_foldchange.txt");
      //			IOUtils.write(file, dataFrame.toString(true, true));
      //			//featureData.save(file);
      //			if ( file.exists() ) {
      //				result.addOutputItem(new Item(test + "_foldchange", file.getName(), testLabel + "
      // fold-change output file", TYPE.FILE, StringUtils.toList("TABLE," + test.toUpperCase() +
      // "_FOLD_CHANGE_TABLE", ","), new HashMap<String, String>(2), testLabel + "
      // fold-change.Output files"));
      //			}
      //
      //			// generating heatmap
      //			//
      //			heatmap = DiffExpressionUtils.generateHeatmap(subDataset, className, columnOrder,
      // rowOrder, test + " fold-change", logRes, null, null);
      //			heatmapFilename = getOutdir() + "/" + test + "_heatmap.png";
      //			try {
      //				heatmap.save(heatmapFilename);
      //				if ( new File(heatmapFilename).exists() ) {
      //					result.addOutputItem(new Item(test + "_heatmap", test + "_heatmap.png", testLabel + ".
      // fold-change heatmap with all terms", TYPE.IMAGE, new ArrayList<String>(2), new
      // HashMap<String, String>(2), testLabel + " fold-change.Heatmap image"));
      //				}
      //			} catch (IOException e) {
      //				printError("ioexception_executet_classcomparison", "error generating heatmap",
      // e.toString(), e);
      //			}
      //
      //
      //			test = "diff";
      //			testLabel = "Diff";
      //
      //			columnOrder =
      // ListUtils.order(subDataset.getVariables().getByName(className).getValues());
      //			rowOrder = ListUtils.order(ArrayUtils.toList(logRes), true);
      //
      //			dataFrame = new DataFrame(subDataset.getFeatureNames().size(), 0);
      //			dataFrame.addColumn(test, ListUtils.ordered(ArrayUtils.toStringList(diffRes), rowOrder));
      //			dataFrame.setRowNames(ListUtils.ordered(subDataset.getFeatureNames(), rowOrder));
      //			featureData = new FeatureData(dataFrame);
      //			file = new File(outdir + "/" + test + "_foldchange.txt");
      //			IOUtils.write(file, dataFrame.toString(true, true));
      //			//featureData.save(file);
      //			if ( file.exists() ) {
      //				result.addOutputItem(new Item(test + "_foldchange", file.getName(), testLabel + "
      // fold-change output file", TYPE.FILE, StringUtils.toList("TABLE," + test.toUpperCase() +
      // "_FOLD_CHANGE_TABLE", ","), new HashMap<String, String>(2), testLabel + "
      // fold-change.Output files"));
      //			}
      //
      //			// generating heatmap
      //			//
      //			heatmap = DiffExpressionUtils.generateHeatmap(subDataset, className, columnOrder,
      // rowOrder, test + " fold-change", diffRes, null, null);
      //			heatmapFilename = getOutdir() + "/" + test + "_heatmap.png";
      //			try {
      //				heatmap.save(heatmapFilename);
      //				if ( new File(heatmapFilename).exists() ) {
      //					result.addOutputItem(new Item(test + "_heatmap", test + "_heatmap.png", testLabel + ".
      // fold-change heatmap with all terms", TYPE.IMAGE, new ArrayList<String>(2), new
      // HashMap<String, String>(2), testLabel + " fold-change.Heatmap image"));
      //				}
      //			} catch (IOException e) {
      //				printError("ioexception_executet_classcomparison", "error generating heatmap",
      // e.toString(), e);
      //			}

    } catch (Exception e) {
      e.printStackTrace();
      abort(
          "exception_executefoldchange_classcomparison",
          "error running fold-change",
          "error running fold-change: " + e.getMessage(),
          "error running fold-change: " + e.getMessage());
    }
  }
Example #2
0
  public void executeAnova() {

    DoubleMatrix matrix = null;
    List<String> vars = new ArrayList<String>();
    List<Integer> indices = new ArrayList<Integer>();
    List<String> values = dataset.getVariables().getByName(className).getValues();

    if (values.size() == classValues.size()) {
      matrix = dataset.getDoubleMatrix();
      vars = values;
    } else {
      for (int i = 0; i < values.size(); i++) {
        if (classValues.contains(values.get(i))) {
          indices.add(i);
          vars.add(values.get(i));
        }
      }
      matrix = dataset.getSubMatrixByColumns(ListUtils.toIntArray(indices));
    }

    try {
      Dataset subDataset = dataset.getSubDataset(className, classValues);

      // apply test and multiple test correction according
      //
      AnovaTest anova = new AnovaTest(matrix, vars);
      TestResultList<AnovaTestResult> res = anova.compute();
      DiffExpressionUtils.multipleTestCorrection(res, correction);

      // create output file
      //
      int[] columnOrder =
          ListUtils.order(subDataset.getVariables().getByName(className).getValues());
      int[] rowOrder = ListUtils.order(ArrayUtils.toList(res.getStatistics()), true);

      DataFrame dataFrame = new DataFrame(subDataset.getFeatureNames().size(), 0);
      dataFrame.addColumn(
          "statistic",
          ListUtils.toStringList(
              ListUtils.ordered(ArrayUtils.toList(res.getStatistics()), rowOrder)));
      dataFrame.addColumn(
          "p-value",
          ListUtils.toStringList(ListUtils.ordered(ArrayUtils.toList(res.getPValues()), rowOrder)));
      dataFrame.addColumn(
          "adj. p-value",
          ListUtils.toStringList(
              ListUtils.ordered(ArrayUtils.toList(res.getAdjPValues()), rowOrder)));
      dataFrame.setRowNames(ListUtils.ordered(subDataset.getFeatureNames(), rowOrder));

      FeatureData featureData = new FeatureData(dataFrame);
      File file = new File(outdir + "/" + test + ".txt");
      featureData.save(file);
      if (file.exists()) {
        result.addOutputItem(
            new Item(
                test + "file",
                file.getName(),
                "Anova output file",
                TYPE.FILE,
                new ArrayList<String>(2),
                new HashMap<String, String>(2),
                "Anova output files"));
      }

      // getting significative genes
      //
      DiffExpressionUtils.addSignificativeResults(
          subDataset,
          test,
          "statistic",
          res.getStatistics(),
          "adj. p-value",
          res.getAdjPValues(),
          "p-value",
          res.getPValues(),
          null,
          null,
          null,
          null,
          className,
          columnOrder,
          pValue,
          maxDisplay,
          this);
      DiffExpressionUtils.createFatiScanRedirection(dataFrame, test, "statistic", result, outdir);
    } catch (Exception e) {
      e.printStackTrace();
      abort(
          "exception_executeanova_classcomparison",
          "error running anova",
          "error running anova: " + e.getMessage(),
          "error running anova: " + e.getMessage());
    }
  }
Example #3
0
  public void executeT() {

    int[] cols = dataset.getColumnIndexesByVariableValue(className, classValues.get(0));
    DoubleMatrix sample1 = dataset.getSubMatrixByColumns(cols);

    cols = dataset.getColumnIndexesByVariableValue(className, classValues.get(1));
    DoubleMatrix sample2 = dataset.getSubMatrixByColumns(cols);

    try {
      Dataset subDataset = dataset.getSubDataset(className, classValues);

      // apply test and multiple test correction according
      //
      TTest tTest = new TTest();
      TestResultList<TTestResult> res = tTest.tTest(sample1, sample2);
      DiffExpressionUtils.multipleTestCorrection(res, correction);

      // create output file
      //
      int[] columnOrder =
          ListUtils.order(subDataset.getVariables().getByName(className).getValues());
      int[] rowOrder = ListUtils.order(ArrayUtils.toList(res.getStatistics()), true);

      DataFrame dataFrame = new DataFrame(subDataset.getFeatureNames().size(), 0);
      dataFrame.addColumn(
          "statistic",
          ListUtils.toStringList(
              ListUtils.ordered(ArrayUtils.toList(res.getStatistics()), rowOrder)));
      dataFrame.addColumn(
          "p-value",
          ListUtils.toStringList(ListUtils.ordered(ArrayUtils.toList(res.getPValues()), rowOrder)));
      dataFrame.addColumn(
          "adj. p-value",
          ListUtils.toStringList(
              ListUtils.ordered(ArrayUtils.toList(res.getAdjPValues()), rowOrder)));
      dataFrame.setRowNames(ListUtils.ordered(subDataset.getFeatureNames(), rowOrder));

      FeatureData featureData = new FeatureData(dataFrame);
      File file = new File(outdir + "/t.txt");
      featureData.save(file);
      if (file.exists()) {
        result.addOutputItem(
            new Item(
                "tfile",
                file.getName(),
                "T-test output file",
                TYPE.FILE,
                new ArrayList<String>(),
                new HashMap<String, String>(),
                "T-test output files"));
      }

      // getting significative genes
      //
      DiffExpressionUtils.addSignificativeResults(
          subDataset,
          test,
          "statistic",
          res.getStatistics(),
          "adj. p-value",
          res.getAdjPValues(),
          "p-value",
          res.getPValues(),
          null,
          null,
          null,
          null,
          className,
          columnOrder,
          pValue,
          maxDisplay,
          this);
      DiffExpressionUtils.createFatiScanRedirection(dataFrame, test, "statistic", result, outdir);
    } catch (Exception e) {
      e.printStackTrace();
      abort("exception_executet_classcomparison", "ERROR", "Error running t-test", "");
    }
  }