Skip to content

Commit

Permalink
fix SBML parse: issue with empty reactants
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgeny Metelkin committed Feb 9, 2024
1 parent 0c5b4f9 commit 5a5121b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 33 deletions.
6 changes: 2 additions & 4 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,17 @@
[ ] dat (DBSolve)
[ ] ModelingToolkit (Julia)
[ ] PGF and TikZ
[ ] Statistics
[x] Statistics

## bugs


## features

- check and warning if core component was replaced
- checking units for diff eq
- AnyUnit for zero numbers
- atStart to exports: Matlab, DBSolve
- checking legal functions inside Expressions and functionDefinition
- `#defineFunction`: different exports, functionDef vs units
- `#defineFunction`: different exports
- write reusable `Build` class

## ideas
Expand Down
4 changes: 2 additions & 2 deletions export-formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,8 @@ _Conversion to SBML's MathML_
|`t`|`<csymbol definitionURL="http://www.sbml.org/sbml/symbols/time">t</csymbol>`|
|`a and b`|`<apply><and/>(a) (b)</apply>`|
|`a or b`|`<apply><or/>(a) (b)</apply>`|
|`a xor b`|`<apply><xor>(a) (b)</apply>`|
|`not a`|`<apply><not>(a)</apply>`|
|`a xor b`|`<apply><xor/>(a) (b)</apply>`|
|`not a`|`<apply><not/>(a)</apply>`|
|`b1 < b2 ? x : y`|`<piecewise><piece>(x)<apply><lt/>(b1) (b2)</apply></piece><otherwise>(y)</otherwise></piecewise>`|
|`piecewise(value1, cond1, value2, cond2, ..., otherwise)`|`<piecewise><piece>(value1) (cond1)</piece><piece>(value2) (cond2)</piece><otherwise>(otherwise)</otherwise></piecewise>`|
|`acos(x)`, `acot(x)`, `acsc(x)`,`asec(x)`, `asin(x)`, `atan(x)`, `cos(x)`, `cot(x)`, `csc(x)`, `sec(x)`, `sin(x)`, `tan(x)`|`<apply><arccos/>(x)</apply>`...|
40 changes: 13 additions & 27 deletions src/module-system/sbml-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,8 @@ function unitDefinitionToUnits(x){
*/
function functionDefinitionToQ(x){

let mathElement = x.elements
&& x.elements.find((y) => y.name === 'math');
let lambdaElement = mathElement.elements
&& mathElement.elements.find((y) => y.name === 'lambda');
let mathElement = x.elements?.find((y) => y.name === 'math');
let lambdaElement = mathElement?.elements?.find((y) => y.name === 'lambda');

// get argument ids
let args = lambdaElement.elements && lambdaElement.elements
Expand Down Expand Up @@ -239,12 +237,10 @@ function baseToQ(x){
let sboTerm = x.attributes?.sboTerm;
if (sboTerm !== undefined) q.aux.sboTerm = sboTerm;
// take only first notes
let notes = x.elements
&& x.elements.find((y) => y.name === 'notes');
let notes = x.elements?.find((y) => y.name === 'notes');
if (notes) q.notes = _toMarkdown(notes.elements);
// annotation
let annotation = x.elements
&& x.elements.find((y) => y.name === 'annotation');
let annotation = x.elements?.find((y) => y.name === 'annotation');
if (annotation) q.aux.annotation = _toAux(annotation.elements);

return q;
Expand Down Expand Up @@ -437,13 +433,10 @@ function reactionToQ(x){

q.class = 'Reaction';

let kineticLaw = x.elements
&& x.elements.find((y) => y.name === 'kineticLaw');
let kineticLaw = x.elements?.find((y) => y.name === 'kineticLaw');

// local parameters
let listOfParameters = kineticLaw
&& kineticLaw.elements
&& kineticLaw.elements.find((y) => y.name === 'listOfParameters');
let listOfParameters = kineticLaw?.elements?.find((y) => y.name === 'listOfParameters');
if (listOfParameters) {
let parameters = listOfParameters.elements
.filter((y) => y.name = 'parameter');
Expand All @@ -461,9 +454,7 @@ function reactionToQ(x){
});
}
// math
let math = kineticLaw
&& kineticLaw.elements
&& kineticLaw.elements.find((y) => y.name === 'math');
let math = kineticLaw?.elements?.find((y) => y.name === 'math');
if (math) {
let expr = _toMathExpr(math);
localConstTranslate.forEach((y) => {
Expand All @@ -484,9 +475,8 @@ function reactionToQ(x){
}

// products
let products = x.elements
&& x.elements.find((y) => y.name === 'listOfProducts');
if (products.elements !== undefined) {
let products = x.elements?.find((y) => y.name === 'listOfProducts');
if (products?.elements) {
var actors0 = products.elements
.filter((y) => y.name === 'speciesReference')
.map((y) => {
Expand All @@ -508,9 +498,8 @@ function reactionToQ(x){
}

// reactants
let reactants = x.elements
&& x.elements.find((y) => y.name === 'listOfReactants');
if (reactants.elements !== undefined) {
let reactants = x.elements?.find((y) => y.name === 'listOfReactants');
if (reactants?.elements) {
var actors1 = reactants.elements
.filter((y) => y.name === 'speciesReference')
.map((y) => {
Expand Down Expand Up @@ -643,11 +632,8 @@ function eventToQ(x){
let useValuesFromTriggerTime = x.attributes?.useValuesFromTriggerTime !== 'false';

// trigger
let trigger = x.elements
&& x.elements.find((y) => y.name === 'trigger');
let triggerMath = trigger
&& trigger.elements
&& trigger.elements.find((y) => y.name === 'math');
let trigger = x.elements?.find((y) => y.name === 'trigger');
let triggerMath = trigger?.elements?.find((y) => y.name === 'math');
if (triggerMath) {
switcher.trigger = _toMathExpr(triggerMath);
}
Expand Down

0 comments on commit 5a5121b

Please sign in to comment.