{ "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "name": "python", "version": "3.9.15", "mimetype": "text/x-python", "codemirror_mode": { "name": "ipython", "version": 3 }, "pygments_lexer": "ipython3", "nbconvert_exporter": "python", "file_extension": ".py" } }, "nbformat_minor": 5, "nbformat": 4, "cells": [ { "cell_type": "markdown", "source": "# Tutorial: SOMA Experiment queries", "metadata": { "tags": [] }, "id": "2b8e72a7-129c-422c-b955-350fb9ee0541" }, { "cell_type": "code", "source": "import tiledbsoma as soma", "metadata": { "tags": [], "trusted": true }, "execution_count": 3, "outputs": [], "id": "3a5fd5d3" }, { "cell_type": "markdown", "source": "In this notebook, we'll take a quick look at the SOMA experiment-query API. The dataset used is from Peripheral Blood Mononuclear Cells (PBMC), which is freely available from 10X Genomics.\n", "metadata": { "tags": [] }, "id": "ccc8709a" }, { "cell_type": "code", "source": "exp = soma.Experiment.open('data/sparse/pbmc3k')", "metadata": { "tags": [], "trusted": true }, "execution_count": 4, "outputs": [], "id": "9b8851d9-27f1-437b-a070-b41a65a5609e" }, { "cell_type": "markdown", "source": "Using the keys of the `obs` dataframe, we can see what fields are available to query on.", "metadata": { "tags": [] }, "id": "fab7898c" }, { "cell_type": "code", "source": "exp.obs.keys()", "metadata": { "tags": [], "trusted": true }, "execution_count": 5, "outputs": [ { "execution_count": 5, "output_type": "execute_result", "data": { "text/plain": "('soma_joinid', 'obs_id', 'n_genes', 'percent_mito', 'n_counts', 'louvain')" }, "metadata": {} } ], "id": "d67dfbc6-0382-4acc-8c56-3670549654f8" }, { "cell_type": "code", "source": "p = exp.obs.read(column_names=['louvain']).concat().to_pandas()\np", "metadata": { "tags": [], "trusted": true }, "execution_count": 6, "outputs": [ { "execution_count": 6, "output_type": "execute_result", "data": { "text/plain": " louvain\n0 CD4 T cells\n1 B cells\n2 CD4 T cells\n3 CD14+ Monocytes\n4 NK cells\n... ...\n2633 CD14+ Monocytes\n2634 B cells\n2635 B cells\n2636 B cells\n2637 CD4 T cells\n\n[2638 rows x 1 columns]", "text/html": "
| \n | louvain | \n
|---|---|
| 0 | \nCD4 T cells | \n
| 1 | \nB cells | \n
| 2 | \nCD4 T cells | \n
| 3 | \nCD14+ Monocytes | \n
| 4 | \nNK cells | \n
| ... | \n... | \n
| 2633 | \nCD14+ Monocytes | \n
| 2634 | \nB cells | \n
| 2635 | \nB cells | \n
| 2636 | \nB cells | \n
| 2637 | \nCD4 T cells | \n
2638 rows × 1 columns
\n| \n | soma_dim_0 | \nsoma_dim_1 | \nsoma_data | \n
|---|---|---|---|
| 0 | \n1 | \n0 | \n-0.214582 | \n
| 1 | \n1 | \n1 | \n-0.372653 | \n
| 2 | \n1 | \n2 | \n-0.054804 | \n
| 3 | \n1 | \n3 | \n-0.683391 | \n
| 4 | \n1 | \n4 | \n0.633951 | \n
| ... | \n... | \n... | \n... | \n
| 911643 | \n2636 | \n1833 | \n-0.149789 | \n
| 911644 | \n2636 | \n1834 | \n-0.325824 | \n
| 911645 | \n2636 | \n1835 | \n-0.005918 | \n
| 911646 | \n2636 | \n1836 | \n-0.135213 | \n
| 911647 | \n2636 | \n1837 | \n-0.482111 | \n
911648 rows × 3 columns
\n