Skip to content
Snippets Groups Projects
Commit e9ffb42c authored by Piotr Gawron's avatar Piotr Gawron
Browse files

species type contains list of all structural state values in the proper feature

parent f9e55b64
No related branches found
No related tags found
2 merge requests!630WIP: Resolve "The privileges of a new user are not saved in some cases",!560Resolve "add support for modifications and states in sbml export/import"
......@@ -3,7 +3,9 @@ package lcsb.mapviewer.converter.model.sbml;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.xml.stream.XMLStreamException;
......@@ -42,6 +44,8 @@ public class SbmlExporter {
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(SbmlExporter.class);
private int idCounter = 0;
/**
* Set of SBML extensions that should be used during export.
*/
......@@ -88,8 +92,10 @@ public class SbmlExporter {
layout = createSbmlLayout(model, result);
}
MultiModelPlugin multiPlugin = null;
if (usedExtensions.contains(SbmlExtension.MULTI)) {
createSbmlMultiPlugin(result);
multiPlugin = createSbmlMultiPlugin(result);
assignStructuralStatesToTypes(multiPlugin, model);
}
SbmlCompartmentExporter compartmentExporter = new SbmlCompartmentExporter(layout, model, usedExtensions);
......@@ -111,6 +117,28 @@ public class SbmlExporter {
return doc;
}
private void assignStructuralStatesToTypes(MultiModelPlugin multiPlugin, lcsb.mapviewer.model.map.model.Model model) {
for (Element element : model.getElements()) {
String structuralState = null;
if (element instanceof Protein) {
structuralState = ((Protein) element).getStructuralState();
} else if (element instanceof Complex) {
structuralState = ((Complex) element).getStructuralState();
}
if (structuralState != null) {
MultiSpeciesType speciesType = speciesTypeByClass.get(element.getClass());
addStructuralStateToPossibleValues(speciesType, structuralState);
}
}
}
private void addStructuralStateToPossibleValues(MultiSpeciesType speciesType, String structuralState) {
SpeciesFeatureType feature = speciesType.getListOfSpeciesFeatureTypes()
.get("minerva_structural_state_" + speciesType.getName());
addPosibleValueToFeature(feature, structuralState);
}
/**
* Create SBML layout for the given model.
*
......@@ -145,6 +173,8 @@ public class SbmlExporter {
return layout;
}
private Map<Class<?>, MultiSpeciesType> speciesTypeByClass = new HashMap<>();
@SuppressWarnings("unchecked")
protected MultiModelPlugin createSbmlMultiPlugin(Model result) {
MultiModelPlugin multiPlugin = new MultiModelPlugin(result);
......@@ -158,19 +188,32 @@ public class SbmlExporter {
SpeciesFeatureType feature = new SpeciesFeatureType();
feature.setName("Structural state");
feature.setId("minerva_structural_state_" + clazz.getSimpleName());
PossibleSpeciesFeatureValue featureEmptyValue = new PossibleSpeciesFeatureValue();
featureEmptyValue.setId("minerva_structural_state_" + clazz.getSimpleName() + "_empty");
featureEmptyValue.setName("");
feature.getListOfPossibleSpeciesFeatureValues().add(featureEmptyValue);
addPosibleValueToFeature(feature, "");
speciesType.getListOfSpeciesFeatureTypes().add(feature);
}
multiPlugin.getListOfSpeciesTypes().add(speciesType);
speciesTypeByClass.put(clazz, speciesType);
speciesType.setSBOTerm(SBOTermSpeciesType.getTermByType((Class<? extends Species>) clazz));
}
}
return multiPlugin;
}
private void addPosibleValueToFeature(SpeciesFeatureType feature, String value) {
boolean alreadyExists = false;
for (PossibleSpeciesFeatureValue existingValue : feature.getListOfPossibleSpeciesFeatureValues()) {
if (existingValue.getName().equals(value)) {
alreadyExists = true;
}
}
if (!alreadyExists) {
PossibleSpeciesFeatureValue featureEmptyValue = new PossibleSpeciesFeatureValue();
featureEmptyValue.setId(feature.getId() + "_" + (idCounter++));
featureEmptyValue.setName(value);
feature.getListOfPossibleSpeciesFeatureValues().add(featureEmptyValue);
}
}
/**
* Creates SBML render plugin for SBML model.
*
......
......@@ -22,6 +22,8 @@ import org.reflections.Reflections;
import org.sbml.jsbml.SBMLDocument;
import org.sbml.jsbml.ext.multi.MultiModelPlugin;
import org.sbml.jsbml.ext.multi.MultiSpeciesType;
import org.sbml.jsbml.ext.multi.PossibleSpeciesFeatureValue;
import org.sbml.jsbml.ext.multi.SpeciesFeatureType;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.converter.ConverterParams;
......@@ -194,9 +196,7 @@ public class SbmlExporterTest {
}
private Model createModelWithReaction() {
Model model = new ModelFullIndexed(null);
model.setWidth(1000);
model.setHeight(1000);
Model model = createEmptyModel();
GenericProtein p1 = new GenericProtein("s1");
p1.setWidth(100);
p1.setHeight(20);
......@@ -263,11 +263,7 @@ public class SbmlExporterTest {
String tempFilename = File.createTempFile("tmp", ".xml").getAbsolutePath();
IConverter converter = new SbmlParser();
Model model = new ModelFullIndexed(null);
model.setWidth(100);
model.setHeight(100);
model.setName("UNKNOWN DISEASE MAP");
model.setIdModel("id1");
Model model = createEmptyModel();
converter.exportModelToFile(model, tempFilename);
......@@ -279,6 +275,15 @@ public class SbmlExporterTest {
}
private Model createEmptyModel() {
Model model = new ModelFullIndexed(null);
model.setWidth(1000);
model.setHeight(1000);
model.setName("UNKNOWN DISEASE MAP");
model.setIdModel("id1");
return model;
}
@Test
public void testExportProblematicNotes() throws Exception {
Model model = createModelWithReaction();
......@@ -332,11 +337,7 @@ public class SbmlExporterTest {
Set<Class<? extends Species>> classes = reflections.getSubTypesOf(Species.class);
for (Class<? extends Element> class1 : classes) {
if (!Modifier.isAbstract(class1.getModifiers())) {
Model model = new ModelFullIndexed(null);
model.setIdModel("Test123");
model.setName("x");
model.setWidth("300");
model.setHeight("300");
Model model = createEmptyModel();
Element element = class1.getConstructor(String.class).newInstance("x");
element.setName("test name");
element.setX(10);
......@@ -463,11 +464,7 @@ public class SbmlExporterTest {
@Test
public void testExportProteinState() throws Exception {
Model model = new ModelFullIndexed(null);
model.setIdModel("Test123");
model.setName("x");
model.setWidth("300");
model.setHeight("300");
Model model = createEmptyModel();
GenericProtein element = new GenericProtein("id");
element.setName("test name");
element.setX(10);
......@@ -481,4 +478,63 @@ public class SbmlExporterTest {
assertEquals("Structural state not exported/imported properly", 0, comparator.compare(model, deserializedModel));
}
@Test
public void testMultiExtensionProteinStateInTypes() throws Exception {
String structuralState = "xxx";
Model model = createEmptyModel();
GenericProtein element = new GenericProtein("id");
element.setName("test name");
element.setX(10);
element.setWidth(10);
element.setY(10);
element.setHeight(10);
element.setStructuralState(structuralState);
model.addElement(element);
org.sbml.jsbml.Model sbmlModel = exporter.toSbmlDocument(model).getModel();
MultiModelPlugin multiPlugin = (MultiModelPlugin) sbmlModel.getExtension("multi");
boolean structuralStateValueFound = false;
for (MultiSpeciesType speciesType : multiPlugin.getListOfSpeciesTypes()) {
for (SpeciesFeatureType featureType : speciesType.getListOfSpeciesFeatureTypes()) {
for (PossibleSpeciesFeatureValue featureValue : featureType.getListOfPossibleSpeciesFeatureValues()) {
if (featureValue.getName().equals(structuralState)) {
structuralStateValueFound = true;
}
}
}
}
assertTrue("Structural state not defined in the list of possible values", structuralStateValueFound);
}
@Test
public void testMultiExtensionProteinStateSuplicateInTypes() throws Exception {
String structuralState = "xxx";
Model model = createEmptyModel();
GenericProtein element = new GenericProtein("id");
element.setName("test name");
element.setX(10);
element.setWidth(10);
element.setY(10);
element.setHeight(10);
element.setStructuralState(structuralState);
model.addElement(element);
element = new GenericProtein("id2");
element.setName("test name");
element.setX(10);
element.setWidth(10);
element.setY(10);
element.setHeight(10);
element.setStructuralState(structuralState);
model.addElement(element);
org.sbml.jsbml.Model sbmlModel = exporter.toSbmlDocument(model).getModel();
MultiModelPlugin multiPlugin = (MultiModelPlugin) sbmlModel.getExtension("multi");
for (MultiSpeciesType speciesType : multiPlugin.getListOfSpeciesTypes()) {
for (SpeciesFeatureType featureType : speciesType.getListOfSpeciesFeatureTypes()) {
assertTrue(featureType.getListOfPossibleSpeciesFeatureValues().size() <= 2);
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment