Skip to content

Commit

Permalink
📝 Mutate tiledbsoma store (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
Koncopd authored Aug 5, 2024
1 parent 73997f3 commit 309238d
Showing 1 changed file with 83 additions and 4 deletions.
87 changes: 83 additions & 4 deletions docs/scrna6.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"source": [
"import lamindb as ln\n",
"import pandas as pd\n",
"import scanpy as sc\n",
"import tiledbsoma\n",
"import tiledbsoma.io\n",
"from functools import reduce"
Expand Down Expand Up @@ -288,14 +289,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Query the array"
"## Query the array store"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Open and query the experiment. We can use the registered `Artifact`."
"Open and query the experiment. We can use the registered `Artifact`. We query `X` and `obs` from the array store."
]
},
{
Expand All @@ -308,8 +309,86 @@
},
"outputs": [],
"source": [
"with soma_artifact.open() as soma_array:\n",
" print(soma_array[\"obs\"].read().concat().to_pandas())"
"with soma_artifact.open() as soma_store:\n",
" obs = soma_store[\"obs\"]\n",
" ms_rna = soma_store[\"ms\"][\"RNA\"]\n",
" \n",
" n_obs = len(obs)\n",
" n_var = len(ms_rna[\"var\"])\n",
" X = ms_rna[\"X\"][\"data\"].read().coos((n_obs, n_var)).concat().to_scipy()\n",
" \n",
" print(obs.read().concat().to_pandas())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Update the array store"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Calculate PCA from the queried `X`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pca_array = sc.pp.pca(X, n_comps=2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"soma_artifact"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Open the array store in write mode and add PCA. When the store is updated, the corresponding artifact also gets updated with a new version. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"with soma_artifact.open(mode=\"w\") as soma_store:\n",
" tiledbsoma.io.add_matrix_to_collection(\n",
" exp=soma_store,\n",
" measurement_name=\"RNA\",\n",
" collection_name=\"obsm\",\n",
" matrix_name=\"pca\",\n",
" matrix_data=pca_array\n",
" )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note that the artifact has been changed."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"soma_artifact"
]
}
],
Expand Down

0 comments on commit 309238d

Please sign in to comment.