{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Retrieving Calcium Imaging Data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This section will serve as an introdution to retrieving two-photon fluorescence imaging data from the Allen Brain Observatory. By the end of this section you will know how to obtain a two-photon imaging dataset for a particular cell type in a specific visual area.\n", "\n", "## Setup\n", "We need a variety of standard Python packages in addition to two different `allensdk` toolboxes. If you have not yet installed the `allensdk`, run the cell below. Otherwise, you can skip to the cell that imports our toolboxes." ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "allensdk already installed.\n" ] } ], "source": [ "# This will ensure that the AllenSDK is installed.\n", "# If not, it will install it for you.\n", "try:\n", " import allensdk\n", " if allensdk.__version__ == '2.11.2':\n", " print('allensdk already installed.')\n", " else:\n", " print('incompatible version of allensdk installed')\n", "except ImportError as e:\n", " !pip install allensdk" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/ashley/anaconda3/lib/python3.7/site-packages/dask/config.py:168: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.\n", " data = yaml.load(f.read()) or {}\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Packages installed.\n" ] } ], "source": [ "# Import our toolboxes\n", "import allensdk.brain_observatory.stimulus_info as stim_info\n", "from allensdk.core.brain_observatory_cache import BrainObservatoryCache\n", "import pandas as pd \n", "import matplotlib.pyplot as plt\n", "print('Packages installed.')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Get a list of all possible transgenic mouse lines and brain areas, and choose which to work with." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Below, we'll create an instance of the [`BrainObservatoryCache`](https://alleninstitute.github.io/AllenSDK/allensdk.core.brain_observatory_cache.html). This object will allow us to retrieve and analyze the Allen Brain Observatory data." ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "# We will create an instance of the Brain Observatory Cache as an object, \"boc.\"\n", "boc = BrainObservatoryCache(manifest_file='manifest.json')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next, we'll use `get_all_cre_lines()` on our `boc` object to return all of the possible Cre lines and brain areas are that we can analyze. We can also use the `get_all_targeted_structures()` method to return all brain areas in our dataset. \n", "\n", "You can find more info about the Cre-lines on the Allen Brain Atlas Transgenic Mouse Lines page. Refer back to the Brain Observatory landing page to learn more about the different visual areas. Make sure to visit the BrainObservatoryCache doucumentation for additional help with the methods used in this notebook. " ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "all cre lines: ['Cux2-CreERT2', 'Emx1-IRES-Cre', 'Fezf2-CreER', 'Nr5a1-Cre', 'Ntsr1-Cre_GN220', 'Pvalb-IRES-Cre', 'Rbp4-Cre_KL100', 'Rorb-IRES2-Cre', 'Scnn1a-Tg3-Cre', 'Slc17a7-IRES2-Cre', 'Sst-IRES-Cre', 'Tlx3-Cre_PL56', 'Vip-IRES-Cre'] \n", "\n", "all brain regions: ['VISal', 'VISam', 'VISl', 'VISp', 'VISpm', 'VISrl']\n" ] } ], "source": [ "# We'll assign the list of cre lines to a variable, 'cre-lines'.\n", "cre_lines = boc.get_all_cre_lines()\n", "print(f\"all cre lines: {cre_lines} \\n\")\n", "\n", "# We'll assign the list of possible structures to a variable, 'brain_areas'.\n", "brain_areas = boc.get_all_targeted_structures()\n", "print(\"all brain regions: \" + str(brain_areas))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Extract an experiment session" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "With access to the cre lines and brain regions from the dataset, we can construct a dataframe of experiement containers from our desired cre lines and brain regions. Each experiment container has a group of experiments that share the same targeted brain area, cre line, and depth. However, the stimuli conditions may differ across experiments for a given contianer. \n", "\n", "We can use the `get_experiment_containers()` method of our `boc` object to return a list of dictionaries with data on the available experiment contianers. The method takes in the arguments `cre_lines` and `targeted_structures` which both require lists as inputs. \n", "\n", "*Note*: Not every cre line and brain region combination will have data. If no data is availabe for a certain combindation, an empty dataframe will be created. You can use the `empty` attribute on your new datafram to check if it is empty. " ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | imaging_depth | \n", "targeted_structure | \n", "cre_line | \n", "reporter_line | \n", "donor_name | \n", "specimen_name | \n", "tags | \n", "failed | \n", "
---|---|---|---|---|---|---|---|---|
id | \n", "\n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " |
637671552 | \n", "375 | \n", "VISp | \n", "Tlx3-Cre_PL56 | \n", "Ai148(TIT2L-GC6f-ICL-tTA2) | \n", "340430 | \n", "Tlx3-Cre_PL56;Ai148-340430 | \n", "[] | \n", "False | \n", "
617381603 | \n", "375 | \n", "VISp | \n", "Tlx3-Cre_PL56 | \n", "Ai148(TIT2L-GC6f-ICL-tTA2) | \n", "336824 | \n", "Tlx3-Cre_PL56;Ai148(CAM)-336824 | \n", "[] | \n", "False | \n", "
627823571 | \n", "375 | \n", "VISp | \n", "Tlx3-Cre_PL56 | \n", "Ai148(TIT2L-GC6f-ICL-tTA2) | \n", "337458 | \n", "Tlx3-Cre_PL56;Ai148-337458 | \n", "[] | \n", "False | \n", "
648377366 | \n", "375 | \n", "VISp | \n", "Tlx3-Cre_PL56 | \n", "Ai148(TIT2L-GC6f-ICL-tTA2) | \n", "352889 | \n", "Tlx3-Cre_PL56;Ai148-352889 | \n", "[] | \n", "False | \n", "
657016265 | \n", "375 | \n", "VISp | \n", "Tlx3-Cre_PL56 | \n", "Ai148(TIT2L-GC6f-ICL-tTA2) | \n", "357093 | \n", "Tlx3-Cre_PL56;Ai148-357093 | \n", "[] | \n", "False | \n", "
637669268 | \n", "375 | \n", "VISp | \n", "Tlx3-Cre_PL56 | \n", "Ai148(TIT2L-GC6f-ICL-tTA2) | \n", "340427 | \n", "Tlx3-Cre_PL56;Ai148-340427 | \n", "[] | \n", "False | \n", "