Example usage for org.dom4j DocumentHelper createDocument

List of usage examples for org.dom4j DocumentHelper createDocument

Introduction

In this page you can find the example usage for org.dom4j DocumentHelper createDocument.

Prototype

public static Document createDocument() 

Source Link

Usage

From source file:gov.nih.nci.rembrandt.web.taglib.HCPlotReport.java

License:BSD License

public StringBuffer quickReporterReport(List<String> reporters, ArrayPlatformType arrayPlatform) {
    StringBuffer html = new StringBuffer();
    Document document = DocumentHelper.createDocument();
    Element table = document.addElement("table").addAttribute("id", "reportTable").addAttribute("class",
            "report");
    Element tr = null;//from w  ww.  j a  v a  2  s  . c  om
    Element td = null;

    tr = table.addElement("tr").addAttribute("class", "header");
    td = tr.addElement("td").addAttribute("class", "header").addText("Reporter");
    td = tr.addElement("td").addAttribute("class", "header").addText("Gene Symbol");
    td = tr.addElement("td").addAttribute("class", "header").addText("GenBank AccId");
    td = tr.addElement("td").addAttribute("class", "header").addText("LocusLink");

    if (reporters != null) {
        try {
            Map reporterResultsetMap = AnnotationHandler.getAllAnnotationsFor(reporters, arrayPlatform);
            for (String reporterId : reporters) {
                if (reporterResultsetMap != null) {
                    ReporterAnnotations ra = (ReporterAnnotations) reporterResultsetMap.get(reporterId);
                    tr = table.addElement("tr").addAttribute("class", "data");

                    String reporter = ra.getReporterName() != null ? ra.getReporterName() : "N/A";

                    td = tr.addElement("td").addText(reporter);
                    //html.append("ReporterID :" +reporterResultset.getReporter().getValue().toString() + "<br/>");
                    String geneSymbols = ra.getGeneSymbol();
                    String genes = "";
                    if (geneSymbols != null)
                        genes = geneSymbols;

                    td = tr.addElement("td").addText(genes);

                    Collection genBank_AccIDS = ra.getAccessions();
                    String accs = "";
                    if (genBank_AccIDS != null) {
                        accs = StringUtils.join(genBank_AccIDS.toArray(), ",");
                    }

                    td = tr.addElement("td").addText(accs);

                    Collection locusLinkIDs = ra.getLocusLinks();
                    String ll = "";
                    if (locusLinkIDs != null) {
                        ll = StringUtils.join(locusLinkIDs.toArray(), ",");
                    }

                    td = tr.addElement("td").addText(ll);

                    /*
                    Collection<String> goIds = (Collection<String>)reporterResultset.getAssociatedGOIds();
                    if(goIds != null){
                       for(String goId: goIds){
                          html.append("Associtaed GO Id :" +goId + "<br/>");
                       }
                    }
                    Collection<String> pathways = (Collection<String>)reporterResultset.getAssociatedPathways();
                    if(pathways != null){
                       for(String pathway: pathways){
                          html.append("Associated Pathway :" +pathway + "<br/>");
                       }
                    }
                    */
                }
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    //return html;
    return html.append(document.asXML());
}

From source file:gov.nih.nci.rembrandt.web.xml.ClassComparisonReport.java

License:BSD License

public static Document getReportXML(Finding finding, Map filterMapParams, boolean allAnnotations,
        ArrayList reporterIdFilter) {

    DecimalFormat resultFormat = new DecimalFormat("0.0000");
    DecimalFormat sciFormat = new DecimalFormat("0.00E0");
    DecimalFormat tmpsciFormat = new DecimalFormat("###0.0000#####################");

    /*/*from w w  w  .  j av a2 s.  c  o  m*/
     *  this is for filtering, we will want a p-value filter for CC
     */
    ArrayList filter_string = new ArrayList(); // hashmap of genes | reporters | cytobands
    String filter_type = "show"; // show | hide
    String filter_element = "none"; // none | gene | reporter | cytoband

    if (filterMapParams.containsKey("filter_string") && filterMapParams.get("filter_string") != null)
        filter_string = (ArrayList) filterMapParams.get("filter_string");
    if (filterMapParams.containsKey("filter_type") && filterMapParams.get("filter_type") != null)
        filter_type = (String) filterMapParams.get("filter_type");
    if (filterMapParams.containsKey("filter_element") && filterMapParams.get("filter_element") != null)
        filter_element = (String) filterMapParams.get("filter_element");

    String defaultV = "--";
    String delim = " | ";

    Document document = DocumentHelper.createDocument();

    Element report = document.addElement("Report");
    Element cell = null;
    Element data = null;
    Element dataRow = null;
    //add the atts
    report.addAttribute("reportType", "Class Comparison");
    report.addAttribute("helpLink", ContextSensitiveHelpTag.getHelpLink("Class Comparison"));
    //fudge these for now
    report.addAttribute("groupBy", "none");
    String queryName = "none";
    queryName = finding.getTaskId();

    //set the queryName to be unique for session/cache access
    report.addAttribute("queryName", queryName);
    report.addAttribute("sessionId", "the session id");
    report.addAttribute("creationTime", "right now");

    StringBuffer sb = new StringBuffer();

    int recordCount = 0;
    int totalSamples = 0;

    //TODO: instance of
    ClassComparisonFinding ccf = (ClassComparisonFinding) finding;

    //process the query details
    ArrayList<String> queryDetails = new ArrayList();
    ClassComparisonQueryDTO ccdto = (ClassComparisonQueryDTO) ccf.getQueryDTO();

    if (ccdto != null) {
        String tmp = "";
        tmp = ccdto.getQueryName() != null ? ccdto.getQueryName() : "";
        queryDetails.add("Query Name: " + tmp);
        tmp = ccdto.getArrayPlatformDE() != null ? ccdto.getArrayPlatformDE().getValue().toString() : "";
        queryDetails.add("Array Platform: " + tmp);

        tmp = "";
        List<ClinicalQueryDTO> grps = ccdto.getComparisonGroups() != null ? ccdto.getComparisonGroups()
                : new ArrayList();
        Collection grs = new ArrayList();
        for (ClinicalQueryDTO cdto : grps) {
            if (cdto.getQueryName() != null)
                grs.add(cdto.getQueryName());
        }

        tmp += StringUtils.join(grs.toArray(), ", ") + " (baseline)";
        queryDetails.add("Groups: " + tmp);
        /*
        noHTMLString = noHTMLString.replaceAll("<", "{");
        noHTMLString = noHTMLString.replaceAll(">", "}");
        noHTMLString = noHTMLString.replaceAll("&nbsp;", " ");
        */
        tmp = ccdto.getExprFoldChangeDE() != null ? ccdto.getExprFoldChangeDE().getValue().toString() : "";
        queryDetails.add("Fold Change: " + tmp);
        //queryDetails.add("Institutions: " + ccdto.getInstitutionDEs());
        tmp = ccdto.getMultiGroupComparisonAdjustmentTypeDE() != null
                ? ccdto.getMultiGroupComparisonAdjustmentTypeDE().getValue().toString()
                : "";
        queryDetails.add("Multi Group: " + tmp);
        tmp = ccdto.getStatisticalSignificanceDE() != null
                ? ccdto.getStatisticalSignificanceDE().getValue().toString()
                : "";
        queryDetails.add("Stat Sig.: " + tmp);
        tmp = ccdto.getStatisticTypeDE() != null ? ccdto.getStatisticTypeDE().getValue().toString() : "";
        queryDetails.add("Stat Type: " + tmp);
    }
    /*
    queryDetails.add("Analysis Result name: " + ccform.getAnalysisResultName());
    queryDetails.add("Array Platform: " + ccform.getArrayPlatform());
    queryDetails.add("Baseline group: " + ccform.getBaselineGroup());
    queryDetails.add("Comparison Groups: " + ccform.getSelectedGroups()[0].toString());
    queryDetails.add("Comparison Adjustment: " + ccform.getComparisonAdjustment());
    //queryDetails.add("Comp. Adj. Coll: " + ccform.getComparisonAdjustmentCollection());
    //queryDetails.add("Existing Groups: " + ccform.getExistingGroups());
    //queryDetails.add("Existing group list: " + ccform.getExistingGroupsList());
    //queryDetails.add("Fold Change: " + ccform.getFoldChange());
    queryDetails.add("Fold Change auto: " + ccform.getFoldChangeAuto());
    //queryDetails.add("Fold change auto list: " + ccform.getFoldChangeAutoList());
    //queryDetails.add("Fold change manual: " + ccform.getFoldChangeManual());
    queryDetails.add("Stastic: " + ccform.getStatistic());
    queryDetails.add("Stastical method: " + ccform.getStatisticalMethod());
    //queryDetails.add("Stastical method coll.: " + ccform.getStatisticalMethodCollection());
    queryDetails.add("Stastical significance: " + ccform.getStatisticalSignificance());
    */
    String qd = "";
    for (String q : queryDetails) {
        qd += q + " ||| ";
    }

    if (ccf != null) {

        Element details = report.addElement("Query_details");
        cell = details.addElement("Data");
        cell.addText(qd);
        cell = null;

        Element headerRow = report.addElement("Row").addAttribute("name", "headerRow");
        cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText("Reporter");
        data = null;
        cell = null;

        //pvalue is fixed in the second column, essential for XSL
        cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header")
                .addAttribute("group", "header");
        String isAdj = ccf.arePvaluesAdjusted() ? " (Adjusted) " : "";
        data = cell.addElement("Data").addAttribute("type", "header")
                .addText(RembrandtConstants.PVALUE + isAdj);
        data = null;
        cell = null;

        cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText("Group Avg");
        data = null;
        cell = null;

        cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText("Fold Change");
        data = null;
        cell = null;

        cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText("Gene Symbol");
        data = null;
        cell = null;

        //starting annotations...get them only if allAnnotations == true
        if (allAnnotations) {
            cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "csv")
                    .addAttribute("group", "header");
            data = cell.addElement("Data").addAttribute("type", "header").addText("GenBank Acc");
            data = null;
            cell = null;
            cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "csv")
                    .addAttribute("group", "header");
            data = cell.addElement("Data").addAttribute("type", "header").addText("Locus link");
            data = null;
            cell = null;
            cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "csv")
                    .addAttribute("group", "header");
            data = cell.addElement("Data").addAttribute("type", "header").addText("GO Id");
            data = null;
            cell = null;
            cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "csv")
                    .addAttribute("group", "header");
            data = cell.addElement("Data").addAttribute("type", "header").addText("Pathways");
            data = null;
            cell = null;
        }

        /* done with the headerRow and SampleRow Elements, time to add data rows */

        /*
        Map<String,ReporterResultset> reporterResultsetMap = null;
        reporterResultsetMap = ccf.getReporterAnnotationsMap();
        */

        List<ClassComparisonResultEntry> classComparisonResultEntrys = ccf.getResultEntries();
        List<String> reporterIds = new ArrayList<String>();
        HashSet<String> reporterIdSet = null;

        if (reporterIdFilter != null) {
            reporterIdSet = new HashSet<String>(reporterIdFilter);
        }

        int index = 0;
        if (reporterIdFilter == null) {
            for (ClassComparisonResultEntry classComparisonResultEntry : classComparisonResultEntrys) {
                if (classComparisonResultEntry.getReporterId() != null) {
                    reporterIds.add(classComparisonResultEntry.getReporterId());
                }
            }
        } else {
            reporterIds = reporterIdFilter;
        }

        Map reporterResultsetMap = null;
        ArrayPlatformType arrayPlatform = ccdto.getArrayPlatformDE() != null
                ? ccdto.getArrayPlatformDE().getValueObjectAsArrayPlatformType()
                : ArrayPlatformType.AFFY_OLIGO_PLATFORM;
        if (allAnnotations) {
            //Map<String, ReporterAnnotations> reporterResultsetMap = null;
            try {
                reporterResultsetMap = AnnotationHandler.getAllAnnotationsFor(reporterIds, arrayPlatform);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            try {
                reporterResultsetMap = AnnotationHandler.getGeneSymbolsFor(reporterIds, arrayPlatform);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        /*
        //this looks like a failsafe for the old method
        if(reporterResultsetMap == null)   {
         try {
            reporterResultsetMap = GeneExprAnnotationService.getAnnotationsMapForReporters(reporterIds);
         }
         catch(Exception e){}
          }
          */

        boolean found = false;
        for (ClassComparisonResultEntry ccre : ccf.getResultEntries()) {

            if (reporterIdFilter != null) {
                found = reporterIdSet.contains(ccre.getReporterId());

                //not found, then skip
                if (!found)
                    continue;
            }

            dataRow = report.addElement("Row").addAttribute("name", "dataRow");
            cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "reporter")
                    .addAttribute("group", "data");
            data = cell.addElement("Data").addAttribute("type", "header").addText(ccre.getReporterId());
            data = null;
            cell = null;

            cell = dataRow.addElement("Cell").addAttribute("type", "pval").addAttribute("class", "data")
                    .addAttribute("group", "data");
            //String pv = (ccre.getPvalue() == null) ? String.valueOf(ccre.getPvalue()) : "N/A";
            BigDecimal bigd = new BigDecimal(ccre.getPvalue());
            data = cell.addElement("Data").addAttribute("type", "header").addText(bigd.toPlainString());
            data = null;
            cell = null;

            cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "data")
                    .addAttribute("group", "data");
            data = cell.addElement("Data").addAttribute("type", "header")
                    .addText(resultFormat.format(ccre.getMeanGrp1()) + " / "
                            + resultFormat.format(ccre.getMeanBaselineGrp()));
            data = null;
            cell = null;

            cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "data")
                    .addAttribute("group", "data");
            data = cell.addElement("Data").addAttribute("type", "header")
                    .addText(String.valueOf(resultFormat.format(ccre.getFoldChange())));
            data = null;
            cell = null;

            //if only showing genes
            if (!allAnnotations && reporterResultsetMap != null) {
                String reporterId = ccre.getReporterId();
                String genes = reporterResultsetMap.get(reporterId) != null
                        ? (String) reporterResultsetMap.get(reporterId)
                        : defaultV;
                cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "gene")
                        .addAttribute("group", "data");
                data = cell.addElement("Data").addAttribute("type", "header").addText(genes);
                data = null;
                cell = null;
            } else {
                //get the gene symbols for this reporter
                //ccre.getReporterId()
                String genes = defaultV;

                //start annotations
                String accIds = defaultV;
                String llink = defaultV;
                String go = defaultV;
                String pw = defaultV;

                if (reporterResultsetMap != null) { // && reporterIds != null
                    //int count = 0;
                    String reporterId = ccre.getReporterId();
                    //ReporterResultset reporterResultset = reporterResultsetMap.get(reporterId);
                    ReporterAnnotations ra = (ReporterAnnotations) reporterResultsetMap.get(reporterId);

                    //Collection<String> geneSymbols = (Collection<String>)reporterResultset.getAssiciatedGeneSymbols();
                    String geneSymbols = ra.getGeneSymbol();
                    if (geneSymbols != null)
                        genes = geneSymbols;
                    /*
                    if(geneSymbols != null){
                       genes = StringUtils.join(geneSymbols.toArray(), delim);
                    }
                    */
                    Collection<String> genBank_AccIDS = (Collection<String>) ra.getAccessions();
                    if (genBank_AccIDS != null) {
                        accIds = StringUtils.join(genBank_AccIDS.toArray(), delim);
                    }
                    Collection<String> locusLinkIDs = (Collection<String>) ra.getLocusLinks();
                    if (locusLinkIDs != null) {
                        llink = StringUtils.join(locusLinkIDs.toArray(), delim);
                    }
                    Collection<String> goIds = (Collection<String>) ra.getGoIDS();
                    if (goIds != null) {
                        go = StringUtils.join(goIds.toArray(), delim);
                    }
                    Collection<String> pathways = (Collection<String>) ra.getPathways();
                    if (pathways != null) {
                        pw = StringUtils.join(pathways.toArray(), delim);
                    }
                }

                cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "gene")
                        .addAttribute("group", "data");
                data = cell.addElement("Data").addAttribute("type", "header").addText(genes);
                data = null;
                cell = null;
                cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "csv")
                        .addAttribute("group", "data");
                data = cell.addElement("Data").addAttribute("type", "header").addText(accIds);
                data = null;
                cell = null;
                cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "csv")
                        .addAttribute("group", "data");
                data = cell.addElement("Data").addAttribute("type", "header").addText(llink);
                data = null;
                cell = null;
                cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "csv")
                        .addAttribute("group", "data");
                data = cell.addElement("Data").addAttribute("type", "header").addText(go);
                data = null;
                cell = null;
                cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "csv")
                        .addAttribute("group", "data");
                data = cell.addElement("Data").addAttribute("type", "header").addText(pw);
                data = null;
                cell = null;

            }
        }
    } else {
        //TODO: handle this error
        sb.append("<br/><br/>Class Comparison is empty<br/>");
    }

    return document;
}

