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()); } }
/** * @throws InvalidColumnIndexException * @throws IOException */ public void executeLimma() { Limma limma = null; if (classValues.size() > 2) { limma = new Limma(babelomicsHomePath + "/bin/diffexp/limma_multiclasses.r"); } else if (classValues.size() == 2) { limma = new Limma(babelomicsHomePath + "/bin/diffexp/limma_twoclasses.r"); } else if (classValues.size() == 1) { limma = new Limma(babelomicsHomePath + "/bin/diffexp/limma_oneclass.r"); } else { abort( "testmismatched_executelimma_classcomparison", "test " + test + " not supported for " + classValues.size() + "-class test", "test " + test + " not supported for " + classValues.size() + "-class test", "test " + test + " not supported for " + classValues.size() + "-class test"); } // System.out.println("dataset = " + dataset.toString()); System.out.println("class name = " + className); limma.setInputFilename(dataset.getDatasetFile().getAbsolutePath()); limma.setClasses(dataset.getVariables().getByName(className).getValues()); limma.setContrast(classValues); try { Dataset subDataset = dataset.getSubDataset(className, classValues); // apply test and multiple test correction according // TestResultList<LimmaTestResult> res = limma.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(), "Limma output file", TYPE.FILE, new ArrayList<String>(2), new HashMap<String, String>(2), "Limma 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_executelimma_classcomparison", "error running limma", "error running limma: " + e.toString(), "error running limma: " + e.toString()); } }
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", ""); } }