Commit 157ce64d authored by Piotr Gawron's avatar Piotr Gawron
Browse files

SBO mapping for SBML modified

parent 2058af41
Pipeline #28332 passed with stage
in 12 minutes and 33 seconds
minerva (15.0.0~beta.5) unstable; urgency=medium
* Backward incompatible: truncation/association/dissocation points are
represented as a dot in all new images/uploaded maps (#1265)
* Backward incompatible: export to SBML uses SBO:0000297 term for complexes
(#1290)
* Backward incompatible: export to SBML uses SBO:0000253 term for
hypothetical complexes (#1290)
* Bug fix: links to Evidence Code Ontology did not appear (#1280)
* Bug fix: export to GPML uses proper arrow types (#1262)
* Bug fix: export to GPML uses dashed lines in reactions when possible
......
package lcsb.mapviewer.converter.model.sbml.species;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import lcsb.mapviewer.common.exception.InvalidStateException;
import lcsb.mapviewer.model.map.species.*;
public enum SBOTermSpeciesType {
ANTISENSE_RNA(AntisenseRna.class, new String[] { "SBO:0000334" }),
COMPLEX(Complex.class, new String[] { "SBO:0000297" }),
COMPLEX(Complex.class, new String[] { "SBO:0000253", "SBO:0000297" }),
HYPOTHETICAL_COMPLEX(Complex.class, new String[] { "SBO:0000289" }, true),
DEGRADED(Degraded.class, new String[] { "SBO:0000291" }),
DRUG(Drug.class, new String[] { "SBO:0000298" }),
GENE(Gene.class, new String[] { "SBO:0000243" }),
......@@ -26,10 +29,12 @@ public enum SBOTermSpeciesType {
;
private static Logger logger = LogManager.getLogger();
Class<? extends Species> clazz;
private List<String> sboTerms = new ArrayList<>();
private boolean hypothetical = false;
private SBOTermSpeciesType(Class<? extends Species> clazz, String[] inputSboTerms) {
this.clazz = clazz;
for (String string : inputSboTerms) {
......@@ -37,32 +42,68 @@ public enum SBOTermSpeciesType {
}
}
public static Class<? extends Species> getTypeSBOTerm(String sboTerm) {
private SBOTermSpeciesType(Class<? extends Species> clazz, String[] inputSboTerms, boolean hypothetical) {
this.clazz = clazz;
for (String string : inputSboTerms) {
sboTerms.add(string);
}
this.hypothetical = hypothetical;
}
private static SBOTermSpeciesType getTypeSBOTerm(String sboTerm) {
if (sboTerm == null || sboTerm.isEmpty()) {
return SimpleMolecule.class;
return SIMPLE_MOLECULE;
}
Class<? extends Species> result = null;
SBOTermSpeciesType result = null;
for (SBOTermSpeciesType term : values()) {
for (String string : term.sboTerms) {
if (string.equalsIgnoreCase(sboTerm)) {
result = term.clazz;
result = term;
}
}
}
if (result == null) {
logger.warn("Don't know how to handle SBOTerm " + sboTerm + " for species");
result = SimpleMolecule.class;
result = SIMPLE_MOLECULE;
}
return result;
}
public static String getTermByType(Class<? extends Species> clazz) {
public static Species createElementForSBOTerm(String sboTerm, String elementId) {
try {
SBOTermSpeciesType type = getTypeSBOTerm(sboTerm);
Class<? extends Species> clazz = type.clazz;
Species result = clazz.getConstructor(String.class).newInstance(elementId);
if (type.hypothetical) {
result.setHypothetical(true);
}
return result;
} catch (SecurityException | NoSuchMethodException | InstantiationException | IllegalAccessException
| IllegalArgumentException | InvocationTargetException e) {
throw new InvalidStateException(e);
}
}
public static String getTermByType(Element element) {
String result = null;
for (SBOTermSpeciesType term : values()) {
if (clazz.equals(term.clazz)) {
return term.getSBO();
if (element.getClass().equals(term.clazz)) {
if (element instanceof Species) {
if (((Species) element).isHypothetical() == term.hypothetical) {
return term.getSBO();
} else {
result = term.getSBO();
}
} else {
result = term.getSBO();
}
}
}
logger.warn("Cannot find SBO term for class: " + clazz);
if (result != null) {
return result;
}
logger.warn("Cannot find SBO term for class: " + element.getClass());
return null;
}
......
......@@ -331,7 +331,7 @@ public class SbmlSpeciesExporter extends SbmlElementExporter<Species, org.sbml.j
private MultiSpeciesType getMultiSpeciesType(Species element) {
MultiSpeciesType speciesType = getMultiPlugin().getSpeciesType(MultiPackageNamingUtils.getSpeciesTypeId(element));
if (speciesType == null) {
speciesType = createSpeciesTypeForClass(getMultiPlugin(), element.getClass());
speciesType = createSpeciesTypeForClass(getMultiPlugin(), element);
}
return speciesType;
}
......@@ -344,7 +344,7 @@ public class SbmlSpeciesExporter extends SbmlElementExporter<Species, org.sbml.j
@Override
public org.sbml.jsbml.Species createSbmlElement(Species element) throws InconsistentModelException {
org.sbml.jsbml.Species result = getSbmlModel().createSpecies("species_" + (getNextId()));
result.setSBOTerm(SBOTermSpeciesType.getTermByType(element.getClass()));
result.setSBOTerm(SBOTermSpeciesType.getTermByType(element));
result.setCompartment(compartmentExporter.getSbmlElement(element.getCompartment()));
if (element.getInitialAmount() != null) {
result.setInitialAmount(element.getInitialAmount());
......@@ -534,12 +534,13 @@ public class SbmlSpeciesExporter extends SbmlElementExporter<Species, org.sbml.j
}
@SuppressWarnings("unchecked")
private MultiSpeciesType createSpeciesTypeForClass(MultiModelPlugin multiPlugin, Class<? extends Element> clazz) {
private MultiSpeciesType createSpeciesTypeForClass(MultiModelPlugin multiPlugin, Element element) {
Class<?> clazz = element.getClass();
MultiSpeciesType speciesType = new MultiSpeciesType();
speciesType.setName(clazz.getSimpleName());
speciesType.setId(MultiPackageNamingUtils.getSpeciesTypeId(clazz));
multiPlugin.getListOfSpeciesTypes().add(speciesType);
speciesType.setSBOTerm(SBOTermSpeciesType.getTermByType((Class<? extends Species>) clazz));
speciesType.setSBOTerm(SBOTermSpeciesType.getTermByType(element));
return speciesType;
}
......
package lcsb.mapviewer.converter.model.sbml.species;
import java.awt.geom.Point2D;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import org.apache.logging.log4j.LogManager;
......@@ -15,7 +14,6 @@ import org.sbml.jsbml.ext.render.LocalStyle;
import com.google.common.base.Objects;
import lcsb.mapviewer.common.Pair;
import lcsb.mapviewer.common.exception.InvalidStateException;
import lcsb.mapviewer.converter.InvalidInputDataExecption;
import lcsb.mapviewer.converter.model.sbml.SbmlElementParser;
import lcsb.mapviewer.converter.model.sbml.extension.multi.BioEntityFeature;
......@@ -497,39 +495,33 @@ public class SbmlSpeciesParser extends SbmlElementParser<org.sbml.jsbml.Species>
@Override
protected Species parse(org.sbml.jsbml.Species species) throws InvalidInputDataExecption {
String sboTerm = extractSBOTermFromSpecies(species);
Class<? extends Species> clazz = SBOTermSpeciesType.getTypeSBOTerm(sboTerm);
try {
Species result = clazz.getConstructor(String.class).newInstance(species.getId());
if (!Double.isNaN(species.getInitialAmount())) {
result.setInitialAmount(species.getInitialAmount());
}
if (!Double.isNaN(species.getInitialConcentration())) {
result.setInitialConcentration(species.getInitialConcentration());
}
if (species.isSetHasOnlySubstanceUnits()) {
result.setOnlySubstanceUnits(species.hasOnlySubstanceUnits());
}
if (species.isSetBoundaryCondition()) {
result.setBoundaryCondition(species.getBoundaryCondition());
}
if (species.isSetConstant()) {
result.setConstant(species.getConstant());
}
if (species.isSetCharge()) {
result.setCharge(species.getCharge());
}
assignBioEntityData(species, result);
if (getLayout() == null) {
assignCompartment(result, species.getCompartment());
}
if (getMultiPlugin() != null) {
assignMultiData(species, result);
}
return result;
} catch (SecurityException | NoSuchMethodException | InstantiationException | IllegalAccessException
| IllegalArgumentException | InvocationTargetException e) {
throw new InvalidStateException(e);
Species result = SBOTermSpeciesType.createElementForSBOTerm(sboTerm, species.getId());
if (!Double.isNaN(species.getInitialAmount())) {
result.setInitialAmount(species.getInitialAmount());
}
if (!Double.isNaN(species.getInitialConcentration())) {
result.setInitialConcentration(species.getInitialConcentration());
}
if (species.isSetHasOnlySubstanceUnits()) {
result.setOnlySubstanceUnits(species.hasOnlySubstanceUnits());
}
if (species.isSetBoundaryCondition()) {
result.setBoundaryCondition(species.getBoundaryCondition());
}
if (species.isSetConstant()) {
result.setConstant(species.getConstant());
}
if (species.isSetCharge()) {
result.setCharge(species.getCharge());
}
assignBioEntityData(species, result);
if (getLayout() == null) {
assignCompartment(result, species.getCompartment());
}
if (getMultiPlugin() != null) {
assignMultiData(species, result);
}
return result;
}
public Species getArtifitialInput() {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment