Skip to content

Commit 2343712

Browse files
Began improving sbgn-converter:
- for now, as tmp solution, will use biopax URIs unescaped for glyph ids (it helps app-ui devel. a lot) - we will use SBGN-ML Notes and Extensions features to store BioPAX metadata, such as URI, IDs, synonyms, etc.; this is the standard way to go (then, e.g., app-ui won't need to parse JSON-LD and use RethinkDb...)
1 parent 73125fb commit 2343712

File tree

1 file changed

+58
-19
lines changed

1 file changed

+58
-19
lines changed

sbgn-converter/src/main/java/org/biopax/paxtools/io/sbgn/L3ToSBGNPDConverter.java

Lines changed: 58 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@
1313
import org.sbgn.bindings.*;
1414
import org.slf4j.Logger;
1515
import org.slf4j.LoggerFactory;
16+
import org.w3c.dom.Document;
17+
import org.w3c.dom.Element;
1618

1719
import javax.xml.bind.JAXBContext;
1820
import javax.xml.bind.JAXBException;
1921
import javax.xml.bind.Marshaller;
22+
import javax.xml.parsers.DocumentBuilder;
23+
import javax.xml.parsers.DocumentBuilderFactory;
24+
import javax.xml.parsers.ParserConfigurationException;
2025
import java.io.File;
2126
import java.io.OutputStream;
2227
import java.text.DecimalFormat;
@@ -132,6 +137,42 @@ public class L3ToSBGNPDConverter
132137
*/
133138
Set<Glyph> ubiqueSet;
134139

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+
135176
//-- Section: Public methods ------------------------------------------------------------------|
136177

137178
/**
@@ -317,6 +358,14 @@ public Sbgn createSBGN(Model model)
317358
map.getGlyph().addAll(compartmentMap.values());
318359
map.getArc().addAll(arcMap.values());
319360

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+
320369
final boolean layout = doLayout && n < this.maxNodes && !arcMap.isEmpty();
321370
try {
322371
//Must call this, although actual layout might never run;
@@ -402,6 +451,13 @@ private Glyph createGlyph(Entity e)
402451
Glyph g = createGlyphBasics(e, true);
403452
glyphMap.put(g.getId(), g);
404453

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+
405461
if (g.getClone() != null)
406462
ubiqueSet.add(g);
407463

@@ -1552,25 +1608,8 @@ public Map<String, Set<String>> getSbgn2BPMap()
15521608
private String convertID(String id)
15531609
{
15541610
//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;
15561613
}
15571614

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-
}
15761615
}

0 commit comments

Comments
 (0)