sbmlteam / libsbml

LibSBML is a native library for reading, writing and manipulating files and data streams containing the Systems Biology Markup Language (SBML). It offers language bindings for C, C++, C#, Java, JavaScript, MATLAB, Perl, PHP, Python, R and Ruby.
https://sbml.org/software/libsbml
Other
38 stars 28 forks source link

checkConsistency does not report undefined function from within another function #327

Closed avandecreme closed 10 months ago

avandecreme commented 1 year ago

Calling checkConsistency on a document will report references to undefined functions, for example with the following file:

<?xml version="1.0" encoding="UTF-8"?>
<sbml xmlns="http://www.sbml.org/sbml/level3/version2/core" level="3" version="2">
  <model timeUnits="second">
    <listOfCompartments>
      <compartment id="compartment" units="dimensionless" constant="false"/>
    </listOfCompartments>
    <listOfRules>
      <assignmentRule variable="compartment">
        <math xmlns="http://www.w3.org/1998/Math/MathML">
          <apply>
            <root/>
            <apply>
              <ci> undefined_function </ci>
            </apply>
          </apply>
        </math>
      </assignmentRule>
    </listOfRules>
  </model>
</sbml>

Running validateSBML will output:

line 8: (10214 [Error]) Outside of a <functionDefinition>, if a <ci> element is the first element within a MathML <apply>, then the <ci>'s value can only be chosen from the set of identifiers of <functionDefinition>s defined in the SBML model.
Reference: L3V2 Section 4.3.2
 The formula 'undefined_function()' in the math element of the <assignmentRule> uses 'undefined_function' which is not a function definition id.

However, if a functionDefinition references an undefined function, no such error is reported. Here is an example file:

<?xml version="1.0" encoding="UTF-8"?>
<sbml xmlns="http://www.sbml.org/sbml/level3/version2/core" level="3" version="2">
  <model timeUnits="second">
    <listOfFunctionDefinitions>
      <functionDefinition metaid="_tt" id="fd" name="ggh">
        <math xmlns="http://www.w3.org/1998/Math/MathML">
          <lambda>
            <bvar>
              <ci> x </ci>
            </bvar>
            <apply>
              <power/>
              <ci> x </ci>
              <apply>
                <ci> undefined_function </ci>
                <cn> 0.5 </cn>
              </apply>
            </apply>
          </lambda>
        </math>
      </functionDefinition>
    </listOfFunctionDefinitions>
  </model>
</sbml>

What do you think about checking function definitions as well for references to undefined functions?

skeating commented 1 year ago

Will sort this. Thanks for the catch.