From source file:gov.nih.nci.rembrandt.web.xml.ClinicalSampleReport.java

License:BSD License

@SuppressWarnings("unchecked")
public Document getReportXML(Resultant resultant, Map filterMapParams) {

    //String theColors[] = { "B6C5F2","F2E3B5","DAE1F9","C4F2B5","819BE9", "E9CF81" };
    DecimalFormat resultFormat = new DecimalFormat("0.0000");
    String defaultV = "-";

    Document document = DocumentHelper.createDocument();

    try {/* w  w w. j  ava  2s. c  o m*/
        Element report = document.addElement("Report");
        Element cell = null;
        Element data = null;
        Element dataRow = null;
        //add the atts
        report.addAttribute("reportType", "Clinical");
        report.addAttribute("helpLink", ContextSensitiveHelpTag.getHelpLink("Clinical"));
        //fudge these for now
        report.addAttribute("groupBy", "none");
        String queryName = resultant.getAssociatedQuery().getQueryName();

        //set the queryName to be unique for session/cache access
        report.addAttribute("queryName", queryName);
        report.addAttribute("sessionId", "the session id");
        report.addAttribute("creationTime", "right now");
        //hold a message to display on the report
        report.addAttribute("msg", (resultant.isOverLimit() ? "over limit" : ""));

        boolean gLinks = false;
        boolean cLinks = false;
        StringBuffer sb = new StringBuffer();

        ResultsContainer resultsContainer = resultant.getResultsContainer();
        SampleViewResultsContainer sampleViewContainer = null;
        if (resultsContainer instanceof DimensionalViewContainer) {

            DimensionalViewContainer dimensionalViewContainer = (DimensionalViewContainer) resultsContainer;
            // Are we making hyperlinks?
            if (dimensionalViewContainer.getGeneExprSingleViewContainer() != null) {
                // show the geneExprHyperlinks
                gLinks = true;
            }
            if (dimensionalViewContainer.getCopyNumberSingleViewContainer() != null) {
                // show the copyNumberHyperlinks
                cLinks = true;
            }

            sampleViewContainer = dimensionalViewContainer.getSampleViewResultsContainer();

        } else if (resultsContainer instanceof SampleViewResultsContainer) {
            sampleViewContainer = (SampleViewResultsContainer) resultsContainer;
        }

        Collection samples = sampleViewContainer.getSampleResultsets();

        //   set up the headers for this table 
        Element headerRow = report.addElement("Row").addAttribute("name", "headerRow");

        for (String h : ClinicalSampleReport.getClinicalHeaderValues()) {
            cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header")
                    .addAttribute("group", "header");
            data = cell.addElement("Data").addAttribute("type", "header").addText(h);
            data = null;
            cell = null;
        }
        //append these to header if necessary
        Iterator si = samples.iterator();
        if (si.hasNext()) {
            SampleResultset sampleResultset = (SampleResultset) si.next();
            if (sampleResultset.getGeneExprSingleViewResultsContainer() != null) {
                cell = headerRow.addElement("Cell").addAttribute("type", "header")
                        .addAttribute("class", "header").addAttribute("group", "header");
                data = cell.addElement("Data").addAttribute("type", "header").addText("GeneExp");
                data = null;
                cell = null;
            }
            if (sampleResultset.getCopyNumberSingleViewResultsContainer() != null) {
                cell = headerRow.addElement("Cell").addAttribute("type", "header")
                        .addAttribute("class", "header").addAttribute("group", "header");
                data = cell.addElement("Data").addAttribute("type", "header").addText("CopyNumber");
                data = null;
                cell = null;
            }
        }
        //DONE header row         

        for (Iterator sampleIterator = samples.iterator(); sampleIterator.hasNext();) {

            SampleResultset sampleResultset = (SampleResultset) sampleIterator.next();

            dataRow = report.addElement("Row").addAttribute("name", "dataRow");

            List rows = new ArrayList();
            rows = ClinicalSampleReport.getClinicalRowValues(sampleResultset);
            /*
            rows.add(sampleResultset.getSampleIDDE());
            rows.add(sampleResultset.getAgeGroup());
            if(!DEUtils.checkNV(sampleResultset.getGenderCode()).equalsIgnoreCase("O"))   {
               rows.add(sampleResultset.getGenderCode());
            }
            else   {   
               rows.add(defaultV);
            }
            rows.add(sampleResultset.getSurvivalLengthRange());
            rows.add(sampleResultset.getDisease());
            rows.add(sampleResultset.getWhoGrade());
            rows.add(sampleResultset.getRaceDE());
            rows.add(sampleResultset.getKarnofskyClinicalEvalDE());
            rows.add(sampleResultset.getNeuroExamDescs());
            rows.add(sampleResultset.getMriScoreDescs());
            rows.add(sampleResultset.getFollowupMonths());
            rows.add(sampleResultset.getSteroidDoseStatuses());
            rows.add(sampleResultset.getAntiConvulsantStatuses());
                    
            rows.add(sampleResultset.getPriorRadiationRadiationSites());
            rows.add(sampleResultset.getPriorRadiationFractionDoses());
            rows.add(sampleResultset.getPriorRadiationFractionNumbers());
            rows.add(sampleResultset.getPriorRadiationRadiationTypes());
            rows.add(sampleResultset.getPriorChemoAgentNames());
            rows.add(sampleResultset.getPriorChemoCourseCounts());
            rows.add(sampleResultset.getPriorSurgeryProcedureTitles());
            rows.add(sampleResultset.getPriorSurgeryTumorHistologys());
            rows.add(sampleResultset.getPriorSurgerySurgeryOutcomes());
                    
            rows.add(sampleResultset.getOnStudyRadiationRadiationSites());
            rows.add(sampleResultset.getOnStudyRadiationFractionDoses());
            rows.add(sampleResultset.getOnStudyRadiationFractionNumbers());
            rows.add(sampleResultset.getOnStudyRadiationNeurosisStatuses());
            rows.add(sampleResultset.getOnStudyRadiationRadiationTypes());
            rows.add(sampleResultset.getOnStudyChemoAgentNames());
            rows.add(sampleResultset.getOnStudyChemoCourseCounts());
            rows.add(sampleResultset.getOnStudySurgeryProcedureTitles());
            rows.add(sampleResultset.getOnStudySurgeryIndications());
            rows.add(sampleResultset.getOnStudySurgeryHistoDiagnoses());
            rows.add(sampleResultset.getOnStudySurgerySurgeryOutcomes());
            */

            cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "data")
                    .addAttribute("group", "sample");
            data = cell.addElement("Data").addAttribute("type", "data").addText(DEUtils.checkNull(rows.get(0)));
            data = null;
            cell = null;

            for (int i = 1; i < rows.size(); i++) {
                cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "data")
                        .addAttribute("group", "data");
                data = cell.addElement("Data").addAttribute("type", "data")
                        .addText(DEUtils.checkNull(rows.get(i)));
                data = null;
                cell = null;
            }

            if (sampleResultset.getGeneExprSingleViewResultsContainer() != null) {
                //TODO: create the links
                cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "data")
                        .addAttribute("group", "data");
                data = cell.addElement("Data").addAttribute("type", "data").addText("G");
                data = null;
                cell = null;
            }
            if (sampleResultset.getCopyNumberSingleViewResultsContainer() != null) {
                //   TODO: create the links
                cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "data")
                        .addAttribute("group", "data");
                data = cell.addElement("Data").addAttribute("type", "data").addText("C");
                data = null;
                cell = null;
            }
        }
    } catch (Exception e) {
        System.out.println(e);
    }
    return document;
}

From source file:gov.nih.nci.rembrandt.web.xml.CopyNumberGeneBasedSampleReport.java

License:BSD License

public Document getReportXML(Resultant resultant, Map filterMapParams) {

    DecimalFormat resultFormat = new DecimalFormat("0.0000");
    String delim = " | ";
    /* testing hardcoded vals - these will be params of this method soon */
    /*//www. j a  v  a  2  s.c  o m
    ArrayList g = new ArrayList();
    g.add("EGFR");
    g.add("VEGF");
    String tmp_filter_type = "hide";
    String tmp_filter_element = "gene";
            
    HashMap filterMapParams = new HashMap();
    filterMapParams.put("filter_string", g);
    filterMapParams.put("filter_type", tmp_filter_type);
    filterMapParams.put("filter_element", tmp_filter_element);
    */

    ArrayList filter_string = new ArrayList(); // hashmap of genes | reporters | cytobands
    String filter_type = "show"; // show | hide
    String filter_element = "none"; // none | gene | reporter | cytoband

    if (filterMapParams.containsKey("filter_string") && filterMapParams.get("filter_string") != null)
        filter_string = (ArrayList) filterMapParams.get("filter_string");
    if (filterMapParams.containsKey("filter_type") && filterMapParams.get("filter_type") != null)
        filter_type = (String) filterMapParams.get("filter_type");
    if (filterMapParams.containsKey("filter_element") && filterMapParams.get("filter_element") != null)
        filter_element = (String) filterMapParams.get("filter_element");

    Document document = DocumentHelper.createDocument();

    Element report = document.addElement("Report");
    Element cell = null;
    Element data = null;
    Element dataRow = null;
    //add the atts
    report.addAttribute("reportType", "Copy Number");
    report.addAttribute("helpLink", ContextSensitiveHelpTag.getHelpLink("Copy Number"));
    //fudge these for now
    report.addAttribute("groupBy", "none");
    String queryName = resultant.getAssociatedQuery().getQueryName();
    //set the queryName to be unique for session/cache access
    report.addAttribute("queryName", queryName);
    report.addAttribute("sessionId", "the session id");
    report.addAttribute("creationTime", "right now");
    //hold a message to display on the report
    report.addAttribute("msg", (resultant.isOverLimit() ? "over limit" : ""));
    ResultsContainer resultsContainer = resultant.getResultsContainer();

    CopyNumberGeneViewResultsContainer copyNumberGeneViewContainer = null;
    StringBuffer sb = new StringBuffer();

    //String helpFul = helpLink + "?sect=sample" + helpLinkClose;

    DimensionalViewContainer dimensionalViewContainer = null;
    int recordCount = 0;
    int totalSamples = 0;

    if (resultsContainer instanceof DimensionalViewContainer) {
        dimensionalViewContainer = (DimensionalViewContainer) resultsContainer;
        if (dimensionalViewContainer != null) {
            copyNumberGeneViewContainer = dimensionalViewContainer.getCopyNumberGeneViewResultsContainer();
        }
    } else if (resultsContainer instanceof CopyNumberGeneViewResultsContainer) { //for single
        copyNumberGeneViewContainer = (CopyNumberGeneViewResultsContainer) resultsContainer;
    }

    if (copyNumberGeneViewContainer != null) {
        Collection genes = copyNumberGeneViewContainer.getGeneResultsets();
        Collection labels = copyNumberGeneViewContainer.getGroupsLabels();
        Collection sampleIds = null;

        StringBuffer header = new StringBuffer();

        //header.append("<table cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n");
        StringBuffer sampleNames = new StringBuffer();
        StringBuffer stringBuffer = new StringBuffer();

        Element headerRow = report.addElement("Row").addAttribute("name", "headerRow");
        cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText("Gene");
        data = null;
        cell = null;
        cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText(" ");//reporter
        data = null;
        cell = null;

        //starting annotations
        cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "csv")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText("Locus link");
        data = null;
        cell = null;
        cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "csv")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText("GenBank Acc");
        data = null;
        cell = null;

        cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "csv")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText("GO Id");
        cell = null;
        cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "csv")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText("Pathways");
        cell = null;

        Element sampleRow = report.addElement("Row").addAttribute("name", "sampleRow");
        cell = sampleRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText(" ");
        data = null;
        cell = null;
        cell = sampleRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText(" ");
        data = null;
        cell = null;

        cell = sampleRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "csv")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText(" ");
        data = null;
        cell = null;
        cell = sampleRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "csv")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText(" ");
        data = null;
        cell = null;
        cell = sampleRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "csv")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText(" ");
        data = null;
        cell = null;
        cell = sampleRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "csv")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText(" ");
        data = null;
        cell = null;

        //set up the header for the table           
        //header.append("<Td id=\"header\">Gene</td>\n<td id=\"header\">Reporter</td>\n");        
        //sampleNames.append("<tr><Td> &nbsp;</td><Td> &nbsp;</tD>"); 

        for (Iterator labelIterator = labels.iterator(); labelIterator.hasNext();) {
            String label = (String) labelIterator.next();
            sampleIds = copyNumberGeneViewContainer.getBiospecimenLabels(label);
            //                theColspan += sampleIds.size();
            totalSamples += sampleIds.size();

            cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", label)
                    .addAttribute("group", label);
            data = cell.addElement("Data").addAttribute("type", "header").addText(label + " Samples");
            data = null;
            cell = null;
            //header.append("<td colspan="+sampleIds.size()+" class='"+label+"' id=\"header\">"+label+" Samples</td>"); 

            for (Iterator sampleIdIterator = sampleIds.iterator(); sampleIdIterator.hasNext();) {
                BioSpecimenIdentifierDE bioSpecimenIdentifierDE = (BioSpecimenIdentifierDE) sampleIdIterator
                        .next();

                cell = sampleRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", label)
                        .addAttribute("group", label)
                        .addAttribute("sampleId", bioSpecimenIdentifierDE.getSampleId());
                //cell = sampleRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", label).addAttribute("group", label).addAttribute("specimen", bioSpecimenIdentifierDE.getSpecimenName());
                //data = cell.addElement("Data").addAttribute("type", "header").addText(s.substring(2));
                if (bioSpecimenIdentifierDE.getSpecimenName() != null) {
                    data = cell.addElement("Data").addAttribute("type", "header")
                            .addText(bioSpecimenIdentifierDE.getSpecimenName());
                } else {
                    data = cell.addElement("Data").addAttribute("type", "header")
                            .addText(bioSpecimenIdentifierDE.getSampleId());
                }
                data = null;
                cell = null;
                //sampleNames.append("<td class='"+label+"' id=\"header\"><a href=\"report.do?s="+s+"&report=ss\">"+s.substring(2)+"</a></td>"); 
                //header.append("\t");

            }
            //header.deleteCharAt(header.lastIndexOf("\t"));
        }
        //sampleNames.append("</tr>");
        //header.append("</tr>"); 

        /* done with the headerRow and SampleRow Elements, time to add data rows */

        for (Iterator geneIterator = genes.iterator(); geneIterator.hasNext();) {
            GeneResultset geneResultset = (GeneResultset) geneIterator.next();
            //Collection reporters = geneResultset.getReporterResultsets();
            String the_gene = "";
            /*  hard code filter for now */
            if (geneResultset.getGeneSymbol() != null) {
                the_gene = geneResultset.getGeneSymbol().getValueObject().toString();
            }

            //if(!the_gene.equalsIgnoreCase(filter_string))   {
            if (FilterHelper.checkFilter(filter_element, "gene", the_gene, filter_type, filter_string)) {
                //if(!filter_element.equals("gene") || (filter_element.equals("gene") && !filter_string.contains(the_gene)))   {
                recordCount += genes.size();

                //for (Iterator reporterIterator = reporters.iterator(); reporterIterator.hasNext();) {
                //   ReporterResultset reporterResultset = (ReporterResultset)reporterIterator.next();
                Collection groupTypes = geneResultset.getGroupByResultsets();
                //String reporterName = reporterResultset.getReporter().getValue().toString();

                /* test filtration by reporter */
                //if(!filter_element.equals("reporter") || (filter_element.equals("reporter") && !filter_string.contains(reporterName)))   {      
                if (FilterHelper.checkFilter(filter_element, "reporter",
                        geneResultset.getGeneSymbol().getValueObject().toString(), filter_type,
                        filter_string)) {
                    GeneSymbol gene = geneResultset.getGeneSymbol();
                    //String geneSymbol = "&#160;";
                    String geneSymbol = "-";
                    if (gene != null) {
                        geneSymbol = geneResultset.getGeneSymbol().getValueObject().toString();
                    }

                    dataRow = report.addElement("Row").addAttribute("name", "dataRow");
                    cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "gene")
                            .addAttribute("group", "header");
                    data = cell.addElement("Data").addAttribute("type", "header").addText(geneSymbol);
                    data = null;
                    cell = null;
                    cell = dataRow.addElement("Cell").addAttribute("type", "data")
                            .addAttribute("class", "reporter").addAttribute("group", "header");
                    data = cell.addElement("Data").addAttribute("type", "header").addText(" ");//reporter
                    data = null;
                    cell = null;
                    //sb.append("<tr><td>"+geneSymbol+"</td><td>"+reporterName+"</td>");

                    /*
                     * adding our 4 annotations. this code needs to be cleaned up...
                     * 
                     * I will pull all this logic out into a seperate Annotations Class ...
                     * or something like that ASAP
                     * 
                     * RCL
                     * 
                     */
                    //                             String ll = "";                             
                    //                             try   {
                    //                                HashSet locusLinkIds = new HashSet(reporterResultset.getAssiciatedLocusLinkIDs());
                    //                                if(locusLinkIds != null){
                    //                                   ll = StringUtils.join(locusLinkIds.toArray(), delim);
                    //                                }
                    //                                else   {
                    //                                   ll = "-";
                    //                                }
                    //                             }
                    //                             catch(Exception e){
                    //                                ll = "--";
                    //                             }
                    //                             
                    //
                    //                             String acc = "";
                    //                             try   {
                    //                                HashSet accNumbers = new HashSet(reporterResultset.getAssiciatedGenBankAccessionNos());
                    //                                if(accNumbers!=null)   {
                    //                                   acc = StringUtils.join(accNumbers.toArray(), delim);      
                    //                                }
                    //                                else   {
                    //                                   acc = "-";
                    //                                }
                    //                             }
                    //                             catch(Exception e){   }
                    //                             
                    //                             String go_ids = "";
                    //                             try   {
                    //                                HashSet go_idsHS = new HashSet(reporterResultset.getAssociatedGOIds());
                    //                                if(go_idsHS!=null)   {
                    //                                   go_ids = StringUtils.join(go_idsHS.toArray(), delim);
                    //                                }
                    //                                else   {
                    //                                    go_ids = "-";
                    //                                }
                    //                             }
                    //                             catch(Exception e){   }
                    //                             
                    //                             String pathways = "";
                    //                             try   {
                    //                                HashSet pathwaysHS = new HashSet(reporterResultset.getAssociatedPathways());
                    //                                if(pathwaysHS!=null)   {
                    //                                   pathways = StringUtils.join(pathwaysHS.toArray(), delim);
                    //                                }
                    //                                else   {
                    //                                    pathways = "-";
                    //                                }
                    //                             }
                    //                             catch(Exception e){   }

                    /*
                    * 
                    *  actually add the annotations to the report
                    * 
                    */
                    //                             cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "csv").addAttribute("group", "header");
                    //                                data = cell.addElement("Data").addAttribute("type", "header").addText(ll);
                    //                                data = null;
                    //                             cell = null;
                    //                             cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "csv").addAttribute("group", "header");
                    //                                data = cell.addElement("Data").addAttribute("type", "header").addText(acc);
                    //                                data = null;
                    //                             cell = null;
                    //                             cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "csv").addAttribute("group", "header");
                    //                                data = cell.addElement("Data").addAttribute("type", "header").addText(go_ids);
                    //                                data = null;
                    //                             cell = null;
                    //                             cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "csv").addAttribute("group", "header");
                    //                                data = cell.addElement("Data").addAttribute("type", "header").addText(pathways);
                    //                                data = null;
                    //                             cell = null;

                    for (Iterator labelIterator = labels.iterator(); labelIterator.hasNext();) {
                        String label = (String) labelIterator.next();
                        ViewByGroupResultset groupResultset = (ViewByGroupResultset) geneResultset
                                .getGroupByResultset(label);

                        sampleIds = copyNumberGeneViewContainer.getBiospecimenLabels(label);
                        String hClass = label;
                        if (groupResultset != null) {
                            for (Iterator sampleIdIterator = sampleIds.iterator(); sampleIdIterator
                                    .hasNext();) {

                                BioSpecimenIdentifierDE sampleId = (BioSpecimenIdentifierDE) sampleIdIterator
                                        .next();
                                SampleCopyNumberValuesResultset biospecimenResultset = (SampleCopyNumberValuesResultset) groupResultset
                                        .getBioSpecimenResultset(sampleId.getSpecimenName());
                                if (biospecimenResultset != null) {

                                    //JB Begin: Add for GForge # 17783 - Advance Query Reports - Make the report more user friendly (Provide tool tip)
                                    String tooltip = "Gene = " + geneSymbol + ", Sample = "
                                            + sampleId.getSampleId() + " (" + sampleId.getSpecimenName() + ")";
                                    //JB End: Add for GForge # 17783 - Advance Query Reports - Make the report more user friendly (Provide tool tip)

                                    if (biospecimenResultset.isHighlighted())
                                        hClass = "highlighted";
                                    else
                                        hClass = label;

                                    Double ratio = (Double) biospecimenResultset.getSegmentMean().getValue();
                                    if (ratio != null) {
                                        cell = dataRow.addElement("Cell").addAttribute("type", "data")
                                                .addAttribute("class", hClass).addAttribute("group", label);
                                        //JB Begin: Add for GForge # 17783 - Advance Query Reports - Make the report more user friendly (Provide tool tip)
                                        //data = cell.addElement("Data").addAttribute("type", "data").addText(resultFormat.format(ratio));
                                        data = cell.addElement("Data").addAttribute("type", "data")
                                                .addAttribute("datainfo", tooltip)
                                                .addText(resultFormat.format(ratio));
                                        //JB End: Add for GForge # 17783 - Advance Query Reports - Make the report more user friendly (Provide tool tip)
                                        data = null;
                                        cell = null;

                                        //sb.append("<Td class='"+label+"'>"+resultFormat.format(ratio)+" </td>");
                                    } else {
                                        cell = dataRow.addElement("Cell").addAttribute("type", "data")
                                                .addAttribute("class", hClass).addAttribute("group", label);
                                        data = cell.addElement("Data").addAttribute("type", "data")
                                                .addText("-");
                                        data = null;
                                        cell = null;
                                        //sb.append("<td class='"+label+"'>-</td>");
                                    }
                                } else {
                                    cell = dataRow.addElement("Cell").addAttribute("type", "data")
                                            .addAttribute("class", hClass).addAttribute("group", label);
                                    data = cell.addElement("Data").addAttribute("type", "data").addText("-");
                                    data = null;
                                    cell = null;
                                    //sb.append("<td class='"+label+"'>-</td>");
                                }
                            }
                        } else {
                            for (int s = 0; s < sampleIds.size(); s++) {
                                cell = dataRow.addElement("Cell").addAttribute("type", "data")
                                        .addAttribute("class", hClass).addAttribute("group", label);
                                data = cell.addElement("Data").addAttribute("type", "data").addText("-");
                                data = null;
                                cell = null;
                                //sb.append("<td class='"+label+"'>-</td>");
                            }
                        }

                    }

                    //sb.append("</tr>\n");
                } /* end reporter filter */
                //sb.append("<tr><td colspan=\""+theColspan+"\" class=\"geneSpacerStyle\">&nbsp;</td></tr>\n");
                //} 
            } /* end gene filter  */
            //sb.append("</table>");
        }
    } else {
        //TODO: handle this error
        sb.append("<br><Br>Copy Number Container is empty<br>");
    }

    //return "<div class=\"rowCount\">"+ helpFul +recordCount+" records returned. " + totalSamples +" samples returned. &nbsp;&nbsp;&nbsp;" + links  + "</div>\n" + sb.toString();

    return document;
}

From source file:gov.nih.nci.rembrandt.web.xml.CopyNumberSampleReport.java

License:BSD License

public Document getReportXML(Resultant resultant, Map filterMapParams) {

    //String theColors[] = { "B6C5F2","F2E3B5","DAE1F9","C4F2B5","819BE9", "E9CF81" };
    DecimalFormat resultFormat = new DecimalFormat("0.0000");
    String delim = " | ";
    ArrayList filter_string = new ArrayList(); // hashmap of genes | reporters | cytobands
    String filter_type = "show"; // show | hide
    String filter_element = "none"; // none | gene | reporter | cytoband

    if (filterMapParams.containsKey("filter_string") && filterMapParams.get("filter_string") != null)
        filter_string = (ArrayList) filterMapParams.get("filter_string");
    if (filterMapParams.containsKey("filter_type") && filterMapParams.get("filter_type") != null)
        filter_type = (String) filterMapParams.get("filter_type");
    if (filterMapParams.containsKey("filter_element") && filterMapParams.get("filter_element") != null)
        filter_element = (String) filterMapParams.get("filter_element");

    Document document = DocumentHelper.createDocument();

    Element report = document.addElement("Report");
    Element cell = null;/*from   ww  w  . ja  v a  2s.  c  o m*/
    Element data = null;
    Element dataRow = null;
    //add the atts
    report.addAttribute("reportType", "Copy Number");
    report.addAttribute("helpLink", ContextSensitiveHelpTag.getHelpLink("Copy Number"));
    //fudge these for now
    report.addAttribute("groupBy", "none");
    String queryName = resultant.getAssociatedQuery().getQueryName();
    //set the queryName to be unique for session/cache access
    report.addAttribute("queryName", queryName);
    report.addAttribute("sessionId", "the session id");
    report.addAttribute("creationTime", "right now");
    //hold a message to display on the report
    report.addAttribute("msg", (resultant.isOverLimit() ? "over limit" : ""));

    StringBuffer sb = new StringBuffer();
    int recordCount = 0;
    int totalSamples = 0;

    ResultsContainer resultsContainer = resultant.getResultsContainer();

    CopyNumberSingleViewResultsContainer copyNumberContainer = null;

    if (resultsContainer instanceof DimensionalViewContainer) {
        DimensionalViewContainer dimensionalViewContainer = (DimensionalViewContainer) resultsContainer;
        if (dimensionalViewContainer != null) {
            copyNumberContainer = dimensionalViewContainer.getCopyNumberSingleViewContainer();
        }
    } else if (resultsContainer instanceof CopyNumberSingleViewResultsContainer) { //for single
        copyNumberContainer = (CopyNumberSingleViewResultsContainer) resultsContainer;
    }
    if (copyNumberContainer != null) {

        if (copyNumberContainer.getCytobandResultsets().size() > 0) {

            Collection cytobands = copyNumberContainer.getCytobandResultsets();
            Collection labels = copyNumberContainer.getGroupsLabels();
            Collection sampleIds = null;

            StringBuffer header = new StringBuffer();
            StringBuffer sampleNames = new StringBuffer();
            StringBuffer stringBuffer = new StringBuffer();

            /*
            sampleNames.append("<Tr>");
            sampleNames.append("<Td>&nbsp;</td><Td>&nbsp;</td>");
                    
            header.append("<tr>");
            header.append("<Td id=\"header\">Cytoband</td><td id=\"header\">Reporter</td>");
            */

            Element headerRow = report.addElement("Row").addAttribute("name", "headerRow");
            cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header")
                    .addAttribute("group", "header");
            data = cell.addElement("Data").addAttribute("type", "header").addText("Position");
            data = null;
            cell = null;
            cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header")
                    .addAttribute("group", "header");
            data = cell.addElement("Data").addAttribute("type", "header").addText("Genes");
            data = null;
            cell = null;
            cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header")
                    .addAttribute("group", "header");
            data = cell.addElement("Data").addAttribute("type", "header").addText("Segment ID");
            data = null;
            cell = null;

            /*
             * Start annotations (csv only)
             *  1) Bp position
             *  2) associated genes (pipe delimimted list)
             */
            cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "csv")
                    .addAttribute("group", "header");
            data = cell.addElement("Data").addAttribute("type", "header").addText("Bp Position");
            data = null;
            cell = null;
            cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "csv")
                    .addAttribute("group", "header");
            data = cell.addElement("Data").addAttribute("type", "header").addText("Genes");
            data = null;
            cell = null;

            Element sampleRow = report.addElement("Row").addAttribute("name", "sampleRow");
            cell = sampleRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header")
                    .addAttribute("group", "header");
            data = cell.addElement("Data").addAttribute("type", "header").addText(" ");
            data = null;
            cell = null;
            cell = sampleRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header")
                    .addAttribute("group", "header");
            data = cell.addElement("Data").addAttribute("type", "header").addText(" ");
            data = null;
            cell = null;
            cell = sampleRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header")
                    .addAttribute("group", "header");
            data = cell.addElement("Data").addAttribute("type", "header").addText("z ");
            data = null;
            cell = null;

            cell = sampleRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "csv")
                    .addAttribute("group", "header");
            data = cell.addElement("Data").addAttribute("type", "header").addText(" ");
            data = null;
            cell = null;
            cell = sampleRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "csv")
                    .addAttribute("group", "header");
            data = cell.addElement("Data").addAttribute("type", "header").addText(" ");
            data = null;
            cell = null;

            //this nested loop generates the header row and the samples row
            for (Iterator labelIterator = labels.iterator(); labelIterator.hasNext();) {
                String label = (String) labelIterator.next();

                sampleIds = copyNumberContainer.getBiospecimenLabels(label);
                totalSamples += sampleIds.size();

                cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", label)
                        .addAttribute("group", label);
                data = cell.addElement("Data").addAttribute("type", "header").addText(label + " Samples");
                data = null;
                cell = null;

                //header.append("<Td colspan='"+sampleIds.size()+"' class=\""+label+"\" id=\"header\">"+label+" Samples</td>"); 

                for (Iterator sampleIdIterator = sampleIds.iterator(); sampleIdIterator.hasNext();) {

                    BioSpecimenIdentifierDE bioSpecimenIdentifierDE = (BioSpecimenIdentifierDE) sampleIdIterator
                            .next();
                    cell = sampleRow.addElement("Cell").addAttribute("type", "header")
                            .addAttribute("class", label).addAttribute("group", label)
                            .addAttribute("sampleId", bioSpecimenIdentifierDE.getSampleId());
                    //cell = sampleRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", label).addAttribute("group", label).addAttribute("specimen", bioSpecimenIdentifierDE.getSpecimenName());
                    //data = cell.addElement("Data").addAttribute("type", "header").addText(s.substring(2));
                    if (bioSpecimenIdentifierDE.getSpecimenName() != null) {
                        data = cell.addElement("Data").addAttribute("type", "header")
                                .addText(bioSpecimenIdentifierDE.getSpecimenName());
                    } else {
                        data = cell.addElement("Data").addAttribute("type", "header")
                                .addText(bioSpecimenIdentifierDE.getSampleId());
                    }
                    data = null;
                    cell = null;
                    //sampleNames.append("<td class='"+label+"' id=\"header\"><a href=\"report.do?s="+s+"&report=ss\">"+s.substring(2)+"</a></td>"); 
                    //theColspan += sampleIds.size();
                }
            }
            //header.append("</tr>\n"); 
            //sampleNames.append("</tr>\n");

            /* done with the headerRow and SampleRow Elements, time to add data rows */

            for (Iterator cytobandIterator = cytobands.iterator(); cytobandIterator.hasNext();) {
                CytobandResultset cytobandResultset = (CytobandResultset) cytobandIterator.next();
                String cytoband = cytobandResultset.getCytoband().getValue().toString();
                Collection reporters = copyNumberContainer.getRepoterResultsets(cytoband);

                //         if(!filter_element.equals("cytoband") || (filter_element.equals("cytoband") && !filter_string.contains(cytoband)))   {
                if (FilterHelper.checkFilter(filter_element, "cytoband", cytoband, filter_type,
                        filter_string)) {

                    recordCount += reporters.size();
                    for (Iterator reporterIterator = reporters.iterator(); reporterIterator.hasNext();) {

                        ReporterResultset reporterResultset = (ReporterResultset) reporterIterator.next();

                        /*
                         * 
                         *  store our annotations
                         * 
                         */
                        String bp_position = "";
                        try {
                            bp_position = reporterResultset.getStartPhysicalLocation().getValue().toString();
                        } catch (Exception e) {
                        }

                        //there is a much better way to do this, but this is reused from 0.50
                        //this code will be cleaned up for 1.0
                        String genes = "";
                        try {
                            if (reporterResultset.getAssiciatedGeneSymbols() != null) {
                                HashSet geneSymbols = new HashSet(reporterResultset.getAssiciatedGeneSymbols());
                                genes = StringUtils.join(geneSymbols.toArray(), delim);

                            } else {
                                genes = "-";
                            }
                        } catch (Exception e) {
                            genes = "--";
                        }

                        String reporterName = reporterResultset.getReporter().getValue().toString();

                        if (FilterHelper.checkFilter(filter_element, "reporter", reporterName, filter_type,
                                filter_string)) {
                            //if(!filter_element.equals("reporter") || (filter_element.equals("reporter") && !filter_string.contains(reporterName)))   {      
                            dataRow = report.addElement("Row").addAttribute("name", "dataRow");
                            cell = dataRow.addElement("Cell").addAttribute("type", "data")
                                    .addAttribute("class", "cytoband").addAttribute("group", "header");
                            data = cell.addElement("Data").addAttribute("type", "header").addText(cytoband);
                            data = null;
                            cell = null;

                            cell = dataRow.addElement("Cell").addAttribute("type", "data")
                                    .addAttribute("class", "gene").addAttribute("group", "header");
                            data = cell.addElement("Data").addAttribute("type", "header").addText(genes);
                            data = null;
                            cell = null;

                            cell = dataRow.addElement("Cell").addAttribute("type", "data")
                                    .addAttribute("class", "reporter").addAttribute("group", "header");
                            data = cell.addElement("Data").addAttribute("type", "header").addText(reporterName);
                            data = null;
                            cell = null;
                            //sb.append("<tr><td>"+cytoband+"</td><td>"+reporterName+"</td>");

                            /*
                             * 
                             *  actually add the annotations to the report
                             * 
                             */
                            cell = dataRow.addElement("Cell").addAttribute("type", "data")
                                    .addAttribute("class", "csv").addAttribute("group", "header");
                            data = cell.addElement("Data").addAttribute("type", "header").addText(bp_position);
                            data = null;
                            cell = null;
                            cell = dataRow.addElement("Cell").addAttribute("type", "data")
                                    .addAttribute("class", "csv").addAttribute("group", "header");
                            data = cell.addElement("Data").addAttribute("type", "header").addText(genes);
                            data = null;
                            cell = null;

                            for (Iterator labelIterator = labels.iterator(); labelIterator.hasNext();) {
                                String label = (String) labelIterator.next();
                                ViewByGroupResultset groupResultset = (ViewByGroupResultset) reporterResultset
                                        .getGroupByResultset(label);

                                sampleIds = copyNumberContainer.getBiospecimenLabels(label);
                                String hClass = label;
                                if (groupResultset != null) {
                                    for (Iterator sampleIdIterator = sampleIds.iterator(); sampleIdIterator
                                            .hasNext();) {

                                        BioSpecimenIdentifierDE sampleId = (BioSpecimenIdentifierDE) sampleIdIterator
                                                .next();
                                        SampleCopyNumberValuesResultset sampleResultset2 = (SampleCopyNumberValuesResultset) groupResultset
                                                .getBioSpecimenResultset(sampleId.getSpecimenName());

                                        if (sampleResultset2 != null) {

                                            //JB Begin: Add for GForge # 17783 - Advance Query Reports - Make the report more user friendly (Provide tool tip)
                                            String tooltip = "Position = " + cytoband + ", Gene = " + genes
                                                    + ", Reporter = " + reporterName + ", Sample = "
                                                    + sampleId.getSampleId() + " (" + sampleId.getSpecimenName()
                                                    + ")";
                                            //JB End: Add for GForge # 17783 - Advance Query Reports - Make the report more user friendly (Provide tool tip)

                                            if (sampleResultset2.isHighlighted())
                                                hClass = "highlighted";
                                            else
                                                hClass = label;

                                            Double ratio = (Double) sampleResultset2.getCopyNumber().getValue();
                                            Double segMean = (Double) sampleResultset2.getSegmentMean()
                                                    .getValue();
                                            if (ratio != null && segMean != null) {
                                                //sb.append("<td class='"+label+"'>"+resultFormat.format(ratio)+"</td>");
                                                cell = dataRow.addElement("Cell").addAttribute("type", "data")
                                                        .addAttribute("class", hClass)
                                                        .addAttribute("group", label);
                                                //JB Begin: Add for GForge # 17783 - Advance Query Reports - Make the report more user friendly (Provide tool tip)
                                                //data = cell.addElement("Data").addAttribute("type", "data").addText(resultFormat.format(ratio));
                                                data = cell.addElement("Data").addAttribute("type", "data")
                                                        .addAttribute("datainfo", tooltip)
                                                        .addText(resultFormat.format(ratio) + "("
                                                                + resultFormat.format(segMean) + ")");
                                                //JB End: Add for GForge # 17783 - Advance Query Reports - Make the report more user friendly (Provide tool tip)
                                                data = null;
                                                cell = null;
                                            } else {
                                                //sb.append("<td class='"+label+"'>-</td>");
                                                cell = dataRow.addElement("Cell").addAttribute("type", "data")
                                                        .addAttribute("class", hClass)
                                                        .addAttribute("group", label);
                                                data = cell.addElement("Data").addAttribute("type", "data")
                                                        .addText("-");
                                                data = null;
                                                cell = null;
                                            }
                                        } else {
                                            //sb.append("<td class='"+label+"'>-</td>");

                                            cell = dataRow.addElement("Cell").addAttribute("type", "data")
                                                    .addAttribute("class", hClass).addAttribute("group", label);
                                            data = cell.addElement("Data").addAttribute("type", "data")
                                                    .addText("-");
                                            data = null;
                                            cell = null;
                                        }
                                    }
                                } else {
                                    for (int s = 0; s < sampleIds.size(); s++) {
                                        cell = dataRow.addElement("Cell").addAttribute("type", "data")
                                                .addAttribute("class", hClass).addAttribute("group", label);
                                        data = cell.addElement("Data").addAttribute("type", "data")
                                                .addText("-");
                                        data = null;
                                        cell = null;
                                        //sb.append("<td class='"+label+"'>-</td>");
                                    }
                                }
                            }
                            //sb.append("</tr>\n");
                        } /* close reporter filter */
                    }
                    //sb.append("<tr><td colspan=\""+theColspan+"\" class=\"geneSpacerStyle\">&nbsp;</td></tr>\n");
                } /* close cyto filter */
                //sb.append("</table><Br><br>");
            }
        }

        else {
            //TODO: handle these errs
            sb.append("<br><br>Copy Number container is empty");
        }

    } else {
        //TODO: handle these errs
        sb.append("<br><br>Copy Number container is empty");
    }

    return document;
    //return "<div class=\"rowCount\">"+ helpFul +recordCount+" records returned. "+ totalSamples + " samples returned. &nbsp;&nbsp;&nbsp;" + links +"</div>\n" + sb.toString();
}

