Commit 093ceca4 authored by lcottret's avatar lcottret
Browse files

remove sbml validation

parent 32412c02
......@@ -40,15 +40,14 @@ import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Set;
import java.util.stream.Collectors;
import javax.xml.stream.XMLStreamException;
import org.sbml.jsbml.Model;
import org.sbml.jsbml.SBMLDocument;
import org.sbml.jsbml.SBMLError;
import org.sbml.jsbml.SBMLError.SEVERITY;
import org.sbml.jsbml.SBMLReader;
import org.sbml.jsbml.validator.SBMLValidator;
import fr.inrae.toulouse.metexplore.met4j_core.biodata.BioNetwork;
import fr.inrae.toulouse.metexplore.met4j_io.jsbml.dataTags.AdditionalDataTag;
......@@ -87,14 +86,6 @@ public class JsbmlReader {
* The SBML Model retrieved through jsbml's
*/
private Model model;
/**
* Attribute that specifies if the input sbml is valid or not
*/
private boolean validSBML = true;
/**
* Set to true to use SBML online validator
*/
private boolean useValidator;
private String xmlString = null;
......@@ -106,19 +97,6 @@ public class JsbmlReader {
*/
public JsbmlReader(String filename) throws IOException {
this.filename = filename;
this.useValidator = false;
}
/**
* Constructor
*
* @param filename the filename
* @param useValidator set the {@link #useValidator} attribute
* @throws java.io.IOException if any.
*/
public JsbmlReader(String filename, boolean useValidator) throws IOException {
this.filename = filename;
this.useValidator = useValidator;
}
/**
......@@ -129,22 +107,9 @@ public class JsbmlReader {
*/
public JsbmlReader(InputStream inputStream) throws IOException {
this.xmlString = this.inputStreamToString(inputStream);
this.useValidator = false;
}
/**
* <p>Constructor for JsbmlReader.</p>
*
* @param inputStream a {@link java.io.InputStream} object.
* @param useValidator a boolean.
* @throws java.io.IOException if any.
*/
public JsbmlReader(InputStream inputStream, boolean useValidator) throws IOException {
this.xmlString = this.inputStreamToString(inputStream);
this.useValidator = useValidator;
}
private String inputStreamToString(InputStream inputStream) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder sb = new StringBuilder();
......@@ -152,9 +117,7 @@ public class JsbmlReader {
while ((line = br.readLine()) != null) {
sb.append(line).append(System.lineSeparator());
}
return sb.toString();
}
/*
......@@ -221,30 +184,24 @@ public class JsbmlReader {
this.initiateModel();
} catch (IOException | XMLStreamException e) {
e.printStackTrace();
this.setValidSBML(false);
}
if (this.isValidSBML()) {
System.err.println("Verifying enabled Plugins...");
ArrayList<PackageParser> verifiedPkgs = this.verifyPackages(userEnabledPackages);
System.err.println("Verifying enabled Plugins...");
ArrayList<PackageParser> verifiedPkgs = this.verifyPackages(userEnabledPackages);
JsbmlToBioNetwork converter = new JsbmlToBioNetwork(this.getModel());
JsbmlToBioNetwork converter = new JsbmlToBioNetwork(this.getModel());
this.setConverter(converter);
try {
converter.setPackages(verifiedPkgs);
} catch (Exception e) {
e.printStackTrace();
throw new Met4jSbmlReaderException("Problem while setting the JSBML packages");
}
this.setConverter(converter);
return parseModel();
} else {
return null;
try {
converter.setPackages(verifiedPkgs);
} catch (Exception e) {
e.printStackTrace();
throw new Met4jSbmlReaderException("Problem while setting the JSBML packages");
}
return parseModel();
}
protected BioNetwork parseModel() throws Met4jSbmlReaderException {
......@@ -328,13 +285,6 @@ public class JsbmlReader {
private void initiateModel() throws IOException, XMLStreamException {
SBMLDocument doc = sbmlRead();
if (this.useValidator) {
System.err.println("Validating Input SBML..");
this.setValidSBML(this.validateSBML(doc));
System.err.println("Validation of input SBML done : " + this.validSBML);
}
this.setModel(doc.getModel());
}
......@@ -352,59 +302,6 @@ public class JsbmlReader {
return doc;
}
/**
* Validates the SBML document using the online validator
*
* @param doc the SBMLDocument object
* @return true if SBMLValidator returns no errors, false otherwise. This
* method returns true if the Validator only returns warnings
*/
public boolean validateSBML(SBMLDocument doc) {
// TODO test if the validator is working properly before checking
// consistency.
doc.setConsistencyChecks(SBMLValidator.CHECK_CATEGORY.GENERAL_CONSISTENCY, true);
doc.setConsistencyChecks(SBMLValidator.CHECK_CATEGORY.IDENTIFIER_CONSISTENCY, true);
doc.setConsistencyChecks(SBMLValidator.CHECK_CATEGORY.UNITS_CONSISTENCY, true);
doc.setConsistencyChecks(SBMLValidator.CHECK_CATEGORY.SBO_CONSISTENCY, true);
doc.setConsistencyChecks(SBMLValidator.CHECK_CATEGORY.MATHML_CONSISTENCY, false);
doc.setConsistencyChecks(SBMLValidator.CHECK_CATEGORY.OVERDETERMINED_MODEL, false);
doc.setConsistencyChecks(SBMLValidator.CHECK_CATEGORY.MODELING_PRACTICE, false);
// Online validator
int code = doc.checkConsistencyOffline();
if (code > 0) {
HashMap<Integer, String> parsedErrors = new HashMap<>();
for (SBMLError err : doc.getErrorLog().getValidationErrors()) {
StringBuilder sb = new StringBuilder();
if (!parsedErrors.containsKey(err.getCode())) {
parsedErrors.put(err.getCode(), "");
} else {
sb.append(parsedErrors.get(err.getCode())).append("\n");
}
sb.append(err.getSeverity()).append(" line ").append(err.getLine())
.append(" : ").append(err.getCategory())
.append(" : ").append(err.getShortMessage().getMessage());
String newMessage = sb.toString();
parsedErrors.put(err.getCode(), newMessage);
}
errorsAndWarnings.addAll(parsedErrors.values());
return doc.getErrorLog().getNumFailsWithSeverity(SEVERITY.ERROR) == 0;
}
return true;
}
/**
* <p>Getter for the field <code>filename</code>.</p>
*
......@@ -459,24 +356,6 @@ public class JsbmlReader {
this.converter = converter;
}
/**
* <p>isValidSBML.</p>
*
* @return the validSBML
*/
public boolean isValidSBML() {
return validSBML;
}
/**
* <p>Setter for the field <code>validSBML</code>.</p>
*
* @param validSBML the validSBML to set
*/
public void setValidSBML(boolean validSBML) {
this.validSBML = validSBML;
}
/**
* <p>Getter for the field <code>errorsAndWarnings</code>.</p>
*
......@@ -494,23 +373,4 @@ public class JsbmlReader {
public void setErrorsAndWarnings(ArrayList<String> errorsAndWarnings) {
this.errorsAndWarnings = errorsAndWarnings;
}
/**
* <p>isUseValidator.</p>
*
* @return the useValidator
*/
public boolean isUseValidator() {
return useValidator;
}
/**
* <p>Setter for the field <code>useValidator</code>.</p>
*
* @param useValidator the useValidator to set
*/
public void setUseValidator(boolean useValidator) {
this.useValidator = useValidator;
}
}
......@@ -73,34 +73,20 @@ public class JsbmlReaderTest {
}
@Test
public void validateSbml() throws IOException, XMLStreamException, Met4jSbmlReaderException {
public void readWithoutNotes() throws IOException, XMLStreamException, Met4jSbmlReaderException {
JsbmlReader reader = spy(new JsbmlReader("test"));
SbmlDocMock docMockGenerator = new SbmlDocMock();
SBMLDocument doc = docMockGenerator.doc;
Boolean check = reader.validateSBML(doc);
System.err.println(reader.errorsAndWarnings);
assertTrue(check);
SbmlDocInvalidMock invalidDocMockGenerator = new SbmlDocInvalidMock();
SBMLDocument invalidDoc = invalidDocMockGenerator.doc;
doReturn(doc).when(reader).sbmlRead();
assertFalse(reader.validateSBML(invalidDoc));
BioNetwork network = reader.readWithoutNotes();
assertNotNull(network);
assertEquals(3, network.getReactionsView().size());
}
@Test
public void readWithoutNotes() {
fail();
}
@Test
public void validateSBML() {
fail();
}
}
\ No newline at end of file
......@@ -64,13 +64,6 @@ public class SbmlDocMock {
c2.setName("compartment2");
c3 = model.createCompartment("c3");
CompartmentType compartmentType = new CompartmentType("cType");
model.addCompartmentType(compartmentType);
c1.setCompartmentType(compartmentType);
c1.setOutside(c2);
c2.setOutside(c1);
c1.setSize(2.0);
c1.setSpatialDimensions(4.0);
......@@ -90,46 +83,12 @@ public class SbmlDocMock {
m1.setInitialAmount(2.0);
m2.setInitialAmount(3.0);
if (model.getLevel() < 3) {
m1.setCharge(3);
m2.setCharge(4);
type1 = model.createSpeciesType("type1");
type1.setSBOTerm(1234567);
type2 = model.createSpeciesType("type2");
Annotation annotation = new Annotation();
CVTerm cvterm = new CVTerm();
cvterm.addResource("urn.miriam.obo.go#GO%3A1234567");
cvterm.setQualifierType(org.sbml.jsbml.CVTerm.Type.BIOLOGICAL_QUALIFIER);
cvterm.setBiologicalQualifierType(CVTerm.Qualifier.BQB_IS);
annotation.addCVTerm(cvterm);
type2.setAnnotation(annotation);
type3 = model.createSpeciesType("type3");
try {
type3.setNotes(
"<notes>\n" + "<body xmlns=\"http://www.w3.org/1999/xhtml\"><p>Attr:val</p></body></notes>");
} catch (XMLStreamException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
m1.setSpeciesType(type1);
m2.setSpeciesType(type2);
m3.setSpeciesType(type3);
}
r1 = model.createReaction("r1");
r1.setName("name1");
r1.setReversible(false);
if (model.getLevel() > 2) {
r1.setSBOTerm("SBO:0000167");
}
r1.setFast(true);
r1.setSBOTerm("SBO:0000167");
r2 = model.createReaction("r2");
......@@ -141,10 +100,8 @@ public class SbmlDocMock {
SpeciesReference m2Ref = new SpeciesReference(m2);
if (model.getLevel() > 2) {
m1Ref.setConstant(true);
m2Ref.setConstant(false);
}
m1Ref.setConstant(true);
m2Ref.setConstant(false);
// This metabolite must not be taken into account
SpeciesReference m4Ref = new SpeciesReference(m4);
......
......@@ -52,7 +52,7 @@ public class Sbml2Graph extends AbstractMet4jApplication {
public void run() throws IOException, Met4jSbmlReaderException {
JsbmlReader reader = new JsbmlReader(this.inputPath, false);
JsbmlReader reader = new JsbmlReader(this.inputPath);
ArrayList<PackageParser> pkgs = new ArrayList<>(Arrays.asList(
new NotesParser(false), new FBCParser(), new GroupPathwayParser()));
BioNetwork network = reader.read(pkgs);
......
......@@ -71,7 +71,7 @@ public class CarbonSkeletonNet extends AbstractMet4jApplication {
public void run() throws IOException, Met4jSbmlReaderException {
System.out.print("Reading SBML...");
JsbmlReader reader = new JsbmlReader(this.inputPath, false);
JsbmlReader reader = new JsbmlReader(this.inputPath);
ArrayList<PackageParser> pkgs = new ArrayList<>(Arrays.asList(
new NotesParser(false), new FBCParser(), new GroupPathwayParser()));
BioNetwork network = reader.read(pkgs);
......
......@@ -47,7 +47,7 @@ public class ChokePoint extends AbstractMet4jApplication {
//import network
System.err.println("reading SBML...");
JsbmlReader reader = new JsbmlReader(this.inputPath, false);
JsbmlReader reader = new JsbmlReader(this.inputPath);
BioNetwork network = reader.read();
//Create compound graph
......
......@@ -56,7 +56,7 @@ public class DistanceMatrix extends AbstractMet4jApplication {
public void run() throws IOException, Met4jSbmlReaderException {
//import network
JsbmlReader reader = new JsbmlReader(this.inputPath, false);
JsbmlReader reader = new JsbmlReader(this.inputPath);
BioNetwork network = reader.read();
//Create compound graph
......
......@@ -61,7 +61,7 @@ public class ExtractSubNetwork extends AbstractMet4jApplication {
public void run() throws IOException, Met4jSbmlReaderException {
//import network
JsbmlReader reader = new JsbmlReader(this.inputPath, false);
JsbmlReader reader = new JsbmlReader(this.inputPath);
BioNetwork network = reader.read();
//Create compound graph
......
......@@ -55,7 +55,7 @@ public class ExtractSubReactionNetwork extends AbstractMet4jApplication {
public void run() throws IOException, Met4jSbmlReaderException {
//import network
JsbmlReader reader = new JsbmlReader(this.inputPath, false);
JsbmlReader reader = new JsbmlReader(this.inputPath);
BioNetwork network = reader.read();
//Graph processing: import side compounds
......
......@@ -50,7 +50,7 @@ public class LoadPoint extends AbstractMet4jApplication {
//import network
System.err.println("reading SBML...");
JsbmlReader reader = new JsbmlReader(this.inputPath, false);
JsbmlReader reader = new JsbmlReader(this.inputPath);
BioNetwork network = reader.read();
//Create compound graph
......
......@@ -138,7 +138,7 @@ public class MetaboRank extends AbstractMet4jApplication {
*
*/
private BioNetwork importModel(String sbmlFilePath) throws IOException, Met4jSbmlReaderException {
JsbmlReader reader = new JsbmlReader(sbmlFilePath, false);
JsbmlReader reader = new JsbmlReader(sbmlFilePath);
BioNetwork model = reader.read();
System.err.println("model imported.");
return model;
......
......@@ -67,7 +67,7 @@ public class NetworkSummary extends AbstractMet4jApplication {
//import network
System.err.println("reading SBML...");
JsbmlReader reader = new JsbmlReader(this.inputPath, false);
JsbmlReader reader = new JsbmlReader(this.inputPath);
BioNetwork network = reader.read();
//Create compound graph
......
......@@ -69,7 +69,7 @@ public class SideCompoundsScan extends AbstractMet4jApplication {
//import network
System.err.println("reading SBML...");
System.err.println(inputPath);
JsbmlReader reader = new JsbmlReader(this.inputPath, false);
JsbmlReader reader = new JsbmlReader(this.inputPath);
BioNetwork network = reader.read();
//Create compound graph
......
Markdown is supported
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