dash-contextnet 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ node_modules/
2
+ # Built by `npm run build` (webpack); shipped in the wheel and sdist, not committed.
3
+ dash_contextnet/dash_contextnet.min.js
4
+ dash_contextnet/dash_contextnet.min.js.map
5
+ dash_contextnet/package-info.json
6
+ dist/
7
+ build/
8
+ *.egg-info/
9
+ __pycache__/
10
+ .pytest_cache/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,159 @@
1
+ Metadata-Version: 2.5
2
+ Name: dash-contextnet
3
+ Version: 0.2.0
4
+ Summary: Plotly Dash component for ContextNet: multi-compartment, condition-aware views of biological interaction networks (Cytoscape.js).
5
+ Project-URL: Homepage, https://github.com/bjoernoest/cytoscapejs_contextnet
6
+ Project-URL: Documentation, https://github.com/bjoernoest/cytoscapejs_contextnet/tree/main/python/dash_contextnet
7
+ Project-URL: Demo, https://bjoernoest.github.io/cytoscapejs_contextnet/
8
+ Project-URL: Issues, https://github.com/bjoernoest/cytoscapejs_contextnet/issues
9
+ Author: Bjoern Oest Hansen
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ License-File: dash_contextnet/THIRD_PARTY_LICENSES.txt
13
+ Keywords: bioinformatics,cytoscape,dash,expression,network,plotly,subcellular-localization
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Framework :: Dash
16
+ Classifier: Intended Audience :: Science/Research
17
+ Classifier: Programming Language :: JavaScript
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
20
+ Classifier: Topic :: Scientific/Engineering :: Visualization
21
+ Requires-Python: >=3.10
22
+ Requires-Dist: dash>=2.9
23
+ Requires-Dist: typing-extensions>=4.1
24
+ Provides-Extra: test
25
+ Requires-Dist: playwright>=1.40; extra == 'test'
26
+ Requires-Dist: pytest>=7; extra == 'test'
27
+ Description-Content-Type: text/markdown
28
+
29
+ # dash-contextnet
30
+
31
+ A [Plotly Dash](https://dash.plotly.com/) component for [ContextNet](https://github.com/bjoernoest/cytoscapejs_contextnet) (`cytoscape-contextnet`), a Cytoscape.js extension for biological interaction networks: proteins in several (sub)cellular compartments, expression-driven sub-networks, orthogroups across species, and evidence layers.
32
+
33
+ ```bash
34
+ pip install dash-contextnet
35
+ ```
36
+
37
+ The package ships one JavaScript bundle with Cytoscape.js, cytoscape-fcose, cytoscape-bubblesets and ContextNet, so nothing else needs to be installed, built or copied into `assets/`. Python ≥ 3.10 and Dash ≥ 2.9 (tested with 2.9.3 and 4.5.2, React 16, 18 and 19).
38
+
39
+ Live demo of the JavaScript library: <https://bjoernoest.github.io/cytoscapejs_contextnet/>
40
+
41
+ ## Minimal app
42
+
43
+ ```python
44
+ from dash import Dash, Input, Output, dcc, html
45
+ from dash_contextnet import ContextNet
46
+
47
+ network = {
48
+ "compartments": [{"id": "cytosol"}, {"id": "nucleus"}],
49
+ "nodes": [
50
+ {"id": "ABI1", "compartments": ["cytosol", "nucleus"]},
51
+ {"id": "SnRK2.6", "compartments": ["cytosol"]},
52
+ {"id": "ABF2", "compartments": ["nucleus"]},
53
+ ],
54
+ "edges": [{"source": "ABI1", "target": "SnRK2.6"}, {"source": "SnRK2.6", "target": "ABF2"}],
55
+ "expression": {
56
+ "metric": "log2fc",
57
+ "values": {"ABI1": {"ABA": 2.1}, "SnRK2.6": {"ABA": 0.2}, "ABF2": {"ABA": 1.6}},
58
+ },
59
+ }
60
+
61
+ app = Dash(__name__)
62
+ app.layout = html.Div([
63
+ dcc.Dropdown(["pie", "clones", "bubbles"], "pie", id="mode", clearable=False),
64
+ dcc.Checklist(["ABA"], [], id="condition"),
65
+ ContextNet(id="net", data=network, style={"height": "500px"}),
66
+ html.Pre(id="selected"),
67
+ ])
68
+
69
+
70
+ @app.callback(Output("net", "compartment_mode"), Input("mode", "value"))
71
+ def set_mode(mode):
72
+ return mode
73
+
74
+
75
+ @app.callback(Output("net", "context"), Input("condition", "value"))
76
+ def set_context(conditions):
77
+ # Proteins with |log2FC| >= 1 under ABA, plus linkers between them.
78
+ return {"condition": "ABA", "threshold": 1, "keepLinkers": True} if conditions else None
79
+
80
+
81
+ @app.callback(Output("selected", "children"), Input("net", "selection"))
82
+ def show_selection(selection):
83
+ return ", ".join((selection or {}).get("proteins", [])) or "Click a node."
84
+
85
+
86
+ if __name__ == "__main__":
87
+ app.run(debug=True)
88
+ ```
89
+
90
+ A complete app with every control (datasets, modes, context with p-value filter, evidence layers, background territories, bubbles, metrics, PNG/SVG export) is in [`examples/dash/`](https://github.com/bjoernoest/cytoscapejs_contextnet/tree/main/examples/dash) of the repository.
91
+
92
+ ## Props
93
+
94
+ The input props follow the ContextNet JavaScript API ([manual](https://github.com/bjoernoest/cytoscapejs_contextnet/blob/main/docs/MANUAL.md)). Keys *inside* dict props keep the camelCase names of that API (`keepLinkers`, `maxP`), so the manual applies as written.
95
+
96
+ | Prop | ContextNet call | Value |
97
+ | --- | --- | --- |
98
+ | `data` | `setData` | `NetworkData`: `nodes`, `edges`, optional `compartments`, `species`, `speciesGroups`, `orthogroups`, `expression` |
99
+ | `compartment_mode` | `setCompartmentMode` | `'pie'` (default), `'clones'`, `'bubbles'`, `'orthogroups'`, `'orthogroup-nodes'` |
100
+ | `context` | `contextualize` / `clearContext` | `ContextOptions`: `condition`, `threshold`, `direction`, `maxP`, `unmeasured`, `keepLinkers`, `minActiveNeighbors`, `minEdgeWeight`, `hideIsolated`, `display`; `None` = whole network |
101
+ | `layout` | `layout` | `LayoutOptions`: `algorithm` (`'fcose'`, `'anchored'`), `anchored`, `scope`, `cache`, `fit`, `fcose`, `incremental` |
102
+ | `edge_layers` | `setEdgeLayers` | list of `EdgeInput.layer` values; `None` or `[]` = all |
103
+ | `edge_view` | `setEdgeView` | `EdgeViewOptions`: `style` (`'split'`, `'merged'`), `filter` (orthogroup-nodes mode) |
104
+ | `bubble_by`, `bubble_min_species`, `bubble_avoid` | `setBubbleBy(key, {minSpecies, avoid})` | `'compartment'` or an annotation key; `None` = no bubbles |
105
+ | `hints` | `setCompartmentHints` | `'territories'`, `'bubbles'`, `True`, a `CompartmentHintOptions` dict, or `None` |
106
+ | `semantic_zoom` | `setSemanticZoom` | `True`, `{'zoom', 'maxMembers'}` or `None` |
107
+ | `keyboard`, `overlay_click` | `enableKeyboard`, `enableOverlayClick` | default `True` |
108
+ | `stylesheet`, `cytoscape_options` | constructor | extra Cytoscape styles / core options, read once |
109
+ | `style`, `className` | | of the container; it needs a height (default 600px) |
110
+
111
+ Whenever data, mode, edge layers, edge view, context or layout options change, the layout runs again (with the `layout` options; `{'incremental': True}` keeps nodes close to where they were). Updates never overlap: changes that arrive during a layout are applied after it.
112
+
113
+ Output props, written by the component:
114
+
115
+ | Prop | Content |
116
+ | --- | --- |
117
+ | `selection` | `{'proteins': [...], 'nodeIds': [...], 'source': 'click' \| 'keyboard' \| 'search' \| 'api'}` on every change. Also an input: set it from Python to select proteins or nodes. |
118
+ | `network_info` | `mode`, `conditions`, `metric`, `overlayKeys`, `annotationKeys`, `layers`, `shownLayers`, `units`, `warnings`, `context` (the context statistics or `None`), `visible` (`nodes`, `edges`). Use it to fill dropdowns. |
119
+ | `metrics` | `net.metrics()` after every layout, only with `compute_metrics=True` (edge crossings are slow on large networks). |
120
+ | `last_event` | The last ContextNet event, `{'type', 'time', ...payload}`: `data`, `mode`, `context` (with `stats`), `layout`, `overlay`, `edgeview`, `layers`, `select`, `expand`, `collapse`, and `tap` (with `id` and `info`, the `info()` of the tapped node or edge). |
121
+ | `error` | Messages of the last update that failed (e.g. an unknown overlay key), else `None`. The rest of the update is still applied. |
122
+
123
+ ### Export
124
+
125
+ Set `export_request` to `{'format': 'png' or 'svg', 'filename': ..., 'options': {...}}` (`options` are ContextNet `ExportOptions`: `scale`, `padding`, `background`, `labels`, `legend`, `fontSize`, `title`, `description`). The component calls `exportPng` / `exportSvg`, writes the file to `export_result` and resets `export_request` to `None`. `export_result` has the keys of `dcc.Download` (`content`, `filename`, `base64`, `type`, plus the `request`), so it can be passed straight on:
126
+
127
+ ```python
128
+ @app.callback(Output("net", "export_request"), Input("png", "n_clicks"), prevent_initial_call=True)
129
+ def export(_):
130
+ return {"format": "png", "filename": "network.png", "options": {"scale": 3}}
131
+
132
+
133
+ @app.callback(Output("download", "data"), Input("net", "export_result"), prevent_initial_call=True)
134
+ def download(result):
135
+ return result # dcc.Download(id="download") in the layout
136
+ ```
137
+
138
+ ## Notes
139
+
140
+ - Do not put `dash-cytoscape` and this component on the same page expecting them to share a graph: each bundles its own Cytoscape.js, and ContextNet builds and owns its elements.
141
+ - Large networks: ContextNet handles a few thousand nodes; keep `compute_metrics` off and prefer `context` over sending a smaller `data`.
142
+
143
+ ## Development
144
+
145
+ The component lives in `python/dash_contextnet/` of the ContextNet repository. Building needs Node ≥ 20.19 and a Python environment with `ci/requirements-build.txt` (Dash is pinned there, because the generated `dash_contextnet/ContextNet.py` depends on the generator's version). The scripts in `ci/` are what CI runs:
146
+
147
+ ```bash
148
+ pip install -r ci/requirements-build.txt
149
+ ci/build.sh # library, webpack bundle, generated Python class, wheel + sdist in dist/, twine check
150
+ ci/test.sh # installs dist/*.whl[test] and runs the tests against it (DASH_VERSION=2.9.3 for the oldest Dash)
151
+ ```
152
+
153
+ `ci/build.sh` fails when the committed generated files (`ContextNet.py`, `_imports_.py`, `metadata.json`, `THIRD_PARTY_LICENSES.txt`) differ from what the build produces; commit them after changing the component. The bundle build writes `THIRD_PARTY_LICENSES.txt` from the modules that end up in the bundle and fails if one of them has a licence other than MIT, ISC, BSD or Apache-2.0.
154
+
155
+ For quick iterations: `npm run build:js -- --mode development` (seconds instead of about a minute), `pip install -e ".[test]"`, `pytest`.
156
+
157
+ ## Licence
158
+
159
+ MIT. The bundled libraries (Cytoscape.js, cytoscape-fcose, cose-base, layout-base, cytoscape-bubblesets, cytoscape-layers, bubblesets-js, lodash.throttle, prop-types) are MIT-licensed; their notices are in `dash_contextnet/THIRD_PARTY_LICENSES.txt`, which is included in the wheel and the sdist.
@@ -0,0 +1,131 @@
1
+ # dash-contextnet
2
+
3
+ A [Plotly Dash](https://dash.plotly.com/) component for [ContextNet](https://github.com/bjoernoest/cytoscapejs_contextnet) (`cytoscape-contextnet`), a Cytoscape.js extension for biological interaction networks: proteins in several (sub)cellular compartments, expression-driven sub-networks, orthogroups across species, and evidence layers.
4
+
5
+ ```bash
6
+ pip install dash-contextnet
7
+ ```
8
+
9
+ The package ships one JavaScript bundle with Cytoscape.js, cytoscape-fcose, cytoscape-bubblesets and ContextNet, so nothing else needs to be installed, built or copied into `assets/`. Python ≥ 3.10 and Dash ≥ 2.9 (tested with 2.9.3 and 4.5.2, React 16, 18 and 19).
10
+
11
+ Live demo of the JavaScript library: <https://bjoernoest.github.io/cytoscapejs_contextnet/>
12
+
13
+ ## Minimal app
14
+
15
+ ```python
16
+ from dash import Dash, Input, Output, dcc, html
17
+ from dash_contextnet import ContextNet
18
+
19
+ network = {
20
+ "compartments": [{"id": "cytosol"}, {"id": "nucleus"}],
21
+ "nodes": [
22
+ {"id": "ABI1", "compartments": ["cytosol", "nucleus"]},
23
+ {"id": "SnRK2.6", "compartments": ["cytosol"]},
24
+ {"id": "ABF2", "compartments": ["nucleus"]},
25
+ ],
26
+ "edges": [{"source": "ABI1", "target": "SnRK2.6"}, {"source": "SnRK2.6", "target": "ABF2"}],
27
+ "expression": {
28
+ "metric": "log2fc",
29
+ "values": {"ABI1": {"ABA": 2.1}, "SnRK2.6": {"ABA": 0.2}, "ABF2": {"ABA": 1.6}},
30
+ },
31
+ }
32
+
33
+ app = Dash(__name__)
34
+ app.layout = html.Div([
35
+ dcc.Dropdown(["pie", "clones", "bubbles"], "pie", id="mode", clearable=False),
36
+ dcc.Checklist(["ABA"], [], id="condition"),
37
+ ContextNet(id="net", data=network, style={"height": "500px"}),
38
+ html.Pre(id="selected"),
39
+ ])
40
+
41
+
42
+ @app.callback(Output("net", "compartment_mode"), Input("mode", "value"))
43
+ def set_mode(mode):
44
+ return mode
45
+
46
+
47
+ @app.callback(Output("net", "context"), Input("condition", "value"))
48
+ def set_context(conditions):
49
+ # Proteins with |log2FC| >= 1 under ABA, plus linkers between them.
50
+ return {"condition": "ABA", "threshold": 1, "keepLinkers": True} if conditions else None
51
+
52
+
53
+ @app.callback(Output("selected", "children"), Input("net", "selection"))
54
+ def show_selection(selection):
55
+ return ", ".join((selection or {}).get("proteins", [])) or "Click a node."
56
+
57
+
58
+ if __name__ == "__main__":
59
+ app.run(debug=True)
60
+ ```
61
+
62
+ A complete app with every control (datasets, modes, context with p-value filter, evidence layers, background territories, bubbles, metrics, PNG/SVG export) is in [`examples/dash/`](https://github.com/bjoernoest/cytoscapejs_contextnet/tree/main/examples/dash) of the repository.
63
+
64
+ ## Props
65
+
66
+ The input props follow the ContextNet JavaScript API ([manual](https://github.com/bjoernoest/cytoscapejs_contextnet/blob/main/docs/MANUAL.md)). Keys *inside* dict props keep the camelCase names of that API (`keepLinkers`, `maxP`), so the manual applies as written.
67
+
68
+ | Prop | ContextNet call | Value |
69
+ | --- | --- | --- |
70
+ | `data` | `setData` | `NetworkData`: `nodes`, `edges`, optional `compartments`, `species`, `speciesGroups`, `orthogroups`, `expression` |
71
+ | `compartment_mode` | `setCompartmentMode` | `'pie'` (default), `'clones'`, `'bubbles'`, `'orthogroups'`, `'orthogroup-nodes'` |
72
+ | `context` | `contextualize` / `clearContext` | `ContextOptions`: `condition`, `threshold`, `direction`, `maxP`, `unmeasured`, `keepLinkers`, `minActiveNeighbors`, `minEdgeWeight`, `hideIsolated`, `display`; `None` = whole network |
73
+ | `layout` | `layout` | `LayoutOptions`: `algorithm` (`'fcose'`, `'anchored'`), `anchored`, `scope`, `cache`, `fit`, `fcose`, `incremental` |
74
+ | `edge_layers` | `setEdgeLayers` | list of `EdgeInput.layer` values; `None` or `[]` = all |
75
+ | `edge_view` | `setEdgeView` | `EdgeViewOptions`: `style` (`'split'`, `'merged'`), `filter` (orthogroup-nodes mode) |
76
+ | `bubble_by`, `bubble_min_species`, `bubble_avoid` | `setBubbleBy(key, {minSpecies, avoid})` | `'compartment'` or an annotation key; `None` = no bubbles |
77
+ | `hints` | `setCompartmentHints` | `'territories'`, `'bubbles'`, `True`, a `CompartmentHintOptions` dict, or `None` |
78
+ | `semantic_zoom` | `setSemanticZoom` | `True`, `{'zoom', 'maxMembers'}` or `None` |
79
+ | `keyboard`, `overlay_click` | `enableKeyboard`, `enableOverlayClick` | default `True` |
80
+ | `stylesheet`, `cytoscape_options` | constructor | extra Cytoscape styles / core options, read once |
81
+ | `style`, `className` | | of the container; it needs a height (default 600px) |
82
+
83
+ Whenever data, mode, edge layers, edge view, context or layout options change, the layout runs again (with the `layout` options; `{'incremental': True}` keeps nodes close to where they were). Updates never overlap: changes that arrive during a layout are applied after it.
84
+
85
+ Output props, written by the component:
86
+
87
+ | Prop | Content |
88
+ | --- | --- |
89
+ | `selection` | `{'proteins': [...], 'nodeIds': [...], 'source': 'click' \| 'keyboard' \| 'search' \| 'api'}` on every change. Also an input: set it from Python to select proteins or nodes. |
90
+ | `network_info` | `mode`, `conditions`, `metric`, `overlayKeys`, `annotationKeys`, `layers`, `shownLayers`, `units`, `warnings`, `context` (the context statistics or `None`), `visible` (`nodes`, `edges`). Use it to fill dropdowns. |
91
+ | `metrics` | `net.metrics()` after every layout, only with `compute_metrics=True` (edge crossings are slow on large networks). |
92
+ | `last_event` | The last ContextNet event, `{'type', 'time', ...payload}`: `data`, `mode`, `context` (with `stats`), `layout`, `overlay`, `edgeview`, `layers`, `select`, `expand`, `collapse`, and `tap` (with `id` and `info`, the `info()` of the tapped node or edge). |
93
+ | `error` | Messages of the last update that failed (e.g. an unknown overlay key), else `None`. The rest of the update is still applied. |
94
+
95
+ ### Export
96
+
97
+ Set `export_request` to `{'format': 'png' or 'svg', 'filename': ..., 'options': {...}}` (`options` are ContextNet `ExportOptions`: `scale`, `padding`, `background`, `labels`, `legend`, `fontSize`, `title`, `description`). The component calls `exportPng` / `exportSvg`, writes the file to `export_result` and resets `export_request` to `None`. `export_result` has the keys of `dcc.Download` (`content`, `filename`, `base64`, `type`, plus the `request`), so it can be passed straight on:
98
+
99
+ ```python
100
+ @app.callback(Output("net", "export_request"), Input("png", "n_clicks"), prevent_initial_call=True)
101
+ def export(_):
102
+ return {"format": "png", "filename": "network.png", "options": {"scale": 3}}
103
+
104
+
105
+ @app.callback(Output("download", "data"), Input("net", "export_result"), prevent_initial_call=True)
106
+ def download(result):
107
+ return result # dcc.Download(id="download") in the layout
108
+ ```
109
+
110
+ ## Notes
111
+
112
+ - Do not put `dash-cytoscape` and this component on the same page expecting them to share a graph: each bundles its own Cytoscape.js, and ContextNet builds and owns its elements.
113
+ - Large networks: ContextNet handles a few thousand nodes; keep `compute_metrics` off and prefer `context` over sending a smaller `data`.
114
+
115
+ ## Development
116
+
117
+ The component lives in `python/dash_contextnet/` of the ContextNet repository. Building needs Node ≥ 20.19 and a Python environment with `ci/requirements-build.txt` (Dash is pinned there, because the generated `dash_contextnet/ContextNet.py` depends on the generator's version). The scripts in `ci/` are what CI runs:
118
+
119
+ ```bash
120
+ pip install -r ci/requirements-build.txt
121
+ ci/build.sh # library, webpack bundle, generated Python class, wheel + sdist in dist/, twine check
122
+ ci/test.sh # installs dist/*.whl[test] and runs the tests against it (DASH_VERSION=2.9.3 for the oldest Dash)
123
+ ```
124
+
125
+ `ci/build.sh` fails when the committed generated files (`ContextNet.py`, `_imports_.py`, `metadata.json`, `THIRD_PARTY_LICENSES.txt`) differ from what the build produces; commit them after changing the component. The bundle build writes `THIRD_PARTY_LICENSES.txt` from the modules that end up in the bundle and fails if one of them has a licence other than MIT, ISC, BSD or Apache-2.0.
126
+
127
+ For quick iterations: `npm run build:js -- --mode development` (seconds instead of about a minute), `pip install -e ".[test]"`, `pytest`.
128
+
129
+ ## Licence
130
+
131
+ MIT. The bundled libraries (Cytoscape.js, cytoscape-fcose, cose-base, layout-base, cytoscape-bubblesets, cytoscape-layers, bubblesets-js, lodash.throttle, prop-types) are MIT-licensed; their notices are in `dash_contextnet/THIRD_PARTY_LICENSES.txt`, which is included in the wheel and the sdist.
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env bash
2
+ # Build dash-contextnet: the ContextNet library, the component bundle, the generated Python class, wheel and sdist.
3
+ # Needs Node >= 20.19 and a Python environment with ci/requirements-build.txt installed.
4
+ # Used by CI (.github/workflows/ci.yml and release.yml) and locally: python/dash_contextnet/ci/build.sh
5
+ set -euo pipefail
6
+ cd "$(dirname "$0")/.."
7
+
8
+ npm ci --prefix ../.. # the ContextNet library (its build goes into the bundle)
9
+ npm ci # the component's JavaScript dependencies
10
+ npm run build # library build, webpack bundle + licence notices, dash-generate-components
11
+
12
+ # The generated files are committed: fail when they are out of date with the component source.
13
+ if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
14
+ git diff --exit-code -- dash_contextnet/ContextNet.py dash_contextnet/_imports_.py \
15
+ dash_contextnet/metadata.json dash_contextnet/THIRD_PARTY_LICENSES.txt \
16
+ || { echo "Generated files changed: run ci/build.sh and commit them." >&2; exit 1; }
17
+ fi
18
+
19
+ rm -rf dist
20
+ python -m build
21
+ twine check --strict dist/*
22
+ ls -l dist
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env bash
2
+ # Release tags must match the package version: dash-contextnet-vX.Y.Z for PyPI, vX.Y.Z for npm.
3
+ set -euo pipefail
4
+ root="$(cd "$(dirname "$0")/../../.." && pwd)"
5
+ tag="${1:?usage: check-tag.sh TAG}"
6
+ case "${tag}" in
7
+ dash-contextnet-v*)
8
+ want="${tag#dash-contextnet-v}"
9
+ have=$(sed -n 's/^__version__ = "\(.*\)"$/\1/p' "${root}/python/dash_contextnet/dash_contextnet/_version.py")
10
+ npm=$(node -p "require('${root}/python/dash_contextnet/package.json').version")
11
+ [ "${npm}" = "${have}" ] || { echo "python/dash_contextnet/package.json has ${npm}, _version.py ${have}" >&2; exit 1; } ;;
12
+ v*)
13
+ want="${tag#v}"
14
+ have=$(node -p "require('${root}/package.json').version") ;;
15
+ *) echo "Unknown release tag ${tag}" >&2; exit 1 ;;
16
+ esac
17
+ [ "${want}" = "${have}" ] || { echo "Tag ${tag} does not match version ${have}" >&2; exit 1; }
18
+ echo "Tag ${tag} matches version ${have}"
@@ -0,0 +1,6 @@
1
+ # Python side of `npm run build` (dash-generate-components) and of packaging.
2
+ # dash is pinned: the generated dash_contextnet/ContextNet.py depends on the generator's version.
3
+ dash==4.5.2
4
+ pyyaml==6.0.4
5
+ build==1.6.1
6
+ twine==7.0.0
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env bash
2
+ # Install the built wheel (dist/*.whl) and run the tests against it, not against the source tree.
3
+ # Optional: DASH_VERSION=2.9.3 tests with that Dash instead of the newest one.
4
+ set -euo pipefail
5
+ cd "$(dirname "$0")/.."
6
+
7
+ wheel=$(ls dist/dash_contextnet-*.whl)
8
+ # Dash 2.x imports pkg_resources, which setuptools 81 removed.
9
+ python -m pip install "${wheel}[test]" ${DASH_VERSION:+"dash==${DASH_VERSION}" "setuptools<81"}
10
+ # System libraries for Chromium only in CI (root in the job image); locally they are usually present.
11
+ python -m playwright install ${CI:+--with-deps} chromium
12
+
13
+ # Run from a copy so that `import dash_contextnet` finds the installed wheel, not the source tree.
14
+ work=$(mktemp -d)
15
+ cp -r tests "${work}/"
16
+ cd "${work}"
17
+ python -c "import dash, dash_contextnet; print('dash', dash.__version__, '| dash-contextnet', dash_contextnet.__version__, dash_contextnet.__file__)"
18
+ python -m pytest -p no:cacheprovider -v tests
@@ -0,0 +1,215 @@
1
+ # AUTO GENERATED FILE - DO NOT EDIT
2
+
3
+ import typing # noqa: F401
4
+ from typing_extensions import TypedDict, NotRequired, Literal # noqa: F401
5
+ from dash.development.base_component import Component, _explicitize_args
6
+ try:
7
+ from dash.types import NumberType # noqa: F401
8
+ except ImportError:
9
+ # Backwards compatibility for dash<=4.1.0
10
+ if typing.TYPE_CHECKING:
11
+ raise
12
+ NumberType = typing.Union[ # noqa: F401
13
+ typing.SupportsFloat, typing.SupportsInt, typing.SupportsComplex
14
+ ]
15
+
16
+ ComponentSingleType = typing.Union[str, int, float, Component, None]
17
+ ComponentType = typing.Union[
18
+ ComponentSingleType,
19
+ typing.Sequence[ComponentSingleType],
20
+ ]
21
+
22
+
23
+ class ContextNet(Component):
24
+ """A ContextNet component.
25
+ ContextNet: multi-compartment, condition-aware network views (Cytoscape.js) as a Dash component.
26
+
27
+ Input props map to the ContextNet JavaScript API (keys inside the dict props use its camelCase names):
28
+ `data` -> setData, `compartment_mode` -> setCompartmentMode, `context` -> contextualize / clearContext,
29
+ `layout` -> layout, `edge_layers` -> setEdgeLayers, `edge_view` -> setEdgeView, `bubble_by` -> setBubbleBy,
30
+ `hints` -> setCompartmentHints, `semantic_zoom` -> setSemanticZoom. After every change that moves nodes
31
+ (data, mode, layers, edge view, context, layout) the layout runs again.
32
+
33
+ Output props: `selection`, `last_event`, `network_info`, `error`, and with `compute_metrics=True` also
34
+ `metrics`. Exports: set `export_request`; the file arrives in `export_result` in the format of
35
+ `dcc.Download`, and `export_request` is reset to None.
36
+
37
+ Keyword arguments:
38
+
39
+ - id (string; optional):
40
+ The ID used to identify this component in Dash callbacks.
41
+
42
+ - bubble_avoid (boolean | a value equal to: 'auto'; optional):
43
+ Route bubble outlines around non-members: True, False or 'auto'
44
+ (default: on up to 200 shown nodes).
45
+
46
+ - bubble_by (string; optional):
47
+ Overlay key for bubble outlines: 'compartment' or an annotation
48
+ key. None removes the bubbles.
49
+
50
+ - bubble_min_species (number; optional):
51
+ Only draw bubbles for values shared by at least this many species.
52
+ Default 1.
53
+
54
+ - className (string; optional):
55
+ CSS class of the container.
56
+
57
+ - compartment_mode (a value equal to: 'pie', 'clones', 'bubbles', 'orthogroups', 'orthogroup-nodes'; optional):
58
+ How compartments are drawn.
59
+
60
+ - compute_metrics (boolean; optional):
61
+ Compute `metrics` after every layout. Off by default: edge
62
+ crossings are slow on large networks.
63
+
64
+ - context (dict; optional):
65
+ Expression context (ContextNet `ContextOptions`): `condition`,
66
+ `threshold`, and optionally `direction` ('both' | 'up' | 'down'),
67
+ `maxP`, `unmeasured` ('inactive' | 'keep'), `keepLinkers`,
68
+ `minActiveNeighbors`, `minEdgeWeight`, `hideIsolated`, `display`
69
+ ('hide' | 'dim'). None (or no `condition`) shows the full network.
70
+
71
+ - cytoscape_options (dict; optional):
72
+ Extra options of the Cytoscape core (e.g. `minZoom`,
73
+ `wheelSensitivity`). Read once, when the network is created.
74
+
75
+ - data (dict; optional):
76
+ The network (ContextNet `NetworkData`): `nodes`, `edges` and
77
+ optionally `compartments`, `species`, `speciesGroups`,
78
+ `orthogroups` and `expression`. See
79
+ https://github.com/bjoernoest/cytoscapejs_contextnet/blob/main/docs/MANUAL.md.
80
+
81
+ - edge_layers (list of strings; optional):
82
+ Evidence layers (`EdgeInput.layer`) to show and analyse. None or
83
+ [] = all layers.
84
+
85
+ - edge_view (dict; optional):
86
+ Edge view of the 'orthogroup-nodes' mode (ContextNet
87
+ `EdgeViewOptions`): `style` ('split' | 'merged') and `filter`.
88
+
89
+ - error (string; optional):
90
+ Output: error messages of the last update (e.g. an unknown overlay
91
+ key), or None.
92
+
93
+ - export_request (dict; optional):
94
+ Request an export: `{'format': 'png' | 'svg', 'filename': ...,
95
+ 'options': {...}}` (`options`: ContextNet `ExportOptions`, e.g.
96
+ `scale`, `background`, `legend`). Reset to None once the export is
97
+ done.
98
+
99
+ - export_result (dict; optional):
100
+ Output: the exported file as `{'content', 'filename', 'base64',
101
+ 'type', 'request'}`, ready for `dcc.Download` (PNG base64-encoded,
102
+ SVG as text).
103
+
104
+ - hints (boolean | string | dict; optional):
105
+ Background hints: 'territories', 'bubbles', True (bubbles by
106
+ compartment), a ContextNet `CompartmentHintOptions` dict (`style`,
107
+ `by`, `minFraction`, `opacity`, `bandwidth`, `labels`), or None.
108
+
109
+ - keyboard (boolean; optional):
110
+ Keyboard navigation of the network (arrow keys, Enter, Escape).
111
+ Default True.
112
+
113
+ - last_event (dict; optional):
114
+ Output: the last ContextNet event as `{'type': ..., 'time': ...,
115
+ **payload}`. Types: 'data', 'mode', 'context' (with `stats`),
116
+ 'layout', 'overlay', 'edgeview', 'layers', 'select', 'expand',
117
+ 'collapse', and 'tap' (with `id` and `info`, ContextNet `info()`
118
+ of the tapped node or edge).
119
+
120
+ - layout (dict; optional):
121
+ Layout options (ContextNet `LayoutOptions`): `algorithm` ('fcose'
122
+ | 'anchored'), `anchored`, `scope`, `cache`, `fit`, `fcose`,
123
+ `incremental`. Used whenever the layout runs; changing it runs the
124
+ layout again.
125
+
126
+ - metrics (dict; optional):
127
+ Output: ContextNet `metrics()` of what is shown (with
128
+ `compute_metrics=True`).
129
+
130
+ - network_info (dict; optional):
131
+ Output: what the network offers and shows: `mode`, `conditions`,
132
+ `metric`, `overlayKeys`, `annotationKeys`, `layers`,
133
+ `shownLayers`, `units`, `warnings`, `context` (stats or None),
134
+ `visible` (`nodes`, `edges`).
135
+
136
+ - overlay_click (boolean; optional):
137
+ Clicking a territory or bubble selects its members. Default True.
138
+
139
+ - selection (dict; optional):
140
+ The selection: `{'proteins': [...], 'nodeIds': [...], 'source':
141
+ ...}`. Written on every change in the browser (`source` 'click',
142
+ 'keyboard', 'search' or 'api'); set it from Python to select
143
+ proteins or nodes.
144
+
145
+ `selection` is a dict with keys:
146
+
147
+ - proteins (list of strings; optional)
148
+
149
+ - nodeIds (list of strings; optional)
150
+
151
+ - source (string; optional)
152
+
153
+ - semantic_zoom (boolean | dict; optional):
154
+ Semantic zoom for the 'orthogroup-nodes' mode: True, a dict
155
+ (`zoom`, `maxMembers`) or None.
156
+
157
+ - stylesheet (list of dicts; optional):
158
+ Extra Cytoscape styles appended to the ContextNet stylesheet. Read
159
+ once, when the network is created."""
160
+ _children_props: typing.List[str] = []
161
+ _base_nodes = ['children']
162
+ _namespace = 'dash_contextnet'
163
+ _type = 'ContextNet'
164
+ Selection = TypedDict(
165
+ "Selection",
166
+ {
167
+ "proteins": NotRequired[typing.Sequence[str]],
168
+ "nodeIds": NotRequired[typing.Sequence[str]],
169
+ "source": NotRequired[str]
170
+ }
171
+ )
172
+
173
+
174
+ def __init__(
175
+ self,
176
+ id: typing.Optional[typing.Union[str, dict]] = None,
177
+ className: typing.Optional[str] = None,
178
+ style: typing.Optional[typing.Any] = None,
179
+ data: typing.Optional[dict] = None,
180
+ compartment_mode: typing.Optional[Literal["pie", "clones", "bubbles", "orthogroups", "orthogroup-nodes"]] = None,
181
+ context: typing.Optional[dict] = None,
182
+ layout: typing.Optional[dict] = None,
183
+ edge_layers: typing.Optional[typing.Sequence[str]] = None,
184
+ edge_view: typing.Optional[dict] = None,
185
+ bubble_by: typing.Optional[str] = None,
186
+ bubble_min_species: typing.Optional[NumberType] = None,
187
+ bubble_avoid: typing.Optional[typing.Union[bool, Literal["auto"]]] = None,
188
+ hints: typing.Optional[typing.Union[bool, str, dict]] = None,
189
+ semantic_zoom: typing.Optional[typing.Union[bool, dict]] = None,
190
+ keyboard: typing.Optional[bool] = None,
191
+ overlay_click: typing.Optional[bool] = None,
192
+ stylesheet: typing.Optional[typing.Sequence[dict]] = None,
193
+ cytoscape_options: typing.Optional[dict] = None,
194
+ selection: typing.Optional["Selection"] = None,
195
+ compute_metrics: typing.Optional[bool] = None,
196
+ metrics: typing.Optional[dict] = None,
197
+ last_event: typing.Optional[dict] = None,
198
+ network_info: typing.Optional[dict] = None,
199
+ error: typing.Optional[str] = None,
200
+ export_request: typing.Optional[dict] = None,
201
+ export_result: typing.Optional[dict] = None,
202
+ **kwargs
203
+ ):
204
+ self._prop_names = ['id', 'bubble_avoid', 'bubble_by', 'bubble_min_species', 'className', 'compartment_mode', 'compute_metrics', 'context', 'cytoscape_options', 'data', 'edge_layers', 'edge_view', 'error', 'export_request', 'export_result', 'hints', 'keyboard', 'last_event', 'layout', 'metrics', 'network_info', 'overlay_click', 'selection', 'semantic_zoom', 'style', 'stylesheet']
205
+ self._valid_wildcard_attributes = []
206
+ self.available_properties = ['id', 'bubble_avoid', 'bubble_by', 'bubble_min_species', 'className', 'compartment_mode', 'compute_metrics', 'context', 'cytoscape_options', 'data', 'edge_layers', 'edge_view', 'error', 'export_request', 'export_result', 'hints', 'keyboard', 'last_event', 'layout', 'metrics', 'network_info', 'overlay_click', 'selection', 'semantic_zoom', 'style', 'stylesheet']
207
+ self.available_wildcard_properties = []
208
+ _explicit_args = kwargs.pop('_explicit_args')
209
+ _locals = locals()
210
+ _locals.update(kwargs) # For wildcard attrs and excess named props
211
+ args = {k: _locals[k] for k in _explicit_args}
212
+
213
+ super(ContextNet, self).__init__(**args)
214
+
215
+ setattr(ContextNet, "__init__", _explicitize_args(ContextNet.__init__))