diff --git a/pom.xml b/pom.xml index 61421c4..cc51473 100644 --- a/pom.xml +++ b/pom.xml @@ -205,7 +205,7 @@ ch.qos.logback logback-classic - 1.4.12 + 1.4.14 diff --git a/src/main/java/org/humanmetabolism/ReconxToBiopax.java b/src/main/java/org/humanmetabolism/ReconxToBiopax.java index 6e05bbe..b360fed 100644 --- a/src/main/java/org/humanmetabolism/ReconxToBiopax.java +++ b/src/main/java/org/humanmetabolism/ReconxToBiopax.java @@ -31,14 +31,14 @@ public static void main(String[] args) throws IOException, XMLStreamException { makePathway = true; } - log.info("Converting SBML model to BioPAX..."); + log.info("Converting the SBML model to BioPAX..."); SbmlToBiopaxConverter sbmlToBiopaxConverter = new SbmlToBiopaxConverter(); sbmlToBiopaxConverter.setMakePathway(makePathway); + sbmlToBiopaxConverter.biopaxModelXmlBase("reconx:"); Model bpModel = sbmlToBiopaxConverter.convert(new File(sbmlFile)); - - log.info("Saving BioPAX model to " + bpFile); + log.info("Saving the BioPAX model to " + bpFile); SimpleIOHandler bpHandler = new SimpleIOHandler(BioPAXLevel.L3); bpHandler.convertToOWL(bpModel, new FileOutputStream(bpFile)); - log.info("Conversion completed."); + log.info("Completed!"); } } diff --git a/src/main/java/org/humanmetabolism/converter/SbmlToBiopaxConverter.java b/src/main/java/org/humanmetabolism/converter/SbmlToBiopaxConverter.java index cc6f5e0..6e36d87 100644 --- a/src/main/java/org/humanmetabolism/converter/SbmlToBiopaxConverter.java +++ b/src/main/java/org/humanmetabolism/converter/SbmlToBiopaxConverter.java @@ -16,6 +16,10 @@ public class SbmlToBiopaxConverter { private final SbmlToBiopaxUtils sbmlToBiopaxUtils = new SbmlToBiopaxUtils(); private boolean makePathway = false; + public void biopaxModelXmlBase(String xmlBase) { + sbmlToBiopaxUtils.setXmlBase(xmlBase); + } + /** * Whether to generate the model's root pathway that contains all the interactions. * @@ -43,7 +47,7 @@ public Model convert(SBMLDocument sbmlDocument) { private Model convert(org.sbml.jsbml.Model sbmlModel) { Model bpModel = sbmlToBiopaxUtils.createModel(); - final Provenance provenance = sbmlToBiopaxUtils.convertProvenance(bpModel,sbmlModel); + final Provenance provenance = sbmlToBiopaxUtils.convertProvenance(bpModel, sbmlModel); // create a Pathway that corresponds to this SBML model (optional) Pathway pathway = null; diff --git a/src/main/java/org/humanmetabolism/converter/SbmlToBiopaxUtils.java b/src/main/java/org/humanmetabolism/converter/SbmlToBiopaxUtils.java index c79ba56..643c0e9 100644 --- a/src/main/java/org/humanmetabolism/converter/SbmlToBiopaxUtils.java +++ b/src/main/java/org/humanmetabolism/converter/SbmlToBiopaxUtils.java @@ -1,5 +1,6 @@ package org.humanmetabolism.converter; +import org.apache.commons.lang3.StringUtils; import org.biopax.paxtools.model.BioPAXFactory; import org.biopax.paxtools.model.BioPAXLevel; import org.biopax.paxtools.model.Model; @@ -16,20 +17,24 @@ public class SbmlToBiopaxUtils { private static Logger log = LoggerFactory.getLogger(SbmlToBiopaxUtils.class); - private BioPAXFactory bioPAXFactory = BioPAXLevel.L3.getDefaultFactory(); + private BioPAXFactory bioPAXFactory; + private String xmlBase; - private String XMLBase = "http://www.humanmetabolism.org/#"; + public SbmlToBiopaxUtils() { + this.xmlBase = ""; + this.bioPAXFactory = BioPAXLevel.L3.getDefaultFactory(); + } - public String getXMLBase() { - return XMLBase; + public String getXmlBase() { + return xmlBase; } - public void setXMLBase(String XMLBase) { - this.XMLBase = XMLBase; + public void setXmlBase(String xmlBase) { + this.xmlBase = (StringUtils.isBlank(xmlBase)) ? "" : xmlBase; } public String completeId(String partialId) { - return getXMLBase() + partialId; + return getXmlBase() + partialId; } public Pathway convertPathway(Model bpModel, org.sbml.jsbml.Model sbmlModel) { @@ -42,15 +47,12 @@ public Pathway convertPathway(Model bpModel, org.sbml.jsbml.Model sbmlModel) { public Provenance convertProvenance(Model bpModel, org.sbml.jsbml.Model sbmlModel) { Provenance p = createBPEfromSBMLE(bpModel, Provenance.class, sbmlModel, - "http://identifiers.org/biomodels.db/" + sbmlModel.getId()); - + "bioregistry.io/biomodels.db:" + sbmlModel.getId()); for (Xref xref : generateXrefsForSBase(bpModel, RelationshipXref.class, sbmlModel)) { p.addXref(xref); } - - final UnificationXref x = bpModel.addNew(UnificationXref.class, - bpModel.getXmlBase() + "xref_biomodels_" + sbmlModel.getId()); - x.setDb("BioModels Database"); + final UnificationXref x = bpModel.addNew(UnificationXref.class,"biomodels.db:" + sbmlModel.getId()); + x.setDb("biomodels.db"); x.setId(sbmlModel.getId()); p.addXref(x); @@ -60,7 +62,7 @@ public Provenance convertProvenance(Model bpModel, org.sbml.jsbml.Model sbmlMode public Model createModel() { Model model = bioPAXFactory.createModel(); // This could change, would be great to make this configurable - model.setXmlBase(getXMLBase()); + model.setXmlBase(getXmlBase()); return model; } @@ -110,9 +112,11 @@ public Control convertModifier(Model bpModel, ModifierSpeciesReference modifierS return control; } - public T convertSpeciesToSPE(Model bpModel, Class entityClass, Class refClass, Species species) { + public T convertSpeciesToSPE( + Model bpModel, Class entityClass, Class refClass, Species species) + { Set xrefs = generateXrefsForSBase(bpModel, UnificationXref.class, species); - HashSet ers = new HashSet(); + HashSet ers = new HashSet<>(); for (Xref xref : xrefs) { for (XReferrable xReferrable : xref.getXrefOf()) { // Only add the entity references @@ -272,9 +276,9 @@ private Set generateXrefsForSBase(Model bpModel, Class } public void fillComplexes(Model bpModel) { - HashMap xrefToProtein = new HashMap(); + HashMap xrefToProtein = new HashMap<>(); // Now let's use xrefs to find the complex components - // First, find the proteinrefs and map them with their xrefs + // First, find the protein refs and map them with their xrefs for (ProteinReference proteinRef : bpModel.getObjects(ProteinReference.class)) { for (Xref xref : proteinRef.getXref()) { xrefToProtein.put(xref.toString(), proteinRef); @@ -282,17 +286,16 @@ public void fillComplexes(Model bpModel) { } // Now let's go to the complexes and see what xrefs they have - Set complexes = new HashSet(bpModel.getObjects(Complex.class)); + Set complexes = new HashSet<>(bpModel.getObjects(Complex.class)); for (Complex complex : complexes) { - HashSet names = new HashSet(Arrays.asList(complex.getDisplayName().split(":"))); + HashSet names = new HashSet<>(Arrays.asList(complex.getDisplayName().split(":"))); // Let's try to capture proteins from the model first - HashSet components = new HashSet(); + HashSet components = new HashSet<>(); for (Xref xref : complex.getXref()) { ProteinReference proteinRef = xrefToProtein.get(xref.toString()); if(proteinRef != null) { String cProteinId = completeId(complex.getUri() + "_" + proteinRef.getUri()); - //TODO: make sure refactoring has gone correct here (compare, test vs. prev. revision...) if(!bpModel.containsID(cProteinId)) { Protein protein = bpModel.addNew(Protein.class, cProteinId); protein.setDisplayName(proteinRef.getDisplayName()); @@ -308,7 +311,6 @@ public void fillComplexes(Model bpModel) { // Let's create proteins for them for (String name : names) { final String nameBasedURI = completeId("protein_" + name); - //TODO: make sure refactoring here was correct (removed 'newBPEs' intermediate map) Protein protein = (Protein) bpModel.getByID(nameBasedURI); if(protein == null) { protein = bpModel.addNew(Protein.class, nameBasedURI); @@ -324,15 +326,15 @@ public void fillComplexes(Model bpModel) { proteinReference.setStandardName(name); } - String xrefId = completeId("symbol_" + name); - UnificationXref unificationXref = (UnificationXref) bpModel.getByID(xrefId); - if(unificationXref == null) { - unificationXref = bpModel.addNew(UnificationXref.class, xrefId); - unificationXref.setDb("HGNC Symbol"); - unificationXref.setId(name); + String u = completeId("symbol_" + name); + RelationshipXref rx = (RelationshipXref) bpModel.getByID(u); + if(rx == null) { + rx = bpModel.addNew(RelationshipXref.class, u); + rx.setDb("hgnc.symbol"); + rx.setId(name); } - proteinReference.addXref(unificationXref); + proteinReference.addXref(rx); protein.setEntityReference(proteinReference); components.add(protein); } @@ -349,18 +351,18 @@ public void fillComplexes(Model bpModel) { public void assignOrganism(Model bpModel) { // Since this is RECON2, everything is human - BioSource bioSource = bpModel.addNew(BioSource.class, "http://identifiers.org/taxonomy/9606"); + BioSource bioSource = bpModel.addNew(BioSource.class, "bioregistry.io/ncbitaxon:9606"); bioSource.setDisplayName("Homo sapiens"); bioSource.setStandardName("Homo sapiens"); - UnificationXref unificationXref = bpModel.addNew(UnificationXref.class, completeId("xref_taxonomy_9606")); - unificationXref.setDb("Taxonomy"); + UnificationXref unificationXref = bpModel.addNew(UnificationXref.class, "ncbitaxon:9606"); + unificationXref.setDb("ncbitaxon"); unificationXref.setId("9606"); bioSource.addXref(unificationXref); for (SequenceEntityReference ser : bpModel.getObjects(SequenceEntityReference.class)) { ser.setOrganism(bioSource); } - for (Gene g : bpModel.getObjects(Gene.class)) { //but, there're probably no Gene objects... + for (Gene g : bpModel.getObjects(Gene.class)) { //but, there are probably no Gene objects... g.setOrganism(bioSource); } for (Pathway p : bpModel.getObjects(Pathway.class)) {