Skip to content

Commit e539ac8

Browse files
committed
Marimo conversion
1 parent 5aa7412 commit e539ac8

File tree

74 files changed

+7944
-9527
lines changed

Some content is hidden

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

74 files changed

+7944
-9527
lines changed

docs/notebooks/cellbrowser_to_vitessce_config_conversion.ipynb

Lines changed: 0 additions & 217 deletions
This file was deleted.
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
import marimo
2+
3+
__generated_with = "0.13.15"
4+
app = marimo.App()
5+
6+
7+
@app.cell(hide_code=True)
8+
def _(mo):
9+
mo.md(
10+
r"""
11+
# Load UCSC Cell Browser project in Vitessce
12+
"""
13+
)
14+
return
15+
16+
17+
@app.cell(hide_code=True)
18+
def _(mo):
19+
mo.md(
20+
r"""
21+
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:
22+
1. Convert it into the AnnData format that is supported by Vitessce
23+
2. Save the AnnData object as a Zarr store
24+
3. Configure Vitessce with the AnnData-Zarr store
25+
4. Render a Vitessce widget based on the config (step 3) directly in the notebook.
26+
27+
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
28+
29+
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.
30+
"""
31+
)
32+
return
33+
34+
35+
@app.cell
36+
def _():
37+
import os
38+
import json
39+
from os.path import join
40+
from vitessce import (
41+
convert_cell_browser_project_to_anndata,
42+
AnnDataWrapper,
43+
VitessceConfig,
44+
)
45+
from vitessce.data_utils import VAR_CHUNK_SIZE
46+
return (
47+
AnnDataWrapper,
48+
VAR_CHUNK_SIZE,
49+
VitessceConfig,
50+
convert_cell_browser_project_to_anndata,
51+
join,
52+
os,
53+
)
54+
55+
56+
@app.cell(hide_code=True)
57+
def _(mo):
58+
mo.md(
59+
r"""
60+
## 1. Convert UCSC Cell Browser project to a format that is supported by Vitessce
61+
#### Output:
62+
An AnnData object
63+
64+
"""
65+
)
66+
return
67+
68+
69+
@app.cell
70+
def _():
71+
## 3. Convert UCSC Cell Browser project to a Vitessce view config
72+
return
73+
74+
75+
@app.cell
76+
def _(convert_cell_browser_project_to_anndata):
77+
# Example run, coverting "adultPancreas" project:
78+
adata = convert_cell_browser_project_to_anndata(project_name="adultPancreas", keep_only_marker_genes=True)
79+
return (adata,)
80+
81+
82+
@app.cell(hide_code=True)
83+
def _(mo):
84+
mo.md(
85+
r"""
86+
## 2. Save the AnnData object as a Zarr store
87+
"""
88+
)
89+
return
90+
91+
92+
@app.cell
93+
def _(VAR_CHUNK_SIZE, adata, join, os):
94+
zarr_filepath = join("data", "out.adata.zarr")
95+
os.makedirs(os.path.dirname(zarr_filepath), exist_ok=True)
96+
adata.write_zarr(zarr_filepath, chunks=[adata.shape[0], VAR_CHUNK_SIZE])
97+
return (zarr_filepath,)
98+
99+
100+
@app.cell(hide_code=True)
101+
def _(mo):
102+
mo.md(
103+
r"""
104+
## 3. Configure Vitessce with the AnnData-Zarr store
105+
"""
106+
)
107+
return
108+
109+
110+
@app.cell
111+
def _(AnnDataWrapper, VitessceConfig, zarr_filepath):
112+
anndata_wrapper_inst = AnnDataWrapper(
113+
adata_path=zarr_filepath,
114+
obs_feature_matrix_path="X",
115+
obs_embedding_paths=["obsm/X_tsne"],
116+
obs_embedding_names=["t-SNE"],
117+
obs_set_paths=["obs/cluster", "obs/age"],
118+
obs_set_names=["cluster", "age"],
119+
)
120+
vc = VitessceConfig(schema_version="1.0.15", name="Vitessce configuration for CellBrowser project adultPancreas")
121+
anndata_wrapper_inst.auto_view_config(vc)
122+
return (vc,)
123+
124+
125+
@app.cell(hide_code=True)
126+
def _(mo):
127+
mo.md(
128+
r"""
129+
## 4. Render the Vitessce widget
130+
"""
131+
)
132+
return
133+
134+
135+
@app.cell
136+
def _(vc):
137+
vw = vc.widget()
138+
vw
139+
return
140+
141+
142+
@app.cell
143+
def _():
144+
import marimo as mo
145+
return (mo,)
146+
147+
148+
if __name__ == "__main__":
149+
app.run()

0 commit comments

Comments
 (0)