Skip to content

Commit e994c08

Browse files
committed
Updates
1 parent e539ac8 commit e994c08

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+7741
-7
lines changed

.github/workflows/test_widget.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ jobs:
2929
- name: Install vitessce
3030
run: uv sync --extra dev --extra all --extra notebook
3131
- name: Export Jupyter notebook to HTML
32-
run: uv run jupyter nbconvert --to=html --execute docs/notebooks/widget_from_dict.ipynb
32+
run: uv run jupyter nbconvert --to=html --execute docs/notebooks/__ipynb__/widget_from_dict.ipynb
3333
- name: Export Marimo notebook to HTML
34-
run: uv run marimo export html docs/notebooks/marimo.py -o docs/notebooks/marimo.html
34+
run: uv run marimo export html docs/notebooks/marimo.mo.py -o docs/notebooks/marimo.mo.html
3535
- name: Export Marimo notebook to HTML-WASM
36-
run: uv run marimo export html-wasm docs/notebooks/marimo-wasm.py -o docs/notebooks/marimo-wasm.html --mode edit
36+
run: uv run marimo export html-wasm docs/notebooks/marimo-wasm.mo.py -o docs/notebooks/marimo-wasm.mo.html --mode edit
3737
- name: Check that widget renders in HTML output using Playwright
3838
run: pnpm exec playwright test
3939
working-directory: ./tests-widget

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ tests/data/*
1111
!tests/data/test.ome.tif
1212
./notebooks/
1313
docs/notebooks/data/
14+
docs/notebooks/data-cropped/
1415
docs/notebooks/*.html
16+
docs/notebooks/*.ipynb
17+
docs/notebooks/*.zarr/
1518
__pycache__/
1619
.snakemake/
1720
.coverage
1821
demos/*/data/
1922
demos/*/vitessce.local.json
2023
demos/*/vitessce.remote.json
2124
.pytest_cache/
25+
__marimo__/
2226

