Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
keller-mark committed Oct 4, 2024
2 parents d4ebe79 + bc5e21c commit f64bd51
Show file tree
Hide file tree
Showing 28 changed files with 2,092 additions and 92 deletions.
4 changes: 3 additions & 1 deletion .coveragerc_omit
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ omit =
vitessce/data_utils/anndata.py
vitessce/data_utils/ome.py
vitessce/data_utils/entities.py
vitessce/data_utils/multivec.py
vitessce/data_utils/multivec.py
vitessce/widget_plugins/demo_plugin.py
vitessce/widget_plugins/spatial_query.py
2 changes: 1 addition & 1 deletion demos/fill_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def render_json(dir_name, version_str, url_type, port):

BASE_URL = {
'local': f'http://localhost:{port}/{dir_name}/data/processed',
'remote': f'https://s3.amazonaws.com/vitessce-data/{version_str}/main/{dir_name}'
'remote': f'https://data-1.vitessce.io/{version_str}/main/{dir_name}'
}
BASE_URL_GCP = {
'local': f'http://localhost:{port}/{dir_name}/data/processed',
Expand Down
3 changes: 2 additions & 1 deletion docs/data_examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ Data preparation examples

notebooks/data_export_s3
notebooks/data_export_files
notebooks/widget_brain_with_base_dir
notebooks/widget_brain_with_base_dir
notebooks/widget_brain_h5ad
39 changes: 39 additions & 0 deletions docs/data_options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,44 @@ Jupyter process: remote service like Colab/Binder; Files: remote & accessed via

Unfortunately, this will not work because the remote server cannot access the files that are on another machine behind SSH.

========================================================================
Jupyter process: anywhere; Files: anywhere that can be accessed via Zarr
========================================================================

If the data is readable via Zarr (i.e., `zarr.storage.*Store`) and the Jupyter process can access the store contents, then the Vitessce widget can access the data by specifying the Zarr store as the data source for Vitessce data wrapper class instances.
This is currently supported for the ``AnnDataWrapper`` class using the ``adata_store`` parameter (as opposed to ``adata_path`` or ``adata_url``).

.. code-block:: python
from vitessce import VitessceConfig, AnnDataWrapper
# ...
adata.write_zarr("my_store.adata.zarr")
vc = VitessceConfig(name="My Vitessce Configuration")
vc.add_dataset(name="My Dataset").add_object(AnnDataWrapper(
adata_store="my_store.adata.zarr",
# ...
))
# ...
vc.widget()
Or, with a Zarr store instance (instead of a local string path to a DirectoryStore):

.. code-block:: python
import zarr
from vitessce import VitessceConfig, AnnDataWrapper
# ...
store = zarr.storage.FSStore("s3://my_bucket/path/to/my_store.adata.zarr")
vc = VitessceConfig(name="My Vitessce Configuration")
vc.add_dataset(name="My Dataset").add_object(AnnDataWrapper(
adata_store=store,
# ...
))
# ...
vc.widget()
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ The Vitessce widget is compatible with the following interactive Python platform
api_config
api_data
data_options
widget_plugins
screenshots


Expand Down
177 changes: 177 additions & 0 deletions docs/notebooks/widget_brain_h5ad.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"nbsphinx": "hidden"
},
"source": [
"# Vitessce Widget Tutorial"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Visualization of single-cell RNA seq data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"from os.path import join, isfile, isdir\n",
"from urllib.request import urlretrieve\n",
"from anndata import read_h5ad\n",
"import scanpy as sc\n",
"import json\n",
"\n",
"from vitessce import (\n",
" VitessceConfig,\n",
" Component as cm,\n",
" CoordinationType as ct,\n",
" AnnDataWrapper,\n",
")\n",
"from vitessce.data_utils import (\n",
" generate_h5ad_ref_spec\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 0. Download data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"h5_url = \"https://datasets.cellxgene.cziscience.com/84df8fa1-ab53-43c9-a439-95dcb9148265.h5ad\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"adata_filepath = join(\"data\", \"84df8fa1-ab53-43c9-a439-95dcb9148265.h5ad\")\n",
"if not isfile(adata_filepath):\n",
" os.makedirs(\"data\", exist_ok=True)\n",
" urlretrieve(h5_url, adata_filepath)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1. Create a Reference Spec JSON file for the H5AD file\n",
"\n",
"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."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"json_filepath = join(\"data\", \"84df8fa1-ab53-43c9-a439-95dcb9148265.h5ad.reference.json\")\n",
"if not isfile(json_filepath):\n",
" ref_dict = generate_h5ad_ref_spec(h5_url)\n",
" with open(json_filepath, \"w\") as f:\n",
" json.dump(ref_dict, f)"
]
},
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
"## 2. Create the Vitessce widget configuration\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"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",
"\n",
"dataset = vc.add_dataset(name='84df8fa1').add_object(AnnDataWrapper(\n",
" adata_path=adata_filepath,\n",
" ref_path=json_filepath, # We specify paths to both the H5AD and JSON files\n",
" obs_embedding_paths=[\"obsm/X_wnn.umap\"],\n",
" obs_embedding_names=[\"UMAP\"],\n",
" obs_set_paths=[\"obs/cell_type\"],\n",
" obs_set_names=[\"Cell Type\"],\n",
" obs_feature_matrix_path=\"X\",\n",
" )\n",
")\n",
"\n",
"scatterplot = vc.add_view(cm.SCATTERPLOT, dataset=dataset, mapping=\"UMAP\")\n",
"cell_sets = vc.add_view(cm.OBS_SETS, dataset=dataset)\n",
"cell_set_sizes = vc.add_view(cm.OBS_SET_SIZES, dataset=dataset)\n",
"genes = vc.add_view(cm.FEATURE_LIST, dataset=dataset)\n",
"\n",
"vc.layout((scatterplot | cell_sets) / (cell_set_sizes | genes));"
]
},
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
"## 3. Create the widget"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"vw = vc.widget()\n",
"vw"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.0"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
15 changes: 5 additions & 10 deletions docs/notebooks/widget_pbmc.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@
"source": [
"## 4. Create a Vitessce view config\n",
"\n",
"Define the data and views you would like to include in the widget."
"Define the data and views you would like to include in the widget.\n",
"\n",
"For more details about how to configure data depending on where the files are located relative to the notebook execution, see https://python-docs.vitessce.io/data_options.html."
]
},
{
Expand All @@ -129,7 +131,7 @@
"source": [
"vc = VitessceConfig(schema_version=\"1.0.15\", name='PBMC Reference')\n",
"dataset = vc.add_dataset(name='PBMC 3k').add_object(AnnDataWrapper(\n",
" adata_path=zarr_filepath,\n",
" adata_store=zarr_filepath,\n",
" obs_set_paths=[\"obs/leiden\"],\n",
" obs_set_names=[\"Leiden\"],\n",
" obs_embedding_paths=[\"obsm/X_umap\", \"obsm/X_pca\"],\n",
Expand All @@ -153,13 +155,6 @@
"## 5. Create the Vitessce widget"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A widget can be created with the `.widget()` method on the config instance. Here, the `proxy=True` parameter allows this widget to be used in a cloud notebook environment, such as Binder."
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -201,7 +196,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.0"
"version": "3.9.0"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit f64bd51

Please sign in to comment.