|
8 | 8 | "\n",
|
9 | 9 | "We can run Sopa on Visium HD, as the 2 micron bins are subcellular. You can follow the [\"normal\" API tutorial](../api_usage), or continue below to get exemples more specific to Visium HD data.\n",
|
10 | 10 | "\n",
|
11 |
| - "For this tutorial, we use the [mouse small intestine public dataset](https://www.10xgenomics.com/datasets/visium-hd-cytassist-gene-expression-libraries-of-mouse-intestine) from 10X Genomics." |
| 11 | + "For this tutorial, we use the [mouse small intestine public dataset](https://www.10xgenomics.com/datasets/visium-hd-cytassist-gene-expression-libraries-of-mouse-intestine) from 10X Genomics.\n" |
12 | 12 | ]
|
13 | 13 | },
|
14 | 14 | {
|
|
25 | 25 | "cell_type": "markdown",
|
26 | 26 | "metadata": {},
|
27 | 27 | "source": [
|
28 |
| - "## Reading the data" |
| 28 | + "## Reading the data\n" |
29 | 29 | ]
|
30 | 30 | },
|
31 | 31 | {
|
|
42 | 42 | "cell_type": "markdown",
|
43 | 43 | "metadata": {},
|
44 | 44 | "source": [
|
45 |
| - "Then, we save it on-disk:" |
| 45 | + "Then, we save it on-disk:\n" |
46 | 46 | ]
|
47 | 47 | },
|
48 | 48 | {
|
|
51 | 51 | "metadata": {},
|
52 | 52 | "outputs": [],
|
53 | 53 | "source": [
|
54 |
| - "sdata.write(\"mouse_small_intestine.zarr\") # save it\n", |
| 54 | + "sdata.write(\"mouse_small_intestine.zarr\") # save it\n", |
55 | 55 | "\n",
|
56 |
| - "sdata = spatialdata.read_zarr(\"mouse_small_intestine.zarr\") # open-it back" |
| 56 | + "sdata = spatialdata.read_zarr(\"mouse_small_intestine.zarr\") # open-it back" |
57 | 57 | ]
|
58 | 58 | },
|
59 | 59 | {
|
60 | 60 | "cell_type": "markdown",
|
61 | 61 | "metadata": {},
|
62 | 62 | "source": [
|
63 |
| - "## Usual pipeline" |
| 63 | + "## Usual pipeline\n" |
64 | 64 | ]
|
65 | 65 | },
|
66 | 66 | {
|
67 | 67 | "cell_type": "markdown",
|
68 | 68 | "metadata": {},
|
69 | 69 | "source": [
|
70 |
| - "Now, we run Sopa as usual. Although, since we don't have transcripts, we can't run Baysor. Therefore, we will run [Stardist](https://github.com/stardist/stardist) on the H&E image." |
| 70 | + "Now, we run Sopa as usual. Although, since we don't have transcripts, we can't run Baysor. Therefore, we will run [Stardist](https://github.com/stardist/stardist) on the H&E image.\n" |
71 | 71 | ]
|
72 | 72 | },
|
73 | 73 | {
|
74 | 74 | "cell_type": "markdown",
|
75 | 75 | "metadata": {},
|
76 | 76 | "source": [
|
77 |
| - "First, we create the patches for the cell segmentation." |
| 77 | + "First, we create the patches for the cell segmentation.\n" |
78 | 78 | ]
|
79 | 79 | },
|
80 | 80 | {
|
81 | 81 | "cell_type": "code",
|
82 |
| - "execution_count": 7, |
| 82 | + "execution_count": 5, |
83 | 83 | "metadata": {},
|
84 | 84 | "outputs": [
|
85 | 85 | {
|
86 | 86 | "name": "stderr",
|
87 | 87 | "output_type": "stream",
|
88 | 88 | "text": [
|
89 |
| - "\u001b[36;20m[INFO] (sopa.patches._patches)\u001b[0m 156 patches were added to sdata['image_patches']\n" |
| 89 | + "\u001b[36;20m[INFO] (sopa.patches._patches)\u001b[0m Added 156 patche(s) to sdata['image_patches']\n" |
90 | 90 | ]
|
91 | 91 | }
|
92 | 92 | ],
|
|
98 | 98 | "cell_type": "markdown",
|
99 | 99 | "metadata": {},
|
100 | 100 | "source": [
|
101 |
| - "Now we can run stardist on the H&E image. Here, we decrease `prob_thresh` and increase `nms_thresh` to get more cells." |
| 101 | + "Now we can run stardist on the H&E image.\n" |
102 | 102 | ]
|
103 | 103 | },
|
104 | 104 | {
|
105 | 105 | "cell_type": "code",
|
106 |
| - "execution_count": 8, |
| 106 | + "execution_count": 6, |
107 | 107 | "metadata": {},
|
108 | 108 | "outputs": [
|
109 | 109 | {
|
110 | 110 | "name": "stderr",
|
111 | 111 | "output_type": "stream",
|
112 | 112 | "text": [
|
113 | 113 | "\u001b[33;20m[WARNING] (sopa._settings)\u001b[0m Running without parallelization backend can be slow. Consider using a backend, e.g. via `sopa.settings.parallelization_backend = 'dask'`, or `export SOPA_PARALLELIZATION_BACKEND=dask`.\n",
|
114 |
| - " 3%|▎ | 4/156 [00:34<22:12, 8.77s/it]" |
| 114 | + " 3%|▎ | 4/156 [00:34<22:03, 8.71s/it]" |
115 | 115 | ]
|
116 | 116 | },
|
117 | 117 | {
|
118 | 118 | "name": "stdout",
|
119 | 119 | "output_type": "stream",
|
120 | 120 | "text": [
|
121 |
| - "WARNING:tensorflow:5 out of the last 5 calls to <function TensorFlowTrainer.make_predict_function.<locals>.one_step_on_data_distributed at 0x3a211ee60> triggered tf.function retracing. Tracing is expensive and the excessive number of tracings could be due to (1) creating @tf.function repeatedly in a loop, (2) passing tensors with different shapes, (3) passing Python objects instead of tensors. For (1), please define your @tf.function outside of the loop. For (2), @tf.function has reduce_retracing=True option that can avoid unnecessary retracing. For (3), please refer to https://www.tensorflow.org/guide/function#controlling_retracing and https://www.tensorflow.org/api_docs/python/tf/function for more details.\n" |
| 121 | + "WARNING:tensorflow:5 out of the last 5 calls to <function TensorFlowTrainer.make_predict_function.<locals>.one_step_on_data_distributed at 0x5638ebb50> triggered tf.function retracing. Tracing is expensive and the excessive number of tracings could be due to (1) creating @tf.function repeatedly in a loop, (2) passing tensors with different shapes, (3) passing Python objects instead of tensors. For (1), please define your @tf.function outside of the loop. For (2), @tf.function has reduce_retracing=True option that can avoid unnecessary retracing. For (3), please refer to https://www.tensorflow.org/guide/function#controlling_retracing and https://www.tensorflow.org/api_docs/python/tf/function for more details.\n" |
122 | 122 | ]
|
123 | 123 | },
|
124 | 124 | {
|
125 | 125 | "name": "stderr",
|
126 | 126 | "output_type": "stream",
|
127 | 127 | "text": [
|
128 |
| - " 3%|▎ | 5/156 [00:36<16:10, 6.42s/it]" |
| 128 | + " 3%|▎ | 5/156 [00:36<16:07, 6.40s/it]" |
129 | 129 | ]
|
130 | 130 | },
|
131 | 131 | {
|
132 | 132 | "name": "stdout",
|
133 | 133 | "output_type": "stream",
|
134 | 134 | "text": [
|
135 |
| - "WARNING:tensorflow:6 out of the last 6 calls to <function TensorFlowTrainer.make_predict_function.<locals>.one_step_on_data_distributed at 0x4e57d3880> triggered tf.function retracing. Tracing is expensive and the excessive number of tracings could be due to (1) creating @tf.function repeatedly in a loop, (2) passing tensors with different shapes, (3) passing Python objects instead of tensors. For (1), please define your @tf.function outside of the loop. For (2), @tf.function has reduce_retracing=True option that can avoid unnecessary retracing. For (3), please refer to https://www.tensorflow.org/guide/function#controlling_retracing and https://www.tensorflow.org/api_docs/python/tf/function for more details.\n" |
| 135 | + "WARNING:tensorflow:6 out of the last 6 calls to <function TensorFlowTrainer.make_predict_function.<locals>.one_step_on_data_distributed at 0x563ab4550> triggered tf.function retracing. Tracing is expensive and the excessive number of tracings could be due to (1) creating @tf.function repeatedly in a loop, (2) passing tensors with different shapes, (3) passing Python objects instead of tensors. For (1), please define your @tf.function outside of the loop. For (2), @tf.function has reduce_retracing=True option that can avoid unnecessary retracing. For (3), please refer to https://www.tensorflow.org/guide/function#controlling_retracing and https://www.tensorflow.org/api_docs/python/tf/function for more details.\n" |
136 | 136 | ]
|
137 | 137 | },
|
138 | 138 | {
|
139 | 139 | "name": "stderr",
|
140 | 140 | "output_type": "stream",
|
141 | 141 | "text": [
|
142 |
| - "100%|██████████| 156/156 [19:26<00:00, 7.48s/it]\n", |
143 |
| - "\u001b[36;20m[INFO] (sopa.segmentation._stainings)\u001b[0m Found 428836 total cells\n", |
144 |
| - "Resolving conflicts: 100%|██████████| 64106/64106 [00:22<00:00, 2885.00it/s]\n", |
145 |
| - "\u001b[36;20m[INFO] (sopa.segmentation._stainings)\u001b[0m Added 408458 cell boundaries in sdata['stardist_boundaries']\n" |
| 142 | + "100%|██████████| 156/156 [16:27<00:00, 6.33s/it]\n", |
| 143 | + "\u001b[36;20m[INFO] (sopa.segmentation._stainings)\u001b[0m Found 430536 total cells\n", |
| 144 | + "Resolving conflicts: 100%|██████████| 63782/63782 [00:23<00:00, 2714.30it/s]\n", |
| 145 | + "\u001b[36;20m[INFO] (sopa.segmentation._stainings)\u001b[0m Added 410196 cell boundaries in sdata['stardist_boundaries']\n" |
146 | 146 | ]
|
147 | 147 | }
|
148 | 148 | ],
|
149 | 149 | "source": [
|
150 |
| - "sopa.segmentation.stardist(sdata, prob_thresh=0.2, nms_thresh=0.6, min_area=30)" |
| 150 | + "sopa.segmentation.stardist(sdata, min_area=30)" |
151 | 151 | ]
|
152 | 152 | },
|
153 | 153 | {
|
154 | 154 | "cell_type": "markdown",
|
155 | 155 | "metadata": {},
|
156 | 156 | "source": [
|
157 |
| - "## Aggregation" |
| 157 | + "## Aggregation\n" |
158 | 158 | ]
|
159 | 159 | },
|
160 | 160 | {
|
|
165 | 165 | "\n",
|
166 | 166 | "Here, `expand_radius_ratio = 1`, which means that the cells will be expanded a value of `1 * mean_radius` before aggregating the means. You can choose any positive float value.\n",
|
167 | 167 | "\n",
|
168 |
| - "> There is an argument `bins_key`, but by default Sopa will understand that it's Visium HD data and that it should use the 2-microns bins. Also, on the example below, we only aggregate the bins, not the H&E channels." |
| 168 | + "> There is an argument `bins_key`, but by default Sopa will understand that it's Visium HD data and that it should use the 2-microns bins. Also, on the example below, we only aggregate the bins, not the H&E channels.\n" |
169 | 169 | ]
|
170 | 170 | },
|
171 | 171 | {
|
|
190 | 190 | "cell_type": "markdown",
|
191 | 191 | "metadata": {},
|
192 | 192 | "source": [
|
193 |
| - "## Single-cell table" |
| 193 | + "## Single-cell table\n" |
194 | 194 | ]
|
195 | 195 | },
|
196 | 196 | {
|
197 | 197 | "cell_type": "markdown",
|
198 | 198 | "metadata": {},
|
199 | 199 | "source": [
|
200 |
| - "Now, we have an AnnData object with the gene expression **per cell**." |
| 200 | + "Now, we have an AnnData object with the gene expression **per cell**.\n" |
201 | 201 | ]
|
202 | 202 | },
|
203 | 203 | {
|
|
229 | 229 | "cell_type": "markdown",
|
230 | 230 | "metadata": {},
|
231 | 231 | "source": [
|
232 |
| - "For instance, we can now use Scanpy to plot gene expression." |
| 232 | + "For instance, we can now use Scanpy to plot gene expression.\n" |
233 | 233 | ]
|
234 | 234 | },
|
235 | 235 | {
|
|
258 | 258 | "cell_type": "markdown",
|
259 | 259 | "metadata": {},
|
260 | 260 | "source": [
|
261 |
| - "We can then use `sc.pl.spatial` to show the gene expression per cells. Note that, here, we show **cells**, not bins." |
| 261 | + "We can then use `sc.pl.spatial` to show the gene expression per cells. Note that, here, we show **cells**, not bins.\n" |
262 | 262 | ]
|
263 | 263 | },
|
264 | 264 | {
|
|
289 | 289 | "\n",
|
290 | 290 | "The 2-micron bins are arranged in a grid, so they can be visualized as an image of `G` channels, where `G` is the number of genes.\n",
|
291 | 291 | "\n",
|
292 |
| - "Creating the image would be massive, so we need to create it lazily. This can be done with `spatialdata.rasterize_bins`." |
| 292 | + "Creating the image would be massive, so we need to create it lazily. This can be done with `spatialdata.rasterize_bins`.\n" |
293 | 293 | ]
|
294 | 294 | },
|
295 | 295 | {
|
296 | 296 | "cell_type": "code",
|
297 |
| - "execution_count": 12, |
| 297 | + "execution_count": null, |
298 | 298 | "metadata": {},
|
299 | 299 | "outputs": [],
|
300 | 300 | "source": [
|
301 |
| - "sdata[\"square_002um\"].X = sdata[\"square_002um\"].X.tocsc() # optimisation with the csc format\n", |
| 301 | + "sdata[\"square_002um\"].X = sdata[\"square_002um\"].X.tocsc() # optimisation with the csc format\n", |
302 | 302 | "\n",
|
303 | 303 | "lazy_bins_image = spatialdata.rasterize_bins(\n",
|
304 | 304 | " sdata,\n",
|
305 |
| - " bins=\"Visium_HD_Mouse_Small_Intestine_square_002um\", # key of the bins shapes\n", |
306 |
| - " table_name=\"square_002um\", # key of the table with the bins gene expression\n", |
| 305 | + " bins=\"Visium_HD_Mouse_Small_Intestine_square_002um\", # key of the bins shapes\n", |
| 306 | + " table_name=\"square_002um\", # key of the table with the bins gene expression\n", |
307 | 307 | " row_key=\"array_row\",\n",
|
308 | 308 | " col_key=\"array_col\",\n",
|
309 | 309 | ")"
|
|
313 | 313 | "cell_type": "markdown",
|
314 | 314 | "metadata": {},
|
315 | 315 | "source": [
|
316 |
| - "Note that `lazy_bins_image` is an image of size `(19059, 690, 690)`, that is `G=19059` genes, and `690x690` bins. This would correspond to a 33.80GB image in memory, if it wasn't lazy." |
| 316 | + "Note that `lazy_bins_image` is an image of size `(19059, 690, 690)`, that is `G=19059` genes, and `690x690` bins. This would correspond to a 33.80GB image in memory, if it wasn't lazy.\n" |
317 | 317 | ]
|
318 | 318 | },
|
319 | 319 | {
|
|
329 | 329 | "cell_type": "markdown",
|
330 | 330 | "metadata": {},
|
331 | 331 | "source": [
|
332 |
| - "We can save this image in the `sdata` object." |
| 332 | + "We can save this image in the `sdata` object.\n" |
333 | 333 | ]
|
334 | 334 | },
|
335 | 335 | {
|
|
345 | 345 | "cell_type": "markdown",
|
346 | 346 | "metadata": {},
|
347 | 347 | "source": [
|
348 |
| - "Then, we can visualize this image with Napari. When showing a gene, it will compute the corresponding layer of the lazy image, and it will be displayed in milliseconds, i.e. looking instantaneous." |
| 348 | + "Then, we can visualize this image with Napari. When showing a gene, it will compute the corresponding layer of the lazy image, and it will be displayed in milliseconds, i.e. looking instantaneous.\n" |
349 | 349 | ]
|
350 | 350 | },
|
351 | 351 | {
|
|
367 | 367 | "\n",
|
368 | 368 | "<p align=\"center\">\n",
|
369 | 369 | " <img src=\"../../assets/napari_visium_hd.png\" alt=\"napari_visium_hd\" width=\"600px\"/>\n",
|
370 |
| - "</p>" |
| 370 | + "</p>\n" |
371 | 371 | ]
|
372 | 372 | },
|
373 | 373 | {
|
374 | 374 | "cell_type": "markdown",
|
375 | 375 | "metadata": {},
|
376 | 376 | "source": [
|
377 | 377 | "## Xenium Explorer\n",
|
378 |
| - "Although the Xenium Explorer can be used (as below), it will not display the bins. If you want to see the bins, use `Napari` as detailed above." |
| 378 | + "\n", |
| 379 | + "Although the Xenium Explorer can be used (as below), it will not display the bins. If you want to see the bins, use `Napari` as detailed above.\n" |
379 | 380 | ]
|
380 | 381 | },
|
381 | 382 | {
|
|
0 commit comments