SBMLToolkit.jl icon indicating copy to clipboard operation
SBMLToolkit.jl copied to clipboard

Flag to drop units

Open oxinabox opened this issue 6 months ago • 5 comments

Is your feature request related to a problem? Please describe. I am trying to import a SMBL file. In particular this one

When I do so i get an error:

julia> using OrdinaryDiffEq
       using SBMLToolkit

julia> 
       odesys = readSBML(model_file(), ODESystemImporter())
┌ Error: SBML reported error: The units of the 'math' formula in a <kineticLaw> definition are expected to be the equivalent of _substance per time_.
│  Expected units are mole (exponent = 1, multiplier = 1, scale = -3), second (exponent = -1, multiplier = 1, scale = 0) but the units returned by the <math> expression in the <kineticLaw> (from the <reaction> with id 'vENO') are second (exponent = -1, multiplier = 1, scale = 0), litre (exponent = 1, multiplier = 1, scale = 0).
└ @ SBML ~/.julia/packages/SBML/9eaHi/src/utils.jl:390
┌ Error: SBML reported error: The units of the 'math' formula in a <kineticLaw> definition are expected to be the equivalent of _substance per time_.
│  Expected units are mole (exponent = 1, multiplier = 1, scale = -3), second (exponent = -1, multiplier = 1, scale = 0) but the units returned by the <math> expression in the <kineticLaw> (from the <reaction> with id 'vDAHPS') are mole (exponent = -4.29497e+09, multiplier = 0, scale = 0), second (exponent = -1, multiplier = 1, scale = 0), litre (exponent = -4.29497e+09, multiplier = 1, scale = 0).
└ @ SBML ~/.julia/packages/SBML/9eaHi/src/utils.jl:390
┌ Error: SBML reported error: The units of the 'math' formula in a <kineticLaw> definition are expected to be the equivalent of _substance per time_.
│  Expected units are mole (exponent = 1, multiplier = 1, scale = -3), second (exponent = -1, multiplier = 1, scale = 0) but the units returned by the <math> expression in the <kineticLaw> (from the <reaction> with id 'vPDH') are mole (exponent = -2.14748e+09, multiplier = 0, scale = 0), second (exponent = -1, multiplier = 1, scale = 0), litre (exponent = nan, multiplier = 1, scale = 0).
└ @ SBML ~/.julia/packages/SBML/9eaHi/src/utils.jl:390
ERROR: Setting of level and version did not succeed
Stacktrace:
  [1] get_error_messages(doc::Ptr{…}, error::ErrorException, report_severities::Vector{…}, throw_severities::Vector{…})
    @ SBML ~/.julia/packages/SBML/9eaHi/src/utils.jl:399
  [2] check_errors
    @ ~/.julia/packages/SBML/9eaHi/src/utils.jl:412 [inlined]
  [3] (::SBML.var"#16#17"{Int64, Int64, Vector{String}, Vector{String}})(doc::Ptr{Nothing})
    @ SBML ~/.julia/packages/SBML/9eaHi/src/converters.jl:15
  [4] #50
    @ ~/.julia/packages/SBMLToolkit/LdVcf/src/utils.jl:101 [inlined]
  [5] _readSBML(symbol::Symbol, fn::String, sbml_conversion::SBMLToolkit.var"#50#51", report_severities::Vector{…}, throw_severities::Vector{…})
    @ SBML ~/.julia/packages/SBML/9eaHi/src/readsbml.jl:183
  [6] readSBML(fn::String, sbml_conversion::Function; report_severities::Vector{String}, throw_severities::Vector{String})
    @ SBML ~/.julia/packages/SBML/9eaHi/src/readsbml.jl:229
  [7] readSBML(fn::String, sbml_conversion::Function)
    @ SBML ~/.julia/packages/SBML/9eaHi/src/readsbml.jl:222
  [8] readSBML
    @ ~/.julia/packages/SBMLToolkit/LdVcf/src/systems.jl:19 [inlined]
  [9] #readSBML#1
    @ ~/.julia/packages/SBMLToolkit/LdVcf/src/systems.jl:30 [inlined]
 [10] readSBML
    @ ~/.julia/packages/SBMLToolkit/LdVcf/src/systems.jl:29 [inlined]
 [11] readSBML(sbmlfile::String, ::ODESystemImporter; include_zero_odes::Bool, kwargs::@Kwargs{})
    @ SBMLToolkit ~/.julia/packages/SBMLToolkit/LdVcf/src/systems.jl:42
 [12] readSBML(sbmlfile::String, ::ODESystemImporter)
    @ SBMLToolkit ~/.julia/packages/SBMLToolkit/LdVcf/src/systems.jl:40
 [13] top-level scope
    @ ~/repos/POC_kinetic/test/script.jl:5
Some type information was truncated. Use `show(err)` to see complete types.

Now I know that that file is internally consistent enough to be workable. because it works with MEWpy's load_ODEModel. Which I suspect just discards unit information.

The file quiet likely is a bit messed up. Most bio data is a mess after all

Describe the solution you’d like

I would like a flag to discard units. readSBML(file, ODESystemImporter; discard_units=true)

Describe alternatives We could instead have flag that controls if bad units gives an error, or warns and then falls back to no units, or silently falls back to no units.

oxinabox avatar Aug 13 '24 07:08 oxinabox