diff --git a/docs/notebooks/subsampling.ipynb b/docs/notebooks/subsampling.ipynb new file mode 100644 index 00000000..bb96e43e --- /dev/null +++ b/docs/notebooks/subsampling.ipynb @@ -0,0 +1,124 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Subsampling cells\n", + "In this tutorial we show how subsampling cells in scverse data objects can be done.\n", + "\n", + "\n", + "This is a placeholder to be filled." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import scanpy as sc\n", + "from imblearn.under_sampling import RandomUnderSampler" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "louvain\n", + "CD4 T cells 1144\n", + "CD14+ Monocytes 480\n", + "B cells 342\n", + "CD8 T cells 316\n", + "NK cells 154\n", + "FCGR3A+ Monocytes 150\n", + "Dendritic cells 37\n", + "Megakaryocytes 15\n", + "Name: count, dtype: int64" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "adata = sc.datasets.pbmc3k_processed()\n", + "adata.obs.louvain.value_counts()" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/eljasroellin/Documents/scverse-tutorials/tutorials_venv_mar/lib/python3.11/site-packages/anndata/_core/aligned_df.py:67: ImplicitModificationWarning: Transforming to str index.\n", + " warnings.warn(\"Transforming to str index.\", ImplicitModificationWarning)\n" + ] + }, + { + "data": { + "text/plain": [ + "louvain\n", + "CD4 T cells 15\n", + "CD14+ Monocytes 15\n", + "B cells 15\n", + "CD8 T cells 15\n", + "NK cells 15\n", + "FCGR3A+ Monocytes 15\n", + "Dendritic cells 15\n", + "Megakaryocytes 15\n", + "Name: count, dtype: int64" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rus = RandomUnderSampler(random_state=0)\n", + "X_resampled, y_resampled = rus.fit_resample(adata.X, adata.obs.louvain)\n", + "adata_resampled = sc.AnnData(X_resampled, obs=pd.DataFrame(y_resampled)) ##adata[y_resampled]\n", + "adata_resampled.obs.louvain.value_counts()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "tutorials_venv_mar", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.8" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/tutorial-registry/tutorials/large-datasets/icon.png b/tutorial-registry/tutorials/large-datasets/icon.png new file mode 100644 index 00000000..73e442ab Binary files /dev/null and b/tutorial-registry/tutorials/large-datasets/icon.png differ diff --git a/tutorial-registry/tutorials/large-datasets/meta.yaml b/tutorial-registry/tutorials/large-datasets/meta.yaml new file mode 100644 index 00000000..3ae94c7e --- /dev/null +++ b/tutorial-registry/tutorials/large-datasets/meta.yaml @@ -0,0 +1,14 @@ +name: Subsampling cells +description: | + In this tutorial, we demonstrate subsampling with scverse data objects. +link: # TODO https://scverse-tutorials.readthedocs.io/en/latest/notebooks/scverse_data_backed.html#working-with-scverse-objects-in-backed-mode +primary_category: Large Datasets # Data structures +image: icon.png +tags: + - large datasets +packages: + - anndata + - mudata + - scanpy +authors: + - eroell