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

export of modifier type added

parent e4ad45eb
No related branches found
No related tags found
1 merge request!186Resolve "upload of sbml"
package lcsb.mapviewer.converter.model.sbml.reaction; package lcsb.mapviewer.converter.model.sbml.reaction;
import java.util.HashSet; import java.util.ArrayList;
import java.util.Set; import java.util.List;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
...@@ -19,7 +19,7 @@ public enum SBOTermModifierType { ...@@ -19,7 +19,7 @@ public enum SBOTermModifierType {
; ;
private static Logger logger = Logger.getLogger(SBOTermModifierType.class); private static Logger logger = Logger.getLogger(SBOTermModifierType.class);
private Set<String> sboTerms = new HashSet<>(); private List<String> sboTerms = new ArrayList<>();
Class<? extends Modifier> clazz; Class<? extends Modifier> clazz;
private SBOTermModifierType(Class<? extends Modifier> clazz, String[] inputSboTerms) { private SBOTermModifierType(Class<? extends Modifier> clazz, String[] inputSboTerms) {
...@@ -47,4 +47,22 @@ public enum SBOTermModifierType { ...@@ -47,4 +47,22 @@ public enum SBOTermModifierType {
} }
return result; return result;
} }
public static String getTermByType(Class<? extends Modifier> clazz) {
for (SBOTermModifierType term : values()) {
if (clazz.equals(term.clazz)) {
return term.getSBO();
}
}
logger.warn("Cannot find SBO term for class: " + clazz);
return null;
}
private String getSBO() {
if (sboTerms.size() != 0) {
return sboTerms.get(0);
}
logger.warn("Cannot find SBO term for class: " + clazz);
return null;
}
} }
...@@ -78,6 +78,10 @@ public class SbmlReactionExporter extends SbmlBioEntityExporter<Reaction, org.sb ...@@ -78,6 +78,10 @@ public class SbmlReactionExporter extends SbmlBioEntityExporter<Reaction, org.sb
Species sbmlSymbol = speciesExporter.getSbmlElementByElementId(modifier.getElement().getElementId()); Species sbmlSymbol = speciesExporter.getSbmlElementByElementId(modifier.getElement().getElementId());
SimpleSpeciesReference speciesReference = result.createModifier(sbmlSymbol); SimpleSpeciesReference speciesReference = result.createModifier(sbmlSymbol);
speciesReferenceByReactionNode.put(modifier, speciesReference); speciesReferenceByReactionNode.put(modifier, speciesReference);
String term = SBOTermModifierType.getTermByType(modifier.getClass());
if (term != null) {
speciesReference.setSBOTerm(term);
}
} }
if (reaction.getKinetics() != null) { if (reaction.getKinetics() != null) {
result.setKineticLaw(createKineticLaw(reaction)); result.setKineticLaw(createKineticLaw(reaction));
......
...@@ -109,32 +109,33 @@ public class SbmlReactionParser extends SbmlBioEntityParser { ...@@ -109,32 +109,33 @@ public class SbmlReactionParser extends SbmlBioEntityParser {
SpeciesGlyph speciesGlyph = layout.getSpeciesGlyph(speciesRefernceGlyph.getSpeciesGlyph()); SpeciesGlyph speciesGlyph = layout.getSpeciesGlyph(speciesRefernceGlyph.getSpeciesGlyph());
ReactionNode minervaNode = null; ReactionNode minervaNode = null;
Class<? extends ReactionNode> nodeClass = null; Class<? extends ReactionNode> nodeClass = null;
switch (speciesRefernceGlyph.getRole()) { if (speciesRefernceGlyph.getRole() != null) {
case ACTIVATOR: switch (speciesRefernceGlyph.getRole()) {
nodeClass = Trigger.class; case ACTIVATOR:
break; nodeClass = Trigger.class;
case INHIBITOR: break;
nodeClass = Inhibition.class; case INHIBITOR:
break; nodeClass = Inhibition.class;
case MODIFIER: break;
nodeClass = Modulation.class; case PRODUCT:
break; nodeClass = Product.class;
case PRODUCT: break;
nodeClass = Product.class; case SIDEPRODUCT:
break; nodeClass = Product.class;
case SIDEPRODUCT: break;
nodeClass = Product.class; case SIDESUBSTRATE:
break; nodeClass = Reactant.class;
case SIDESUBSTRATE: break;
nodeClass = Reactant.class; case SUBSTRATE:
break; nodeClass = Reactant.class;
case SUBSTRATE: break;
nodeClass = Reactant.class; case UNDEFINED:
break; case MODIFIER:
case UNDEFINED: nodeClass = null;
nodeClass = null; break;
break; }
} }
if (reactionWithLayout.isReversible() && (nodeClass == Reactant.class || nodeClass == Product.class)) { if (reactionWithLayout.isReversible() && (nodeClass == Reactant.class || nodeClass == Product.class)) {
nodeClass = null; nodeClass = null;
} }
...@@ -148,7 +149,11 @@ public class SbmlReactionParser extends SbmlBioEntityParser { ...@@ -148,7 +149,11 @@ public class SbmlReactionParser extends SbmlBioEntityParser {
} }
} }
} }
if (nodeClass == Modifier.class) {
nodeClass = Modulation.class;
}
if (minervaNode == null) { if (minervaNode == null) {
logger.debug(nodeClass);
throw new InvalidInputDataExecption( throw new InvalidInputDataExecption(
"Cannot find reaction node for layouted reaction: " + speciesGlyph.getSpecies() + ", " + glyph.getId()); "Cannot find reaction node for layouted reaction: " + speciesGlyph.getSpecies() + ", " + glyph.getId());
} }
......
...@@ -53,6 +53,7 @@ public class GenericSbmlToXmlParserTest { ...@@ -53,6 +53,7 @@ public class GenericSbmlToXmlParserTest {
@Test @Test
public void toXmlModelTest() throws Exception { public void toXmlModelTest() throws Exception {
try { try {
String dir = Files.createTempDirectory("sbgn-temp-images-dir").toFile().getAbsolutePath(); String dir = Files.createTempDirectory("sbgn-temp-images-dir").toFile().getAbsolutePath();
IConverter converter = new SbmlParser(); IConverter converter = new SbmlParser();
...@@ -64,7 +65,7 @@ public class GenericSbmlToXmlParserTest { ...@@ -64,7 +65,7 @@ public class GenericSbmlToXmlParserTest {
+ filePath.getFileName().toString().substring(0, filePath.getFileName().toString().indexOf(".xml")); + filePath.getFileName().toString().substring(0, filePath.getFileName().toString().indexOf(".xml"));
String xmlFilePath = pathWithouExtension.concat(".xml"); String xmlFilePath = pathWithouExtension.concat(".xml");
converter.exportModelToFile(model, xmlFilePath); converter.exportModelToFile(model, xmlFilePath);
Model model2 = converter.createModel(new ConverterParams().filename(xmlFilePath)); Model model2 = converter.createModel(new ConverterParams().filename(xmlFilePath));
model2.setName(null); model2.setName(null);
......
...@@ -6,6 +6,7 @@ import java.io.FileNotFoundException; ...@@ -6,6 +6,7 @@ import java.io.FileNotFoundException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.junit.Test; import org.junit.Test;
import org.sbml.jsbml.SBMLDocument;
import lcsb.mapviewer.converter.ConverterParams; import lcsb.mapviewer.converter.ConverterParams;
import lcsb.mapviewer.converter.InvalidInputDataExecption; import lcsb.mapviewer.converter.InvalidInputDataExecption;
...@@ -128,4 +129,5 @@ public class SbmlSpeciesParserTest { ...@@ -128,4 +129,5 @@ public class SbmlSpeciesParserTest {
assertTrue(element instanceof Unknown); assertTrue(element instanceof Unknown);
} }
} }
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