From source file:gov.nih.nci.rembrandt.web.xml.CopyNumberSegmentReport.java

License:BSD License

@SuppressWarnings("unchecked")
public Document getReportXML(Resultant resultant, Map filterMapParams) {

    //String theColors[] = { "B6C5F2","F2E3B5","DAE1F9","C4F2B5","819BE9", "E9CF81" };
    DecimalFormat resultFormat = new DecimalFormat("0.0000");
    String defaultV = "-";

    Document document = DocumentHelper.createDocument();

    try {/*from  w w  w .  ja va 2s .  c o m*/
        Element report = document.addElement("Report");
        Element cell = null;
        Element data = null;
        Element dataRow = null;
        //add the atts
        report.addAttribute("reportType", "Copy Number");
        report.addAttribute("helpLink", ContextSensitiveHelpTag.getHelpLink("Copy Number"));
        //fudge these for now
        report.addAttribute("groupBy", "none");
        String queryName = resultant.getAssociatedQuery().getQueryName();

        //set the queryName to be unique for session/cache access
        report.addAttribute("queryName", queryName);
        report.addAttribute("sessionId", "the session id");
        report.addAttribute("creationTime", "right now");
        //hold a message to display on the report
        report.addAttribute("msg", (resultant.isOverLimit() ? "over limit" : ""));

        StringBuffer sb = new StringBuffer();

        ResultsContainer resultsContainer = resultant.getResultsContainer();
        CopyNumberSegmentViewResultsContainer segmentViewResultsContainer = null;
        if (resultsContainer instanceof DimensionalViewContainer) {

            DimensionalViewContainer dimensionalViewContainer = (DimensionalViewContainer) resultsContainer;

            segmentViewResultsContainer = dimensionalViewContainer.getCopyNumberSegmentViewResultsContainer();

        } else if (resultsContainer instanceof CopyNumberSegmentViewResultsContainer) {
            segmentViewResultsContainer = (CopyNumberSegmentViewResultsContainer) resultsContainer;
        }

        Collection segments = segmentViewResultsContainer.getSampleCopyNumberValuesResultsets();

        //   set up the headers for this table 
        Element headerRow = report.addElement("Row").addAttribute("name", "headerRow");

        for (String h : CopyNumberSegmentReport.getCopyNumberSegmentHeaderValues()) {
            cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header")
                    .addAttribute("group", "header");
            data = cell.addElement("Data").addAttribute("type", "header").addText(h);
            data = null;
            cell = null;
        }

        for (Iterator sampleIterator = segments.iterator(); sampleIterator.hasNext();) {

            SampleCopyNumberValuesResultset sampleResultset = (SampleCopyNumberValuesResultset) sampleIterator
                    .next();

            dataRow = report.addElement("Row").addAttribute("name", "dataRow");

            List rows = new ArrayList();
            rows = CopyNumberSegmentReport.getClinicalRowValues(sampleResultset);

            cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "data")
                    .addAttribute("group", "sample");
            data = cell.addElement("Data").addAttribute("type", "data").addText(DEUtils.checkNull(rows.get(0)));
            data = null;
            cell = null;

            String tooltip = "Specimen = " + rows.get(0);

            for (int i = 1; i < rows.size(); i++) {
                switch (i) {
                case 1:
                    tooltip = "Specimen = " + rows.get(0) + " (Chr No.)";
                    break;
                case 2:
                    tooltip = "Specimen = " + rows.get(0) + " (Start Position)";
                    break;
                case 3:
                    tooltip = "Specimen = " + rows.get(0) + " (End Position)";
                    break;
                case 4:
                    tooltip = "Specimen = " + rows.get(0) + " (Number of Marks)";
                    break;
                case 5:
                    tooltip = "Specimen = " + rows.get(0) + " (Segment Mean)";
                    break;
                default:
                    tooltip = "Specimen = " + rows.get(0);
                    break;
                }

                cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "data")
                        .addAttribute("group", "data");
                data = cell.addElement("Data").addAttribute("type", "data").addAttribute("datainfo", tooltip)
                        .addText(DEUtils.checkNull(rows.get(i)));
                data = null;
                cell = null;
            }

        }
    } catch (Exception e) {
        System.out.println(e);
    }
    return document;
}

