Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -929,4 +929,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
24 changes: 17 additions & 7 deletions notebooks/examples/sdata_from_scratch.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down Expand Up @@ -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\"]]"
Expand Down