{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "IPython magic command to render matplotlib plots." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# MERFISH whole brain spatial transcriptomics (part 2a)\n", "\n", "In part 1, we explored two examples looking at the expression of canonical neurotransmitter transporter genes and gene Tac2 in the one coronal section. In this notebook, we will prepare data so that we can repeat the examples for all cells spanning the whole brain. This notebook takes ~10 seconds to run.\n", "\n", "The results from this notebook has already been cached and saved. As such, if needed you can skip this notebook and continue with part 2b.\n", "\n", "You need to be connected to the internet to run this notebook and have run through the [getting started notebook](https://alleninstitute.github.io/abc_atlas_access/notebooks/getting_started.html)." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "from pathlib import Path\n", "import numpy as np\n", "import anndata\n", "import time\n", "\n", "from abc_atlas_access.abc_atlas_cache.abc_project_cache import AbcProjectCache" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We will interact with the data using the **AbcProjectCache**. This cache object tracks which data has been downloaded and serves the path to the requsted data on disk. For metadata, the cache can also directly serve a up a Pandas Dataframe. See the ``getting_started`` notebook for more details on using the cache including installing it if it has not already been.\n", "\n", "**Change the download_base variable to where you have downloaded the data in your system.**" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'releases/20240831/manifest.json'" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "download_base = Path('../../data/abc_atlas')\n", "abc_cache = AbcProjectCache.from_cache_dir(download_base)\n", "\n", "abc_cache.current_manifest" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "3938808\n" ] } ], "source": [ "cell = abc_cache.get_metadata_dataframe(\n", " directory='MERFISH-C57BL6J-638850',\n", " file_name='cell_metadata',\n", " dtype={'cell_label': str}\n", ")\n", "cell.set_index('cell_label', inplace=True)\n", "print(len(cell))" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/Users/chris.morrison/src/data/abc_atlas/expression_matrices/MERFISH-C57BL6J-638850/20230830/C57BL6J-638850-log2.h5ad\n" ] } ], "source": [ "file = abc_cache.get_data_path(\n", " directory='MERFISH-C57BL6J-638850',\n", " file_name='C57BL6J-638850/log2'\n", ")\n", "print(file)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "adata = anndata.read_h5ad(file, backed='r')\n", "gene = adata.var" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | gene_symbol | \n", "transcript_identifier | \n", "
---|---|---|
gene_identifier | \n", "\n", " | \n", " |
ENSMUSG00000030500 | \n", "Slc17a6 | \n", "ENSMUST00000032710 | \n", "
ENSMUSG00000037771 | \n", "Slc32a1 | \n", "ENSMUST00000045738 | \n", "
ENSMUSG00000025400 | \n", "Tac2 | \n", "ENSMUST00000026466 | \n", "
ENSMUSG00000039728 | \n", "Slc6a5 | \n", "ENSMUST00000056442 | \n", "
ENSMUSG00000070570 | \n", "Slc17a7 | \n", "ENSMUST00000085374 | \n", "
ENSMUSG00000019935 | \n", "Slc17a8 | \n", "ENSMUST00000020102 | \n", "
ENSMUSG00000021609 | \n", "Slc6a3 | \n", "ENSMUST00000022100 | \n", "
ENSMUSG00000020838 | \n", "Slc6a4 | \n", "ENSMUST00000021195 | \n", "