|
13 | 13 | import org.sbgn.bindings.*;
|
14 | 14 | import org.slf4j.Logger;
|
15 | 15 | import org.slf4j.LoggerFactory;
|
| 16 | +import org.w3c.dom.Document; |
| 17 | +import org.w3c.dom.Element; |
16 | 18 |
|
17 | 19 | import javax.xml.bind.JAXBContext;
|
18 | 20 | import javax.xml.bind.JAXBException;
|
19 | 21 | import javax.xml.bind.Marshaller;
|
| 22 | +import javax.xml.parsers.DocumentBuilder; |
| 23 | +import javax.xml.parsers.DocumentBuilderFactory; |
| 24 | +import javax.xml.parsers.ParserConfigurationException; |
20 | 25 | import java.io.File;
|
21 | 26 | import java.io.OutputStream;
|
22 | 27 | import java.text.DecimalFormat;
|
@@ -132,6 +137,42 @@ public class L3ToSBGNPDConverter
|
132 | 137 | */
|
133 | 138 | Set<Glyph> ubiqueSet;
|
134 | 139 |
|
| 140 | + /** |
| 141 | + * For adding BioPAX metadata (XML elements) using the SBGN-ML Extensions feature. |
| 142 | + */ |
| 143 | + private static Document biopaxMetaDoc; |
| 144 | + private static final String BIOPAX_NS = "http://www.biopax.org/release/biopax-level3.owl#"; |
| 145 | + |
| 146 | + //-- Section: Static initialization -----------------------------------------------------------| |
| 147 | + static |
| 148 | + { |
| 149 | + factory = new ObjectFactory(); |
| 150 | + typeMatchMap = new HashMap<Class<? extends BioPAXElement>, String>(); |
| 151 | + typeMatchMap.put(Protein.class, MACROMOLECULE.getClazz()); |
| 152 | + typeMatchMap.put(SmallMolecule.class, SIMPLE_CHEMICAL.getClazz()); |
| 153 | + typeMatchMap.put(Dna.class, NUCLEIC_ACID_FEATURE.getClazz()); |
| 154 | + typeMatchMap.put(Rna.class, NUCLEIC_ACID_FEATURE.getClazz()); |
| 155 | + typeMatchMap.put(DnaRegion.class, NUCLEIC_ACID_FEATURE.getClazz()); |
| 156 | + typeMatchMap.put(RnaRegion.class, NUCLEIC_ACID_FEATURE.getClazz()); |
| 157 | + typeMatchMap.put(NucleicAcid.class, NUCLEIC_ACID_FEATURE.getClazz()); |
| 158 | + typeMatchMap.put(PhysicalEntity.class, UNSPECIFIED_ENTITY.getClazz()); |
| 159 | + //TODO: SimplePhysicalEntity is a non-instantiable abstract type in Paxtools; remove the mapping below? |
| 160 | + typeMatchMap.put(SimplePhysicalEntity.class, UNSPECIFIED_ENTITY.getClazz()); |
| 161 | + typeMatchMap.put(Complex.class, COMPLEX.getClazz()); |
| 162 | + typeMatchMap.put(Gene.class, NUCLEIC_ACID_FEATURE.getClazz()); |
| 163 | + |
| 164 | + // init the DOM document here for adding biopax elements as extensions to SBGN-ML PD glyphs, etc. |
| 165 | + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); |
| 166 | + try { |
| 167 | + DocumentBuilder db = dbf.newDocumentBuilder(); |
| 168 | + db.reset(); |
| 169 | + biopaxMetaDoc = db.newDocument(); |
| 170 | + } catch (ParserConfigurationException e) { |
| 171 | + throw new RuntimeException("Cannot initialize BioPAX extensions DOM.", e); |
| 172 | + } |
| 173 | + |
| 174 | + } |
| 175 | + |
135 | 176 | //-- Section: Public methods ------------------------------------------------------------------|
|
136 | 177 |
|
137 | 178 | /**
|
@@ -317,6 +358,14 @@ public Sbgn createSBGN(Model model)
|
317 | 358 | map.getGlyph().addAll(compartmentMap.values());
|
318 | 359 | map.getArc().addAll(arcMap.values());
|
319 | 360 |
|
| 361 | + biopaxMetaDoc.setDocumentURI(model.getUri()); //can be null |
| 362 | + Element elt = biopaxMetaDoc.createElementNS(BIOPAX_NS, "Model"); |
| 363 | + elt.setPrefix("bp"); |
| 364 | + elt.setAttribute("name", model.getName()); //can be null/empty too |
| 365 | + SBGNBase.Notes modelNotes = new SBGNBase.Notes(); |
| 366 | + sbgn.setNotes(modelNotes); |
| 367 | + modelNotes.getAny().add(elt); |
| 368 | + |
320 | 369 | final boolean layout = doLayout && n < this.maxNodes && !arcMap.isEmpty();
|
321 | 370 | try {
|
322 | 371 | //Must call this, although actual layout might never run;
|
@@ -402,6 +451,13 @@ private Glyph createGlyph(Entity e)
|
402 | 451 | Glyph g = createGlyphBasics(e, true);
|
403 | 452 | glyphMap.put(g.getId(), g);
|
404 | 453 |
|
| 454 | + SBGNBase.Extension ext = new SBGNBase.Extension(); |
| 455 | + g.setExtension(ext); |
| 456 | + Element el = biopaxMetaDoc.createElementNS(BIOPAX_NS, e.getModelInterface().getSimpleName()); |
| 457 | + el.setPrefix("bp"); |
| 458 | + el.setAttribute("uri", e.getUri()); |
| 459 | + ext.getAny().add(el); |
| 460 | + |
405 | 461 | if (g.getClone() != null)
|
406 | 462 | ubiqueSet.add(g);
|
407 | 463 |
|
@@ -1552,25 +1608,8 @@ public Map<String, Set<String>> getSbgn2BPMap()
|
1552 | 1608 | private String convertID(String id)
|
1553 | 1609 | {
|
1554 | 1610 | //make valid XML ID - a hack; see #39; ideally would be using an equivalent to javascript encodeURI()
|
1555 |
| - return id.replaceAll("[^-\\w]", "_"); |
| 1611 | +// return id.replaceAll("[^-\\w]", "_"); |
| 1612 | + return id; |
1556 | 1613 | }
|
1557 | 1614 |
|
1558 |
| - |
1559 |
| - //-- Section: Static initialization -----------------------------------------------------------| |
1560 |
| - static |
1561 |
| - { |
1562 |
| - factory = new ObjectFactory(); |
1563 |
| - typeMatchMap = new HashMap<Class<? extends BioPAXElement>, String>(); |
1564 |
| - typeMatchMap.put(Protein.class, MACROMOLECULE.getClazz()); |
1565 |
| - typeMatchMap.put(SmallMolecule.class, SIMPLE_CHEMICAL.getClazz()); |
1566 |
| - typeMatchMap.put(Dna.class, NUCLEIC_ACID_FEATURE.getClazz()); |
1567 |
| - typeMatchMap.put(Rna.class, NUCLEIC_ACID_FEATURE.getClazz()); |
1568 |
| - typeMatchMap.put(DnaRegion.class, NUCLEIC_ACID_FEATURE.getClazz()); |
1569 |
| - typeMatchMap.put(RnaRegion.class, NUCLEIC_ACID_FEATURE.getClazz()); |
1570 |
| - typeMatchMap.put(NucleicAcid.class, NUCLEIC_ACID_FEATURE.getClazz()); |
1571 |
| - typeMatchMap.put(PhysicalEntity.class, UNSPECIFIED_ENTITY.getClazz()); |
1572 |
| - typeMatchMap.put(SimplePhysicalEntity.class, UNSPECIFIED_ENTITY.getClazz());//TODO: abstract type (doesn't occur in BioPAX) |
1573 |
| - typeMatchMap.put(Complex.class, COMPLEX.getClazz()); |
1574 |
| - typeMatchMap.put(Gene.class, NUCLEIC_ACID_FEATURE.getClazz()); |
1575 |
| - } |
1576 | 1615 | }
|
0 commit comments