Example #1
0
 /*
  * Annotations count
  */
 private void addAnnotationReport(GeneSetAnalysis fatiscan, String dbName) {
   DecimalFormat formatter = new DecimalFormat("#######.##");
   double list1Percentage =
       ((double) (fatiscan.getAnnotatedCounter()) / (double) fatiscan.getIdList().size()) * 100.0;
   String listMessage =
       fatiscan.getAnnotatedCounter()
           + " of "
           + fatiscan.getIdList().size()
           + " ("
           + formatter.format(list1Percentage)
           + "%) "
           + formatter.format(fatiscan.getMeanAnnotationsPerId())
           + " annotations/id";
   annotationReport.append(dbName).append("\t").append(listMessage).append("\n");
 }
Example #2
0
  private void doYourAnnotationsTest(
      FeatureData rankedList, FeatureList<AnnotationItem> annotations, Method method)
      throws IOException, SQLException, IllegalAccessException, ClassNotFoundException,
          InstantiationException, InvalidParameterException, InvalidIndexException {

    // db attributes
    FunctionalDbDescriptor filterInfo =
        new FunctionalDbDescriptor(
            "your_annotation", "Your annotations", "your_annotations", "Your annotations");

    // get term sizes
    Map<String, Integer> termSizes = getYourAnnotationsTermSizes();

    logger.info(filterInfo.getTitle() + "...\n");

    GeneSetAnalysis gsea;

    if (method == Method.Logistic) {
      gsea = new LogisticScan(rankedList, annotations, order);
    } else {
      gsea =
          new FatiScan(
              rankedList,
              annotations,
              numberOfPartitions,
              testMode,
              outputFormat,
              order,
              duplicatesMode);
    }

    // run
    try {

      gsea.setLogger(logger);

      // set term sizes
      gsea.setTermSizes(termSizes);

      gsea.run();

      // save results
      saveGeneSetAnalysisResults(gsea, filterInfo);

    } catch (EmptyAnnotationException ene) {
      result.addOutputItem(
          new Item(
              "annot_" + filterInfo.getName(),
              "No annotation was found for " + filterInfo.getTitle() + " ids",
              "Annotations for " + filterInfo.getTitle(),
              Item.TYPE.MESSAGE,
              Arrays.asList("WARNING"),
              new HashMap<String, String>(),
              "Annotation files"));
    } catch (Exception ene) {
      result.addOutputItem(
          new Item(
              "annot_" + filterInfo.getName(),
              "Unexpected error was found while running analysis for "
                  + filterInfo.getTitle()
                  + " ids",
              filterInfo.getTitle(),
              Item.TYPE.MESSAGE,
              Arrays.asList("ERROR"),
              new HashMap<String, String>(),
              "All results"));
      ene.printStackTrace();
    }

    logger.info("...end of " + filterInfo.getTitle());
  }
