Skip to content

Commit

Permalink
Polished how we generate URIs (bioregistry, xml:base)
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorRodchenkov committed Feb 19, 2024
1 parent e6d84e9 commit a99a18d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 40 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.4.12</version>
<version>1.4.14</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/humanmetabolism/ReconxToBiopax.java
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
Expand Down
70 changes: 36 additions & 34 deletions src/main/java/org/humanmetabolism/converter/SbmlToBiopaxUtils.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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) {
Expand All @@ -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);

Expand All @@ -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;
}

Expand Down Expand Up @@ -110,9 +112,11 @@ public Control convertModifier(Model bpModel, ModifierSpeciesReference modifierS
return control;
}

public <T extends SimplePhysicalEntity, S extends EntityReference> T convertSpeciesToSPE(Model bpModel, Class<T> entityClass, Class<S> refClass, Species species) {
public <T extends SimplePhysicalEntity, S extends EntityReference> T convertSpeciesToSPE(
Model bpModel, Class<T> entityClass, Class<S> refClass, Species species)
{
Set<Xref> xrefs = generateXrefsForSBase(bpModel, UnificationXref.class, species);
HashSet<XReferrable> ers = new HashSet<XReferrable>();
HashSet<XReferrable> ers = new HashSet<>();
for (Xref xref : xrefs) {
for (XReferrable xReferrable : xref.getXrefOf()) {
// Only add the entity references
Expand Down Expand Up @@ -272,27 +276,26 @@ private <T extends Xref> Set<Xref> generateXrefsForSBase(Model bpModel, Class<T>
}

public void fillComplexes(Model bpModel) {
HashMap<String, ProteinReference> xrefToProtein = new HashMap<String, ProteinReference>();
HashMap<String, ProteinReference> 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);
}
}

// Now let's go to the complexes and see what xrefs they have
Set<Complex> complexes = new HashSet<Complex>(bpModel.getObjects(Complex.class));
Set<Complex> complexes = new HashSet<>(bpModel.getObjects(Complex.class));
for (Complex complex : complexes) {
HashSet<String> names = new HashSet<String>(Arrays.asList(complex.getDisplayName().split(":")));
HashSet<String> names = new HashSet<>(Arrays.asList(complex.getDisplayName().split(":")));

// Let's try to capture proteins from the model first
HashSet<Protein> components = new HashSet<Protein>();
HashSet<Protein> 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());
Expand All @@ -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);
Expand All @@ -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);
}
Expand All @@ -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)) {
Expand Down

0 comments on commit a99a18d

Please sign in to comment.