Closed hgscott closed 6 months ago
It looks like I can validate files in COBRApy- so I don't have to install any new tools: https://cobrapy.readthedocs.io/en/latest/autoapi/cobra/io/sbml/index.html#cobra.io.sbml.validate_sbml_model
It works- when I run the following code:
cobra.io.sbml.validate_sbml_model('model.xml')
I get the following output:
SBML errors in validation, check error log for details.
COBRA errors in validation, check error log for details.
(<Model at 0x1645ef970>, {'SBML_FATAL': [], 'SBML_ERROR': ["E0 (Error): SBML component consistency (fbc, L615); Chemical formula must be string; The value of attribute 'fbc:chemicalFormula' on the SBML <species> object must be set to a string consisting only of atomic names or user defined compounds and their occurrence.\nReference: L3V1 Fbc V3 Section 3.4\n Encountered 'n' when expecting a capital letter. The chemicalFormula 'null' has incorrect syntax.\n", "E1 (Error): SBML component consistency (fbc, L5679); Chemical formula must be string; The value of attribute 'fbc:chemicalFormula' on the SBML <species> object must be set to a string consisting only of atomic names or user defined compounds and their occurrence.\nReference: L3V1 Fbc V3 Section 3.4\n Encountered 'n' when expecting a capital letter. The chemicalFormula 'null' has incorrect syntax.\n", "E2 (Error): SBML component consistency (fbc, L7148); Chemical formula must be string; The value of attribute 'fbc:chemicalFormula' on the SBML <species> object must be set to a string consisting only of atomic names or user defined compounds and their occurrence.\nReference: L3V1 Fbc V3 Section 3.4\n Encountered 'n' when expecting a capital letter. The chemicalFormula 'null' has incorrect syntax.\n", "E3 (Error): SBML component consistency (fbc, L12950); Chemical formula must be string; The value of attribute 'fbc:chemicalFormula' on the SBML <species> object must be set to a string consisting only of atomic names or user defined compounds and their occurrence.\nReference: L3V1 Fbc V3 Section 3.4\n Encountered 'n' when expecting a capital letter. The chemicalFormula 'nan' has incorrect syntax.\n", "E4 (Error): SBML component consistency (fbc, L13740); Chemical formula must be string; The value of attribute 'fbc:chemicalFormula' on the SBML <species> object must be set to a string consisting only of atomic names or user defined compounds and their occurrence.\nReference: L3V1 Fbc V3 Section 3.4\n Encountered 'n' when expecting a capital letter. The chemicalFormula 'null' has incorrect syntax.\n", 'E5 (Error): XML content (core, L35556); Attribute type mismatch; Data type mismatch for the value of an attribute. The http://www.sbml.org/sbml/level3/version1/core reaction reversible attribute must have a value of either "true" or "false" (all lowercase). The numbers "1" (true) and "0" (false) are also allowed, but not preferred. For more information, see: http://www.w3.org/TR/xmlschema-2/#boolean.\n', "E6 (Error): SBML component consistency (core, L35556); Invalid attribute for a Reaction object; A <reaction> object must have the required attributes 'id', 'reversible' and 'fast', and may have the optional attributes 'metaid', 'sboTerm', 'name' and 'compartment'. No other attributes from the SBML Level 3 Core namespace are permitted on a Reaction object.\nReference: L3V1 Section 4.11\n The required attribute 'reversible' is missing from the <reaction> with the id 'R_rxn08192_c0'.\n", "E7 (Error): SBML component consistency (fbc, L615); Chemical formula must be string; The value of attribute 'fbc:chemicalFormula' on the SBML <species> object must be set to a string consisting only of atomic names or user defined compounds and their occurrence.\nReference: L3V1 Fbc V3 Section 3.4\n Encountered 'n' when expecting a capital letter. The chemicalFormula 'null' has incorrect syntax.\n", "E8 (Error): SBML component consistency (fbc, L5679); Chemical formula must be string; The value of attribute 'fbc:chemicalFormula' on the SBML <species> object must be set to a string consisting only of atomic names or user defined compounds and their occurrence.\nReference: L3V1 Fbc V3 Section 3.4\n Encountered 'n' when expecting a capital letter. The chemicalFormula 'null' has incorrect syntax.\n", "E9 (Error): SBML component consistency (fbc, L7148); Chemical formula must be string; The value of attribute 'fbc:chemicalFormula' on the SBML <species> object must be set to a string consisting only of atomic names or user defined compounds and their occurrence.\nReference: L3V1 Fbc V3 Section 3.4\n Encountered 'n' when expecting a capital letter. The chemicalFormula 'null' has incorrect syntax.\n", "E10 (Error): SBML component consistency (fbc, L12950); Chemical formula must be string; The value of attribute 'fbc:chemicalFormula' on the SBML <species> object must be set to a string consisting only of atomic names or user defined compounds and their occurrence.\nReference: L3V1 Fbc V3 Section 3.4\n Encountered 'n' when expecting a capital letter. The chemicalFormula 'nan' has incorrect syntax.\n", "E11 (Error): SBML component consistency (fbc, L13740); Chemical formula must be string; The value of attribute 'fbc:chemicalFormula' on the SBML <species> object must be set to a string consisting only of atomic names or user defined compounds and their occurrence.\nReference: L3V1 Fbc V3 Section 3.4\n Encountered 'n' when expecting a capital letter. The chemicalFormula 'null' has incorrect syntax.\n", "E12 (Error): SBML component consistency (core, L35556); Invalid attribute for a Reaction object; A <reaction> object must have the required attributes 'id', 'reversible' and 'fast', and may have the optional attributes 'metaid', 'sboTerm', 'name' and 'compartment'. No other attributes from the SBML Level 3 Core namespace are permitted on a Reaction object.\nReference: L3V1 Section 4.11\n The required attribute 'reversible' is missing from the <reaction> with the id 'R_rxn08192_c0'.\n"], 'SBML_SCHEMA_ERROR': [], 'SBML_WARNING': [], 'COBRA_FATAL': [], 'COBRA_ERROR': ["'' is not a valid SBML 'SId'."], 'COBRA_WARNING': [], 'COBRA_CHECK': []})
I wrote the following unittest:
class TestValidSBML(unittest.TestCase):
def test_valid_sbml(self):
# Validate the SBML file with COBRApy
results = cobra.io.validate_sbml_model('model.xml')
# Check that the SBML file is valid
# By checking that there are no errors in the 'SBML_ERROR' key
# of the second element of the results tuple. The first element
# is the model itself.
# A valid file should have 0 errors.
self.assertEqual(0, len(results[1]['SBML_ERROR']))
Here's what the results
object looks like:
It doesn't look like there's a single boolean for valid or not, so I went by if there are no errors or not.
When the test runs on GitHub actions, this is the summary:
Is there a way I can make the failure more informative?
I ran my newest model (made using the MS2 app) through the online validator, and got the same errors about formulas:
No update from KBase on the ticket.
I already have a test in my own workflow that checks if the SBML file is valid, and the bug on the KBase side is small enough that I can ix those issues as needed.
I opened an issue on the KBase Jira: https://kbase-jira.atlassian.net/browse/PUBLIC-2581
It would be nice to add SBML validation to the Action workflow.