From source file:gov.nih.nci.rembrandt.web.xml.FTestReport.java

License:BSD License

public static Document getReportXML(Finding finding, Map filterMapParams, boolean allAnnotations) {

    DecimalFormat resultFormat = new DecimalFormat("0.0000");
    DecimalFormat sciFormat = new DecimalFormat("0.00E0");
    DecimalFormat tmpsciFormat = new DecimalFormat("###0.0000#####################");

    /*//from   w w  w  .  j a v  a  2  s .c o m
     *  this is for filtering, we will want a p-value filter for CC
     */
    ArrayList filter_string = new ArrayList(); // hashmap of genes | reporters | cytobands
    String filter_type = "show"; // show | hide
    String filter_element = "none"; // none | gene | reporter | cytoband

    if (filterMapParams.containsKey("filter_string") && filterMapParams.get("filter_string") != null)
        filter_string = (ArrayList) filterMapParams.get("filter_string");
    if (filterMapParams.containsKey("filter_type") && filterMapParams.get("filter_type") != null)
        filter_type = (String) filterMapParams.get("filter_type");
    if (filterMapParams.containsKey("filter_element") && filterMapParams.get("filter_element") != null)
        filter_element = (String) filterMapParams.get("filter_element");

    String defaultV = "--";
    String delim = " | ";

    Document document = DocumentHelper.createDocument();

    Element report = document.addElement("Report");
    Element cell = null;
    Element data = null;
    Element dataRow = null;
    //add the atts
    report.addAttribute("reportType", "Class Comparison");
    report.addAttribute("helpLink", ContextSensitiveHelpTag.getHelpLink("Class Comparison"));
    //lets flag this as Ftest
    report.addAttribute("reportSubType", "FTEST");
    //fudge these for now
    report.addAttribute("groupBy", "none");
    String queryName = "none";
    queryName = finding.getTaskId();

    //set the queryName to be unique for session/cache access
    report.addAttribute("queryName", queryName);
    report.addAttribute("sessionId", "the session id");
    report.addAttribute("creationTime", "right now");

    StringBuffer sb = new StringBuffer();

    int recordCount = 0;
    int totalSamples = 0;

    //TODO: instance of
    FTestFinding ccf = (FTestFinding) finding;

    //process the query details

    ArrayList<String> queryDetails = new ArrayList();

    ClassComparisonQueryDTO ccdto = (ClassComparisonQueryDTO) ccf.getQueryDTO();

    if (ccdto != null) {
        String tmp = "";
        tmp = ccdto.getQueryName() != null ? ccdto.getQueryName() : "";
        queryDetails.add("Query Name: " + tmp);
        tmp = ccdto.getArrayPlatformDE() != null ? ccdto.getArrayPlatformDE().getValue().toString() : "";
        queryDetails.add("Array Platform: " + tmp);

        tmp = "";
        List<ClinicalQueryDTO> grps = ccdto.getComparisonGroups() != null ? ccdto.getComparisonGroups()
                : new ArrayList();
        Collection grs = new ArrayList();
        for (ClinicalQueryDTO cdto : grps) {
            if (cdto.getQueryName() != null)
                grs.add(cdto.getQueryName());
        }

        tmp += StringUtils.join(grs.toArray(), ", ") + " (baseline)";
        queryDetails.add("Groups: " + tmp);

        tmp = ccdto.getExprFoldChangeDE() != null ? ccdto.getExprFoldChangeDE().getValue().toString() : "";
        queryDetails.add("Fold Change: " + tmp);
        //queryDetails.add("Institutions: " + ccdto.getInstitutionDEs());
        tmp = ccdto.getMultiGroupComparisonAdjustmentTypeDE() != null
                ? ccdto.getMultiGroupComparisonAdjustmentTypeDE().getValue().toString()
                : "";
        queryDetails.add("Multi Group: " + tmp);
        tmp = ccdto.getStatisticalSignificanceDE() != null
                ? ccdto.getStatisticalSignificanceDE().getValue().toString()
                : "";
        queryDetails.add("Stat Sig.: " + tmp);
        tmp = ccdto.getStatisticTypeDE() != null ? ccdto.getStatisticTypeDE().getValue().toString() : "";
        queryDetails.add("Stat Type: " + tmp);
    }

    String qd = "";
    for (String q : queryDetails) {
        qd += q + " ||| ";
    }

    if (ccf != null) {

        Element details = report.addElement("Query_details");
        cell = details.addElement("Data");
        cell.addText(qd);
        cell = null;

        Element headerRow = report.addElement("Row").addAttribute("name", "headerRow");
        cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText("Reporter");
        data = null;
        cell = null;

        //pvalue is fixed in the second column, essential for XSL
        cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header")
                .addAttribute("group", "header");
        String isAdj = ccf.arePvaluesAdjusted() ? " (Adjusted) " : "";
        data = cell.addElement("Data").addAttribute("type", "header")
                .addText(RembrandtConstants.PVALUE + isAdj);
        data = null;
        cell = null;

        //one col for each group in the comparison
        List<String> groupNames = ccf.getGroupNames();
        for (String n : groupNames) {
            cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header")
                    .addAttribute("group", "header");
            data = cell.addElement("Data").addAttribute("type", "header").addText(n + " Group Avg");
            data = null;
            cell = null;
        }

        cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText("Fold Change");
        data = null;
        cell = null;

        cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText("Gene Symbol");
        data = null;
        cell = null;

        //starting annotations...get them only if allAnnotations == true
        if (allAnnotations) {
            cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "csv")
                    .addAttribute("group", "header");
            data = cell.addElement("Data").addAttribute("type", "header").addText("GenBank Acc");
            data = null;
            cell = null;
            cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "csv")
                    .addAttribute("group", "header");
            data = cell.addElement("Data").addAttribute("type", "header").addText("Locus link");
            data = null;
            cell = null;
            cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "csv")
                    .addAttribute("group", "header");
            data = cell.addElement("Data").addAttribute("type", "header").addText("GO Id");
            data = null;
            cell = null;
            cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "csv")
                    .addAttribute("group", "header");
            data = cell.addElement("Data").addAttribute("type", "header").addText("Pathways");
            data = null;
            cell = null;
        }

        /* done with the headerRow and SampleRow Elements, time to add data rows */

        List<FTestResultEntry> fTestResultEntrys = ccf.getResultEntries();
        List<String> reporterIds = new ArrayList<String>();

        for (FTestResultEntry fTestResultEntry : fTestResultEntrys) {
            if (fTestResultEntry.getReporterId() != null) {
                reporterIds.add(fTestResultEntry.getReporterId());
            }
        }

        ArrayPlatformType arrayPlatform = ccdto.getArrayPlatformDE() != null
                ? ccdto.getArrayPlatformDE().getValueObjectAsArrayPlatformType()
                : ArrayPlatformType.AFFY_OLIGO_PLATFORM;
        Map reporterResultsetMap = null;
        if (allAnnotations) {
            //Map<String, ReporterAnnotations> reporterResultsetMap = null;
            try {
                reporterResultsetMap = AnnotationHandler.getAllAnnotationsFor(reporterIds, arrayPlatform);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            //Map<String, String> reporterResultsetMap = null;
            try {
                reporterResultsetMap = AnnotationHandler.getGeneSymbolsFor(reporterIds, arrayPlatform);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        for (FTestResultEntry ccre : ccf.getResultEntries()) {

            dataRow = report.addElement("Row").addAttribute("name", "dataRow");
            cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "reporter")
                    .addAttribute("group", "data");
            data = cell.addElement("Data").addAttribute("type", "header").addText(ccre.getReporterId());
            data = null;
            cell = null;

            cell = dataRow.addElement("Cell").addAttribute("type", "pval").addAttribute("class", "data")
                    .addAttribute("group", "data");
            //String pv = (ccre.getPvalue() == null) ? String.valueOf(ccre.getPvalue()) : "N/A";
            BigDecimal bigd = new BigDecimal(ccre.getPvalue());
            data = cell.addElement("Data").addAttribute("type", "header").addText(bigd.toPlainString());
            data = null;
            cell = null;

            //one col for each group
            for (int i = 0; i < ccre.getGroupMeans().length; i++) {
                cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "data")
                        .addAttribute("group", "data");
                data = cell.addElement("Data").addAttribute("type", "header")
                        .addText(resultFormat.format(ccre.getGroupMeans()[i]));
                data = null;
                cell = null;
            }

            cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "data")
                    .addAttribute("group", "data");
            data = cell.addElement("Data").addAttribute("type", "header")
                    .addText(String.valueOf(resultFormat.format(ccre.getMaximumFoldChange())));
            data = null;
            cell = null;

            //if only showing genes
            if (!allAnnotations && reporterResultsetMap != null) {
                String reporterId = ccre.getReporterId();
                String genes = reporterResultsetMap.get(reporterId) != null
                        ? (String) reporterResultsetMap.get(reporterId)
                        : defaultV;
                cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "gene")
                        .addAttribute("group", "data");
                data = cell.addElement("Data").addAttribute("type", "header").addText(genes);
                data = null;
                cell = null;
            } else {
                //get the gene symbols for this reporter
                //ccre.getReporterId()
                String genes = defaultV;

                //start annotations
                String accIds = defaultV;
                String llink = defaultV;
                String go = defaultV;
                String pw = defaultV;

                if (reporterResultsetMap != null) { // && reporterIds != null
                    //int count = 0;
                    String reporterId = ccre.getReporterId();
                    //ReporterResultset reporterResultset = reporterResultsetMap.get(reporterId);
                    ReporterAnnotations ra = (ReporterAnnotations) reporterResultsetMap.get(reporterId);

                    //Collection<String> geneSymbols = (Collection<String>)reporterResultset.getAssiciatedGeneSymbols();
                    String geneSymbols = ra.getGeneSymbol();
                    if (geneSymbols != null)
                        genes = geneSymbols;
                    /*
                    if(geneSymbols != null){
                       genes = StringUtils.join(geneSymbols.toArray(), delim);
                    }
                    */
                    Collection<String> genBank_AccIDS = (Collection<String>) ra.getAccessions();
                    if (genBank_AccIDS != null) {
                        accIds = StringUtils.join(genBank_AccIDS.toArray(), delim);
                    }
                    Collection<String> locusLinkIDs = (Collection<String>) ra.getLocusLinks();
                    if (locusLinkIDs != null) {
                        llink = StringUtils.join(locusLinkIDs.toArray(), delim);
                    }
                    Collection<String> goIds = (Collection<String>) ra.getGoIDS();
                    if (goIds != null) {
                        go = StringUtils.join(goIds.toArray(), delim);
                    }
                    Collection<String> pathways = (Collection<String>) ra.getPathways();
                    if (pathways != null) {
                        pw = StringUtils.join(pathways.toArray(), delim);
                    }
                }

                cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "gene")
                        .addAttribute("group", "data");
                data = cell.addElement("Data").addAttribute("type", "header").addText(genes);
                data = null;
                cell = null;
                cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "csv")
                        .addAttribute("group", "data");
                data = cell.addElement("Data").addAttribute("type", "header").addText(accIds);
                data = null;
                cell = null;
                cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "csv")
                        .addAttribute("group", "data");
                data = cell.addElement("Data").addAttribute("type", "header").addText(llink);
                data = null;
                cell = null;
                cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "csv")
                        .addAttribute("group", "data");
                data = cell.addElement("Data").addAttribute("type", "header").addText(go);
                data = null;
                cell = null;
                cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "csv")
                        .addAttribute("group", "data");
                data = cell.addElement("Data").addAttribute("type", "header").addText(pw);
                data = null;
                cell = null;

            }
        }
    } else {
        //TODO: handle this error
        sb.append("<br/><br/>Class Comparison is empty<br/>");
    }

    logger.info(document.toString());
    return document;
}

