@Override protected void execute() { try { // update status jobStatus.addStatusMessage("10", "Preparing data"); // infrared connector // DBConnector dbConnector = new DBConnector(species, new File(babelomicsHomePath + // "/conf/infrared.properties")); // prepare params prepare(); // run fatigo's if (filterList.size() == 0 && !isYourAnnotations) { throw new ParseException("No biological database selected (eg. --go-bp)"); } else { // save id lists IOUtils.write(outdir + "/ranked_list.txt", rankedList.toString()); result.addOutputItem( new Item( "ranked_list", "ranked_list.txt", "Ranked list", Item.TYPE.FILE, Arrays.asList("RANKED_LIST", "CLEAN"), new HashMap<String, String>(), "Input data")); // order ranked list and save genes and rank separately // FatiScan fatiscan = new // FatiScan(rankedList,null,dbConnector,FatiScan.DEFAULT_NUMBER_OF_PARTITIONS,testMode,outputFormat,order,duplicatesMode); FatiScan fatiscan = new FatiScan( rankedList, null, null, FatiScan.DEFAULT_NUMBER_OF_PARTITIONS, testMode, outputFormat, order, duplicatesMode); fatiscan.prepareLists(); IOUtils.write(outdir + "/id_list.txt", fatiscan.getIdList()); result.addOutputItem( new Item( "id_list", "id_list.txt", "Id list (sorted)", Item.TYPE.FILE, Arrays.asList("IDLIST", "SORTED"), new HashMap<String, String>(), "Input data")); IOUtils.write(outdir + "/statistic.txt", ListUtils.toStringArray(fatiscan.getStatistic())); result.addOutputItem( new Item( "statistic", "statistic.txt", "Statistic (sorted)", Item.TYPE.FILE, Arrays.asList("STATISTIC", "SORTED"), new HashMap<String, String>(), "Input data")); // significant count significantCount = new ArrayList<StringBuilder>(); for (int i = 0; i < DEFAULT_PVALUES.length; i++) { significantCount.add(new StringBuilder("#DB\tNº of significant terms\n")); } // annotation report annotationReport = new StringBuilder(); annotationReport.append("#DB").append("\t").append("Number of annotations").append("\n"); // do fatiscans double progress = 20; double inc = 60.0 / filterList.size(); for (FunctionalFilter filter : filterList) { doTest(rankedList, filter, method); jobStatus.addStatusMessage("" + progress, "Executing test"); progress += inc; } // update status jobStatus.addStatusMessage("90", "Executing test"); if (isYourAnnotations) { doYourAnnotationsTest(rankedList, yourAnnotations, method); } // update status jobStatus.addStatusMessage("95", "Saving results"); saveAnnotationsReport(); // save significant count table for (int i = 0; i < DEFAULT_PVALUES.length; i++) { IOUtils.write( outdir + "/significant_count_" + pvalueFormatter.format(DEFAULT_PVALUES[i]) + ".txt", significantCount.get(i).toString()); } result .getOutputItems() .add( 3, new Item( "significant", "significant_count_${pvalue}.txt", "Number of significant terms per DB", Item.TYPE.FILE, Arrays.asList("TABLE,SUMMARY_TABLE,SIGNIFICANT_COUNT_TABLE"), new HashMap<String, String>(), "Significant Results")); result.addMetaItem(new Item("flags", "SHOW_PVALUES", "", TYPE.MESSAGE)); } } catch (Exception e) { e.printStackTrace(); } }
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", ""); } }