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

when parsing sbml reaction with invalid number of reactant/products is...

when parsing sbml reaction with invalid number of reactant/products is encountered the default reaction type is used
parent 3e38a4e8
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",!521Resolve "SBML upload error, files from BioModels"
......@@ -51,6 +51,7 @@ import lcsb.mapviewer.model.map.reaction.AbstractNode;
import lcsb.mapviewer.model.map.reaction.AndOperator;
import lcsb.mapviewer.model.map.reaction.AssociationOperator;
import lcsb.mapviewer.model.map.reaction.DissociationOperator;
import lcsb.mapviewer.model.map.reaction.InvalidReactionParticipantNumberException;
import lcsb.mapviewer.model.map.reaction.Modifier;
import lcsb.mapviewer.model.map.reaction.NodeOperator;
import lcsb.mapviewer.model.map.reaction.Product;
......@@ -453,14 +454,34 @@ public class SbmlReactionParser extends SbmlBioEntityParser {
}
}
String sboTerm = sbmlReaction.getSBOTermID();
reaction = createProperReactionClassForSboTerm(reaction, sboTerm);
return reaction;
}
private Reaction createProperReactionClassForSboTerm(Reaction reaction, String sboTerm)
throws InvalidInputDataExecption {
Class<? extends Reaction> reactionClass = SBOTermReactionType.getTypeSBOTerm(sboTerm);
try {
Class<? extends Reaction> reactionClass = SBOTermReactionType.getTypeSBOTerm(sbmlReaction.getSBOTermID());
reaction = reactionClass.getConstructor(Reaction.class).newInstance(reaction);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | SecurityException e) {
throw new InvalidInputDataExecption("Problem with creating reaction", e);
if (e.getCause() instanceof InvalidReactionParticipantNumberException) {
try {
logger.warn(eu.getElementTag(reaction) + "SBO term indicated " + reactionClass.getSimpleName()
+ " class. However number of reactants/products is insufficient for such class type. Using default.");
reactionClass = SBOTermReactionType.getTypeSBOTerm(null);
reaction = reactionClass.getConstructor(Reaction.class).newInstance(reaction);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | SecurityException e1) {
throw new InvalidInputDataExecption(eu.getElementTag(reaction) + "Problem with creating reaction", e);
}
} else {
throw new InvalidInputDataExecption(eu.getElementTag(reaction) + "Problem with creating reaction", e);
}
}
return reaction;
}
......
......@@ -159,6 +159,17 @@ public class SbmlParserTest {
new ConverterParams().filename("testFiles/invalidReaction/reaction_with_missing_part_of_layout.xml"));
}
@Test
public void test() throws Exception {
try {
parser.createModel(
new ConverterParams().filename("/home/gawi/Desktop/biomodels/BIOMD0000000001_url.xml"));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testDefaultColors() throws Exception {
Model model = parser.createModel(new ConverterParams().filename("testFiles/small/default_colors.xml"));
......
......@@ -125,6 +125,21 @@ public class SbmlReactionParserTest {
assertTrue(reaction instanceof HeterodimerAssociationReaction);
}
@Test
public void testParseHeterodimerAssociationWithSingleReactant() throws Exception {
try {
Model model = parser
.createModel(new ConverterParams()
.filename("testFiles/small/reaction/heterodimer_association_with_single_reactant.xml"));
Reaction reaction = model.getReactions().iterator().next();
assertNotNull(reaction);
assertTrue(reaction instanceof Reaction);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testParseDissociation() throws FileNotFoundException, InvalidInputDataExecption {
Model model = parser.createModel(new ConverterParams().filename("testFiles/small/reaction/dissociation.xml"));
......
<?xml version="1.0" encoding="UTF-8"?>
<sbml xmlns="http://www.sbml.org/sbml/level2/version4" level="2" version="4">
<model id="TestGEN">
<annotation/>
<listOfCompartments>
<compartment constant="true" id="cell" name="cell" sboTerm="SBO:0000290" size="1">
<annotation>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:bqmodel="http://biomodels.net/model-qualifiers/" xmlns:bqbiol="http://biomodels.net/biology-qualifiers/">
<rdf:Description rdf:about="#">
<bqbiol:isVersionOf>
<rdf:Bag>
<rdf:li rdf:resource="urn:miriam:obo.go:GO:0005623"/>
</rdf:Bag>
</bqbiol:isVersionOf>
</rdf:Description>
</rdf:RDF>
</annotation>
</compartment>
</listOfCompartments>
<listOfSpecies>
<species compartment="cell" initialConcentration="1" id="s1" name="nm1">
<annotation/>
</species>
<species compartment="cell" initialConcentration="1" id="s2" name="nm2">
<annotation/>
</species>
</listOfSpecies>
<listOfReactions>
<reaction id="re1" sboTerm="SBO:0000177">
<listOfReactants>
<speciesReference species="s1" stoichiometry="1"/>
</listOfReactants>
<listOfProducts>
<speciesReference species="s2" stoichiometry="1"/>
</listOfProducts>
</reaction>
</listOfReactions>
</model>
</sbml>
\ No newline at end of file
package lcsb.mapviewer.model.map.reaction;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
/**
* Exception to be thrown when number of reactants or products is invalid when
* creating reaction.
*
* @author Piotr Gawron
*
*/
public class InvalidReactionParticipantNumberException extends InvalidArgumentException {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Default constructor - initializes instance variable to unknown.
*/
public InvalidReactionParticipantNumberException() {
super(); // call superclass constructor
}
/**
* Public constructor with parent exception that was caught.
*
* @param e
* parent exception
*/
public InvalidReactionParticipantNumberException(final String e) {
super(e);
}
/**
* Public constructor with parent exception that was caught.
*
* @param e
* parent exception
*/
public InvalidReactionParticipantNumberException(final Exception e) {
super(e);
}
/**
* Public constructor with parent exception that was caught.
*
* @param message
* exception message
* @param e
* parent exception
*/
public InvalidReactionParticipantNumberException(final String message, final Exception e) {
super(message, e);
}
}
......@@ -268,12 +268,12 @@ public class Reaction implements BioEntity {
minProducts = 2;
}
if (original.getProducts().size() < minProducts) {
throw new InvalidArgumentException(new ElementUtils().getElementTag(original)
throw new InvalidReactionParticipantNumberException(new ElementUtils().getElementTag(original)
+ "Invalid source reaction: number of products must be at least " + minProducts);
}
if (original.getReactants().size() < minReactants) {
throw new InvalidArgumentException(new ElementUtils().getElementTag(original)
throw new InvalidReactionParticipantNumberException(new ElementUtils().getElementTag(original)
+ "Invalid source reaction: number of reactants must be at least " + minReactants);
}
}
......
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