-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'robertvi-feat/sedml-validator' into experimental
- Loading branch information
Showing
10 changed files
with
413 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
""" | ||
use libsedml getErrorLog().getNumFailsWithSeverity(libsedml.LIBSEDML_SEV_ERROR) to validate SEDML file(s) | ||
based on example here https://github.com/SED-ML/libSEDML/blob/master/examples/python/echo_sedml.py | ||
""" | ||
|
||
import os | ||
import errno | ||
import libsedml | ||
from typing import List | ||
|
||
|
||
def check_file(file_name): | ||
""" | ||
check string path points to a file and that we have read access to it | ||
""" | ||
|
||
if not os.path.isfile(file_name): | ||
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), file_name) | ||
|
||
if not os.access(file_name, os.R_OK): | ||
raise IOError(f"Could not read file {file_name}") | ||
|
||
|
||
def validate_sedml_files(input_files: List[str]) -> bool: | ||
""" | ||
validate SEDML file(s) | ||
input_files is a list of one or more filepaths | ||
""" | ||
|
||
if not len(input_files) >= 1: | ||
raise ValueError("No input files specified") | ||
|
||
all_valid = True | ||
|
||
for file_name in input_files: | ||
# check file exists and is readable | ||
check_file(file_name) | ||
|
||
try: | ||
doc = libsedml.readSedML(file_name) | ||
except Exception: | ||
raise IOError(f"readSedML failed trying to open the file {file_name}") | ||
|
||
# readSedML does not check existance of model source files, do it ourselves here | ||
for model in doc.getListOfModels(): | ||
# treat file path as relative to SEDML file | ||
dir_name = os.path.dirname(file_name) | ||
source_file = os.path.join(dir_name, model.getSource()) | ||
|
||
try: | ||
check_file(source_file) | ||
except Exception: | ||
all_valid = False | ||
print("Cannot find or access model source file {source_file}") | ||
|
||
if doc.getErrorLog().getNumFailsWithSeverity(libsedml.LIBSEDML_SEV_ERROR) > 0: | ||
all_valid = False | ||
print(doc.getErrorLog().toString()) | ||
|
||
return all_valid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- Created by phraSED-ML version v0.5beta on 2015-12-01 15:44 with libSBML version 5.11.9. --> | ||
<sedML xmlns="http://sed-ml.org/sed-ml/level1/version2" level="1" version="2"> | ||
<listOfSimulations> | ||
<uniformTimeCourse id="sim1" initialTime="0" outputStartTime="0" outputEndTime="10" numberOfPoints="10"> | ||
<algorithm kisaoID="KISAO:0000019"/> | ||
</uniformTimeCourse> | ||
</listOfSimulationz> | ||
<listOfModels> | ||
<model id="mod1" language="urn:sedml:language:sbml.level-3.version-1" source="00001-sbml.xml"/> | ||
</listOfModels> | ||
<listOfTasks> | ||
<task id="task1" modelReference="mod1" simulationReference="sim1"/> | ||
</listOfTasks> | ||
<listOfDataGenerators> | ||
<dataGenerator id="report_0_0_0" name="time"> | ||
<listOfVariables> | ||
<variable id="time" symbol="urn:sedml:symbol:time" taskReference="task1"/> | ||
</listOfVariables> | ||
<math xmlns="http://www.w3.org/1998/Math/MathML"> | ||
<ci> time </ci> | ||
</math> | ||
</dataGenerator> | ||
<dataGenerator id="report_0_0_1" name="a"> | ||
<listOfVariables> | ||
<variable id="a" target="/sbml:sbml/sbml:model/descendant::*[@id='a']" taskReference="task1" modelReference="mod1"/> | ||
</listOfVariables> | ||
<math xmlns="http://www.w3.org/1998/Math/MathML"> | ||
<ci> a </ci> | ||
</math> | ||
</dataGenerator> | ||
</listOfDataGenerators> | ||
<listOfOutputs> | ||
<report id="report_0"> | ||
<listOfDataSets> | ||
<dataSet id="report_0_0_0_dataset" label="time" dataReference="report_0_0_0"/> | ||
<dataSet id="report_0_0_1_dataset" label="a" dataReference="report_0_0_1"/> | ||
</listOfDataSets> | ||
</report> | ||
</listOfOutputs> | ||
</sedML> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- Created by phraSED-ML version v0.5beta on 2015-12-01 15:44 with libSBML version 5.11.9. --> | ||
<sedML xmlns="http://sed-ml.org/sed-ml/level1/version2" level="1" version="2"> | ||
<listOfSimulations> | ||
<uniformTimeCourse id="sim1" initialTime="0" outputStartTime="0" outputEndTime="10" numberOfPoints="10"> | ||
<algorithm kisaoID="KISAO:0000019"/> | ||
</uniformTimeCourse> | ||
</listOfSimulations> | ||
<listOfNoodles> | ||
<model id="mod1" language="urn:sedml:language:sbml.level-3.version-1" source="00001-sbml.xml"/> | ||
</listOfNoodles> | ||
<listOfTasks> | ||
<task id="task1" modelReference="mod1" simulationReference="sim1"/> | ||
</listOfTasks> | ||
<listOfDataGenerators> | ||
<dataGenerator id="report_0_0_0" name="time"> | ||
<listOfVariables> | ||
<variable id="time" symbol="urn:sedml:symbol:time" taskReference="task1"/> | ||
</listOfVariables> | ||
<math xmlns="http://www.w3.org/1998/Math/MathML"> | ||
<ci> time </ci> | ||
</math> | ||
</dataGenerator> | ||
<dataGenerator id="report_0_0_1" name="a"> | ||
<listOfVariables> | ||
<variable id="a" target="/sbml:sbml/sbml:model/descendant::*[@id='a']" taskReference="task1" modelReference="mod1"/> | ||
</listOfVariables> | ||
<math xmlns="http://www.w3.org/1998/Math/MathML"> | ||
<ci> a </ci> | ||
</math> | ||
</dataGenerator> | ||
</listOfDataGenerators> | ||
<listOfOutputs> | ||
<report id="report_0"> | ||
<listOfDataSets> | ||
<dataSet id="report_0_0_0_dataset" label="time" dataReference="report_0_0_0"/> | ||
<dataSet id="report_0_0_1_dataset" label="a" dataReference="report_0_0_1"/> | ||
</listOfDataSets> | ||
</report> | ||
</listOfOutputs> | ||
</sedML> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- Created by phraSED-ML version v0.5beta on 2015-12-01 15:44 with libSBML version 5.11.9. --> | ||
<sedML xmlns="http://sed-ml.org/sed-ml/level1/version2" level="1" version="2"> | ||
<listOfSimulations> | ||
<uniformTimeCourse id="sim1" initialTime="0" outputStartTime="0" outputEndTime="10" numberOfPoints="10"> | ||
<algorithm kisaoID="KISAO:0000019"/> | ||
</uniformTimeCourse> | ||
</listOfSimulations> | ||
<listOfModels> | ||
<model id="mod1" language="urn:sedml:language:sbml.level-3.version-1" source="nonexistant.sbml"/> | ||
</listOfModels> | ||
<listOfTasks> | ||
<task id="task1" modelReference="mod1" simulationReference="sim1"/> | ||
</listOfTasks> | ||
<listOfDataGenerators> | ||
<dataGenerator id="report_0_0_0" name="time"> | ||
<listOfVariables> | ||
<variable id="time" symbol="urn:sedml:symbol:time" taskReference="task1"/> | ||
</listOfVariables> | ||
<math xmlns="http://www.w3.org/1998/Math/MathML"> | ||
<ci> time </ci> | ||
</math> | ||
</dataGenerator> | ||
<dataGenerator id="report_0_0_1" name="a"> | ||
<listOfVariables> | ||
<variable id="a" target="/sbml:sbml/sbml:model/descendant::*[@id='a']" taskReference="task1" modelReference="mod1"/> | ||
</listOfVariables> | ||
<math xmlns="http://www.w3.org/1998/Math/MathML"> | ||
<ci> a </ci> | ||
</math> | ||
</dataGenerator> | ||
</listOfDataGenerators> | ||
<listOfOutputs> | ||
<report id="report_0"> | ||
<listOfDataSets> | ||
<dataSet id="report_0_0_0_dataset" label="time" dataReference="report_0_0_0"/> | ||
<dataSet id="report_0_0_1_dataset" label="a" dataReference="report_0_0_1"/> | ||
</listOfDataSets> | ||
</report> | ||
</listOfOutputs> | ||
</sedML> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- Created by phraSED-ML version v0.5beta on 2015-12-01 15:44 with libSBML version 5.11.9. --> | ||
<sedML xmlns="http://sed-ml.org/sed-ml/level1/version2" level="1" version="2"> | ||
<listOfSimulations> | ||
<uniformTimeCourse id="sim1" initialTime="0" outputStartTime="0" outputEndTime="10" numberOfPoints="10"> | ||
<algorithm kisaoID="KISAO:0000019"/> | ||
</uniformTimeCourse> | ||
</listOfSimulations> | ||
<listOfModels> | ||
<model id="mod1" language="urn:sedml:language:sbml.level-3.version-1" source="00001-sbml.xml"/> | ||
</listOfModels> | ||
<listOfTasks> | ||
<task id="task1" modelReference="mod1" simulationReference="sim1"/> | ||
</listOfTasks> | ||
<listOfDataGenerators> | ||
<dataGenerator id="report_0_0_0" name="time"> | ||
<listOfVariables> | ||
<variable id="time" symbol="urn:sedml:symbol:time" taskReference="task1"/> | ||
</listOfVariables> | ||
<math xmlns="http://www.w3.org/1998/Math/MathML"> | ||
<ci> time </ci> | ||
</math> | ||
</dataGenerator> | ||
<dataGenerator id="report_0_0_1" name="a"> | ||
<listOfVariables> | ||
<variable id="a" target="/sbml:sbml/sbml:model/descendant::*[@id='a']" taskReference="task1" modelReference="mod1"/> | ||
</listOfVariables> | ||
<math xmlns="http://www.w3.org/1998/Math/MathML"> | ||
<ci> a </ci> | ||
</math> | ||
</dataGenerator> | ||
</listOfDataGenerators> | ||
<listOfOutputs> | ||
<report id="report_0"> | ||
<listOfDataSets> | ||
<dataSet id="report_0_0_0_dataset" label="time" dataReference="report_0_0_0"/> | ||
<dataSet id="report_0_0_1_dataset" label="a" dataReference="report_0_0_1"/> | ||
</listOfDataSets> | ||
</report> | ||
</listOfOutputs> | ||
</sedML> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- Created by libAntimony version v2.8.1 on 2015-12-02 12:55 with libSBML version 5.11.9. --> | ||
<sbml xmlns="http://www.sbml.org/sbml/level3/version1/core" xmlns:comp="http://www.sbml.org/sbml/level3/version1/comp/version1" level="3" version="1" comp:required="true"> | ||
<model id="__main" name="__main"> | ||
<listOfParameters> | ||
<parameter id="a" value="3" constant="true"/> | ||
</listOfParameters> | ||
</model> | ||
</sbml> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- Created by phraSED-ML version v0.5beta on 2015-12-01 15:44 with libSBML version 5.11.9. --> | ||
<sedML xmlns="http://sed-ml.org/sed-ml/level1/version2" level="1" version="2"> | ||
<listOfSimulations> | ||
<uniformTimeCourse id="sim1" initialTime="0" outputStartTime="0" outputEndTime="10" numberOfPoints="10"> | ||
<algorithm kisaoID="KISAO:0000019"/> | ||
</uniformTimeCourse> | ||
</listOfSimulations> | ||
<listOfModels> | ||
<model id="mod1" language="urn:sedml:language:sbml.level-3.version-1" source="valid_doc.sbml"/> | ||
</listOfModels> | ||
<listOfTasks> | ||
<task id="task1" modelReference="mod1" simulationReference="sim1"/> | ||
</listOfTasks> | ||
<listOfDataGenerators> | ||
<dataGenerator id="report_0_0_0" name="time"> | ||
<listOfVariables> | ||
<variable id="time" symbol="urn:sedml:symbol:time" taskReference="task1"/> | ||
</listOfVariables> | ||
<math xmlns="http://www.w3.org/1998/Math/MathML"> | ||
<ci> time </ci> | ||
</math> | ||
</dataGenerator> | ||
<dataGenerator id="report_0_0_1" name="a"> | ||
<listOfVariables> | ||
<variable id="a" target="/sbml:sbml/sbml:model/descendant::*[@id='a']" taskReference="task1" modelReference="mod1"/> | ||
</listOfVariables> | ||
<math xmlns="http://www.w3.org/1998/Math/MathML"> | ||
<ci> a </ci> | ||
</math> | ||
</dataGenerator> | ||
</listOfDataGenerators> | ||
<listOfOutputs> | ||
<report id="report_0"> | ||
<listOfDataSets> | ||
<dataSet id="report_0_0_0_dataset" label="time" dataReference="report_0_0_0"/> | ||
<dataSet id="report_0_0_1_dataset" label="a" dataReference="report_0_0_1"/> | ||
</listOfDataSets> | ||
</report> | ||
</listOfOutputs> | ||
</sedML> |
Oops, something went wrong.