From source file:gov.nih.nci.rembrandt.web.xml.GeneExprDiseaseReport.java

License:BSD License

public Document getReportXML(Resultant resultant, Map filterMapParams) {

    //   have setter or put in props file
    //String theColors[] = { "B6C5F2","F2E3B5","DAE1F9","C4F2B5","819BE9", "E9CF81" };
    DecimalFormat resultFormat = new DecimalFormat("0.0000");

    Document document = DocumentHelper.createDocument();

    Element report = document.addElement("Report");
    Element cell = null;//w w w.j  av a2 s  . com
    Element data = null;
    Element dataRow = null;
    //add the atts
    report.addAttribute("reportType", "Gene Expression Disease");
    report.addAttribute("helpLink", ContextSensitiveHelpTag.getHelpLink("Gene Expression Disease"));

    //fudge these for now
    report.addAttribute("groupBy", "none");
    String queryName = resultant.getAssociatedQuery().getQueryName();
    //set the queryName to be unique for session/cache access
    report.addAttribute("queryName", queryName);
    report.addAttribute("sessionId", "the session id");
    report.addAttribute("creationTime", "right now");
    //hold a message to display on the report
    report.addAttribute("msg", (resultant.isOverLimit() ? "over limit" : ""));

    ResultsContainer resultsContainer = resultant.getResultsContainer();

    StringBuffer sb = new StringBuffer();

    //String helpFul = helpLink + "?sect=diseaseGroup" + helpLinkClose;

    GeneExprResultsContainer geneExprDiseaseContainer = (GeneExprResultsContainer) resultsContainer;
    /*         
             if(resultsContainer instanceof DimensionalViewContainer)   {
    DimensionalViewContainer dimensionalViewContainer = (DimensionalViewContainer) resultsContainer;
    if(dimensionalViewContainer != null)   {
       geneExprDiseaseContainer = dimensionalViewContainer.;
    }
             }
             else if(resultsContainer instanceof CopyNumberSingleViewResultsContainer)   { //for single
    geneExprDiseaseContainer = (CopyNumberSingleViewResultsContainer) resultsContainer;
             }
    */

    StringBuffer css = new StringBuffer();
    int recordCount = 0;
    if (geneExprDiseaseContainer != null) {
        Collection genes = geneExprDiseaseContainer.getGeneResultsets();
        Collection labels = geneExprDiseaseContainer.getGroupsLabels();
        Collection sampleIds = null;

        //get group size (as Disease or Agegroup )from label.size
        String label = null;

        //sb.append("<table cellpadding=\"0\" cellspacing=\"0\">\n");

        //set up the header for the table
        Element headerRow = report.addElement("Row").addAttribute("name", "headerRow");
        cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText("Gene");
        data = null;
        cell = null;
        cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText("Reporter");
        data = null;
        cell = null;
        //sb.append("<tr><Td id=\"header\">Gene</td><td id=\"header\">Reporter</td>");

        for (Iterator labelIterator = labels.iterator(); labelIterator.hasNext();) {
            label = (String) labelIterator.next();

            cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", label)
                    .addAttribute("group", label);
            data = cell.addElement("Data").addAttribute("type", "header").addText(label);
            data = null;
            cell = null;

            //sb.append("<Td id=\"header\" class=\""+label+"\">"+label+"</td>");

        }

        //sb.append("</tr>\n");

        for (Iterator geneIterator = genes.iterator(); geneIterator.hasNext();) {
            GeneResultset geneResultset = (GeneResultset) geneIterator.next();

            Collection reporters = geneResultset.getReporterResultsets();

            for (Iterator reporterIterator = reporters.iterator(); reporterIterator.hasNext();) {
                recordCount += reporters.size();

                ReporterResultset reporterResultset = (ReporterResultset) reporterIterator.next();
                Collection groupTypes = reporterResultset.getGroupByResultsets();

                String reporterName = "-";
                try {
                    reporterName = reporterResultset.getReporter().getValue().toString();
                } catch (Exception e) {
                    reporterName = "-";
                }

                GeneSymbol gene = geneResultset.getGeneSymbol();
                String geneSymbol = "-";
                if (gene != null) {
                    try {
                        geneSymbol = geneResultset.getGeneSymbol().getValueObject().toString();
                    } catch (Exception e) {
                        geneSymbol = " - ";
                    }
                    //logger.debug("Gene Symbol: "+ geneSymbol);
                }

                //start the new data row
                dataRow = report.addElement("Row").addAttribute("name", "dataRow");
                cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "gene")
                        .addAttribute("group", "header");
                data = cell.addElement("Data").addAttribute("type", "header").addText(geneSymbol);
                data = null;
                cell = null;
                cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "reporter")
                        .addAttribute("group", "header");
                data = cell.addElement("Data").addAttribute("type", "header").addText(reporterName);
                data = null;
                cell = null;
                //sb.append("<tr><td>"+geneSymbol+"</td><td>" + reporterName + "</td>");

                for (Iterator labelIterator = labels.iterator(); labelIterator.hasNext();) {
                    sb = new StringBuffer();
                    label = (String) labelIterator.next();
                    DiseaseGroupResultset diseaseResultset = (DiseaseGroupResultset) reporterResultset
                            .getGroupByResultset(label);
                    if (diseaseResultset != null) {

                        cell = dataRow.addElement("Cell").addAttribute("type", "data")
                                .addAttribute("class", label).addAttribute("group", label);

                        //sb.append("<td class=\""+label+"\">");
                        try {
                            Double ratio = (Double) diseaseResultset.getFoldChangeRatioValue().getValue();
                            sb.append(resultFormat.format(ratio));
                        } catch (Exception e) {
                            sb.append("-");
                        }
                        try {
                            Double pvalue = (Double) diseaseResultset.getRatioPval().getValue();
                            sb.append(" (" + resultFormat.format(pvalue) + ")");
                        } catch (Exception e) {
                            sb.append("-");
                        }
                        data = cell.addElement("Data").addAttribute("type", "data").addText(sb.toString());
                        data = null;
                        cell = null;
                        //sb.append("</td>");
                    } else {
                        cell = dataRow.addElement("Cell").addAttribute("type", "data")
                                .addAttribute("class", label).addAttribute("group", label);
                        data = cell.addElement("Data").addAttribute("type", "data").addText("-");
                        data = null;
                        cell = null;
                        //sb.append("<Td class=\""+label+"\">-</td>");
                    }
                }
                //sb.append("</tr>");
            }

            // add the line between genes
            //sb.append("<tr><td colspan=\""+(labels.size() + 2)+"\" class=\"geneSpacerStyle\">&nbsp;</td></tr>\n");

        }
        //sb.append("</table>\n\n");
    } else {
        sb.append("<br/><br/>Gene Disease View container is empty");
        //TODO: something fancy here w/errors
    }

    //return "<div class=\"rowCount\">"+helpFul +recordCount+" records returned &nbsp;&nbsp;&nbsp;" + links + "</div>\n" + css.toString() + sb.toString();

    return document;
}

From source file:gov.nih.nci.rembrandt.web.xml.GeneExprSampleReport.java

License:BSD License