2327
# Compiled javascript
2428
vitessce/static/
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "vblA",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"import os\n",
11+
"import json\n",
12+
"from os.path import join\n",
13+
"from vitessce import (\n",
14+
" convert_cell_browser_project_to_anndata,\n",
15+
" AnnDataWrapper,\n",
16+
" VitessceConfig,\n",
17+
")\n",
18+
"from vitessce.data_utils import VAR_CHUNK_SIZE"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": null,
24+
"id": "lEQa",
25+
"metadata": {},
26+
"outputs": [],
27+
"source": [
28+
"## 3. Convert UCSC Cell Browser project to a Vitessce view config"
29+
]
30+
},
31+
{
32+
"cell_type": "code",
33+
"execution_count": null,
34+
"id": "Hstk",
35+
"metadata": {},
36+
"outputs": [],
37+
"source": [
38+
"import marimo as mo"
39+
]
40+
},
41+
{
42+
"cell_type": "code",
43+
"execution_count": null,
44+
"id": "PKri",
45+
"metadata": {},
46+
"outputs": [],
47+
"source": [
48+
"# Example run, coverting \"adultPancreas\" project:\n",
49+
"adata = convert_cell_browser_project_to_anndata(project_name=\"adultPancreas\", keep_only_marker_genes=True)"
50+
]
51+
},
52+
{
53+
"cell_type": "markdown",
54+
"id": "BYtC",
55+
"metadata": {},
56+
"source": [
57+
"## 3. Configure Vitessce with the AnnData-Zarr store"
58+
]
59+
},
60+
{
61+
"cell_type": "markdown",
62+
"id": "bkHC",
63+
"metadata": {},
64+
"source": [
65+
"## 1. Convert UCSC Cell Browser project to a format that is supported by Vitessce\n",
66+
"#### Output:\n",
67+
"An AnnData object"
68+
]
69+
},
70+
{
71+
"cell_type": "markdown",
72+
"id": "MJUe",
73+
"metadata": {},
74+
"source": [
75+
"This notebook shows you how to use the `convert_cell_browser_project_to_anndata` function, which allows you to take an existing project, published in https://cells.ucsc.edu/ and:\n",
76+
"1. Convert it into the AnnData format that is supported by Vitessce\n",
77+
"2. Save the AnnData object as a Zarr store\n",
78+
"3. Configure Vitessce with the AnnData-Zarr store\n",
79+
"4. Render a Vitessce widget based on the config (step 3) directly in the notebook.\n",
80+
"\n",
81+
"The dataset that you choose to convert needs to be a valid UCSC Cell Browser \"project\", accessible from https://cells.ucsc.edu/, with a configuration available in https://github.com/ucscGenomeBrowser/cellbrowser-confs\n",
82+
"\n",
83+
"The `convert_cell_browser_project_to_anndata` function takes the name of that project as an input. For example, to convert this project, https://cells.ucsc.edu/?ds=adultPancreas, you will neeed to pass `\"adultPancreas\"` as the project name."
84+
]
85+
},
86+
{
87+
"cell_type": "markdown",
88+
"id": "Kclp",
89+
"metadata": {},
90+
"source": [
91+
"## 4. Render the Vitessce widget"
92+
]
93+
},
94+
{
95+
"cell_type": "markdown",
96+
"id": "Xref",
97+
"metadata": {},
98+
"source": [
99+
"## 2. Save the AnnData object as a Zarr store"
100+
]
101+
},
102+
{
103+
"cell_type": "markdown",
104+
"id": "Hbol",
105+
"metadata": {},
106+
"source": [
107+
"# Load UCSC Cell Browser project in Vitessce"
108+
]
109+
},
110+
{
111+
"cell_type": "code",
112+
"execution_count": null,
113+
"id": "SFPL",
114+
"metadata": {},
115+
"outputs": [],
116+
"source": [
117+
"zarr_filepath = join(\"data\", \"out.adata.zarr\")\n",
118+
"os.makedirs(os.path.dirname(zarr_filepath), exist_ok=True)\n",
119+
"adata.write_zarr(zarr_filepath, chunks=[adata.shape[0], VAR_CHUNK_SIZE])"
120+
]
121+
},
122+
{
123+
"cell_type": "code",
124+
"execution_count": null,
125+
"id": "RGSE",
126+
"metadata": {},
127+
"outputs": [],
128+
"source": [
129+
"anndata_wrapper_inst = AnnDataWrapper(\n",
130+
" adata_path=zarr_filepath,\n",
131+
" obs_feature_matrix_path=\"X\",\n",
132+
" obs_embedding_paths=[\"obsm/X_tsne\"],\n",
133+
" obs_embedding_names=[\"t-SNE\"],\n",
134+
" obs_set_paths=[\"obs/cluster\", \"obs/age\"],\n",
135+
" obs_set_names=[\"cluster\", \"age\"],\n",
136+
")\n",
137+
"vc = VitessceConfig(schema_version=\"1.0.15\", name=\"Vitessce configuration for CellBrowser project adultPancreas\")\n",
138+
"anndata_wrapper_inst.auto_view_config(vc)"
139+
]
140+
},
141+
{
142+
"cell_type": "code",
143+
"execution_count": null,
144+
"id": "emfo",
145+
"metadata": {},
146+
"outputs": [],
147+
"source": [
148+
"vw = vc.widget()\n",
149+
"vw"
150+
]
151+
}
152+
],
153+
"metadata": {},
154+
"nbformat": 4,
155+
"nbformat_minor": 5
156+
}
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "MJUe",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"from vitessce import VitessceConfig, VitessceChainableConfig, VitessceConfigDatasetFile"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": null,
16+
"id": "vblA",
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"from example_configs import dries as dries_config"
21+
]
22+
},
23+
{
24+
"cell_type": "code",
25+
"execution_count": null,
26+
"id": "ROlb",
27+
"metadata": {},
28+
"outputs": [],
29+
"source": [
30+
"import marimo as mo"
31+
]
32+
},
33+
{
34+
"cell_type": "code",
35+
"execution_count": null,
36+
"id": "lEQa",
37+
"metadata": {},
38+
"outputs": [],
39+
"source": [
40+
"vc = VitessceConfig.from_dict(dries_config)"
41+
]
42+
},
43+
{
44+
"cell_type": "markdown",
45+
"id": "nWHF",
46+
"metadata": {},
47+
"source": [
48+
"## Evaluate the code and render a Vitessce widget"
49+
]
50+
},
51+
{
52+
"cell_type": "markdown",
53+
"id": "Hstk",
54+
"metadata": {},
55+
"source": [
56+
"The second value is the code snippet. When evaluated, the result will be a new `VitessceConfig` instance."
57+
]
58+
},
59+
{
60+
"cell_type": "markdown",
61+
"id": "PKri",
62+
"metadata": {},
63+
"source": [
64+
"## Print to JSON"
65+
]
66+
},
67+
{
68+
"cell_type": "markdown",
69+
"id": "SFPL",
70+
"metadata": {},
71+
"source": [
72+
"## Print to Python\n",
73+
"\n",
74+
"The `vc.to_python` function generates formatted Python code which can be used to re-generate the `vc` instance."
75+
]
76+
},
77+
{
78+
"cell_type": "markdown",
79+
"id": "RGSE",
80+
"metadata": {},
81+
"source": [
82+
"The first value returned is a list of classes used by the code snippet."
83+
]
84+
},
85+
{
86+
"cell_type": "markdown",
87+
"id": "bkHC",
88+
"metadata": {},
89+
"source": [
90+
"## Load a view config from a dict representation"
91+
]
92+
},
93+
{
94+
"cell_type": "markdown",
95+
"id": "Hbol",
96+
"metadata": {},
97+
"source": [
98+
"# Generate Python code to reconstruct a VitessceConfig instance"
99+
]
100+
},
101+
{
102+
"cell_type": "code",
103+
"execution_count": null,
104+
"id": "BYtC",
105+
"metadata": {},
106+
"outputs": [],
107+
"source": [
108+
"imports, code = vc.to_python()"
109+
]
110+
},
111+
{
112+
"cell_type": "code",
113+
"execution_count": null,
114+
"id": "Xref",
115+
"metadata": {},
116+
"outputs": [],
117+
"source": [
118+
"import json\n",
119+
"print(json.dumps(vc.to_dict(), indent=2))"
120+
]
121+
},
122+
{
123+
"cell_type": "code",
124+
"execution_count": null,
125+
"id": "iLit",
126+
"metadata": {},
127+
"outputs": [],
128+
"source": [
129+
"reconstructed_vc = eval(code)"
130+
]
131+
},
132+
{
133+
"cell_type": "code",
134+
"execution_count": null,
135+
"id": "emfo",
136+
"metadata": {},
137+
"outputs": [],
138+
"source": [
139+
"print(code)"
140+
]
141+
},
142+
{
143+
"cell_type": "code",
144+
"execution_count": null,
145+
"id": "Kclp",
146+
"metadata": {},
147+
"outputs": [],
148+
"source": [
149+
"imports"
150+
]
151+
},
152+
{
153+
"cell_type": "code",
154+
"execution_count": null,
155+
"id": "ZHCJ",
156+
"metadata": {},
157+
"outputs": [],
158+
"source": [
159+
"reconstructed_vc.widget()"
160+
]
161+
}
162+
],
163+
"metadata": {},
164+
"nbformat": 4,
165+
"nbformat_minor": 5
166+
}

0 commit comments

Comments
 (0)