From 1c9b303a8116ff6d2913149ea0242c9ca11160f8 Mon Sep 17 00:00:00 2001 From: Evgeny Metelkin Date: Sat, 25 Nov 2023 22:18:43 +0200 Subject: [PATCH] deleteNS --- TODO.md | 15 ++++++--------- package.json | 2 +- src/container/actions.js | 12 ++++++++++++ src/sbml-export/index.js | 8 ++++++++ test/container/container-actions.js | 26 ++++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 10 deletions(-) diff --git a/TODO.md b/TODO.md index 7127b168..436a7b20 100644 --- a/TODO.md +++ b/TODO.md @@ -30,30 +30,27 @@ ## bugs +- highlight multiline comments in Heta dictionary and array (with/without comma) +- multiple single-line comments in dict result in error + ## features -- write reusable `Build` class +- atStart to exports: Matlab, DBSolve - checking legal functions inside Expressions and functionDefinition - `#defineFunction`: circular dependences within functions, internal functions, different exports, functionDef vs units -- calculate units for pow function +- write reusable `Build` class - remove unnecessary rules in export - checking units for diff eq - check unit consistency for Species: amount/area if compartment is area - AnyUnit for zero numbers -- highlight multiline comments in Heta dictionary and array (with/without comma) -- atStart to exports: Matlab, DBSolve - remove `isAmount`, `compartment` properties from `@Reaction` ## ideas - generation of 'platform.yml' by `heta init` -- deprecated `include` statement -- `#move`, `#moveNS` -- `#deleteNS` action - `#move`, `#moveNS` -- remove support of `include` statement is deprecated, use `#include` action (v0.7.0) +- `include` statement is deprecated, use `#include` action (v0.8.0) - check file format for modules -- syntax highlight in web - add "ignoreCompartment" property in Species - do not translate base units in SBML export like second => _second - automatic creation of modifiers in SBML diff --git a/package.json b/package.json index f842e471..fc1abfeb 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Programming platform for Quantitative Systems Pharmacology modeling in NodeJS", "main": "src/index.js", "scripts": { - "test:dev": "mocha test/check-units/calc-unit --config=./test/.mocharc.json", + "test:dev": "mocha test/container/container-actions --config=./test/.mocharc.json", "test": "mocha test --config=./test/.mocharc.json", "jsdoc": "jsdoc -r -c .jsdoc.json --readme api-references.md -d docs/dev src", "test:cov": "nyc --reporter=lcov npm run test", diff --git a/src/container/actions.js b/src/container/actions.js index 0a2c5bde..fce115a0 100644 --- a/src/container/actions.js +++ b/src/container/actions.js @@ -323,6 +323,18 @@ Container.prototype.setNS = function(q = {}){ this.logger.info(`Namespace "${space}" was set as "${typeString}"`); }; +Container.prototype.deleteNS = function(_q = {}) { + let q = Object.assign({space: 'nameless'}, _q); + if (this.namespaceStorage.has(q.space)) { + this.namespaceStorage.delete(q.space); + this.logger.info(`Namespace "${q.space}" was deleted.`); + } else { + this.logger.error(`Namespace "${q.space}" is not found.`); + } + + return this; +}; + /** * Clones and rename all components to another space. * diff --git a/src/sbml-export/index.js b/src/sbml-export/index.js index ffd9e923..a7f6332d 100644 --- a/src/sbml-export/index.js +++ b/src/sbml-export/index.js @@ -72,6 +72,14 @@ class SBMLExport extends AbstractExport { } else { try { listOfUnitDefinitions = ns.getUniqueUnits() + /* + .filter((units) => { + return units.length !== 1 + || legalUnits.indexOf(units[0].kind) < 0 + || units[0].exponent !== 1 + || units[0].multiplier !== 1; + }) + */ .map((units) => { return units .toXmlUnitDefinition(legalUnits, { nameStyle: 'string', simplify: true }); diff --git a/test/container/container-actions.js b/test/container/container-actions.js index e31b4fac..a29e6896 100644 --- a/test/container/container-actions.js +++ b/test/container/container-actions.js @@ -215,3 +215,29 @@ describe('Unit tests for Container load', () => { c.logger.resetErrors(); }); }); + +describe('Test deleting NS', () => { + let c = new Container(); + + it('Create NS', () => { + c.setNS({space: 'one'}); + c.setNS({space: 'two'}); + + expect(c.namespaceStorage.size).to.equal(3); + }); + + it('Delete NS one', () => { + c.deleteNS({space: 'one'}); + + expect(c.namespaceStorage.size).to.equal(2); + }); + + it('Delete not existed NS', () => { + c.deleteNS({space: 'one'}); + c.deleteNS({space: 'three'}); + + expect(c.logger.hasErrors).to.be.true; + expect(c.namespaceStorage.size).to.equal(2); + }); + +});