diff --git a/notebooks/developers_resources/storage_format/_latest_run_notebook.ipynb b/notebooks/developers_resources/storage_format/_latest_run_notebook.ipynb index bb2ca6c..e511f69 100644 --- a/notebooks/developers_resources/storage_format/_latest_run_notebook.ipynb +++ b/notebooks/developers_resources/storage_format/_latest_run_notebook.ipynb @@ -929,4 +929,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +} diff --git a/notebooks/examples/sdata_from_scratch.ipynb b/notebooks/examples/sdata_from_scratch.ipynb index 8cada9a..5c51d4b 100644 --- a/notebooks/examples/sdata_from_scratch.ipynb +++ b/notebooks/examples/sdata_from_scratch.ipynb @@ -3653,12 +3653,23 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Connect the `AnnData` to the `Shapes` object" + "### Connect the `AnnData` to the `Shapes` object\n", + "\n", + "The connection between `AnnData` and SpatialData regions is recorded as a dict in `.uns[\"spatialdata_attrs]`. \n", + "The following entries are required: \n", + "\n", + " * `region`: This refers to the SpatialData element that the AnnData object annotates. It may be a list\n", + " if multiple elements are annotated. In our case, it is the name of the Shapes element we will use later\n", + " (i.e. the object with centers and radii of the Visium spots).\n", + " * `region_key`: Column in `adata.obs` that will link a given obs to the elements it annotates. This column may only contain\n", + " identifiers that are specified in the `region` key.\n", + " * `instance_key`: Column that matches a given obs in the table to a given circle. It must contain values that are \n", + " in the dataframe index of the points/shapes element. " ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -3771,12 +3782,11 @@ ], "source": [ "adata_for_sdata.uns[\"spatialdata_attrs\"] = {\n", - " \"region\": \"spots\", # name of the Shapes element we will use later (i.e. the object with centers\n", - " # and radii of the Visium spots)\n", - " \"region_key\": \"region\", # column in adata.obs that will link a given obs to the elements it annotates\n", - " \"instance_key\": \"spot_id\", # column that matches a given obs in the table to a given circle\n", + " \"region\": \"spots\",\n", + " \"region_key\": \"region\",\n", + " \"instance_key\": \"spot_id\",\n", "}\n", - "# all the rows of adata annotate the same element, called \"spots\" (as we declared above)\n", + "# In this example, all the rows of adata annotate the same element, called \"spots\" (as we declared above)\n", "adata.obs[\"region\"] = pd.Categorical([\"spots\"] * len(adata))\n", "adata.obs[\"spot_id\"] = shapes_for_sdata.index\n", "adata.obs[[\"region\", \"spot_id\"]]"