From d2c33771c974d3b68b4514e0206a50baaba659f0 Mon Sep 17 00:00:00 2001 From: Evgeny Metelkin Date: Fri, 24 Nov 2023 14:07:47 +0200 Subject: [PATCH] fix dot export for abstract namespaces --- TODO.md | 3 --- bin/heta-build.js | 4 ++-- src/dot-export/index.js | 25 ++++++++++++------------- src/templates/dot.dot.njk | 2 +- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/TODO.md b/TODO.md index 6f9def8d..e2b59b8c 100644 --- a/TODO.md +++ b/TODO.md @@ -30,9 +30,6 @@ ## bugs -- wrong figures for abstract namespaces in DOT: no references to compartment -- nothing is dislayed if you use wrong cli command: `heta builds` - ## features - write reusable `Build` class diff --git a/bin/heta-build.js b/bin/heta-build.js index a7dc18ac..7207e0bc 100644 --- a/bin/heta-build.js +++ b/bin/heta-build.js @@ -5,7 +5,7 @@ const fs = require('fs'); const path = require('path'); const { Builder } = require('../src/builder'); const { load } = require('js-yaml'); // https://www.npmjs.com/package/js-yaml -const _ = require('lodash'); +const _merge = require('lodash/merge'); const semver = require('semver'); const { version, bugs } = require('../package'); const colors = require('colors'); @@ -100,7 +100,7 @@ program }; // === update declaration === - _.merge(declaration, CLIDeclaration); + _merge(declaration, CLIDeclaration); // === wrong version throws, if no version stated than skip === let satisfiesVersion = declaration.builderVersion diff --git a/src/dot-export/index.js b/src/dot-export/index.js index 53082cf8..aceb2f92 100644 --- a/src/dot-export/index.js +++ b/src/dot-export/index.js @@ -51,20 +51,19 @@ class DotExport extends AbstractExport{ .forEach((comp) => clustersDict[comp.id] = []); ns.selectByInstanceOf('Process') .forEach((proc) => { - let substrates = proc.actors - .filter((x) => x.stoichiometry < 0); - let hasFirstSubstrate = substrates.length > 0 - && substrates[0].targetObj !== undefined - && substrates[0].targetObj.compartment !== undefined; - if (hasFirstSubstrate) { - let mainComp = substrates[0].targetObj.compartment; - clustersDict[mainComp].push(proc); - } else { - clustersDict['_'].push(proc); - } + let substrates = proc.actors.filter((x) => x.stoichiometry < 0); + // push records + proc.actors.forEach((actor) => { + let record = ns.get(actor.target) || { id: actor.target }; // use fake record + let compartmentId = record.compartment || '_'; + clustersDict[compartmentId]?.push(record) || (clustersDict[compartmentId] = [record]); + }); + // push process + let compartmentOfFirstSubstrate = ns.get(substrates[0]?.target)?.compartment || '_'; + clustersDict[compartmentOfFirstSubstrate]?.push(proc); }); + /* display all records ns.selectByInstanceOf('Record') - .filter((rec) => rec.isDynamic) .forEach((rec) => { if (rec.compartment !== undefined) { clustersDict[rec.compartment].push(rec); @@ -72,7 +71,7 @@ class DotExport extends AbstractExport{ clustersDict['_'].push(rec); } }); - + */ return { ns, clustersDict diff --git a/src/templates/dot.dot.njk b/src/templates/dot.dot.njk index c9a974a3..55f70b9b 100644 --- a/src/templates/dot.dot.njk +++ b/src/templates/dot.dot.njk @@ -20,7 +20,7 @@ digraph {{ ns.spaceName }} { tooltip="{{ key }}" // {%- for component in val %} - {%- if component.instanceOf('Process') %} + {%- if component.instanceOf and component.instanceOf('Process') %} {{ component.id }} [shape=circle,width=.1,height=.1,label=""] // xlabel="{{ component.id }}" {%- else %} {{ component.id }} [shape=box]