|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": null, |
| 6 | + "metadata": { |
| 7 | + "tags": [] |
| 8 | + }, |
| 9 | + "outputs": [], |
| 10 | + "source": [ |
| 11 | + "#!pip install \"vitessce[all]==3.3.0\" esbuild_py anndata\n", |
| 12 | + "!pip install \"mlxtend~=0.23.0\"\n", |
| 13 | + "#!pip install -i \"https://test.pypi.org/simple/\" SpatialQuery\n", |
| 14 | + "!pip install \"SpatialQuery @ git+https://github.com/ShaokunAn/Spatial-Query@main\"" |
| 15 | + ] |
| 16 | + }, |
| 17 | + { |
| 18 | + "cell_type": "code", |
| 19 | + "execution_count": 1, |
| 20 | + "metadata": {}, |
| 21 | + "outputs": [], |
| 22 | + "source": [ |
| 23 | + "from os.path import join\n", |
| 24 | + "from anndata import read_h5ad\n", |
| 25 | + "from vitessce import (\n", |
| 26 | + " VitessceConfig,\n", |
| 27 | + " AnnDataWrapper,\n", |
| 28 | + " ViewType as vt,\n", |
| 29 | + " CoordinationType as ct,\n", |
| 30 | + " CoordinationLevel as CL,\n", |
| 31 | + ")\n", |
| 32 | + "from vitessce.widget_plugins import SpatialQueryPlugin" |
| 33 | + ] |
| 34 | + }, |
| 35 | + { |
| 36 | + "cell_type": "code", |
| 37 | + "execution_count": 2, |
| 38 | + "metadata": {}, |
| 39 | + "outputs": [], |
| 40 | + "source": [ |
| 41 | + "adata = read_h5ad(join(\"data\", \"HBM987_KWLK_254\", \"secondary_analysis.h5ad\"))\n", |
| 42 | + "zarr_path = join(\"data\", \"HBM987_KWLK_254\", \"secondary_analysis.h5ad.zarr\")\n", |
| 43 | + "adata.write_zarr(zarr_path)" |
| 44 | + ] |
| 45 | + }, |
| 46 | + { |
| 47 | + "cell_type": "code", |
| 48 | + "execution_count": 3, |
| 49 | + "metadata": {}, |
| 50 | + "outputs": [], |
| 51 | + "source": [ |
| 52 | + "plugin = SpatialQueryPlugin(adata)" |
| 53 | + ] |
| 54 | + }, |
| 55 | + { |
| 56 | + "cell_type": "code", |
| 57 | + "execution_count": 12, |
| 58 | + "metadata": {}, |
| 59 | + "outputs": [], |
| 60 | + "source": [ |
| 61 | + "vc = VitessceConfig(schema_version=\"1.0.16\", name=\"Spatial-Query\")\n", |
| 62 | + "dataset = vc.add_dataset(\"Query results\").add_object(AnnDataWrapper(\n", |
| 63 | + " adata_path=zarr_path,\n", |
| 64 | + " obs_feature_matrix_path=\"X\",\n", |
| 65 | + " obs_set_paths=[\"obs/predicted.ASCT.celltype\"],\n", |
| 66 | + " obs_set_names=[\"Cell Type\"],\n", |
| 67 | + " obs_spots_path=\"obsm/X_spatial\",\n", |
| 68 | + " feature_labels_path=\"var/hugo_symbol\",\n", |
| 69 | + " coordination_values={\n", |
| 70 | + " \"featureLabelsType\": \"Gene symbol\",\n", |
| 71 | + " }\n", |
| 72 | + "))\n", |
| 73 | + "\n", |
| 74 | + "spatial_view = vc.add_view(\"spatialBeta\", dataset=dataset)\n", |
| 75 | + "lc_view = vc.add_view(\"layerControllerBeta\", dataset=dataset)\n", |
| 76 | + "sets_view = vc.add_view(\"obsSets\", dataset=dataset)\n", |
| 77 | + "features_view = vc.add_view(\"featureList\", dataset=dataset)\n", |
| 78 | + "sq_view = vc.add_view(\"spatialQuery\", dataset=dataset)\n", |
| 79 | + "\n", |
| 80 | + "obs_set_selection_scope, = vc.add_coordination(\"obsSetSelection\",)\n", |
| 81 | + "obs_set_selection_scope.set_value(None)\n", |
| 82 | + "\n", |
| 83 | + "sets_view.use_coordination(obs_set_selection_scope)\n", |
| 84 | + "sq_view.use_coordination(obs_set_selection_scope)\n", |
| 85 | + "spatial_view.use_coordination(obs_set_selection_scope)\n", |
| 86 | + "features_view.use_coordination(obs_set_selection_scope)\n", |
| 87 | + "\n", |
| 88 | + "vc.link_views([spatial_view, lc_view, sets_view, features_view],\n", |
| 89 | + " [\"additionalObsSets\", \"obsSetColor\"],\n", |
| 90 | + " [plugin.additional_obs_sets, plugin.obs_set_color]\n", |
| 91 | + ")\n", |
| 92 | + "vc.link_views_by_dict([spatial_view, lc_view], {\n", |
| 93 | + " \"spotLayer\": CL([\n", |
| 94 | + " {\n", |
| 95 | + " \"obsType\": \"cell\",\n", |
| 96 | + " \"spatialSpotRadius\": 15,\n", |
| 97 | + " },\n", |
| 98 | + " ])\n", |
| 99 | + "})\n", |
| 100 | + "\n", |
| 101 | + "vc.layout((spatial_view | (lc_view / features_view)) / (sets_view | sq_view));" |
| 102 | + ] |
| 103 | + }, |
| 104 | + { |
| 105 | + "cell_type": "code", |
| 106 | + "execution_count": 13, |
| 107 | + "metadata": {}, |
| 108 | + "outputs": [ |
| 109 | + { |
| 110 | + "name": "stderr", |
| 111 | + "output_type": "stream", |
| 112 | + "text": [ |
| 113 | + "/Users/mkeller/software/miniconda3/envs/vitessce-python-notebooks/lib/python3.9/site-packages/traitlets/traitlets.py:869: DeprecationWarning: Deprecated in traitlets 4.1, use the instance .metadata dictionary directly, like x.metadata[key] or x.metadata.get(key, default)\n", |
| 114 | + " warn(\"Deprecated in traitlets 4.1, \" + msg, DeprecationWarning, stacklevel=2)\n", |
| 115 | + "/Users/mkeller/software/miniconda3/envs/vitessce-python-notebooks/lib/python3.9/site-packages/traitlets/traitlets.py:869: DeprecationWarning: Deprecated in traitlets 4.1, use the instance .metadata dictionary directly, like x.metadata[key] or x.metadata.get(key, default)\n", |
| 116 | + " warn(\"Deprecated in traitlets 4.1, \" + msg, DeprecationWarning, stacklevel=2)\n" |
| 117 | + ] |
| 118 | + }, |
| 119 | + { |
| 120 | + "data": { |
| 121 | + "application/vnd.jupyter.widget-view+json": { |
| 122 | + "model_id": "6f30fb3eac1644478df256bf79a986e9", |
| 123 | + "version_major": 2, |
| 124 | + "version_minor": 1 |
| 125 | + }, |
| 126 | + "text/plain": [ |
| 127 | + "VitessceWidget(config={'version': '1.0.16', 'name': 'Spatial-Query', 'description': '', 'datasets': [{'uid': '…" |
| 128 | + ] |
| 129 | + }, |
| 130 | + "execution_count": 13, |
| 131 | + "metadata": {}, |
| 132 | + "output_type": "execute_result" |
| 133 | + } |
| 134 | + ], |
| 135 | + "source": [ |
| 136 | + "vw = vc.widget(height=900, plugins=[plugin], remount_on_uid_change=False)\n", |
| 137 | + "vw" |
| 138 | + ] |
| 139 | + }, |
| 140 | + { |
| 141 | + "cell_type": "code", |
| 142 | + "execution_count": null, |
| 143 | + "metadata": {}, |
| 144 | + "outputs": [], |
| 145 | + "source": [] |
| 146 | + } |
| 147 | + ], |
| 148 | + "metadata": { |
| 149 | + "kernelspec": { |
| 150 | + "display_name": "Python 3 (ipykernel)", |
| 151 | + "language": "python", |
| 152 | + "name": "python3" |
| 153 | + }, |
| 154 | + "language_info": { |
| 155 | + "codemirror_mode": { |
| 156 | + "name": "ipython", |
| 157 | + "version": 3 |
| 158 | + }, |
| 159 | + "file_extension": ".py", |
| 160 | + "mimetype": "text/x-python", |
| 161 | + "name": "python", |
| 162 | + "nbconvert_exporter": "python", |
| 163 | + "pygments_lexer": "ipython3", |
| 164 | + "version": "3.9.0" |
| 165 | + } |
| 166 | + }, |
| 167 | + "nbformat": 4, |
| 168 | + "nbformat_minor": 4 |
| 169 | +} |
0 commit comments