1 package uk.ac.ebi.intenz.webapp.helper;
2
3 import java.util.ArrayList;
4 import java.util.Iterator;
5 import java.util.List;
6 import java.util.Set;
7 import java.util.SortedSet;
8 import java.util.TreeSet;
9
10 import org.apache.log4j.Logger;
11
12 import uk.ac.ebi.biobabel.util.StringUtil;
13 import uk.ac.ebi.biobabel.util.collections.OperatorSet;
14 import uk.ac.ebi.intenz.domain.constants.EnzymeNameQualifierConstant;
15 import uk.ac.ebi.intenz.domain.constants.EnzymeStatusConstant;
16 import uk.ac.ebi.intenz.domain.constants.EnzymeViewConstant;
17 import uk.ac.ebi.intenz.domain.constants.EventConstant;
18 import uk.ac.ebi.intenz.domain.constants.Status;
19 import uk.ac.ebi.intenz.domain.enzyme.Cofactor;
20 import uk.ac.ebi.intenz.domain.enzyme.EnzymaticReactions;
21 import uk.ac.ebi.intenz.domain.enzyme.EnzymeComment;
22 import uk.ac.ebi.intenz.domain.enzyme.EnzymeEntry;
23 import uk.ac.ebi.intenz.domain.enzyme.EnzymeLink;
24 import uk.ac.ebi.intenz.domain.enzyme.EnzymeName;
25 import uk.ac.ebi.intenz.domain.history.HistoryEvent;
26 import uk.ac.ebi.intenz.domain.reference.Book;
27 import uk.ac.ebi.intenz.domain.reference.Journal;
28 import uk.ac.ebi.intenz.domain.reference.Patent;
29 import uk.ac.ebi.intenz.domain.reference.Reference;
30 import uk.ac.ebi.intenz.tools.sib.helper.FFWriterHelper;
31 import uk.ac.ebi.intenz.tools.sib.helper.SibEntryHelper;
32 import uk.ac.ebi.intenz.tools.sib.sptr_enzyme.EnzymeEntryImpl;
33 import uk.ac.ebi.intenz.tools.sib.writer.EnzymeFlatFileWriter;
34 import uk.ac.ebi.intenz.webapp.IntEnzUtilities;
35 import uk.ac.ebi.interfaces.sptr.SPTRException;
36 import uk.ac.ebi.rhea.domain.Compound;
37 import uk.ac.ebi.rhea.domain.Reaction;
38 import uk.ac.ebi.rhea.domain.XRef;
39 import uk.ac.ebi.xchars.SpecialCharacters;
40 import uk.ac.ebi.xchars.domain.EncodingType;
41
42
43
44
45
46
47
48
49 public class EnzymeEntryHelper {
50
51 private static final Logger LOGGER = Logger.getLogger(EnzymeClassHelper.class);
52
53 private EnzymeEntryHelper() { }
54
55 public static String toHTML(EnzymeEntry enzymeEntry, SpecialCharacters encoding, EncodingType encodingType,
56 EnzymeViewConstant view) throws SPTRException {
57 if (enzymeEntry.getHistory().isDeletedRootNode() || enzymeEntry.getHistory().isTransferredRootNode()) {
58 return deletedEntryToHTML(enzymeEntry, encoding, encodingType, view);
59 } else {
60 return wholeEntryToHTML(enzymeEntry, encoding, encodingType, view);
61 }
62 }
63
64
65
66
67
68
69
70
71
72
73 private static String deletedEntryToHTML(EnzymeEntry enzymeEntry,
74 SpecialCharacters encoding, EncodingType encodingType, EnzymeViewConstant view)
75 throws SPTRException {
76 StringBuffer htmlStringBuffer = new StringBuffer();
77 HistoryEvent latestHistoryEvent = enzymeEntry.getHistory().getLatestHistoryEventOfRoot();
78
79 if (enzymeEntry.isGhost()) {
80 htmlStringBuffer.append("<tr>\n");
81 htmlStringBuffer.append("<td align=\"left\">\n");
82 htmlStringBuffer.append("<a href=\"query?cmd=SearchEC&ec=")
83 .append(enzymeEntry.getEc().toString())
84 .append("\" style=\"white-space: nowrap;\">EC ")
85 .append(enzymeEntry.getEc().toString()).append("</a>\n");
86 htmlStringBuffer.append("</td>\n");
87 htmlStringBuffer.append("<td align=\"left\">\n");
88 htmlStringBuffer.append("<span class=\"inactiveEntry\">");
89 if (enzymeEntry.getHistory().isDeletedRootNode()){
90 htmlStringBuffer.append("deleted");
91 } else if (enzymeEntry.getHistory().isTransferredRootNode()){
92 if (latestHistoryEvent.getNote() != null && !latestHistoryEvent.getNote().equals("")){
93 htmlStringBuffer.append(IntEnzUtilities.linkEcNumber(latestHistoryEvent.getNote(), true));
94
95 }
96 else {
97 htmlStringBuffer.append("<i>Transferred to EC ")
98 .append(IntEnzUtilities.linkEcNumber(latestHistoryEvent.getAfterNode().getEnzymeEntry().getEc().toString(), false))
99 .append("</i>");
100
101 }
102 }
103 htmlStringBuffer.append("</span>").append("</td>\n").append("</tr>\n");
104 return htmlStringBuffer.toString();
105 }
106
107 if (view == EnzymeViewConstant.INTENZ || view == EnzymeViewConstant.IUBMB)
108 htmlStringBuffer.append(getIubmbIntEnzDeletedEntry(enzymeEntry, latestHistoryEvent, encoding, view ==
109 EnzymeViewConstant.IUBMB));
110 if (view == EnzymeViewConstant.SIB){
111
112 htmlStringBuffer.append(getSibView(enzymeEntry, encoding, encodingType));
113 }
114
115 return getViewsTabs(enzymeEntry, view) + htmlStringBuffer.toString();
116 }
117
118 private static String getIubmbIntEnzDeletedEntry(EnzymeEntry enzymeEntry, HistoryEvent latestHistoryEvent,
119 SpecialCharacters encoding, boolean isIubmbView) {
120 StringBuffer htmlStringBuffer = new StringBuffer();
121
122 if (!isIubmbView && !enzymeEntry.getStatus().equals(Status.PROPOSED)){
123 htmlStringBuffer.append(getXmlLink(enzymeEntry));
124 }
125
126
127 htmlStringBuffer.append("<table align=\"center\" style=\"margin-bottom: 0px\">\n")
128 .append("<tr><td class=\"centered\"><b>");
129 if (isIubmbView)
130 htmlStringBuffer.append("NC-IUBMB Enzyme Nomenclature");
131 else
132 htmlStringBuffer.append("IntEnz Enzyme Nomenclature");
133 htmlStringBuffer.append("</b></td></tr>\n");
134 htmlStringBuffer.append("<tr><td class=\"centered\"><b style=\"font-size: 150%\">EC ")
135 .append(enzymeEntry.getEc().toString()).append("</b></td></tr>\n");
136 if (enzymeEntry.getStatus() == Status.PROPOSED) {
137 htmlStringBuffer.append("<tr><td class=\"centered\">(proposal)</td></tr>\n");
138 }
139 htmlStringBuffer.append("</table>\n");
140
141 htmlStringBuffer.append("<table width=\"100%\" border=\"0\">\n");
142 htmlStringBuffer.append("<tr>\n");
143
144 if (latestHistoryEvent.getEventClass() == EventConstant.DELETION)
145 htmlStringBuffer.append("<td><b>Deleted entry</b>:\n");
146 if (latestHistoryEvent.getEventClass() == EventConstant.TRANSFER)
147 htmlStringBuffer.append("<td><b>Transferred entry</b>:\n");
148
149 if (!enzymeEntry.getCommonName(EnzymeViewConstant.INTENZ).getName().equals("")) {
150 htmlStringBuffer.append(encoding.xml2Display(enzymeEntry.getCommonName(EnzymeViewConstant.INTENZ).getName()));
151 htmlStringBuffer.append(". ");
152 }
153
154 if (!latestHistoryEvent.getNote().equals("")) {
155
156 htmlStringBuffer.append(IntEnzUtilities.cleanInternalLinks(latestHistoryEvent.getNote(), true));
157 if (!latestHistoryEvent.getNote().endsWith(".")) htmlStringBuffer.append(".");
158 htmlStringBuffer.append("<br/>");
159 }
160 if (latestHistoryEvent.getEventClass() == EventConstant.TRANSFER){
161 htmlStringBuffer.append("<i>Transferred to EC ")
162 .append(IntEnzUtilities.linkEcNumber(latestHistoryEvent.getAfterNode().getEnzymeEntry().getEc().toString(), false))
163 .append("</i>");
164 }
165
166 htmlStringBuffer.append("</td>\n");
167 htmlStringBuffer.append("</tr>\n");
168 htmlStringBuffer.append("<tr>\n");
169 htmlStringBuffer.append("<td align=\"center\">\n");
170 htmlStringBuffer.append("<b class=\"centered\">[" + enzymeEntry.getHistory().getRootNode().getHistoryLine() + "]</b>\n");
171 htmlStringBuffer.append("</td>\n");
172 htmlStringBuffer.append("</tr>\n");
173 htmlStringBuffer.append("</table>\n");
174 return htmlStringBuffer.toString();
175 }
176
177 private static String getSibContentTitle(String ecString) {
178 StringBuffer htmlStringBuffer = new StringBuffer();
179 htmlStringBuffer.append("<div style=\"font-size: larger\"><b>ENZYME: </b>");
180 htmlStringBuffer.append(ecString);
181 htmlStringBuffer.append("</div>\n");
182 return htmlStringBuffer.toString();
183 }
184
185
186
187
188
189
190 private static String wholeEntryToHTML(EnzymeEntry enzymeEntry, SpecialCharacters encoding,
191 EncodingType encodingType, EnzymeViewConstant view)
192 throws SPTRException {
193
194 if (enzymeEntry.isGhost()) {
195 StringBuffer htmlStringBuffer = new StringBuffer();
196 htmlStringBuffer.append("<tr>\n");
197 htmlStringBuffer.append("<td valign=\"top\" align=\"left\">\n");
198 htmlStringBuffer.append("<a href=\"query?cmd=SearchEC&ec=");
199 htmlStringBuffer.append(enzymeEntry.getEc().toString());
200 htmlStringBuffer.append("&status=");
201 htmlStringBuffer.append(enzymeEntry.getStatus().getCode());
202 htmlStringBuffer.append("\" style=\"white-space: nowrap;\">");
203 htmlStringBuffer.append("EC ").append(enzymeEntry.getEc().toString());
204 htmlStringBuffer.append("</a>\n");
205 htmlStringBuffer.append("</td>\n");
206 htmlStringBuffer.append("<td valign=\"top\" align=\"left\">\n");
207 htmlStringBuffer.append(encoding.xml2Display(enzymeEntry.getCommonName(EnzymeViewConstant.INTENZ).getName()));
208 if (enzymeEntry.getStatus() == Status.PROPOSED) {
209 htmlStringBuffer.append(" <small><b>(proposal)</b></small>");
210 }
211 htmlStringBuffer.append("</td>\n");
212 htmlStringBuffer.append("</tr>\n");
213 return htmlStringBuffer.toString();
214 }
215
216 String html = null;
217 if (view == EnzymeViewConstant.INTENZ)
218 html = getIntEnzView(enzymeEntry, encoding, encodingType);
219 else if (view == EnzymeViewConstant.SIB)
220 html = getSibView(enzymeEntry, encoding, encodingType);
221 else html = getIubmbView(enzymeEntry, encoding, encodingType);
222
223 return getViewsTabs(enzymeEntry, view) + html;
224 }
225
226 private static String getViewsTabs(EnzymeEntry entry, EnzymeViewConstant view){
227 StringBuffer tabs = new StringBuffer();
228 tabs.append("\n<div class=\"viewsTabBar\"> ");
229 tabs.append(getTab(entry, view, EnzymeViewConstant.INTENZ));
230 tabs.append(getTab(entry, view, EnzymeViewConstant.IUBMB));
231 tabs.append(getTab(entry, view, EnzymeViewConstant.SIB));
232 tabs.append("</div>\n");
233
234 return tabs.toString();
235 }
236
237 private static String getTab(EnzymeEntry entry, EnzymeViewConstant view, EnzymeViewConstant tabView){
238 StringBuffer tab = new StringBuffer();
239 String tabLinkOpen = view.equals(tabView)?
240 "" : "<a href=\"query?cmd=SearchID&id="+entry.getId()+"&view="+tabView.toString()+"\">";
241 String tabClass = view.equals(tabView)?
242 "selected viewTab" : "unselected viewTab";
243 String tabName = tabView.equals(EnzymeViewConstant.INTENZ)?
244 "IntEnz view" : tabView.toDisplayString()+" view";
245 String tabTitle = tabView.equals(EnzymeViewConstant.INTENZ)?
246 "" : "EC "+entry.getEc().toString()+" as seen on the "+tabView.toDisplayString()+" website";
247 String tabLinkClose = view.equals(tabView)?
248 "" : "</a>";
249 tab.append("<span class=\"").append(tabClass).append("\" title=\"")
250 .append(tabTitle).append("\">");
251 tab.append(tabLinkOpen).append(tabName).append(tabLinkClose);
252 tab.append("</span>");
253 return tab.toString();
254 }
255
256
257 private static String getIubmbView(EnzymeEntry enzymeEntry, SpecialCharacters encoding, EncodingType encodingType) {
258 StringBuffer htmlStringBuffer = new StringBuffer();
259
260 htmlStringBuffer.append("<table width=\"100%\" border=\"0\">\n");
261 htmlStringBuffer.append("<tr>\n");
262 htmlStringBuffer.append("<td width=\"25%\"></td>\n");
263 htmlStringBuffer.append("<td align=\"center\" width=\"50%\">\n");
264 htmlStringBuffer.append("<b>IUBMB Enzyme Nomenclature</b>\n");
265 htmlStringBuffer.append("</td>\n");
266 htmlStringBuffer.append("<td width=\"25%\"></td>\n");
267 htmlStringBuffer.append("</tr>\n");
268 htmlStringBuffer.append("<tr>\n");
269 htmlStringBuffer.append("<td width=\"25%\"></td>\n");
270 htmlStringBuffer.append("<td align=\"center\" width=\"50%\">\n");
271 htmlStringBuffer.append("<b style=\"font-size: 150%\">EC " + enzymeEntry.getEc().toString() + "</b>\n");
272 if (enzymeEntry.getStatus() == Status.PROPOSED) {
273 htmlStringBuffer.append("<br>(proposal)\n");
274 }
275
276 htmlStringBuffer.append("</td>\n");
277 htmlStringBuffer.append("<td width=\"25%\">\n");
278 htmlStringBuffer.append("</td>\n");
279 htmlStringBuffer.append("</tr>\n");
280 htmlStringBuffer.append("</table>\n");
281
282 htmlStringBuffer.append("<div class=\"iubmb\"><b>Accepted name:</b> ")
283 .append(encoding.xml2Display(enzymeEntry.getCommonName(EnzymeViewConstant.IUBMB).getName()))
284 .append("</div>");
285
286 htmlStringBuffer.append("<div class=\"iubmb\"><b>Reaction:</b> ");
287 List reactions = getIubmbReactions(enzymeEntry.getEnzymaticReactions());
288 for (int i = 0, steps = 0; i < reactions.size(); i++){
289 Reaction reaction = (Reaction) reactions.get(i);
290 if (reactions.size() > 1 && !reaction.getTextualRepresentation().matches("\\(?\\d\\p{Lower}\\)?\\s.*"))
291 htmlStringBuffer.append("(").append(i+1-steps).append(") ");
292 else steps++;
293 htmlStringBuffer.append(EnzymeReactionHelper.textualRepresentationToHTML(reaction, encoding, encodingType));
294 if (i < reactions.size()-1)
295 htmlStringBuffer.append("<br/>");
296 }
297 htmlStringBuffer.append("</div>");
298
299 List synonyms = getIubmbSynonyms(enzymeEntry.getSynonyms());
300 if (!synonyms.isEmpty()){
301 htmlStringBuffer.append("<div class=\"iubmb\"><b>Other name(s):</b> ");
302 for (Iterator it = synonyms.iterator(); it.hasNext();) {
303 EnzymeName synonym = (EnzymeName) it.next();
304 htmlStringBuffer.append(encoding.xml2Display(synonym.getName()));
305 if (synonym.getQualifier() == EnzymeNameQualifierConstant.MISLEADING)
306 htmlStringBuffer.append(" [misleading]");
307 if (synonym.getQualifier() == EnzymeNameQualifierConstant.OBSOLETE)
308 htmlStringBuffer.append(" [obsolete]");
309 if (synonym.getQualifier() == EnzymeNameQualifierConstant.AMBIGUOUS)
310 htmlStringBuffer.append(" [ambiguous]");
311 if (it.hasNext()) htmlStringBuffer.append("; ");
312 }
313 htmlStringBuffer.append("</div>");
314 }
315
316 if (!enzymeEntry.getSystematicName().getName().equals("") &&
317 !enzymeEntry.getSystematicName().getName().equals("-")) {
318 htmlStringBuffer.append("<div class=\"iubmb\"><b>Systematic name:</b> ")
319 .append(encoding.xml2Display(enzymeEntry.getSystematicName().getName()))
320 .append("</div>");
321 }
322
323 List comments = getIubmbComments(enzymeEntry.getComments());
324 if (comments.size() > 0){
325 htmlStringBuffer.append("<div class=\"iubmb\"><b>Comments:</b> ");
326 for (Iterator it = comments.iterator(); it.hasNext();){
327 EnzymeComment comment = (EnzymeComment) it.next();
328 htmlStringBuffer.append(
329 IntEnzUtilities.cleanInternalLinks(encoding.xml2Display(comment.getCommentText()), true));
330 if (it.hasNext()) htmlStringBuffer.append("<br/>");
331 }
332 htmlStringBuffer.append("</div>");
333 }
334
335 SortedSet links = enzymeEntry.getLinks();
336
337 htmlStringBuffer.append("<div class=\"iubmb\"><b>Links to other databases:</b> ")
338 .append(EnzymeLinkHelper.renderIubmbLinks(getIubmbLinksOnly(links), enzymeEntry.getEc().toString()))
339 .append("</div>");
340
341
342 htmlStringBuffer.append("<div class=\"iubmb\"><b>References:</b><br/>");
343 List references = enzymeEntry.getReferences();
344 for (int i = 0; i < references.size(); i++){
345 Reference reference = (Reference) references.get(i);
346 htmlStringBuffer.append(i+1).append(". ")
347 .append(encoding.xml2Display(reference.toString()));
348 if (i < references.size() - 1) htmlStringBuffer.append("<br/>");
349 }
350 htmlStringBuffer.append("</div>");
351
352 htmlStringBuffer.append("<div class=\"iubmbHistory\">[")
353 .append(enzymeEntry.getHistory().getRootNode().getHistoryLine())
354 .append("]</div>");
355
356 return htmlStringBuffer.toString();
357 }
358
359 private static List getIubmbComments(List comments) {
360 List iubmbComments = new ArrayList();
361 for (Iterator it = comments.iterator(); it.hasNext();) {
362 EnzymeComment comment = (EnzymeComment) it.next();
363 if(comment.getView().isInIUBMBView()) iubmbComments.add(comment);
364 }
365 return iubmbComments;
366 }
367
368 private static List getIubmbSynonyms(List synonyms) {
369 List iubmbSynonyms = new ArrayList();
370 for (Iterator it = synonyms.iterator(); it.hasNext();) {
371 EnzymeName synonym = (EnzymeName) it.next();
372 if(synonym.getView().isInIUBMBView()) iubmbSynonyms.add(synonym);
373 }
374 return iubmbSynonyms;
375 }
376
377 private static List<Reaction> getIubmbReactions(EnzymaticReactions reactions) {
378 List<Reaction> iubmbReactions = new ArrayList<Reaction>();
379 for (int i = 0; i < reactions.size(); i++){
380 Reaction reaction = reactions.getReaction(i);
381
382 if (reaction.getId() > Reaction.NO_ID_ASSIGNED
383
384 continue;
385 if (reactions.getReactionView(i).isInIUBMBView()) iubmbReactions.add(reaction);
386 }
387 return iubmbReactions;
388 }
389
390 private static SortedSet getIubmbLinksOnly(SortedSet links) {
391 SortedSet iubmbLinks = new TreeSet();
392 for (Iterator it = links.iterator(); it.hasNext();) {
393 EnzymeLink link = (EnzymeLink) it.next();
394 if(link.getView().isInIUBMBView()) iubmbLinks.add(link);
395 }
396 iubmbLinks.add(EnzymeLink.PDB);
397 iubmbLinks.add(EnzymeLink.EXPASY);
398 iubmbLinks.add(EnzymeLink.BRENDA);
399 iubmbLinks.add(EnzymeLink.KEGG);
400 return iubmbLinks;
401 }
402
403 public static String getSibView(EnzymeEntry enzymeEntry, SpecialCharacters encoding, EncodingType encodingType)
404 throws SPTRException {
405 EnzymeEntryImpl sibEnzymeEntry = SibEntryHelper.getSibEnzymeEntry(enzymeEntry, encoding, encodingType);
406 StringBuffer htmlStringBuffer = new StringBuffer();
407
408
409 htmlStringBuffer.append(getSibContentTitle(enzymeEntry.getEc().toString()));
410
411 if (enzymeEntry.getStatus() == Status.PROPOSED) {
412 htmlStringBuffer.append("<div class=\"centered\">\n");
413 htmlStringBuffer.append("(proposal)\n");
414 htmlStringBuffer.append("</div>\n");
415 }
416
417 htmlStringBuffer.append("<hr/>\n");
418 htmlStringBuffer.append("<div><pre>");
419 String xrefHyperlinks = FFWriterHelper.createXrefHyperlinks(EnzymeFlatFileWriter.export(sibEnzymeEntry));
420 htmlStringBuffer.append(xrefHyperlinks);
421 htmlStringBuffer.append("</pre></div>\n");
422
423 return htmlStringBuffer.toString();
424 }
425
426 private static String getXmlLink(EnzymeEntry enzymeEntry){
427 StringBuffer xmlLink = new StringBuffer();
428 String xmlBase = "ftp://ftp.ebi.ac.uk/pub/databases/intenz/xml/ASCII/";
429 String classEc = new StringBuffer("EC_")
430 .append(enzymeEntry.getEc().getEc1())
431 .toString();
432 String subclassEc = new StringBuffer(classEc).append('.')
433 .append(enzymeEntry.getEc().getEc2())
434 .toString();
435 String subsubclassEc = new StringBuffer(subclassEc).append('.')
436 .append(enzymeEntry.getEc().getEc3())
437 .toString();
438 String xmlTree = new StringBuffer(classEc).append('/')
439 .append(subclassEc).append('/')
440 .append(subsubclassEc).append('/')
441 .append("EC_").append(enzymeEntry.getEc().toString()).append(".xml")
442 .toString();
443 xmlLink.append("<div class=\"xml\" title=\"Download EC ")
444 .append(enzymeEntry.getEc().toString()).append(" in XML format\">")
445 .append("<a href=\"").append(xmlBase).append(xmlTree)
446 .append("\" class=\"xml\">")
447 .append("<span class=\"xml\">XML</span></a></div>");
448 return xmlLink.toString();
449 }
450
451 private static String getIntEnzView(EnzymeEntry enzymeEntry, SpecialCharacters encoding, EncodingType encodingType) {
452 StringBuffer htmlStringBuffer = new StringBuffer();
453
454 if (!enzymeEntry.getStatus().equals(EnzymeStatusConstant.PROPOSED)){
455 htmlStringBuffer.append(getXmlLink(enzymeEntry));
456 }
457
458
459 htmlStringBuffer.append("<table align=\"center\" style=\"margin-bottom: 0px\">\n")
460 .append("<tr><td class=\"centered\"><b>IntEnz Enzyme Nomenclature</b></td></tr>\n")
461 .append("<tr><td class=\"centered\"><b style=\"font-size: 150%\">EC ")
462 .append(enzymeEntry.getEc().toString()).append("</b></td></tr>\n");
463 if (enzymeEntry.getStatus() == Status.PROPOSED) {
464 htmlStringBuffer.append("<tr><td class=\"centered\">(proposal)</td></tr>\n");
465 }
466 htmlStringBuffer.append("</table>\n");
467
468
469 if (enzymeEntry.hasNames()) {
470 htmlStringBuffer.append(getBlockHeader("Names"));
471 htmlStringBuffer.append("<table border=\"0\" cellspacing=\"5\" style=\"margin-left: 2em\">\n");
472 EnzymeName commonName = enzymeEntry.getCommonName(EnzymeViewConstant.INTENZ);
473 EnzymeName systematicName = enzymeEntry.getSystematicName();
474 List synonyms = enzymeEntry.getSynonyms(EnzymeViewConstant.INTENZ);
475 if (commonName != null && !commonName.getName().equals(""))
476 htmlStringBuffer.append(getIntEnzCommonName(commonName, encoding));
477 if (synonyms != null && synonyms.size() > 0)
478 htmlStringBuffer.append(getIntEnzSynonyms(synonyms, encoding));
479 if (systematicName != null && !systematicName.getName().equals("") &&
480 !systematicName.getName().equals("-"))
481 htmlStringBuffer.append(getIntEnzSystematicName(systematicName, encoding));
482 htmlStringBuffer.append("</table>\n");
483 }
484
485
486 EnzymaticReactions er = enzymeEntry.getEnzymaticReactions();
487 if (er != null && er.size() > 0) {
488 htmlStringBuffer.append(getBlockHeader("Reaction"));
489 htmlStringBuffer.append(getIntEnzReaction(er, encoding, encodingType));
490 }
491
492
493 final Set<Object> cofactors = enzymeEntry.getCofactors();
494 if (cofactors != null && cofactors.size() > 0) {
495 htmlStringBuffer.append(getBlockHeader("Cofactors"));
496 htmlStringBuffer.append(getIntEnzCofactor(cofactors, encoding, encodingType));
497 }
498
499
500 final List comments = enzymeEntry.getComments(EnzymeViewConstant.INTENZ);
501 if (comments != null && comments.size() > 0) {
502 htmlStringBuffer.append(getBlockHeader("Comments"));
503 htmlStringBuffer.append(getIntEnzComments(comments, encoding));
504 }
505
506
507 final SortedSet links = enzymeEntry.getLinks();
508
509 htmlStringBuffer.append(getBlockHeader("Links to other databases"));
510 htmlStringBuffer.append(getIntEnzLinks(links, enzymeEntry.getEc().toString()));
511
512
513
514 final List references = enzymeEntry.getReferences();
515 if (references != null && references.size() > 0) {
516 htmlStringBuffer.append(getBlockHeader("References"));
517 htmlStringBuffer.append(getIntEnzReferences(references, encoding));
518 }
519
520 htmlStringBuffer.append("<div class=\"centered\"><b>[")
521 .append(enzymeEntry.getHistory().getRootNode().getHistoryLine())
522 .append("]</b></div>");
523
524 return htmlStringBuffer.toString();
525 }
526
527 private static String getIntEnzCommonName(EnzymeName commonName, SpecialCharacters encoding) {
528 StringBuffer htmlStringBuffer = new StringBuffer();
529 htmlStringBuffer.append("<tr>\n");
530 htmlStringBuffer.append("<td nowrap=\"nowrap\" valign=\"top\">\n");
531 htmlStringBuffer.append("<b>Accepted name:</b>\n");
532 htmlStringBuffer.append("</td>\n");
533 htmlStringBuffer.append("<td width=\"100%\" valign=\"top\">\n");
534 htmlStringBuffer.append(encoding.xml2Display(commonName.getName()));
535 htmlStringBuffer.append("</td>\n");
536 htmlStringBuffer.append("</tr>\n");
537 return htmlStringBuffer.toString();
538 }
539
540 private static String getIntEnzSynonyms(List synonyms, SpecialCharacters encoding) {
541 StringBuffer htmlStringBuffer = new StringBuffer();
542 htmlStringBuffer.append("<tr>\n");
543 htmlStringBuffer.append("<td nowrap=\"nowrap\" valign=\"top\">\n");
544 htmlStringBuffer.append("<b>Other name(s):</b>\n");
545 htmlStringBuffer.append("</td>\n");
546 for (int iii = 0; iii < synonyms.size(); iii++) {
547 EnzymeName synonym = (EnzymeName) synonyms.get(iii);
548 if (iii > 0) {
549 htmlStringBuffer.append("<tr>\n");
550 htmlStringBuffer.append("<td> </td>\n");
551 }
552 htmlStringBuffer.append("<td bgcolor=\"#FFFFFF\" width=\"100%\" valign=\"top\">\n");
553 htmlStringBuffer.append(encoding.xml2Display(synonym.getName()));
554 if (synonym.getQualifier() == EnzymeNameQualifierConstant.MISLEADING)
555 htmlStringBuffer.append(" [misleading]");
556 if (synonym.getQualifier() == EnzymeNameQualifierConstant.OBSOLETE)
557 htmlStringBuffer.append(" [obsolete]");
558 if (synonym.getQualifier() == EnzymeNameQualifierConstant.AMBIGUOUS)
559 htmlStringBuffer.append(" [ambiguous]");
560 if (synonym.getQualifier() == EnzymeNameQualifierConstant.INCORRECT)
561 htmlStringBuffer.append(" [incorrect]");
562 if (synonym.getQualifier() == EnzymeNameQualifierConstant.MISPRINT)
563 htmlStringBuffer.append(" [misprint]");
564 htmlStringBuffer.append("</td>\n");
565 htmlStringBuffer.append("</tr>\n");
566 }
567 return htmlStringBuffer.toString();
568 }
569
570 private static String getIntEnzSystematicName(EnzymeName systematicName, SpecialCharacters encoding) {
571 StringBuffer htmlStringBuffer = new StringBuffer();
572 htmlStringBuffer.append("<tr>\n");
573 htmlStringBuffer.append("<td nowrap=\"nowrap\" valign=\"top\">\n");
574 htmlStringBuffer.append("<b>Systematic name:</b>\n");
575 htmlStringBuffer.append("</td>\n");
576 htmlStringBuffer.append("<td width=\"100%\" valign=\"top\">\n");
577 htmlStringBuffer.append(encoding.xml2Display(systematicName.getName()));
578 htmlStringBuffer.append("</td>\n");
579 htmlStringBuffer.append("</tr>\n");
580 return htmlStringBuffer.toString();
581 }
582
583 private static String getIntEnzReaction(EnzymaticReactions reactions,
584 SpecialCharacters encoding, EncodingType encodingType) {
585 StringBuffer htmlStringBuffer = new StringBuffer();
586 htmlStringBuffer.append("<table border=\"0\" cellspacing=\"5\" style=\"margin-left: 2em\">\n");
587 if (reactions != null) {
588 for (int iii = 0, counter= 1
589 Reaction reaction = reactions.getReaction(iii);
590
591 if (reaction.getId() > Reaction.NO_ID_ASSIGNED
592
593
594 continue;
595 }
596 if (!reactions.getReactionView(iii).isInIntEnzView()) continue;
597 htmlStringBuffer.append("<tr>\n");
598 if (reactions.size() > 1) {
599 htmlStringBuffer.append("<td valign=\"top\">");
600 if (!reaction.getTextualRepresentation().matches("\\(?\\d\\p{Lower}\\)?\\s.*")){
601
602 htmlStringBuffer.append('(').append(counter++).append(')');
603
604
605 }
606 htmlStringBuffer.append("</td>\n");
607 }
608 htmlStringBuffer.append("<td>");
609 htmlStringBuffer.append(EnzymeReactionHelper.textualRepresentationToHTML(reaction, encoding, encodingType));
610 htmlStringBuffer.append("</td>\n");
611 htmlStringBuffer.append("</tr>\n");
612 }
613 }
614 htmlStringBuffer.append("</table>\n");
615 return htmlStringBuffer.toString();
616 }
617
618 protected static String getIntEnzCofactor(Set<Object> cofactors,
619 SpecialCharacters xchars, EncodingType encodingType) {
620 StringBuffer htmlStringBuffer = new StringBuffer();
621 htmlStringBuffer.append("<table border=\"0\" cellspacing=\"5\" style=\"margin-left: 2em\">\n");
622 int i = 1;
623 for (Object cofactor : cofactors) {
624 htmlStringBuffer.append("<tr>\n");
625 if (cofactors.size() > 1) {
626 htmlStringBuffer.append("<td valign=\"top\">(");
627 htmlStringBuffer.append(i++);
628 htmlStringBuffer.append(")</td>\n");
629 }
630 htmlStringBuffer.append("<td>");
631 htmlStringBuffer.append(getCofactorObjectLinks(cofactor, xchars, encodingType, false));
632 htmlStringBuffer.append("</td>\n");
633 htmlStringBuffer.append("</tr>\n");
634 }
635
636 htmlStringBuffer.append("</table>\n");
637 return htmlStringBuffer.toString();
638 }
639
640 protected static String getCofactorObjectLinks(Object o,
641 SpecialCharacters xchars, EncodingType encodingType, boolean useBrakets){
642 StringBuilder sb = new StringBuilder();
643 if (o instanceof Cofactor){
644 sb.append(getCompoundLink(((Cofactor) o).getCompound(), xchars, encodingType));
645 } else if (o instanceof OperatorSet){
646 sb.append(getCofactorSetLinks((OperatorSet) o, xchars, encodingType, useBrakets));
647 } else {
648 LOGGER.error(o + "should be a Cofactor or an OperatorSet");
649 sb.append(o.toString());
650 }
651 return sb.toString();
652 }
653
654 protected static String getCompoundLink(Compound compound,
655 SpecialCharacters xchars, EncodingType encodingType){
656 StringBuilder sb =
657 new StringBuilder(xchars.xml2Display(compound.toString(), encodingType));
658 XRef compoundXref = compound.getXref();
659 if (compoundXref != null){
660 sb.insert(0, "\" target=\"_blank\">")
661 .insert(0, compoundXref.getUrl())
662 .insert(0, "<a href=\"");
663 sb.append("</a>");
664 }
665 return sb.toString();
666 }
667
668 protected static String getCofactorSetLinks(OperatorSet os,
669 SpecialCharacters xchars, EncodingType encodingType, boolean useBrakets){
670 StringBuilder sb = new StringBuilder();
671 int i = 0;
672 for (Object o : os){
673 sb.append(getCofactorObjectLinks(o, xchars, encodingType, true));
674 if (i++ < os.size() - 1){
675 sb.append(' ')
676 .append(os.getOperator().replaceAll("OR\\d", "or").toLowerCase())
677 .append(' ');
678 }
679 }
680 if (useBrakets){
681 sb.insert(0, '(').append(')');
682 }
683 return sb.toString();
684 }
685
686 private static String getIntEnzComments(List comments, SpecialCharacters encoding) {
687 StringBuffer htmlStringBuffer = new StringBuffer();
688 htmlStringBuffer.append("<table border=\"0\" cellspacing=\"5\" style=\"margin-left: 2em\">\n");
689 for (int iii = 0; iii < comments.size(); iii++) {
690 EnzymeComment comment = (EnzymeComment) comments.get(iii);
691 htmlStringBuffer.append("<tr>\n");
692 htmlStringBuffer.append("<td>\n");
693 htmlStringBuffer.append(IntEnzUtilities.cleanInternalLinks(encoding.xml2Display(comment.getCommentText()), true));
694 htmlStringBuffer.append("</td>\n");
695 htmlStringBuffer.append("</tr>\n");
696 }
697 htmlStringBuffer.append("</table>\n");
698 return htmlStringBuffer.toString();
699 }
700
701 private static String getIntEnzLinks(SortedSet links, String ec) {
702 SortedSet completeLinks = new TreeSet(links);
703 completeLinks.add(EnzymeLink.PDB);
704 completeLinks.add(EnzymeLink.CSA);
705 completeLinks.add(EnzymeLink.EXPASY);
706 completeLinks.add(EnzymeLink.BRENDA);
707 completeLinks.add(EnzymeLink.KEGG);
708 completeLinks.add(EnzymeLink.NC_IUBMB);
709 StringBuffer htmlStringBuffer = new StringBuffer();
710 htmlStringBuffer.append(EnzymeLinkHelper.renderLinks(completeLinks, ec));
711 return htmlStringBuffer.toString();
712 }
713
714 private static String getIntEnzReferences(List references, SpecialCharacters encoding) {
715 StringBuffer htmlStringBuffer = new StringBuffer();
716 htmlStringBuffer.append("<table border=\"0\" cellspacing=\"5\" style=\"margin-left: 2em\">\n");
717
718 for (int iii = 0; iii < references.size(); iii++) {
719 Reference reference = (Reference) references.get(iii);
720 htmlStringBuffer.append("<tr>\n");
721 htmlStringBuffer.append("<td valign=\"top\">\n");
722 htmlStringBuffer.append(iii + 1);
723 htmlStringBuffer.append(".");
724 htmlStringBuffer.append("</td>\n");
725 htmlStringBuffer.append("<td valign=\"top\">\n");
726
727 htmlStringBuffer.append(encoding.xml2Display(getReferenceHtml(reference)));
728 htmlStringBuffer.append("</td>\n");
729 htmlStringBuffer.append("</tr>\n");
730 }
731 htmlStringBuffer.append("</table>\n");
732 return htmlStringBuffer.toString();
733 }
734
735 private static String getReferenceHtml(Reference ref){
736 StringBuffer html = new StringBuffer();
737 html.append("<div class=\"pubauthors\">").append(ref.getAuthors()).append("</div>");
738 html.append("<div class=\"pubtitle\">").append(ref.getTitle()).append("</div>");
739 html.append("<div class=\"pubjournal\">");
740 if (ref instanceof Journal){
741 Journal journal = (Journal) ref;
742 html.append("<span class=\"pubName\">").append(journal.getPubName())
743 .append("</span>");
744 boolean hasVolume = !StringUtil.isNullOrEmpty(journal.getVolume());
745 if (hasVolume){
746 html.append(" <b>").append(journal.getVolume()).append("</b>");
747 }
748 if (!StringUtil.isNullOrEmpty(journal.getFirstPage())){
749 if (hasVolume) html.append(": ");
750 html.append(journal.getFirstPage());
751 if (!StringUtil.isNullOrEmpty(journal.getLastPage())){
752 html.append('-').append(journal.getLastPage());
753 }
754 }
755 html.append(" (").append(ref.getYear()).append(").");
756 if (!journal.getPubMedId().equals("")) {
757 String url = "http://www.ebi.ac.uk/citexplore/citationDetails.do?dataSource=MED&externalId=";
758 html.append(" [PMID: <a target=\"_blank\" href=\"").append(url)
759 .append(journal.getPubMedId())
760 .append("\">")
761 .append(journal.getPubMedId())
762 .append("</a>]");
763 }
764 } else if (ref instanceof Book){
765 Book book = (Book) ref;
766 if (!StringUtil.isNullOrEmpty(book.getEditor(false))){
767 html.append("<span style=\"font-style: normal\">In: ")
768 .append(book.getEditor(true)).append("</span>");
769 }
770 if (!StringUtil.isNullOrEmpty(book.getPubName())){
771 html.append(' ').append(book.getPubName());
772 }
773 if (!StringUtil.isNullOrEmpty(book.getEdition(false))){
774 html.append(", ").append(book.getEdition(true));
775 }
776 if (!StringUtil.isNullOrEmpty(book.getVolume())){
777 html.append(" vol. ").append(book.getVolume());
778 }
779 if (!StringUtil.isNullOrEmpty(book.getPublisher())){
780 html.append(", ").append(book.getPublisher());
781 }
782 if (!StringUtil.isNullOrEmpty(book.getPublisherPlace())){
783 html.append(", ").append(book.getPublisherPlace());
784 }
785 if (!StringUtil.isNullOrEmpty(book.getYear())){
786 html.append(", ").append(book.getYear());
787 }
788 if (!StringUtil.isNullOrEmpty(book.getFirstPage())){
789 html.append(", ").append(book.getFirstPage());
790 if (!StringUtil.isNullOrEmpty(book.getLastPage())){
791 html.append('-').append(book.getLastPage());
792 }
793 }
794 html.append('.');
795 } else if (ref instanceof Patent){
796 Patent patent = (Patent) ref;
797 html.append(patent.getPatentNumber());
798 }
799 html.append("</div>");
800 return html.toString();
801 }
802
803 private static String getBlockHeader(String name) {
804 StringBuffer blockHeader = new StringBuffer();
805 blockHeader.append("<h2>").append(name).append("</h2>");
806 return blockHeader.toString();
807 }
808 }