Skip to content

Commit 017bb6a

Browse files
committed
Merge
2 parents a8e904a + 83fa4bb commit 017bb6a

24 files changed

+1708
-159
lines changed

.coveragerc_omit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
omit =
33
vitessce/config.py
44
vitessce/export.py
5+
vitessce/file_def_utils.py
56
vitessce/routes.py
67
vitessce/widget.py
78
vitessce/wrappers.py

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
version: ['3.8', '3.12']
10+
version: ['3.9', '3.12']
1111
steps:
1212
- uses: actions/checkout@v2
1313
- uses: actions/setup-python@v2

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 Gehlenborg Lab
3+
Copyright (c) 2020 HIDIVE Lab
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
# -- Project information -----------------------------------------------------
2929

3030
project = 'vitessce'
31-
copyright = '2020, Gehlenborg Lab'
32-
author = 'Gehlenborg Lab'
31+
copyright = '2020, HIDIVE Lab'
32+
author = 'HIDIVE Lab'
3333

3434

3535
# -- General configuration ---------------------------------------------------

docs/data_examples.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ Data preparation examples
77

88
notebooks/data_export_s3
99
notebooks/data_export_files
10-
notebooks/widget_brain_with_base_dir
10+
notebooks/widget_brain_with_base_dir
11+
notebooks/widget_brain_h5ad

