List of usage examples for org.dom4j Element addText
Element addText(String text);
Text
node with the given text to this element. From source file:feedForwardNetwork.FeedForwardNetwork.java
License:Open Source License
/** Method used for saving the properties of this component */ public void exportToXmlElement(Element element) { Element nn = element.addElement("ThreeLayerNetwork"); nn.addAttribute("input_nodes", String.valueOf(this.input_nodes)); nn.addAttribute("output_nodes", String.valueOf(this.output_nodes)); nn.addAttribute("nodes", String.valueOf(this.nodes)); nn.addAttribute("layers", String.valueOf(this.layers)); nn.addAttribute("weight_range", String.valueOf(this.weight_range)); nn.addAttribute("bias_range", String.valueOf(this.bias_range)); if (this.isEvaluated()) { nn.addAttribute("fitness", String.valueOf(this.getFitness())); }//from w ww . j a v a 2 s. co m Element dnodes = nn.addElement("nodes"); for (int i = 0; i < this.nodes; i++) { Element node; if (i < input_nodes) { node = dnodes.addElement("node"); node.addAttribute("nr", String.valueOf(i)); node.addAttribute("type", "inputNode"); } else { node = dnodes.addElement("node"); node.addAttribute("nr", String.valueOf(i)); node.addAttribute("type", "node"); Element bias = node.addElement("bias"); bias.addText(String.valueOf(this.bias[i])); Element weights = node.addElement("weights"); for (int j = 0; j < this.nodes; j++) { Element weight = weights.addElement("weight"); weight.addAttribute("from", String.valueOf(j)); weight.addText(String.valueOf(this.getWeight(i, j))); } } } }
From source file:fr.gouv.culture.vitam.eml.PstExtract.java
License:Open Source License
private String extractInfoMessage(PSTMessage email) { if (email instanceof PSTContact) { Element node = extractInfoContact((PSTContact) email); config.addRankId(node);//from w w w.ja v a 2 s .c o m //node.addAttribute(EMAIL_FIELDS.rankId.name, id); Element identifications = XmlDom.factory.createElement("identification"); Element identity = XmlDom.factory.createElement("identity"); identity.addAttribute("format", "Microsoft Outlook Address Book"); identity.addAttribute("mime", "application/vnd.ms-outlook"); identifications.add(identity); node.add(identifications); node.addAttribute(EMAIL_FIELDS.status.name, "ok"); currentRoot.add(node); return ""; } else if (email instanceof PSTTask) { Element node = extractInfoTask((PSTTask) email); config.addRankId(node); //node.addAttribute(EMAIL_FIELDS.rankId.name, id); Element identifications = XmlDom.factory.createElement("identification"); Element identity = XmlDom.factory.createElement("identity"); identity.addAttribute("format", "Microsoft Outlook Task"); identity.addAttribute("mime", "application/vnd.ms-outlook"); identifications.add(identity); node.add(identifications); node.addAttribute(EMAIL_FIELDS.status.name, "ok"); currentRoot.add(node); return ""; } else if (email instanceof PSTActivity) { Element node = extractInfoActivity((PSTActivity) email); config.addRankId(node); //node.addAttribute(EMAIL_FIELDS.rankId.name, id); Element identifications = XmlDom.factory.createElement("identification"); Element identity = XmlDom.factory.createElement("identity"); identity.addAttribute("format", "Microsoft Outlook Activity"); identity.addAttribute("mime", "application/vnd.ms-outlook"); identifications.add(identity); node.add(identifications); node.addAttribute(EMAIL_FIELDS.status.name, "ok"); currentRoot.add(node); return ""; } else if (email instanceof PSTRss) { Element node = extractInfoRss((PSTRss) email); config.addRankId(node); //node.addAttribute(EMAIL_FIELDS.rankId.name, id); Element identifications = XmlDom.factory.createElement("identification"); Element identity = XmlDom.factory.createElement("identity"); identity.addAttribute("format", "Microsoft Outlook Rss"); identity.addAttribute("mime", "application/vnd.ms-outlook"); identifications.add(identity); node.add(identifications); node.addAttribute(EMAIL_FIELDS.status.name, "ok"); currentRoot.add(node); return ""; } else if (email instanceof PSTAppointment) { Element node = extractInfoAppointment((PSTAppointment) email); config.addRankId(node); //node.addAttribute(EMAIL_FIELDS.rankId.name, id); Element identifications = XmlDom.factory.createElement("identification"); Element identity = XmlDom.factory.createElement("identity"); identity.addAttribute("format", "Microsoft Outlook Appointment"); identity.addAttribute("mime", "application/vnd.ms-outlook"); identifications.add(identity); node.add(identifications); node.addAttribute(EMAIL_FIELDS.status.name, "ok"); currentRoot.add(node); return ""; } Element root = XmlDom.factory.createElement(EMAIL_FIELDS.formatMSG.name); Element keywords = XmlDom.factory.createElement(EMAIL_FIELDS.keywords.name); Element metadata = XmlDom.factory.createElement(EMAIL_FIELDS.metadata.name); String id = config.addRankId(root); //root.addAttribute(EMAIL_FIELDS.rankId.name, id); Element identifications = XmlDom.factory.createElement("identification"); Element identity = XmlDom.factory.createElement("identity"); identity.addAttribute("format", "Microsoft Outlook Email Message"); identity.addAttribute("mime", "application/vnd.ms-outlook"); identity.addAttribute("puid", "x-fmt/430"); identity.addAttribute("extensions", "msg"); identifications.add(identity); root.add(identifications); Element sub = XmlDom.factory.createElement(EMAIL_FIELDS.from.name); addAddress(sub, EMAIL_FIELDS.fromUnit.name, email.getSenderName(), email.getSenderEmailAddress()); metadata.add(sub); int NumberOfRecipients = 0; Element toRecipients = XmlDom.factory.createElement(EMAIL_FIELDS.toRecipients.name); Element ccRecipients = XmlDom.factory.createElement(EMAIL_FIELDS.ccRecipients.name); Element bccRecipients = XmlDom.factory.createElement(EMAIL_FIELDS.bccRecipients.name); try { NumberOfRecipients = email.getNumberOfRecipients(); } catch (PSTException e1) { } catch (IOException e1) { } for (int i = 0; i < NumberOfRecipients; i++) { try { PSTRecipient recipient = email.getRecipient(i); // MAPI_TO = 1; MAPI_CC = 2; MAPI_BCC = 3; Element choose = null; String type = "??"; switch (recipient.getRecipientType()) { case PSTRecipient.MAPI_TO: type = EMAIL_FIELDS.toUnit.name; choose = toRecipients; break; case PSTRecipient.MAPI_CC: type = EMAIL_FIELDS.ccUnit.name; choose = ccRecipients; break; case PSTRecipient.MAPI_BCC: type = EMAIL_FIELDS.bccUnit.name; choose = bccRecipients; break; } if (choose != null) { addAddress(choose, type, recipient.getDisplayName(), recipient.getEmailAddress()); } } catch (PSTException e) { } catch (IOException e) { } } if (toRecipients.hasContent()) { metadata.add(toRecipients); } if (ccRecipients.hasContent()) { metadata.add(ccRecipients); } if (bccRecipients.hasContent()) { metadata.add(bccRecipients); } // get the subject String Subject = email.getSubject(); if (Subject != null) { sub = XmlDom.factory.createElement(EMAIL_FIELDS.subject.name); sub.setText(StringUtils.unescapeHTML(Subject, true, false)); metadata.add(sub); } // Conversation topic This is basically the subject from which Fwd:, Re, etc. Subject = email.getConversationTopic(); if (Subject != null) { sub = XmlDom.factory.createElement(EMAIL_FIELDS.conversationTopic.name); sub.setText(StringUtils.unescapeHTML(Subject, true, false)); metadata.add(sub); } // get the client submit time (sent ?) Date ClientSubmitTime = email.getClientSubmitTime(); if (ClientSubmitTime != null) { sub = XmlDom.factory.createElement(EMAIL_FIELDS.sentDate.name); sub.setText(ClientSubmitTime.toString()); metadata.add(sub); } // Message delivery time Date MessageDeliveryTime = email.getMessageDeliveryTime(); if (MessageDeliveryTime != null) { sub = XmlDom.factory.createElement(EMAIL_FIELDS.receivedDate.name); sub.setText(MessageDeliveryTime.toString()); metadata.add(sub); } // Transport message headers ASCII or Unicode string These contain the SMTP e-mail headers. String TransportMessageHeaders = email.getTransportMessageHeaders(); if (TransportMessageHeaders != null) { sub = XmlDom.factory.createElement(EMAIL_FIELDS.receptionTrace.name); sub.add(XmlDom.factory.createElement(EMAIL_FIELDS.trace.name) .addText(StringUtils.unescapeHTML(TransportMessageHeaders, true, false))); metadata.add(sub); if (TransportMessageHeaders.contains("X-RDF:")) { System.err.println("Found a X-RDF"); int pos = TransportMessageHeaders.indexOf("X-RDF:") + "X-RDF:".length(); while (pos < TransportMessageHeaders.length()) { char test = TransportMessageHeaders.charAt(pos); if (test != ' ' && test != '\r' && test != '\n') { pos++; } else { break; } } int pos2 = TransportMessageHeaders.indexOf(":", pos); while (pos2 > pos) { char test = TransportMessageHeaders.charAt(pos2); if (test != ' ' && test != '\r' && test != '\n') { pos2--; } else { break; } } String xrdf = TransportMessageHeaders.substring(pos, pos2); String rdf = null; try { byte[] decoded = org.apache.commons.codec.binary.Base64.decodeBase64(xrdf); //byte [] decoded = Base64.decode(xrdf); rdf = new String(decoded); System.err.println(rdf); try { Document tempDocument = DocumentHelper.parseText(rdf); Element erdf = sub.addElement("x-rdf"); erdf.add(tempDocument.getRootElement()); } catch (Exception e) { System.err.println("Cannot decode X-RDF: " + e.getMessage()); e.printStackTrace(); Element erdf = sub.addElement("x-rdf"); erdf.addText(rdf); } } catch (Exception e) { System.err.println("Cannot decode X-RDF: " + e.getMessage()); System.err.println(xrdf); e.printStackTrace(); } } TransportMessageHeaders = null; } long internalSize = email.getMessageSize(); if (internalSize > 0) { sub = XmlDom.factory.createElement(EMAIL_FIELDS.emailSize.name); sub.setText(Long.toString(internalSize)); metadata.add(sub); } // Message ID for this email as allocated per rfc2822 String InternetMessageId = email.getInternetMessageId(); if (InternetMessageId != null) { InternetMessageId = StringUtils.removeChevron(StringUtils.unescapeHTML(InternetMessageId, true, false)) .trim(); if (InternetMessageId.length() > 1) { sub = XmlDom.factory.createElement(EMAIL_FIELDS.messageId.name); sub.setText(InternetMessageId); metadata.add(sub); } } // In-Reply-To String InReplyToId = email.getInReplyToId(); if (InReplyToId != null) { InReplyToId = StringUtils.removeChevron(StringUtils.unescapeHTML(InReplyToId, true, false)).trim(); if (InReplyToId.length() > 1) { sub = XmlDom.factory.createElement(EMAIL_FIELDS.inReplyTo.name); sub.setText(InReplyToId); if (InternetMessageId != null && InternetMessageId.length() > 1) { String old = EmlExtract.filEmls.get(InReplyToId); if (old == null) { old = InternetMessageId; } else { old += "," + InternetMessageId; } EmlExtract.filEmls.put(InReplyToId, old); } metadata.add(sub); } InReplyToId = null; InternetMessageId = null; } sub = XmlDom.factory.createElement(EMAIL_FIELDS.properties.name); // is the action flag for this item "forward"? boolean Forwarded = email.hasForwarded(); sub.addAttribute(EMAIL_FIELDS.propForwarded.name, Boolean.toString(Forwarded)); // is the action flag for this item "replied"? boolean Replied = email.hasReplied(); sub.addAttribute(EMAIL_FIELDS.propReplied.name, Boolean.toString(Replied)); // boolean Read = email.isRead(); sub.addAttribute(EMAIL_FIELDS.propRead.name, Boolean.toString(Read)); // boolean Unsent = email.isUnsent(); sub.addAttribute(EMAIL_FIELDS.propUnsent.name, Boolean.toString(Unsent)); // Recipient Reassignment Prohibited Boolean 0 = false 0 != true boolean RecipientReassignmentProhibited = email.getRecipientReassignmentProhibited(); sub.addAttribute(EMAIL_FIELDS.propRecipientReassignmentProhibited.name, Boolean.toString(RecipientReassignmentProhibited)); // get the importance of the email // PSTMessage.IMPORTANCE_LOW + PSTMessage.IMPORTANCE_NORMAL + PSTMessage.IMPORTANCE_HIGH int Importance = email.getImportance(); String imp = "??"; switch (Importance) { case PSTMessage.IMPORTANCE_LOW: imp = "LOW"; break; case PSTMessage.IMPORTANCE_NORMAL: imp = "NORMAL"; break; case PSTMessage.IMPORTANCE_HIGH: imp = "HIGH"; break; } sub.addAttribute(EMAIL_FIELDS.importance.name, imp); // Priority Integer 32-bit signed -1 = NonUrgent 0 = Normal 1 = Urgent int Priority = email.getPriority(); switch (Priority) { case -1: imp = "LOW"; break; case 0: imp = "NORMAL"; break; case 1: imp = "HIGH"; break; default: imp = "LEV" + Priority; } sub.addAttribute(EMAIL_FIELDS.priority.name, imp); // Sensitivity Integer 32-bit signed sender's opinion of the sensitivity of an email 0 = // None 1 = Personal 2 = Private 3 = Company Confidential int Sensitivity = email.getSensitivity(); String sens = "??"; switch (Sensitivity) { case 0: sens = "None"; break; case 1: sens = "Personal"; break; case 2: sens = "Private"; break; case 3: sens = "Confidential"; break; } sub.addAttribute(EMAIL_FIELDS.sensitivity.name, sens); // boolean Attachments = email.hasAttachments(); sub.addAttribute(EMAIL_FIELDS.hasAttachment.name, Boolean.toString(Attachments)); metadata.add(sub); String result = ""; Element identification = null; if (Attachments) { File oldPath = curPath; if (config.extractFile) { File newDir = new File(curPath, id); newDir.mkdirs(); curPath = newDir; argument.currentOutputDir = curPath; } identification = XmlDom.factory.createElement(EMAIL_FIELDS.attachments.name); // get the number of attachments for this message int NumberOfAttachments = email.getNumberOfAttachments(); identification.addAttribute(EMAIL_FIELDS.attNumber.name, Integer.toString(NumberOfAttachments)); // get a specific attachment from this email. for (int attachmentNumber = 0; attachmentNumber < NumberOfAttachments; attachmentNumber++) { try { PSTAttachment attachment = email.getAttachment(attachmentNumber); if (argument.extractKeyword) { result += " " + extractInfoAttachment(attachment, identification); } else { extractInfoAttachment(attachment, identification); } } catch (PSTException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } curPath = oldPath; argument.currentOutputDir = curPath; } // Plain text e-mail body String body = ""; if (argument.extractKeyword || config.extractFile) { body = email.getBody(); boolean isTxt = true; boolean isHttp = false; if (body == null || body.isEmpty()) { isTxt = false; body = email.getBodyHTML(); isHttp = true; if (body == null || body.isEmpty()) { isHttp = false; try { body = email.getRTFBody(); } catch (PSTException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } if (body != null && !body.isEmpty()) { if (config.extractFile) { // XXX FIXME could saved email from HTML Body (clearer) if possible // use curRank in name, and attachment will be under directory named // add currank in field File newDir = new File(curPath, id); newDir.mkdirs(); File oldPath = curPath; curPath = newDir; argument.currentOutputDir = curPath; String filenamebody = InternetMessageId; if (filenamebody == null || !filenamebody.isEmpty()) { filenamebody = id; } String html = null; if (isHttp) { html = body; } String rtf = null; if (!isTxt && !isHttp) { rtf = body; } if (isTxt) { FileOutputStream output = null; try { output = new FileOutputStream(new File(newDir, filenamebody + ".txt")); byte[] bb = body.getBytes(); output.write(bb, 0, bb.length); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (output != null) { try { output.close(); } catch (IOException e) { } } } html = email.getBodyHTML(); } if (html != null && !html.isEmpty()) { FileOutputStream output = null; try { output = new FileOutputStream(new File(newDir, filenamebody + ".html")); byte[] bb = html.getBytes(); output.write(bb, 0, bb.length); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (output != null) { try { output.close(); } catch (IOException e) { } } } html = null; } if (isTxt || isHttp) { try { rtf = email.getRTFBody(); } catch (PSTException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } if (rtf != null && !rtf.isEmpty()) { FileOutputStream output = null; try { output = new FileOutputStream(new File(newDir, filenamebody + ".rtf")); byte[] bb = rtf.getBytes(); output.write(bb, 0, bb.length); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (output != null) { try { output.close(); } catch (IOException e) { } } } rtf = null; } curPath = oldPath; argument.currentOutputDir = curPath; } } } if (metadata.hasContent()) { root.add(metadata); } if (identification != null && identification.hasContent()) { root.add(identification); } if (argument.extractKeyword) { result = body + " " + result; body = null; ExtractInfo.exportMetadata(keywords, result, "", config, null); if (keywords.hasContent()) { root.add(keywords); } } root.addAttribute(EMAIL_FIELDS.status.name, "ok"); currentRoot.add(root); return result; }
From source file:fullyMeshedNet.FullyMeshedNet.java
License:Open Source License
/** Method used for saving the properties of this component */ public void exportToXmlElement(Element element) { Element nn = element.addElement("FullyMeshedNet"); nn.addAttribute("input_nodes", String.valueOf(this.input_nodes)); nn.addAttribute("output_nodes", String.valueOf(this.output_nodes)); nn.addAttribute("nodes", String.valueOf(this.nodes)); nn.addAttribute("weight_range", String.valueOf(this.weight_range)); nn.addAttribute("bias_range", String.valueOf(this.bias_range)); nn.addAttribute("random_bias_range", String.valueOf(this.random_bias_range)); nn.addAttribute("random_source", String.valueOf(this.random_source)); nn.addAttribute("variable_mutation_rate", String.valueOf(this.variable_mutation_rate)); nn.addAttribute("activation_function", String.valueOf(this.activationFunction)); if (variable_mutation_rate) nn.addAttribute("mutation_rate", String.valueOf(this.mutationRate)); if (this.isEvaluated()) { nn.addAttribute("fitness", String.valueOf(this.getFitness())); } else {//from w w w .j av a2 s . co m nn.addAttribute("fitness", String.valueOf(-1)); } Element dnodes = nn.addElement("nodes"); for (int i = 0; i < this.nodes; i++) { Element node; if (i < input_nodes) { node = dnodes.addElement("node"); node.addAttribute("nr", String.valueOf(i)); node.addAttribute("type", "inputNode"); } else { node = dnodes.addElement("node"); node.addAttribute("nr", String.valueOf(i)); node.addAttribute("type", "node"); Element bias = node.addElement("bias"); bias.addText(String.valueOf(this.bias[i])); if (random_source) { Element randombias = node.addElement("randombias"); randombias.addText(String.valueOf(this.randombias[i])); } Element weights = node.addElement("weights"); for (int j = 0; j < this.nodes; j++) { Element weight = weights.addElement("weight"); weight.addAttribute("from", String.valueOf(j)); weight.addText(String.valueOf(this.getWeight(i, j))); } } } }
From source file:gov.nih.nci.caintegrator.application.report.LevelOfExpressionIHCReport.java
License:BSD License
/** * @param finding//from w ww .j av a 2 s.c o m * @param filterMapParams * @return Document */ public static Document getReportXML(Finding finding, Map filterMapParams) { Document document = DocumentHelper.createDocument(); Element report = document.addElement("Report"); Element cell = null; Element data = null; Element dataRow = null; //ADD BASIC ATTRIBUTED report.addAttribute("reportType", "levelExpression"); report.addAttribute("groupBy", "none"); String queryName = finding.getTaskId(); report.addAttribute("queryName", queryName); report.addAttribute("sessionId", "the session id"); StringBuffer sb = new StringBuffer(); /* ************************************************************************************************* * * PROCESS QUERY DETAILS * * ************************************************************************************************* * */ LevelOfExpressionIHCFindingCriteria criteria = (LevelOfExpressionIHCFindingCriteria) finding.getQueryDTO(); ArrayList<String> queryDetails = new ArrayList(); if (criteria != null) { String tmp = ""; ArrayList<String> tmpCollection = new ArrayList<String>(); tmp = criteria.getQueryName() != null ? criteria.getQueryName() : ""; queryDetails.add("Query Name: " + tmp); tmp = ""; if (criteria.getProteinBiomarkerCrit() != null && criteria.getProteinBiomarkerCrit().getProteinNameCollection() != null && !criteria.getProteinBiomarkerCrit().getProteinNameCollection().isEmpty()) { Set<String> biomarkers = criteria.getProteinBiomarkerCrit().getProteinNameCollection(); tmpCollection = new ArrayList<String>(biomarkers); for (String bm : tmpCollection) { if (bm != tmpCollection.get(0)) { tmp += ", " + bm; } else { tmp += bm; } } } queryDetails.add("Biomarker(s): " + tmp); tmpCollection.clear(); tmp = ""; if (criteria.getSpecimenCriteria() != null && criteria.getSpecimenCriteria().getTimeCourseCollection() != null && !criteria.getSpecimenCriteria().getTimeCourseCollection().isEmpty()) { Set<String> timepoints = criteria.getSpecimenCriteria().getTimeCourseCollection(); tmpCollection = new ArrayList<String>(timepoints); TimepointStringComparator ts = new TimepointStringComparator(); Collections.sort(tmpCollection, ts); for (String tc : tmpCollection) { if (tc != tmpCollection.get(0)) { tmp += ", " + tc; } else { tmp += tc; } } } queryDetails.add("Timepoint(s): " + tmp); tmpCollection.clear(); tmp = ""; if (criteria.getStainIntensityCollection() != null && !criteria.getStainIntensityCollection().isEmpty()) { Set<String> intensity = (Set<String>) criteria.getStainIntensityCollection(); tmpCollection = new ArrayList<String>(intensity); for (String in : tmpCollection) { if (in != tmpCollection.get(0)) { tmp += ", " + in; } else { tmp += in; } } } queryDetails.add("Intensity: " + tmp); tmpCollection.clear(); tmp = ""; tmp = criteria.getPercentPositiveRangeMin() != null ? criteria.getPercentPositiveRangeMin().toString() : ""; queryDetails.add("% Positive Min: " + tmp); tmp = ""; tmp = criteria.getPercentPositiveRangeMax() != null ? criteria.getPercentPositiveRangeMax().toString() : ""; queryDetails.add("% Positive Max: " + tmp); tmp = ""; if (criteria.getStainLocalizationCollection() != null && !criteria.getStainLocalizationCollection().isEmpty()) { Set<String> locale = (Set<String>) criteria.getStainLocalizationCollection(); tmpCollection = new ArrayList<String>(locale); for (String lc : tmpCollection) { if (lc != tmpCollection.get(0)) { tmp += ", " + lc; } else { tmp += lc; } } } queryDetails.add("Localization: " + tmp); tmpCollection.clear(); tmp = ""; } String qd = ""; for (String q : queryDetails) { qd += q + " ||| "; } /* ************************************************************************************************************** * * BUILD REPORT AS XML * * ************************************************************************************************************** */ //GET FINDINGS, CAST TO APPROPRIATE FINDINGS AND ADD TO ARRAYLIST (RESULTS) ArrayList dFindings = new ArrayList(finding.getDomainFindings()); ArrayList<LevelOfExpressionIHCFinding> domainFindings = new ArrayList<LevelOfExpressionIHCFinding>( dFindings); ArrayList<LevelOfExpressionIHCFindingReportBean> results = new ArrayList<LevelOfExpressionIHCFindingReportBean>(); for (LevelOfExpressionIHCFinding loef : domainFindings) { LevelOfExpressionIHCFindingReportBean reportBean = new LevelOfExpressionIHCFindingReportBean(loef); results.add(reportBean); } if (!results.isEmpty()) { //SORT THE ARRAYLIST(RESULTS) BY PATIENT DID PatientComparator p = new PatientComparator(); Collections.sort(results, p); //CREATE A HASHMAP SORTED BY PATIENT DID AS THE KEY AND THE ARRAYLIST OF REPORTBEANS AS THE VALUE Map<String, ArrayList<LevelOfExpressionIHCFindingReportBean>> reportBeanMap = new HashMap<String, ArrayList<LevelOfExpressionIHCFindingReportBean>>(); int j = results.size(); for (int i = 0; i < results.size(); i++) { boolean found = false; Set<String> keys = reportBeanMap.keySet(); int key = keys.size(); if (!keys.isEmpty()) { for (String k : keys) { String s = results.get(i).getSpecimenIdentifier() + "_" + results.get(i).getBiomarkerName(); if (s.equals(k)) { found = true; reportBeanMap.get(k).add(results.get(i)); break; } } if (!found) { reportBeanMap.put( results.get(i).getSpecimenIdentifier() + "_" + results.get(i).getBiomarkerName(), new ArrayList<LevelOfExpressionIHCFindingReportBean>()); reportBeanMap.get( results.get(i).getSpecimenIdentifier() + "_" + results.get(i).getBiomarkerName()) .add(results.get(i)); } } else { reportBeanMap.put( results.get(i).getSpecimenIdentifier() + "_" + results.get(i).getBiomarkerName(), new ArrayList<LevelOfExpressionIHCFindingReportBean>()); reportBeanMap .get(results.get(i).getSpecimenIdentifier() + "_" + results.get(i).getBiomarkerName()) .add(results.get(i)); } // } //IF THE USER SELECTED TIMEPOINTS FOR WHICH THAT PATIENT DID DID NOT HAVE DATA, CREATE NULL BEANS SO AS TO RENDER A READABLE REPORT Set<String> b = reportBeanMap.keySet(); for (String g : b) { while (reportBeanMap.get(g) .size() < (reportBeanMap.get(g).get(0).getTimepointHeaders(criteria).size())) { reportBeanMap.get(g) .add(new LevelOfExpressionIHCFindingReportBean(new LevelOfExpressionIHCFinding())); } } //ADD QUERY DETAILS Element details = report.addElement("Query_details"); cell = details.addElement("Data"); cell.addText(qd); cell = null; //ADD HEADERS THAT ARE TIMEPOINT-INDEPENDENT (PATIENT AND BIOMARKER) Element headerRow = report.addElement("Row").addAttribute("name", "headerRow"); ArrayList<String> ntpHeaders = results.get(0).getNonTimepointHeaders(); for (String ntpHeader : ntpHeaders) { cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header") .addAttribute("group", "ntpHeader"); data = cell.addElement("Data").addAttribute("type", "header").addText(ntpHeader); data = null; cell = null; } //ADD HEADERS THAT ARE TIMEPOINT DEPENDENT ArrayList<String> headers = results.get(0).getHeaders(); for (String header : headers) { cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header") .addAttribute("group", "header"); data = cell.addElement("Data").addAttribute("type", "header").addText(header); data = null; cell = null; } //ADD TIMEPOINT SUBHEADERS ArrayList<String> tpHeaders = results.get(0).getTimepointHeaders(criteria); //ArrayList<String> localizations = results.get(0).getTimepointHeaders(criteria); TimepointStringComparator ts = new TimepointStringComparator(); Collections.sort(tpHeaders, ts); Element tpHeaderRow = report.addElement("Row").addAttribute("name", "tpHeaderRow"); // for(String tpHeader : tpHeaders){ for (int i = 0; i < tpHeaders.size(); i++) { cell = tpHeaderRow.addElement("Cell").addAttribute("type", "header") .addAttribute("class", "firstTP").addAttribute("group", "tpHeader"); data = cell.addElement("Data").addAttribute("type", "header").addText(tpHeaders.get(i)); data = null; cell = null; } Set<String> keys = reportBeanMap.keySet(); // ADD DATA ROWS for (String key : keys) { String tp = reportBeanMap.get(key).get(0).getTimepoint(); Collection<String> localizationCollection = criteria.getStainLocalizationCollection(); Collection<String> intensityCollection = criteria.getStainIntensityCollection(); String localization = reportBeanMap.get(key).get(0).getStainLocalization(); String intensity = reportBeanMap.get(key).get(0).getStainIntensity(); if (tpHeaders.contains(tp) && (localizationCollection == null || (localizationCollection != null && localizationCollection.contains(localization))) && (intensityCollection == null || (intensityCollection != null && intensityCollection.contains(intensity)))) { dataRow = report.addElement("Row").addAttribute("name", "dataRow"); cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "sample") .addAttribute("group", "data"); data = cell.addElement("Data").addAttribute("type", "selectable") .addText(reportBeanMap.get(key).get(0).getPatientDID()); 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(reportBeanMap.get(key).get(0).getBiomarkerName()); data = null; cell = null; //GRAB EACH REPORT BEAN IN EACH ARRAYLIST AND MATCH UP TO THE APPROPRIATE TIMEPOINT AS A MAP WITH THE TIMEPOINT AS KEY AND REPORTBEAN THE VALUE ArrayList<LevelOfExpressionIHCFindingReportBean> myList = reportBeanMap.get(key); Map<String, LevelOfExpressionIHCFindingReportBean> myMap = new HashMap<String, LevelOfExpressionIHCFindingReportBean>(); ArrayList<LevelOfExpressionIHCFindingReportBean> mySortedMap = new ArrayList<LevelOfExpressionIHCFindingReportBean>(); for (LevelOfExpressionIHCFindingReportBean ggg : myList) { for (int i = 0; i < tpHeaders.size(); i++) { if (ggg.getTimepoint().equalsIgnoreCase(tpHeaders.get(i))) { myMap.put(tpHeaders.get(i), ggg); break; } else if (ggg.getTimepoint().equals("--")) { if (!myMap.containsKey(tpHeaders.get(i))) { myMap.put(tpHeaders.get(i), ggg); break; } } } } //SORT MAP BY TIMEPOINT SO THAT THE REPORT BEAN DATA CAN EASILY BE DISPLAYED UNDER THE APPROPRIATE TIEMPOINT for (int i = 0; i < tpHeaders.size(); i++) { for (String k : myMap.keySet()) { if (k.equalsIgnoreCase(tpHeaders.get(i))) { mySortedMap.add(myMap.get(k)); } } } //ITERATE OVER THE MAP FOR EACH DATA FIELD WITH ITS CORRESPONDING TIMEPOINT AND BUILD DATA ROWS for (LevelOfExpressionIHCFindingReportBean reportBean : mySortedMap) { cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "data") .addAttribute("group", "data"); data = cell.addElement("Data").addAttribute("type", "header") .addText(reportBean.getPercentPositive()); data = null; cell = null; } for (LevelOfExpressionIHCFindingReportBean reportBean : mySortedMap) { cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "data") .addAttribute("group", "data"); data = cell.addElement("Data").addAttribute("type", "header") .addText(reportBean.getStainIntensity()); data = null; cell = null; } for (LevelOfExpressionIHCFindingReportBean reportBean : mySortedMap) { cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "data") .addAttribute("group", "data"); data = cell.addElement("Data").addAttribute("type", "header") .addText(reportBean.getStainLocalization()); data = null; cell = null; } for (LevelOfExpressionIHCFindingReportBean reportBean : mySortedMap) { cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "data") .addAttribute("group", "data"); data = cell.addElement("Data").addAttribute("type", "header") .addText(reportBean.getInvasivePresentation()); data = null; cell = null; } for (LevelOfExpressionIHCFindingReportBean reportBean : mySortedMap) { cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "data") .addAttribute("group", "data"); data = cell.addElement("Data").addAttribute("type", "header") .addText(reportBean.getOverallExpression()); data = null; cell = null; } } } } else { //TODO: handle this error sb.append("<br><Br>Level of Expression is empty<br>"); } return document; }
From source file:gov.nih.nci.caintegrator.application.report.LossOfExpressionIHCReport.java
License:BSD License
public static Document getReportXML(Finding finding, Map filterMapParams) { Document document = DocumentHelper.createDocument(); Element report = document.addElement("Report"); Element cell = null; Element data = null;//from ww w . j a va 2 s . c o m Element dataRow = null; //ADD BASIC ATTRIBUTED report.addAttribute("reportType", "IHC Loss Of Expression"); report.addAttribute("groupBy", "none"); String queryName = finding.getTaskId(); report.addAttribute("queryName", queryName); report.addAttribute("sessionId", "the session id"); StringBuffer sb = new StringBuffer(); /* ************************************************************************************************* * * PROCESS QUERY DETAILS * * ************************************************************************************************* * */ LossOfExpressionIHCFindingCriteria criteria = (LossOfExpressionIHCFindingCriteria) finding.getQueryDTO(); ArrayList<String> queryDetails = new ArrayList(); if (criteria != null) { String tmp = ""; ArrayList<String> tmpCollection = new ArrayList<String>(); tmp = criteria.getQueryName() != null ? criteria.getQueryName() : ""; queryDetails.add("Query Name: " + tmp); tmp = ""; if (criteria.getProteinBiomarkerCrit() != null && criteria.getProteinBiomarkerCrit().getProteinNameCollection() != null && !criteria.getProteinBiomarkerCrit().getProteinNameCollection().isEmpty()) { Set<String> biomarkers = criteria.getProteinBiomarkerCrit().getProteinNameCollection(); tmpCollection = new ArrayList<String>(biomarkers); for (String bm : tmpCollection) { if (bm != tmpCollection.get(0)) { tmp += ", " + bm; } else { tmp += bm; } } } queryDetails.add("Biomarker(s): " + tmp); tmpCollection.clear(); tmp = ""; if (criteria.getSpecimenCriteria() != null && criteria.getSpecimenCriteria().getTimeCourseCollection() != null && !criteria.getSpecimenCriteria().getTimeCourseCollection().isEmpty()) { Set<String> timepoints = criteria.getSpecimenCriteria().getTimeCourseCollection(); tmpCollection = new ArrayList<String>(timepoints); TimepointStringComparator ts = new TimepointStringComparator(); Collections.sort(tmpCollection, ts); for (String tc : tmpCollection) { if (tc != tmpCollection.get(0)) { tmp += ", " + tc; } else { tmp += tc; } } } queryDetails.add("Timepoint(s): " + tmp); tmpCollection.clear(); tmp = ""; if (criteria.getBenignSumOperator() != null && criteria.getBenignSum() != null) { tmp = criteria.getBenignSumOperator() + " " + criteria.getBenignSum().toString(); } queryDetails.add("Benign Sum: " + tmp); tmp = ""; if (criteria.getInvasiveSumOperator() != null && criteria.getInvasiveSum() != null) { tmp = criteria.getInvasiveSumOperator() + " " + criteria.getInvasiveSum().toString(); } queryDetails.add("Invasive Sum: " + tmp); tmp = ""; if (criteria.getResultCodeCollection() != null && !criteria.getResultCodeCollection().isEmpty()) { Set<String> resultCodes = (Set<String>) criteria.getResultCodeCollection(); tmpCollection = new ArrayList<String>(resultCodes); for (String rc : tmpCollection) { if (rc != tmpCollection.get(0)) { tmp += ", " + rc; } else { tmp += rc; } } } queryDetails.add("Loss Result: " + tmp); tmpCollection.clear(); tmp = ""; } String qd = ""; for (String q : queryDetails) { qd += q + " ||| "; } /* ************************************************************************************************************** * * BUILD REPORT AS XML * * ************************************************************************************************************** */ //GET FINDINGS, CAST TO APPROPRIATE FINDINGS AND ADD TO ARRAYLIST (RESULTS) ArrayList dFindings = new ArrayList(finding.getDomainFindings()); ArrayList<LossOfExpressionIHCFinding> domainFindings = new ArrayList<LossOfExpressionIHCFinding>(dFindings); ArrayList<LossOfExpressionIHCFindingReportBean> results = new ArrayList<LossOfExpressionIHCFindingReportBean>(); for (LossOfExpressionIHCFinding loef : domainFindings) { LossOfExpressionIHCFindingReportBean reportBean = new LossOfExpressionIHCFindingReportBean(loef); results.add(reportBean); } if (!results.isEmpty()) { //SORT THE ARRAYLIST(RESULTS) BY PATIENT DID PatientComparator p = new PatientComparator(); Collections.sort(results, p); //CREATE A HASHMAP SORTED BY PATIENT DID AS THE KEY AND THE ARRAYLIST OF REPORTBEANS AS THE VALUE Map<String, ArrayList<LossOfExpressionIHCFindingReportBean>> reportBeanMap = new HashMap<String, ArrayList<LossOfExpressionIHCFindingReportBean>>(); for (int i = 0; i < results.size(); i++) { boolean found = false; Set<String> keys = reportBeanMap.keySet(); if (!keys.isEmpty()) { for (String k : keys) { String s = results.get(i).getSpecimenIdentifier() + "_" + results.get(i).getBiomarkerName(); if (s.equals(k)) { found = true; reportBeanMap.get(k).add(results.get(i)); break; } } if (!found) { reportBeanMap.put( results.get(i).getSpecimenIdentifier() + "_" + results.get(i).getBiomarkerName(), new ArrayList<LossOfExpressionIHCFindingReportBean>()); reportBeanMap.get( results.get(i).getSpecimenIdentifier() + "_" + results.get(i).getBiomarkerName()) .add(results.get(i)); } } else { reportBeanMap.put( results.get(i).getSpecimenIdentifier() + "_" + results.get(i).getBiomarkerName(), new ArrayList<LossOfExpressionIHCFindingReportBean>()); reportBeanMap .get(results.get(i).getSpecimenIdentifier() + "_" + results.get(i).getBiomarkerName()) .add(results.get(i)); } } //IF THE USER SELECTED TIMEPOINTS FOR WHICH THAT PATIENT DID DID NOT HAVE DATA, CREATE NULL BEANS SO AS TO RENDER A READABLE REPORT Set<String> b = reportBeanMap.keySet(); for (String g : b) { while (reportBeanMap.get(g) .size() < (reportBeanMap.get(g).get(0).getTimepointHeaders(criteria).size())) { reportBeanMap.get(g) .add(new LossOfExpressionIHCFindingReportBean(new LossOfExpressionIHCFinding())); } } //ADD QUERY DETAILS Element details = report.addElement("Query_details"); cell = details.addElement("Data"); cell.addText(qd); cell = null; //ADD HEADERS THAT ARE TIMEPOINT-INDEPENDENT (PATIENT AND BIOMARKER) Element headerRow = report.addElement("Row").addAttribute("name", "headerRow"); ArrayList<String> ntpHeaders = results.get(0).getNonTimepointHeaders(); for (String ntpHeader : ntpHeaders) { cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header") .addAttribute("group", "ntpHeader"); data = cell.addElement("Data").addAttribute("type", "header").addText(ntpHeader); data = null; cell = null; } //ADD HEADERS THAT ARE TIMEPOINT DEPENDENT ArrayList<String> headers = results.get(0).getHeaders(); for (String header : headers) { cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header") .addAttribute("group", "header"); data = cell.addElement("Data").addAttribute("type", "header").addText(header); data = null; cell = null; } //ADD TIMEPOINT SUBHEADERS ArrayList<String> tpHeaders = results.get(0).getTimepointHeaders(criteria); TimepointStringComparator ts = new TimepointStringComparator(); Collections.sort(tpHeaders, ts); Element tpHeaderRow = report.addElement("Row").addAttribute("name", "tpHeaderRow"); // for(String tpHeader : tpHeaders){ for (int i = 0; i < tpHeaders.size(); i++) { cell = tpHeaderRow.addElement("Cell").addAttribute("type", "header") .addAttribute("class", "firstTP").addAttribute("group", "tpHeader"); data = cell.addElement("Data").addAttribute("type", "header").addText(tpHeaders.get(i)); data = null; cell = null; } Set<String> keys = reportBeanMap.keySet(); // ADD DATA ROWS for (String key : keys) { String tp = reportBeanMap.get(key).get(0).getTimepoint(); Integer invasiveSumCrit = criteria.getInvasiveSum(); String invasiveSumOpCrit = criteria.getInvasiveSumOperator(); String invasiveSum = reportBeanMap.get(key).get(0).getInvasiveSum(); String invasiveSumOp = reportBeanMap.get(key).get(0).getInvasiveSumOperator(); int j = 0; if (invasiveSumCrit != null && invasiveSumOpCrit != null) { j = new Integer(invasiveSum).compareTo(invasiveSumCrit); } Integer benignSumCrit = criteria.getBenignSum(); String benignSumOpCrit = criteria.getBenignSumOperator(); String benignSum = reportBeanMap.get(key).get(0).getBenignSum(); String benignSumOp = reportBeanMap.get(key).get(0).getBenignSumOperator(); int h = 0; if (benignSumCrit != null && benignSumOpCrit != null) { h = new Integer(benignSum).compareTo(benignSumCrit); } Collection<String> resultCodeCollection = criteria.getResultCodeCollection(); String resultCode = reportBeanMap.get(key).get(0).getLossResult(); // filter time points, invasice sum, benign sum, and result code to match what were in the search criteria if (tpHeaders.contains(tp) && (resultCodeCollection == null || (resultCodeCollection != null && resultCodeCollection.contains(resultCode))) && ((invasiveSumCrit == null && invasiveSumOpCrit == null) || (invasiveSumCrit != null && (invasiveSumOpCrit != null && invasiveSumOpCrit.equals("=")) && invasiveSumCrit.toString().equals(invasiveSum)) || (invasiveSumCrit != null && (invasiveSumOpCrit != null && invasiveSumOpCrit.equals(">=")) && j >= 0) || (invasiveSumCrit != null && (invasiveSumOpCrit != null && invasiveSumOpCrit.equals("<=")) && j <= 0)) && ((benignSumCrit == null && benignSumOpCrit == null) || (benignSumCrit != null && (benignSumOpCrit != null && benignSumOpCrit.equals("=")) && benignSumCrit.toString().equals(benignSum)) || (benignSumCrit != null && (benignSumOpCrit != null && benignSumOpCrit.equals(">=")) && h >= 0) || (benignSumCrit != null && (benignSumOpCrit != null && benignSumOpCrit.equals("<=")) && h <= 0))) { dataRow = report.addElement("Row").addAttribute("name", "dataRow"); cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "sample") .addAttribute("group", "data"); data = cell.addElement("Data").addAttribute("type", "selectable") .addText(reportBeanMap.get(key).get(0).getPatientDID()); 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(reportBeanMap.get(key).get(0).getBiomarkerName()); data = null; cell = null; //GRAB EACH REPORT BEAN IN EACH ARRAYLIST AND MATCH UP TO THE APPROPRIATE TIMEPOINT AS A MAP WITH THE TIMEPOINT AS KEY AND REPORTBEAN THE VALUE ArrayList<LossOfExpressionIHCFindingReportBean> myList = reportBeanMap.get(key); Map<String, LossOfExpressionIHCFindingReportBean> myMap = new HashMap<String, LossOfExpressionIHCFindingReportBean>(); ArrayList<LossOfExpressionIHCFindingReportBean> mySortedMap = new ArrayList<LossOfExpressionIHCFindingReportBean>(); for (LossOfExpressionIHCFindingReportBean ggg : myList) { for (int i = 0; i < tpHeaders.size(); i++) { if (ggg.getTimepoint().equalsIgnoreCase(tpHeaders.get(i))) { myMap.put(tpHeaders.get(i), ggg); break; } else if (ggg.getTimepoint().equals("--")) { if (!myMap.containsKey(tpHeaders.get(i))) { myMap.put(tpHeaders.get(i), ggg); break; } } } } //SORT MAP BY TIMEPOINT SO THAT THE REPORT BEAN DATA CAN EASILY BE DISPLAYED UNDER THE APPROPRIATE TIEMPOINT for (int i = 0; i < tpHeaders.size(); i++) { for (String k : myMap.keySet()) { if (k.equalsIgnoreCase(tpHeaders.get(i))) { mySortedMap.add(myMap.get(k)); } } } //ITERATE OVER THE MAP FOR EACH DATA FIELD WITH ITS CORRESPONDING TIMEPOINT AND BUILD DATA ROWS for (LossOfExpressionIHCFindingReportBean reportBean : mySortedMap) { cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "data") .addAttribute("group", "data"); data = cell.addElement("Data").addAttribute("type", "header") .addText(reportBean.getBenignPresentValue()); data = null; cell = null; } if (invasiveSumOp.equals("--")) { for (LossOfExpressionIHCFindingReportBean reportBean : mySortedMap) { cell = dataRow.addElement("Cell").addAttribute("type", "data") .addAttribute("class", "data").addAttribute("group", "data"); data = cell.addElement("Data").addAttribute("type", "header") .addText(reportBean.getInvasiveSum()); data = null; cell = null; } } for (LossOfExpressionIHCFindingReportBean reportBean : mySortedMap) { cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "data") .addAttribute("group", "data"); data = cell.addElement("Data").addAttribute("type", "header") .addText(reportBean.getBenignSum()); data = null; cell = null; } for (LossOfExpressionIHCFindingReportBean reportBean : mySortedMap) { cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "data") .addAttribute("group", "data"); data = cell.addElement("Data").addAttribute("type", "header") .addText(reportBean.getInvasiveBenignDiff()); data = null; cell = null; } for (LossOfExpressionIHCFindingReportBean reportBean : mySortedMap) { cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "data") .addAttribute("group", "data"); data = cell.addElement("Data").addAttribute("type", "header") .addText(reportBean.getComments()); data = null; cell = null; } for (LossOfExpressionIHCFindingReportBean reportBean : mySortedMap) { cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "data") .addAttribute("group", "data"); data = cell.addElement("Data").addAttribute("type", "header") .addText(reportBean.getLossResult()); data = null; cell = null; } } } } else { //TODO: handle this error sb.append("<br><Br>Loss of Expression is empty<br>"); } return document; }
From source file:gov.nih.nci.caintegrator.application.report.P53Report.java
License:BSD License
/** * @param finding// ww w . j ava2 s. co m * @param filterMapParams * @return Document */ public static Document getReportXML(Finding finding, Map filterMapParams) { Document document = DocumentHelper.createDocument(); Element report = document.addElement("Report"); Element cell = null; Element data = null; Element dataRow = null; //ADD BASIC ATTRIBUTED report.addAttribute("reportType", "p53Mutation"); report.addAttribute("groupBy", "none"); String queryName = finding.getTaskId(); report.addAttribute("queryName", queryName); report.addAttribute("sessionId", "the session id"); StringBuffer sb = new StringBuffer(); /* ************************************************************************************************* * * PROCESS QUERY DETAILS * * ************************************************************************************************* * */ P53FindingCriteria criteria = (P53FindingCriteria) finding.getQueryDTO(); ArrayList<String> queryDetails = new ArrayList(); if (criteria != null) { String tmp = ""; ArrayList<String> tmpCollection = new ArrayList<String>(); tmp = criteria.getQueryName() != null ? criteria.getQueryName() : ""; queryDetails.add("Query Name: " + tmp); tmp = ""; if (criteria.getSpecimenCriteria() != null && criteria.getSpecimenCriteria().getTimeCourseCollection() != null && !criteria.getSpecimenCriteria().getTimeCourseCollection().isEmpty()) { Set<String> timepoints = criteria.getSpecimenCriteria().getTimeCourseCollection(); tmpCollection = new ArrayList<String>(timepoints); TimepointStringComparator ts = new TimepointStringComparator(); Collections.sort(tmpCollection, ts); for (String tc : tmpCollection) { if (tc != tmpCollection.get(0)) { tmp += ", " + tc; } else { tmp += tc; } } } queryDetails.add("Timepoint(s): " + tmp); tmpCollection.clear(); tmp = ""; if (criteria.getMutationStatusCollection() != null && !criteria.getMutationStatusCollection().isEmpty()) { Set<String> mutationStatus = (Set<String>) criteria.getMutationStatusCollection(); tmpCollection = new ArrayList<String>(mutationStatus); for (String in : tmpCollection) { if (in != tmpCollection.get(0)) { tmp += ", " + in; } else { tmp += in; } } } queryDetails.add("Mutation Status: " + tmp); tmpCollection.clear(); tmp = ""; if (criteria.getMutationTypeCollection() != null && !criteria.getMutationTypeCollection().isEmpty()) { Set<String> mutationType = (Set<String>) criteria.getMutationTypeCollection(); tmpCollection = new ArrayList<String>(mutationType); for (String lc : tmpCollection) { if (lc != tmpCollection.get(0)) { tmp += ", " + lc; } else { tmp += lc; } } } queryDetails.add("Mutation Type: " + tmp); tmpCollection.clear(); tmp = ""; } String qd = ""; for (String q : queryDetails) { qd += q + " ||| "; } /* ************************************************************************************************************** * * BUILD REPORT AS XML * * ************************************************************************************************************** */ //GET FINDINGS, CAST TO APPROPRIATE FINDINGS AND ADD TO ARRAYLIST (RESULTS) ArrayList dFindings = new ArrayList(finding.getDomainFindings()); ArrayList<P53MutationFinding> domainFindings = new ArrayList<P53MutationFinding>(dFindings); ArrayList<P53FindingReportBean> results = new ArrayList<P53FindingReportBean>(); for (P53MutationFinding p53f : domainFindings) { P53FindingReportBean reportBean = new P53FindingReportBean(p53f); results.add(reportBean); } if (!results.isEmpty()) { //SORT THE ARRAYLIST(RESULTS) BY PATIENT DID PatientComparator p = new PatientComparator(); Collections.sort(results, p); //CREATE A HASHMAP SORTED BY PATIENT DID AS THE KEY AND THE ARRAYLIST OF REPORTBEANS AS THE VALUE // Map<String,ArrayList<P53FindingReportBean>> reportBeanMap = new HashMap<String,ArrayList<P53FindingReportBean>>(); Map<String, ArrayList<P53FindingReportBean>> reportBeanMap = new HashMap<String, ArrayList<P53FindingReportBean>>(); int j = results.size(); for (int i = 0; i < results.size(); i++) { boolean found = false; Set<String> keys = reportBeanMap.keySet(); int key = keys.size(); if (!keys.isEmpty()) { for (String k : keys) { String s = results.get(i).getSpecimenIdentifier(); if (s.equals(k)) { found = true; reportBeanMap.get(k).add(results.get(i)); break; } } if (!found) { reportBeanMap.put(results.get(i).getSpecimenIdentifier(), new ArrayList<P53FindingReportBean>()); reportBeanMap.get(results.get(i).getSpecimenIdentifier()).add(results.get(i)); } } else { reportBeanMap.put(results.get(i).getSpecimenIdentifier(), new ArrayList<P53FindingReportBean>()); reportBeanMap.get(results.get(i).getSpecimenIdentifier()).add(results.get(i)); } // } //IF THE USER SELECTED TIMEPOINTS FOR WHICH THAT PATIENT DID DID NOT HAVE DATA, CREATE NULL BEANS SO AS TO RENDER A READABLE REPORT Set<String> b = reportBeanMap.keySet(); for (String g : b) { while (reportBeanMap.get(g) .size() < (reportBeanMap.get(g).get(0).getTimepointHeaders(criteria).size())) { reportBeanMap.get(g).add(new P53FindingReportBean(new P53MutationFinding())); } } //ADD QUERY DETAILS Element details = report.addElement("Query_details"); cell = details.addElement("Data"); cell.addText(qd); cell = null; //ADD HEADERS THAT ARE TIMEPOINT-INDEPENDENT (PATIENT) Element headerRow = report.addElement("Row").addAttribute("name", "headerRow"); ArrayList<String> ntpHeaders = results.get(0).getNonTimepointHeaders(); for (String ntpHeader : ntpHeaders) { // on the report page, should not display labtrak id if (!ntpHeader.equalsIgnoreCase("LabTrak ID")) { cell = headerRow.addElement("Cell").addAttribute("type", "header") .addAttribute("class", "header").addAttribute("group", "ntpHeader"); data = cell.addElement("Data").addAttribute("type", "header").addText(ntpHeader); data = null; cell = null; } } //ADD HEADERS THAT ARE TIMEPOINT DEPENDENT ArrayList<String> headers = results.get(0).getHeaders(); for (String header : headers) { cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header") .addAttribute("group", "header"); data = cell.addElement("Data").addAttribute("type", "header").addText(header); data = null; cell = null; } //ADD TIMEPOINT SUBHEADERS ArrayList<String> tpHeaders = results.get(0).getTimepointHeaders(criteria); TimepointStringComparator ts = new TimepointStringComparator(); Collections.sort(tpHeaders, ts); Element tpHeaderRow = report.addElement("Row").addAttribute("name", "tpHeaderRow"); // this is leave the first space empty cell = headerRow.addElement("Cell").addAttribute("type", "header").addAttribute("class", "header") .addAttribute("group", "ntpHeader"); data = cell.addElement("Data").addAttribute("type", "header").addText(""); System.out.println(")))" + data.toString()); data = null; cell = null; for (int i = 0; i < tpHeaders.size(); i++) { cell = tpHeaderRow.addElement("Cell").addAttribute("type", "header") .addAttribute("class", "firstTP").addAttribute("group", "tpHeader"); data = cell.addElement("Data").addAttribute("type", "header").addText(tpHeaders.get(i)); data = null; cell = null; } Set<String> keys = reportBeanMap.keySet(); // ADD DATA ROWS for (String key : keys) { String tp = reportBeanMap.get(key).get(0).getTimepoint(); Collection<String> mutationStatusCollection = criteria.getMutationStatusCollection(); Collection<String> mutationTypeCollection = criteria.getMutationTypeCollection(); String mutationStatus = reportBeanMap.get(key).get(0).getMutationStatus(); String mutationType = reportBeanMap.get(key).get(0).getMutationType(); if (tpHeaders.contains(tp) && (mutationStatusCollection == null || (mutationStatusCollection != null && mutationStatusCollection.contains(mutationStatus))) && (mutationTypeCollection == null || (mutationTypeCollection != null && mutationTypeCollection.contains(mutationType)))) { dataRow = report.addElement("Row").addAttribute("name", "dataRow"); cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "sample") .addAttribute("group", "data"); data = cell.addElement("Data").addAttribute("type", "selectable") .addText(reportBeanMap.get(key).get(0).getPatientDID()); data = null; cell = null; //GRAB EACH REPORT BEAN IN EACH ARRAYLIST AND MATCH UP TO THE APPROPRIATE TIMEPOINT AS A MAP WITH THE TIMEPOINT AS KEY AND REPORTBEAN THE VALUE ArrayList<P53FindingReportBean> myList = reportBeanMap.get(key); Map<String, P53FindingReportBean> myMap = new HashMap<String, P53FindingReportBean>(); ArrayList<P53FindingReportBean> mySortedMap = new ArrayList<P53FindingReportBean>(); for (P53FindingReportBean ggg : myList) { for (int i = 0; i < tpHeaders.size(); i++) { if (ggg.getTimepoint().equalsIgnoreCase(tpHeaders.get(i))) { myMap.put(tpHeaders.get(i), ggg); break; } else if (ggg.getTimepoint().equals("--")) { if (!myMap.containsKey(tpHeaders.get(i))) { myMap.put(tpHeaders.get(i), ggg); break; } } } } //SORT MAP BY TIMEPOINT SO THAT THE REPORT BEAN DATA CAN EASILY BE DISPLAYED UNDER THE APPROPRIATE TIEMPOINT for (int i = 0; i < tpHeaders.size(); i++) { for (String k : myMap.keySet()) { if (k.equalsIgnoreCase(tpHeaders.get(i))) { mySortedMap.add(myMap.get(k)); } } } //ITERATE OVER THE MAP FOR EACH DATA FIELD WITH ITS CORRESPONDING TIMEPOINT AND BUILD DATA ROWS for (P53FindingReportBean reportBean : mySortedMap) { cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "data") .addAttribute("group", "data"); data = cell.addElement("Data").addAttribute("type", "header") .addText(reportBean.getMutationStatus()); data = null; cell = null; } for (P53FindingReportBean reportBean : mySortedMap) { cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "data") .addAttribute("group", "data"); data = cell.addElement("Data").addAttribute("type", "header") .addText(reportBean.getMutationType()); data = null; cell = null; } for (P53FindingReportBean reportBean : mySortedMap) { cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "data") .addAttribute("group", "data"); data = cell.addElement("Data").addAttribute("type", "header") .addText(reportBean.getExonOrIntronLocation()); data = null; cell = null; } for (P53FindingReportBean reportBean : mySortedMap) { cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "data") .addAttribute("group", "data"); data = cell.addElement("Data").addAttribute("type", "header") .addText(reportBean.getBaseChange()); data = null; cell = null; } for (P53FindingReportBean reportBean : mySortedMap) { cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "data") .addAttribute("group", "data"); data = cell.addElement("Data").addAttribute("type", "header") .addText(reportBean.getCodonAminoacidChange()); data = null; cell = null; } for (P53FindingReportBean reportBean : mySortedMap) { cell = dataRow.addElement("Cell").addAttribute("type", "data").addAttribute("class", "data") .addAttribute("group", "data"); data = cell.addElement("Data").addAttribute("type", "header") .addText(reportBean.getProteinStructuralDomain()); data = null; cell = null; } } } } else { //TODO: handle this error sb.append("<br><Br>Level of Expression is empty<br>"); } return document; }
From source file:gov.nih.nci.ispy.web.xml.ClassComparisonReport.java
License:BSD License
public static Document getReportXML(Finding finding, Map filterMapParams, boolean allAnnotations) { allAnnotations = true; //force this for now ISPY prerelease - RCL 3/2 DecimalFormat resultFormat = new DecimalFormat("0.0000"); DecimalFormat sciFormat = new DecimalFormat("0.00E0"); DecimalFormat tmpsciFormat = new DecimalFormat("###0.0000#####################"); /*/*from ww w.j a v a2 s . co 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"); //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(); String reporterType = ccdto.getArrayPlatformDE().getValueObject(); 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(" ", " "); */ 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; 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"); String isAdj = ccf.arePvaluesAdjusted() ? " (Adjusted) " : ""; data = cell.addElement("Data").addAttribute("type", "header").addText("P-Value" + 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("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>(); for (ClassComparisonResultEntry classComparisonResultEntry : classComparisonResultEntrys) { if (classComparisonResultEntry.getReporterId() != null) { reporterIds.add(classComparisonResultEntry.getReporterId()); } } Map reporterResultsetMap = null; try { GeneExprAnnotationService geService = GeneExprAnnotationServiceFactory.getInstance(); reporterResultsetMap = geService.getAnnotationsMapForReporters(reporterIds); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } /* //new stuff AnnotationHandler h = new AnnotationHandler(); Map reporterResultsetMap = null; if(allAnnotations){ //Map<String, ReporterAnnotations> reporterResultsetMap = null; try { reporterResultsetMap = h.getAllAnnotationsFor(reporterIds); } catch (Exception e) { e.printStackTrace(); } } else { //Map<String, String> reporterResultsetMap = null; try { reporterResultsetMap = h.getGeneSymbolsFor(reporterIds); } 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){} } */ for (ClassComparisonResultEntry 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", reporterType).addText(ccre.getReporterId()); 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", "pval").addAttribute("class", "data") .addAttribute("group", "data"); //String pv = (ccre.getPvalue() == null) ? String.valueOf(ccre.getPvalue()) : "N/A"; String pv = defaultV; BigDecimal bigd; try { bigd = new BigDecimal(ccre.getPvalue()); pv = bigd.toPlainString(); } catch (Exception e) { //missing value } data = cell.addElement("Data").addAttribute("type", "header").addText(pv); 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().toUpperCase().trim(); 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().toUpperCase().trim(); //ReporterResultset reporterResultset = reporterResultsetMap.get(reporterId); ReporterAnnotation ra = (ReporterAnnotation) reporterResultsetMap.get(reporterId); //Collection<String> geneSymbols = (Collection<String>)reporterResultset.getAssiciatedGeneSymbols(); if (ra != null) { List geneSymbols = ra.getGeneSymbols(); //if(geneSymbols != null) // genes = geneSymbols.toString(); if (geneSymbols != null) { genes = StringUtils.join(geneSymbols.toArray(), delim); } Collection<String> genBank_AccIDS = (Collection<String>) ra.getGenbankAccessions(); if (genBank_AccIDS != null) { accIds = StringUtils.join(genBank_AccIDS.toArray(), delim); } Collection<String> locusLinkIDs = (Collection<String>) ra.getLocusLinkIds(); 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.getPathwayIds(); 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.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 ww w .j a v a2s . 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(" ", " "); */ 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.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#####################"); /*//ww w. j a va 2 s . com * 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:gr.abiss.calipso.domain.Field.java
License:Open Source License
private void copyTo(Element e) { // appending empty strings to create new objects for "clone" support e.addAttribute(NAME, name + ""); e.addAttribute(PRIORITY, priority + ""); if (this.groupId != null) { e.addAttribute(GROUP_ID, this.groupId); }//from ww w. j av a 2 s .co m if (fieldType != null) { e.addAttribute(FIELDTYPE, fieldType); } if (validationExpressionId != null && validationExpressionId.longValue() != 0) { e.addAttribute(VALIDATIONEXPR, validationExpressionId + ""); } if (this.defaultValueExpression != null) { e.addAttribute(DEFAULT_VALUE, this.defaultValueExpression); } if (this.getName().isFreeText()) { e.addAttribute(LINECOUNT, this.lineCount.toString()); e.addAttribute(MULTIVALUE, this.multivalue.toString()); } e.addAttribute(LABEL, label + ""); Element configElem = FieldConfig.asDom4j(this.xmlConfig); if (configElem != null) { e.add(configElem); } if (optional) { e.addAttribute(OPTIONAL, TRUE); } if (options == null) { return; } for (Map.Entry<String, String> entry : options.entrySet()) { Element option = e.addElement(OPTION); option.addAttribute(VALUE, entry.getKey() + ""); option.addText((String) entry.getValue() + ""); } }