Example #3
0
  private void saveGeneSetAnalysisResults(GeneSetAnalysis gsea, FunctionalDbDescriptor filterInfo)
      throws IOException {

    String fileName = filterInfo.getName() + ".txt";
    String annotFileName = filterInfo.getName() + ".annot";

    // save statistic results
    IOUtils.write(outdir + "/" + fileName, ListUtils.toString(gsea.resultsToStringList(), "\n"));
    result.addOutputItem(
        new Item(
            filterInfo.getName(),
            fileName,
            filterInfo.getTitle(),
            Item.TYPE.FILE,
            Arrays.asList(filterInfo.getPrefix().toUpperCase() + "_TERM"),
            new HashMap<String, String>(),
            "All results"));

    // save significant results
    int numberOfSignificantTerms;
    List<GeneSetAnalysisTestResult> significant;
    String formattedPValue;
    for (int i = 0; i < DEFAULT_PVALUES.length; i++) {
      formattedPValue = pvalueFormatter.format(DEFAULT_PVALUES[i]);
      significant = gsea.getSignificant(DEFAULT_PVALUES[i]);
      if (significant != null && significant.size() > 0) {
        IOUtils.write(
            outdir + "/significant_" + filterInfo.getName() + "_" + formattedPValue + ".txt",
            gsea.significantResultsToStringList(significant, DEFAULT_PVALUES[i]));
        numberOfSignificantTerms = significant.size();
      } else {
        numberOfSignificantTerms = 0;
      }
      significantCount
          .get(i)
          .append(filterInfo.getTitle())
          .append("\t")
          .append(numberOfSignificantTerms)
          .append("\n");
      if (numberOfSignificantTerms > 0) {
        // go graph
        if (filterInfo.getPrefix().equalsIgnoreCase("go")) {
          try {
            String limitMessage = "";
            boolean outOfbounds = createGseaGoGraph(significant, DEFAULT_PVALUES[i], filterInfo);
            if (outOfbounds) limitMessage = " just most 100 significant terms";
            Item item =
                new Item(
                    "go_graph_significant_" + filterInfo.getName() + "_" + formattedPValue,
                    "go_graph_" + filterInfo.getName() + "_" + formattedPValue + "_graphimage.png",
                    filterInfo.getTitle()
                        + " DAG (significant terms, pvalue<"
                        + formattedPValue
                        + ") "
                        + limitMessage,
                    Item.TYPE.IMAGE,
                    Arrays.asList("SIGNIFICANT,THUMBNAIL,GO_GRAPH_VIZ_JNLP"),
                    new HashMap<String, String>(),
                    "Significant Results." + filterInfo.getTitle());
            item.setContext("pvalue==" + formattedPValue);
            result.getOutputItems().add(4, item);
          } catch (GoGraphException gge) {
            Item item =
                new Item(
                    "go_graph_significant_" + filterInfo.getName() + "_" + formattedPValue,
                    "Graph not found",
                    filterInfo.getTitle()
                        + " DAG (significant terms, pvalue<"
                        + formattedPValue
                        + ")",
                    Item.TYPE.MESSAGE,
                    Arrays.asList("ERROR"),
                    new HashMap<String, String>(),
                    "Significant Results." + filterInfo.getTitle());
            item.setContext("pvalue==" + formattedPValue);
            result.getOutputItems().add(4, item);
          }
        }
        // table
        Item item =
            new Item(
                "significant_" + filterInfo.getName(),
                "significant_" + filterInfo.getName() + "_" + formattedPValue + ".txt",
                filterInfo.getTitle() + " significant terms (pvalue<" + formattedPValue + ")",
                Item.TYPE.FILE,
                Arrays.asList(
                    "SIGNIFICANT",
                    "TABLE",
                    gsea.getMethod().toUpperCase() + "_TABLE",
                    filterInfo.getPrefix().toUpperCase() + "_TERM"),
                new HashMap<String, String>(),
                "Significant Results." + filterInfo.getTitle());
        item.setContext("pvalue==" + formattedPValue);
        result.getOutputItems().add(4, item);

      } else {
        Item item =
            new Item(
                "significant_" + filterInfo.getName(),
                "No significant terms for current pvalue " + formattedPValue,
                filterInfo.getTitle() + " significant terms (pvalue<" + formattedPValue + ")",
                Item.TYPE.MESSAGE,
                Arrays.asList("WARNING"),
                new HashMap<String, String>(),
                "Significant Results." + filterInfo.getTitle());
        item.setContext("pvalue==" + formattedPValue);
        result.getOutputItems().add(4, item);
      }
    }

    // annotations report
    addAnnotationReport(gsea, filterInfo.getTitle());

    // save annotations
    if (gsea.getAnnotations() != null && gsea.getAnnotations().size() > 0) {
      IOUtils.write(outdir + "/" + annotFileName, gsea.getAnnotations().toString());
      result.addOutputItem(
          new Item(
              "annot_" + filterInfo.getName(),
              annotFileName,
              "Annotations for " + filterInfo.getTitle(),
              Item.TYPE.FILE,
              Arrays.asList("ANNOTATION"),
              new HashMap<String, String>(),
              "Annotation files"));
    } else {
      result.addOutputItem(
          new Item(
              "annot_" + filterInfo.getName(),
              "no annotations found for input ids",
              "Annotations for " + filterInfo.getTitle(),
              Item.TYPE.MESSAGE,
              Arrays.asList("WARNING"),
              new HashMap<String, String>(),
              "Annotation files"));
    }
  }
Example #4
0
  private void doTest(FeatureData rankedList, FunctionalFilter filter, Method method)
      throws SQLException, IllegalAccessException, ClassNotFoundException, InstantiationException {

    // db attributes
    FunctionalDbDescriptor filterInfo = new FunctionalDbDescriptor(filter);

    // get term sizes
    //		AnnotationDBManager adbm = new AnnotationDBManager(dbConnector);
    //		Map<String, Integer> termSizes = adbm.getAnnotationTermsSize(filterInfo.getPrefix());

    logger.info(filterInfo.getTitle() + "...\n");

    GeneSetAnalysis gsea;

    if (method == Method.Logistic) {
      gsea = new LogisticScan(rankedList, filter, species, order);
      ((LogisticScan) gsea).setWorkingDirectory(outdir);
    } else {
      gsea =
          new FatiScan(
              rankedList,
              filter,
              null,
              numberOfPartitions,
              testMode,
              outputFormat,
              order,
              duplicatesMode);
    }

    // run
    try {

      gsea.setLogger(logger);

      // set term sizes
      //			gsea.setTermSizes(termSizes);

      gsea.run();

      logger.print("saving results...");
      // save results
      saveGeneSetAnalysisResults(gsea, filterInfo);
      logger.println("OK");

    } catch (EmptyAnnotationException ene) {
      result.addOutputItem(
          new Item(
              "annot_" + filterInfo.getName(),
              "No annotation was found for " + filterInfo.getTitle() + " ids",
              "Annotations for " + filterInfo.getTitle(),
              Item.TYPE.MESSAGE,
              Arrays.asList("WARNING"),
              new HashMap<String, String>(),
              "Annotation files"));
    } catch (Exception ene) {
      ene.printStackTrace();
      result.addOutputItem(
          new Item(
              "annot_" + filterInfo.getName(),
              "Unexpected error was found while running analysis for "
                  + filterInfo.getTitle()
                  + " ids",
              filterInfo.getTitle(),
              Item.TYPE.MESSAGE,
              Arrays.asList("ERROR"),
              new HashMap<String, String>(),
              "All results"));
    }

    logger.info("...end of " + filterInfo.getTitle());
  }