docs/notebooks/spatial_data.ipynb

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {
6+
"nbsphinx": "hidden"
7+
},
8+
"source": [
9+
"# Vitessce Widget Tutorial"
10+
]
11+
},
12+
{
13+
"cell_type": "markdown",
14+
"metadata": {},
15+
"source": [
16+
"# Visualization of a SpatialData object"
17+
]
18+
},
19+
{
20+
"cell_type": "markdown",
21+
"metadata": {},
22+
"source": [
23+
"## Import dependencies\n"
24+
]
25+
},
26+
{
27+
"cell_type": "code",
28+
"execution_count": null,
29+
"metadata": {},
30+
"outputs": [],
31+
"source": [
32+
"import os\n",
33+
"from os.path import join, isfile, isdir\n",
34+
"from urllib.request import urlretrieve\n",
35+
"import zipfile\n",
36+
"\n",
37+
"from vitessce import (\n",
38+
" VitessceConfig,\n",
39+
" ViewType as vt,\n",
40+
" CoordinationType as ct,\n",
41+
" CoordinationLevel as CL,\n",
42+
" SpatialDataWrapper,\n",
43+
" get_initial_coordination_scope_prefix\n",
44+
")"
45+
]
46+
},
47+
{
48+
"cell_type": "code",
49+
"execution_count": null,
50+
"metadata": {},
51+
"outputs": [],
52+
"source": [
53+
"data_dir = \"data\"\n",
54+
"zip_filepath = join(data_dir, \"visium.spatialdata.zarr.zip\")\n",
55+
"spatialdata_filepath = join(data_dir, \"visium.spatialdata.zarr\")"
56+
]
57+
},
58+
{
59+
"cell_type": "code",
60+
"execution_count": null,
61+
"metadata": {},
62+
"outputs": [],
63+
"source": [
64+
"if not isdir(spatialdata_filepath):\n",
65+
" if not isfile(zip_filepath):\n",
66+
" os.makedirs(data_dir, exist_ok=True)\n",
67+
" urlretrieve('https://s3.embl.de/spatialdata/spatialdata-sandbox/visium_associated_xenium_io.zip', zip_filepath)\n",
68+
" with zipfile.ZipFile(zip_filepath,\"r\") as zip_ref:\n",
69+
" zip_ref.extractall(data_dir)\n",
70+
" os.rename(join(data_dir, \"data.zarr\"), spatialdata_filepath)"
71+
]
72+
},
73+
{
74+
"cell_type": "markdown",
75+
"metadata": {},
76+
"source": [
77+
"## Configure Vitessce\n",
78+
"\n",
79+
"Vitessce needs to know which pieces of data we are interested in visualizing, the visualization types we would like to use, and how we want to coordinate (or link) the views."
80+
]
81+
},
82+
{
83+
"cell_type": "code",
84+
"execution_count": null,
85+
"metadata": {},
86+
"outputs": [],
87+
"source": [
88+
"vc = VitessceConfig(\n",
89+
" schema_version=\"1.0.16\",\n",
90+
" name='Visium SpatialData Demo (visium_associated_xenium_io)',\n",
91+
")\n",
92+
"# Add data to the configuration:\n",
93+
"wrapper = SpatialDataWrapper(\n",
94+
" sdata_path=spatialdata_filepath,\n",
95+
" # The following paths are relative to the root of the SpatialData zarr store on-disk.\n",
96+
" image_path=\"images/CytAssist_FFPE_Human_Breast_Cancer_full_image\",\n",
97+
" table_path=\"table/table\",\n",
98+
" obs_feature_matrix_path=\"table/table/X\",\n",
99+
" obs_spots_path=\"shapes/CytAssist_FFPE_Human_Breast_Cancer\",\n",
100+
" region=\"CytAssist_FFPE_Human_Breast_Cancer\",\n",
101+
" coordinate_system=\"global\",\n",
102+
" coordination_values={\n",
103+
" # The following tells Vitessce to consider each observation as a \"spot\"\n",
104+
" \"obsType\": \"spot\",\n",
105+
" }\n",
106+
")\n",
107+
"dataset = vc.add_dataset(name='Breast Cancer Visium').add_object(wrapper)\n",
108+
"\n",
109+
"# Add views (visualizations) to the configuration:\n",
110+
"spatial = vc.add_view(\"spatialBeta\", dataset=dataset)\n",
111+
"feature_list = vc.add_view(vt.FEATURE_LIST, dataset=dataset)\n",
112+
"layer_controller = vc.add_view(\"layerControllerBeta\", dataset=dataset)\n",
113+
"vc.link_views_by_dict([spatial, layer_controller], {\n",
114+
" 'imageLayer': CL([{\n",
115+
" 'photometricInterpretation': 'RGB',\n",
116+
" }]),\n",
117+
"}, scope_prefix=get_initial_coordination_scope_prefix(\"A\", \"image\"))\n",
118+
"obs_sets = vc.add_view(vt.OBS_SETS, dataset=dataset)\n",
119+
"vc.link_views([spatial, layer_controller, feature_list, obs_sets], ['obsType'], [wrapper.obs_type_label])\n",
120+
"\n",
121+
"# Layout the views\n",
122+
"vc.layout(spatial | (feature_list / layer_controller / obs_sets));"
123+
]
124+
},
125+
{
126+
"cell_type": "markdown",
127+
"metadata": {},
128+
"source": [
129+
"### Render the widget"
130+
]
131+
},
132+
{
133+
"cell_type": "code",
134+
"execution_count": null,
135+
"metadata": {},
136+
"outputs": [],
137+
"source": [
138+
"vw = vc.widget()\n",
139+
"vw"
140+
]
141+
},
142+
{
143+
"cell_type": "code",
144+
"execution_count": null,
145+
"metadata": {},
146+
"outputs": [],
147+
"source": []
148+
}
149+
],
150+
"metadata": {
151+
"kernelspec": {
152+
"display_name": "Python 3 (ipykernel)",
153+
"language": "python",
154+
"name": "python3"
155+
},
156+
"language_info": {
157+
"codemirror_mode": {
158+
"name": "ipython",
159+
"version": 3
160+
},
161+
"file_extension": ".py",
162+
"mimetype": "text/x-python",
163+
"name": "python",
164+
"nbconvert_exporter": "python",
165+
"pygments_lexer": "ipython3",
166+
"version": "3.9.0"
167+
}
168+
},
169+
"nbformat": 4,
170+
"nbformat_minor": 4
171+
}
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {
6+
"nbsphinx": "hidden"
7+
},
8+
"source": [
9+
"# Vitessce Widget Tutorial"
10+
]
11+
},
12+
{
13+
"cell_type": "markdown",
14+
"metadata": {},
15+
"source": [
16+
"# Visualization of single-cell RNA seq data"
17+
]
18+
},
19+
{
20+
"cell_type": "code",
21+
"execution_count": null,
22+
"metadata": {},
23+
"outputs": [],
24+
"source": [
25+
"import os\n",
26+
"from os.path import join, isfile, isdir\n",
27+
"from urllib.request import urlretrieve\n",
28+
"from anndata import read_h5ad\n",
29+
"import scanpy as sc\n",
30+
"import json\n",
31+
"\n",
32+
"from vitessce import (\n",
33+
" VitessceConfig,\n",
34+
" Component as cm,\n",
35+
" CoordinationType as ct,\n",
36+
" AnnDataWrapper,\n",
37+
")\n",
38+
"from vitessce.data_utils import (\n",
39+
" generate_h5ad_ref_spec\n",
40+
")"
41+
]
42+
},
43+
{
44+
"cell_type": "markdown",
45+
"metadata": {},
46+
"source": [
47+
"## 0. Download data"
48+
]
49+
},
50+
{
51+
"cell_type": "code",
52+
"execution_count": null,
53+
"metadata": {},
54+
"outputs": [],
55+
"source": [
56+
"h5_url = \"https://datasets.cellxgene.cziscience.com/84df8fa1-ab53-43c9-a439-95dcb9148265.h5ad\""
57+
]
58+
},
59+
{
60+
"cell_type": "code",
61+
"execution_count": null,
62+
"metadata": {},
63+
"outputs": [],
64+
"source": [
65+
"adata_filepath = join(\"data\", \"84df8fa1-ab53-43c9-a439-95dcb9148265.h5ad\")\n",
66+
"if not isfile(adata_filepath):\n",
67+
" os.makedirs(\"data\", exist_ok=True)\n",
68+
" urlretrieve(h5_url, adata_filepath)"
69+
]
70+
},
71+
{
72+
"cell_type": "markdown",
73+
"metadata": {},
74+
"source": [
75+
"## 1. Create a Reference Spec JSON file for the H5AD file\n",
76+
"\n",
77+
"In order for Vitessce to load H5AD files, we also need to provide a corresponding [Reference Spec](https://fsspec.github.io/kerchunk/spec.html) JSON file which contains mappings between AnnData object keys and the byte offsets at which those AnnData object values begin within the H5AD file binary contents."
78+
]
79+
},
80+
{
81+
"cell_type": "code",
82+
"execution_count": null,
83+
"metadata": {},
84+
"outputs": [],
85+
"source": [
86+
"json_filepath = join(\"data\", \"84df8fa1-ab53-43c9-a439-95dcb9148265.h5ad.reference.json\")\n",
87+
"if not isfile(json_filepath):\n",
88+
" ref_dict = generate_h5ad_ref_spec(h5_url)\n",
89+
" with open(json_filepath, \"w\") as f:\n",
90+
" json.dump(ref_dict, f)"
91+
]
92+
},
93+
{
94+
"cell_type": "markdown",
95+
"metadata": {
96+
"tags": []
97+
},
98+
"source": [
99+
"## 2. Create the Vitessce widget configuration\n"
100+
]
101+
},
102+
{
103+
"cell_type": "code",
104+
"execution_count": null,
105+
"metadata": {},
106+
"outputs": [],
107+
"source": [
108+
"vc = VitessceConfig(schema_version=\"1.0.17\", name='Nakshatri et al', description='snRNA-seq analyses of breast tissues of healthy women of diverse genetic ancestry')\n",
109+
"\n",
110+
"dataset = vc.add_dataset(name='84df8fa1').add_object(AnnDataWrapper(\n",
111+
" adata_path=adata_filepath,\n",
112+
" ref_path=json_filepath, # We specify paths to both the H5AD and JSON files\n",
113+
" obs_embedding_paths=[\"obsm/X_wnn.umap\"],\n",
114+
" obs_embedding_names=[\"UMAP\"],\n",
115+
" obs_set_paths=[\"obs/cell_type\"],\n",
116+
" obs_set_names=[\"Cell Type\"],\n",
117+
" obs_feature_matrix_path=\"X\",\n",
118+
" )\n",
119+
")\n",
120+
"\n",
121+
"scatterplot = vc.add_view(cm.SCATTERPLOT, dataset=dataset, mapping=\"UMAP\")\n",
122+
"cell_sets = vc.add_view(cm.OBS_SETS, dataset=dataset)\n",
123+
"cell_set_sizes = vc.add_view(cm.OBS_SET_SIZES, dataset=dataset)\n",
124+
"genes = vc.add_view(cm.FEATURE_LIST, dataset=dataset)\n",
125+
"\n",
126+
"vc.layout((scatterplot | cell_sets) / (cell_set_sizes | genes));"
127+
]
128+
},
129+
{
130+
"cell_type": "markdown",
131+
"metadata": {
132+
"tags": []
133+
},
134+
"source": [
135+
"## 3. Create the widget"
136+
]
137+
},
138+
{
139+
"cell_type": "code",
140+
"execution_count": null,
141+
"metadata": {},
142+
"outputs": [],
143+
"source": [
144+
"vw = vc.widget()\n",
145+
"vw"
146+
]
147+
},
148+
{
149+
"cell_type": "code",
150+
"execution_count": null,
151+
"metadata": {},
152+
"outputs": [],
153+
"source": []
154+
}
155+
],
156+
"metadata": {
157+
"kernelspec": {
158+
"display_name": "Python 3 (ipykernel)",
159+
"language": "python",
160+
"name": "python3"
161+
},
162+
"language_info": {
163+
"codemirror_mode": {
164+
"name": "ipython",
165+
"version": 3
166+
},
167+
"file_extension": ".py",
168+
"mimetype": "text/x-python",
169+
"name": "python",
170+
"nbconvert_exporter": "python",
171+
"pygments_lexer": "ipython3",
172+
"version": "3.9.0"
173+
}
174+
},
175+
"nbformat": 4,
176+
"nbformat_minor": 4
177+
}

0 commit comments

Comments
 (0)