public Document getReportXML(Resultant resultant, Map filterMapParams) {

    DecimalFormat resultFormat = new DecimalFormat("0.0000");
    String delim = " | ";
    /* testing hardcoded vals - these will be params of this method soon */
    /*/* w  w w .ja  v  a2 s .  c om*/
    ArrayList g = new ArrayList();
    g.add("EGFR");
    g.add("VEGF");
    String tmp_filter_type = "hide";
    String tmp_filter_element = "gene";
            
    HashMap filterMapParams = new HashMap();
    filterMapParams.put("filter_string", g);
    filterMapParams.put("filter_type", tmp_filter_type);
    filterMapParams.put("filter_element", tmp_filter_element);
    */

    ArrayList filter_string = new ArrayList(); // hashmap of genes | reporters | cytobands
    String filter_type = "show"; // show | hide
    String filter_element = "none"; // none | gene | reporter | cytoband

    if (filterMapParams.containsKey("filter_string") && filterMapParams.get("filter_string") != null)
        filter_string = (ArrayList) filterMapParams.get("filter_string");
    if (filterMapParams.containsKey("filter_type") && filterMapParams.get("filter_type") != null)
        filter_type = (String) filterMapParams.get("filter_type");
    if (filterMapParams.containsKey("filter_element") && filterMapParams.get("filter_element") != null)
        filter_element = (String) filterMapParams.get("filter_element");

    Document document = DocumentHelper.createDocument();

    Element report = document.addElement("Report");
    Element cell = null;
    Element data = null;
    Element dataRow = null;
    //add the atts
    report.addAttribute("reportType", "Gene Expression Sample");
    report.addAttribute("helpLink", ContextSensitiveHelpTag.getHelpLink("Gene Expression Sample"));

    //fudge these for now
    report.addAttribute("groupBy", "none");
    String queryName = resultant.getAssociatedQuery().getQueryName();
    //set the queryName to be unique for session/cache access
    report.addAttribute("queryName", queryName);
    report.addAttribute("sessionId", "the session id");
    report.addAttribute("creationTime", "right now");
    //hold a message to display on the report
    report.addAttribute("msg", (resultant.isOverLimit() ? "over limit" : ""));
    ResultsContainer resultsContainer = resultant.getResultsContainer();

    GeneExprSingleViewResultsContainer geneViewContainer = null;
    StringBuffer sb = new StringBuffer();

    //String helpFul = helpLink + "?sect=sample" + helpLinkClose;

    DimensionalViewContainer dimensionalViewContainer = null;
    int recordCount = 0;
    int totalSamples = 0;

    if (resultsContainer instanceof DimensionalViewContainer) {
        dimensionalViewContainer = (DimensionalViewContainer) resultsContainer;
        if (dimensionalViewContainer != null) {
            geneViewContainer = dimensionalViewContainer.getGeneExprSingleViewContainer();
        }
    } else if (resultsContainer instanceof GeneExprSingleViewResultsContainer) { //for single
        geneViewContainer = (GeneExprSingleViewResultsContainer) resultsContainer;
    }

    if (geneViewContainer != null) {
        Collection genes = geneViewContainer.getGeneResultsets();
        Collection labels = geneViewContainer.getGroupsLabels();
        Collection sampleIds = null;

        StringBuffer header = new StringBuffer();

        //header.append("<table cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n");
        StringBuffer sampleNames = new StringBuffer();
        StringBuffer stringBuffer = new StringBuffer();

        Element headerRow = report.addElement("Row").addAttribute("name", "headerRow");
        cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText("Gene");
        data = null;
        cell = null;
        cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText("Reporter");
        data = null;
        cell = null;

        //starting annotations
        cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "csv")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText("Locus link");
        data = null;
        cell = null;
        cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "csv")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText("GenBank Acc");
        data = null;
        cell = null;

        cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "csv")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText("GO Id");
        data = null;
        cell = null;
        cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "csv")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText("Pathways");
        data = null;
        cell = null;

        Element sampleRow = report.addElement("Row").addAttribute("name", "sampleRow");
        cell = sampleRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText(" ");
        data = null;
        cell = null;
        cell = sampleRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText(" ");
        data = null;
        cell = null;

        cell = sampleRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "csv")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText(" ");
        data = null;
        cell = null;
        cell = sampleRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "csv")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText(" ");
        data = null;
        cell = null;
        cell = sampleRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "csv")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText(" ");
        data = null;
        cell = null;
        cell = sampleRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "csv")
                .addAttribute("group", "header");
        data = cell.addElement("Data").addAttribute("type", "header").addText(" ");
        data = null;
        cell = null;

        //set up the header for the table           
        //header.append("<Td id=\"header\">Gene</td>\n<td id=\"header\">Reporter</td>\n");        
        //sampleNames.append("<tr><Td> &nbsp;</td><Td> &nbsp;</tD>"); 

        for (Iterator labelIterator = labels.iterator(); labelIterator.hasNext();) {
            String label = (String) labelIterator.next();
            sampleIds = geneViewContainer.getBiospecimenLabels(label);
            //                theColspan += sampleIds.size();
            totalSamples += sampleIds.size();

            cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", label)
                    .addAttribute("group", label);
            data = cell.addElement("Data").addAttribute("type", "header").addText(label + " Samples");
            data = null;
            cell = null;
            //header.append("<td colspan="+sampleIds.size()+" class='"+label+"' id=\"header\">"+label+" Samples</td>"); 

            for (Iterator sampleIdIterator = sampleIds.iterator(); sampleIdIterator.hasNext();) {
                BioSpecimenIdentifierDE bioSpecimenIdentifierDE = (BioSpecimenIdentifierDE) sampleIdIterator
                        .next();

                cell = sampleRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", label)
                        .addAttribute("group", label)
                        .addAttribute("sampleId", bioSpecimenIdentifierDE.getSampleId());
                //cell = sampleRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", label).addAttribute("group", label).addAttribute("specimen", bioSpecimenIdentifierDE.getSpecimenName());
                //data = cell.addElement("Data").addAttribute("type", "header").addText(s.substring(2));
                if (bioSpecimenIdentifierDE.getSpecimenName() != null) {
                    data = cell.addElement("Data").addAttribute("type", "header")
                            .addText(bioSpecimenIdentifierDE.getSpecimenName());
                } else {
                    data = cell.addElement("Data").addAttribute("type", "header")
                            .addText(bioSpecimenIdentifierDE.getSampleId());
                }
                data = null;
                cell = null;
                //sampleNames.append("<td class='"+label+"' id=\"header\"><a href=\"report.do?s="+s+"&report=ss\">"+s.substring(2)+"</a></td>"); 
                //header.append("\t");

            }
            //header.deleteCharAt(header.lastIndexOf("\t"));
        }
        //sampleNames.append("</tr>");
        //header.append("</tr>"); 

        /* done with the headerRow and SampleRow Elements, time to add data rows */

        for (Iterator geneIterator = genes.iterator(); geneIterator.hasNext();) {
            GeneResultset geneResultset = (GeneResultset) geneIterator.next();
            Collection reporters = geneResultset.getReporterResultsets();
            String the_gene = "";
            /*  hard code filter for now */
            if (geneResultset.getGeneSymbol() != null) {
                the_gene = geneResultset.getGeneSymbol().getValueObject().toString();
            }

            //if(!the_gene.equalsIgnoreCase(filter_string))   {
            if (FilterHelper.checkFilter(filter_element, "gene", the_gene, filter_type, filter_string)) {
                //if(!filter_element.equals("gene") || (filter_element.equals("gene") && !filter_string.contains(the_gene)))   {
                recordCount += reporters.size();

                for (Iterator reporterIterator = reporters.iterator(); reporterIterator.hasNext();) {
                    ReporterResultset reporterResultset = (ReporterResultset) reporterIterator.next();
                    Collection groupTypes = reporterResultset.getGroupByResultsets();
                    String reporterName = reporterResultset.getReporter().getValue().toString();

                    /* test filtration by reporter */
                    //if(!filter_element.equals("reporter") || (filter_element.equals("reporter") && !filter_string.contains(reporterName)))   {      
                    if (FilterHelper.checkFilter(filter_element, "reporter", reporterName, filter_type,
                            filter_string)) {
                        GeneSymbol gene = geneResultset.getGeneSymbol();
                        //String geneSymbol = "&#160;";
                        String geneSymbol = "-";
                        if (gene != null) {
                            geneSymbol = geneResultset.getGeneSymbol().getValueObject().toString();
                        }

                        dataRow = report.addElement("Row").addAttribute("name", "dataRow");
                        cell = dataRow.addElement("Cell").addAttribute("type", "data")
                                .addAttribute("class", "gene").addAttribute("group", "header");
                        data = cell.addElement("Data").addAttribute("type", "header").addText(geneSymbol);
                        data = null;
                        cell = null;
                        cell = dataRow.addElement("Cell").addAttribute("type", "data")
                                .addAttribute("class", "reporter").addAttribute("group", "header");
                        data = cell.addElement("Data").addAttribute("type", "header").addText(reporterName);
                        data = null;
                        cell = null;
                        //sb.append("<tr><td>"+geneSymbol+"</td><td>"+reporterName+"</td>");

                        /*
                         * adding our 4 annotations. this code needs to be cleaned up...
                         * 
                         * I will pull all this logic out into a seperate Annotations Class ...
                         * or something like that ASAP
                         * 
                         * RCL
                         * 
                         */
                        String ll = "";
                        try {
                            HashSet locusLinkIds = new HashSet(reporterResultset.getAssiciatedLocusLinkIDs());
                            if (locusLinkIds != null) {
                                ll = StringUtils.join(locusLinkIds.toArray(), delim);
                            } else {
                                ll = "-";
                            }
                        } catch (Exception e) {
                            ll = "--";
                        }

                        String acc = "";
                        try {
                            HashSet accNumbers = new HashSet(
                                    reporterResultset.getAssiciatedGenBankAccessionNos());
                            if (accNumbers != null) {
                                acc = StringUtils.join(accNumbers.toArray(), delim);
                            } else {
                                acc = "-";
                            }
                        } catch (Exception e) {
                        }

                        String go_ids = "";
                        try {
                            HashSet go_idsHS = new HashSet(reporterResultset.getAssociatedGOIds());
                            if (go_idsHS != null) {
                                go_ids = StringUtils.join(go_idsHS.toArray(), delim);
                            } else {
                                go_ids = "-";
                            }
                        } catch (Exception e) {
                        }

                        String pathways = "";
                        try {
                            HashSet pathwaysHS = new HashSet(reporterResultset.getAssociatedPathways());
                            if (pathwaysHS != null) {
                                pathways = StringUtils.join(pathwaysHS.toArray(), delim);
                            } else {
                                pathways = "-";
                            }
                        } catch (Exception e) {
                        }

                        /*
                        * 
                        *  actually add the annotations to the report
                        * 
                        */
                        cell = dataRow.addElement("Cell").addAttribute("type", "data")
                                .addAttribute("class", "csv").addAttribute("group", "header");
                        data = cell.addElement("Data").addAttribute("type", "header").addText(ll);
                        data = null;
                        cell = null;
                        cell = dataRow.addElement("Cell").addAttribute("type", "data")
                                .addAttribute("class", "csv").addAttribute("group", "header");
                        data = cell.addElement("Data").addAttribute("type", "header").addText(acc);
                        data = null;
                        cell = null;
                        cell = dataRow.addElement("Cell").addAttribute("type", "data")
                                .addAttribute("class", "csv").addAttribute("group", "header");
                        data = cell.addElement("Data").addAttribute("type", "header").addText(go_ids);
                        data = null;
                        cell = null;
                        cell = dataRow.addElement("Cell").addAttribute("type", "data")
                                .addAttribute("class", "csv").addAttribute("group", "header");
                        data = cell.addElement("Data").addAttribute("type", "header").addText(pathways);
                        data = null;
                        cell = null;

                        for (Iterator labelIterator = labels.iterator(); labelIterator.hasNext();) {
                            String label = (String) labelIterator.next();
                            ViewByGroupResultset groupResultset = (ViewByGroupResultset) reporterResultset
                                    .getGroupByResultset(label);

                            sampleIds = geneViewContainer.getBiospecimenLabels(label);
                            String hClass = label;
                            if (groupResultset != null) {
                                for (Iterator sampleIdIterator = sampleIds.iterator(); sampleIdIterator
                                        .hasNext();) {

                                    BioSpecimenIdentifierDE sampleId = (BioSpecimenIdentifierDE) sampleIdIterator
                                            .next();
                                    SampleFoldChangeValuesResultset biospecimenResultset = (SampleFoldChangeValuesResultset) groupResultset
                                            .getBioSpecimenResultset(sampleId.getSpecimenName());
                                    if (biospecimenResultset != null) {

                                        //JB Begin: Add for GForge # 17783 - Advance Query Reports - Make the report more user friendly (Provide tool tip)
                                        String tooltip = "Gene = " + geneSymbol + ", Reporter = " + reporterName
                                                + ", Sample = " + sampleId.getSampleId() + " ("
                                                + sampleId.getSpecimenName() + ")";
                                        //JB End: Add for GForge # 17783 - Advance Query Reports - Make the report more user friendly (Provide tool tip)

                                        if (biospecimenResultset.isHighlighted())
                                            hClass = "highlighted";
                                        else
                                            hClass = label;

                                        Double ratio = (Double) biospecimenResultset.getFoldChangeRatioValue()
                                                .getValue();
                                        if (ratio != null) {
                                            cell = dataRow.addElement("Cell").addAttribute("type", "data")
                                                    .addAttribute("class", hClass).addAttribute("group", label);
                                            //JB Begin: Add for GForge # 17783 - Advance Query Reports - Make the report more user friendly (Provide tool tip)
                                            //data = cell.addElement("Data").addAttribute("type", "data").addText(resultFormat.format(ratio));
                                            data = cell.addElement("Data").addAttribute("type", "data")
                                                    .addAttribute("datainfo", tooltip)
                                                    .addText(resultFormat.format(ratio));
                                            //JB End: Add for GForge # 17783 - Advance Query Reports - Make the report more user friendly (Provide tool tip)
                                            data = null;
                                            cell = null;

                                            //sb.append("<Td class='"+label+"'>"+resultFormat.format(ratio)+" </td>");
                                        } else {
                                            cell = dataRow.addElement("Cell").addAttribute("type", "data")
                                                    .addAttribute("class", hClass).addAttribute("group", label);
                                            data = cell.addElement("Data").addAttribute("type", "data")
                                                    .addText("-");
                                            data = null;
                                            cell = null;
                                            //sb.append("<td class='"+label+"'>-</td>");
                                        }
                                    } else {
                                        cell = dataRow.addElement("Cell").addAttribute("type", "data")
                                                .addAttribute("class", hClass).addAttribute("group", label);
                                        data = cell.addElement("Data").addAttribute("type", "data")
                                                .addText("-");
                                        data = null;
                                        cell = null;
                                        //sb.append("<td class='"+label+"'>-</td>");
                                    }
                                }
                            } else {
                                for (int s = 0; s < sampleIds.size(); s++) {
                                    cell = dataRow.addElement("Cell").addAttribute("type", "data")
                                            .addAttribute("class", hClass).addAttribute("group", label);
                                    data = cell.addElement("Data").addAttribute("type", "data").addText("-");
                                    data = null;
                                    cell = null;
                                    //sb.append("<td class='"+label+"'>-</td>");
                                }
                            }

                        }

                        //sb.append("</tr>\n");
                    } /* end reporter filter */
                    //sb.append("<tr><td colspan=\""+theColspan+"\" class=\"geneSpacerStyle\">&nbsp;</td></tr>\n");
                }
            } /* end gene filter  */
            //sb.append("</table>");
        }
    } else {
        //TODO: handle this error
        sb.append("<br><Br>Gene Container is empty<br>");
    }

    //return "<div class=\"rowCount\">"+ helpFul +recordCount+" records returned. " + totalSamples +" samples returned. &nbsp;&nbsp;&nbsp;" + links  + "</div>\n" + sb.toString();

    return document;
}

From source file:gr.abiss.calipso.util.XmlUtils.java

License:Open Source License

public static Document getNewDocument(String rootElementName) {
    Document d = DocumentHelper.createDocument();
    d.addElement(rootElementName);
    return d;
}