{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "12:13:51 [I] klustakwik KlustaKwik2 version 0.2.6\n" ] } ], "source": [ "import os\n", "import expipe\n", "import pathlib\n", "import numpy as np\n", "import spatial_maps.stats as stats\n", "import septum_mec\n", "import septum_mec.analysis.data_processing as dp\n", "import septum_mec.analysis.registration\n", "import head_direction.head as head\n", "import spatial_maps as sp\n", "import speed_cells.speed as spd\n", "import re\n", "import joblib\n", "import multiprocessing\n", "import shutil\n", "import psutil\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "import matplotlib\n", "# import seaborn as sns\n", "from distutils.dir_util import copy_tree\n", "from neo import SpikeTrain\n", "import scipy\n", "\n", "from tqdm import tqdm_notebook as tqdm\n", "from tqdm._tqdm_notebook import tqdm_notebook\n", "tqdm_notebook.pandas()\n", "\n", "from spike_statistics.core import permutation_resampling\n", "\n", "from spikewaveform.core import calculate_waveform_features_from_template, cluster_waveform_features\n", "\n", "from septum_mec.analysis.plotting import violinplot, despine" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "plt.rc('axes', titlesize=12)\n", "plt.rcParams.update({\n", " 'font.size': 12, \n", " 'figure.figsize': (6, 4), \n", " 'figure.dpi': 150\n", "})\n", "\n", "output_path = pathlib.Path(\"output\") / \"stimulus-response\"\n", "(output_path / \"statistics\").mkdir(exist_ok=True, parents=True)\n", "(output_path / \"figures\").mkdir(exist_ok=True, parents=True)\n", "output_path.mkdir(exist_ok=True)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "data_loader = dp.Data()\n", "actions = data_loader.actions\n", "project = data_loader.project" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "identification_action = actions['identify-neurons']\n", "sessions = pd.read_csv(identification_action.data_path('sessions'))\n", "units = pd.read_csv(identification_action.data_path('units'))\n", "session_units = pd.merge(sessions, units, on='action')" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "stim_action = actions['stimulus-response']\n", "stim_results = pd.read_csv(stim_action.data_path('results'))" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "# lfp_results has old unit id's but correct on (action, unit_name, channel_group)\n", "stim_results = stim_results.drop('unit_id', axis=1)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "statistics_action = actions['calculate-statistics']\n", "shuffling = actions['shuffling']\n", "\n", "statistics_results = pd.read_csv(statistics_action.data_path('results'))\n", "statistics_results = session_units.merge(statistics_results, how='left')\n", "quantiles_95 = pd.read_csv(shuffling.data_path('quantiles_95'))\n", "action_columns = ['action', 'channel_group', 'unit_name']\n", "data = pd.merge(statistics_results, quantiles_95, on=action_columns, suffixes=(\"\", \"_threshold\"))" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "data['unit_day'] = data.apply(lambda x: str(x.unit_idnum) + '_' + x.action.split('-')[1], axis=1)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "data = data.merge(stim_results, how='left')" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "waveform_action = actions['waveform-analysis']\n", "waveform_results = pd.read_csv(waveform_action.data_path('results')).drop('template', axis=1)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "data = data.merge(waveform_results, how='left')" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "colors = ['#d95f02','#e7298a']\n", "labels = ['11 Hz', '30 HZ']\n", "queries = ['frequency==11', 'frequency==30']" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "data.bs = data.bs.astype(bool)" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "data.loc[data.eval('not t_i_peak.isnull() and not bs'), 'ns_inhibited'] = True\n", "data.ns_inhibited.fillna(False, inplace=True)\n", "\n", "data.loc[data.eval('t_i_peak.isnull() and not bs'), 'ns_not_inhibited'] = True\n", "data.ns_not_inhibited.fillna(False, inplace=True)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of sessions above threshold 194\n", "Number of animals 4\n" ] } ], "source": [ "query = (\n", " 'gridness > gridness_threshold and '\n", " 'information_rate > information_rate_threshold and '\n", " 'gridness > .2 and '\n", " 'average_rate < 25'\n", ")\n", "sessions_above_threshold = data.query(query)\n", "print(\"Number of sessions above threshold\", len(sessions_above_threshold))\n", "print(\"Number of animals\", len(sessions_above_threshold.groupby(['entity'])))" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of gridcells 139\n", "Number of gridcell recordings 231\n", "Number of animals 4\n" ] } ], "source": [ "gridcell_sessions = data[data.unit_day.isin(sessions_above_threshold.unit_day.values)]\n", "print(\"Number of gridcells\", gridcell_sessions.unit_idnum.nunique())\n", "print(\"Number of gridcell recordings\", len(gridcell_sessions))\n", "print(\"Number of animals\", len(gridcell_sessions.groupby(['entity'])))" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "data.loc[:,'gridcell'] = np.nan\n", "data['gridcell'] = data.isin(gridcell_sessions)\n", "\n", "data.loc[data.eval('not gridcell and bs'), 'bs_not_gridcell'] = True\n", "data.bs_not_gridcell.fillna(False, inplace=True)" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | action | \n", "baseline | \n", "entity | \n", "frequency | \n", "i | \n", "ii | \n", "session | \n", "stim_location | \n", "stimulated | \n", "tag | \n", "... | \n", "half_width | \n", "peak_to_trough | \n", "average_firing_rate | \n", "bs | \n", "bs_stim | \n", "bs_ctrl | \n", "ns_inhibited | \n", "ns_not_inhibited | \n", "gridcell | \n", "bs_not_gridcell | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
33 | \n", "1833-260619-1 | \n", "True | \n", "1833 | \n", "NaN | \n", "True | \n", "False | \n", "1 | \n", "NaN | \n", "False | \n", "baseline i | \n", "... | \n", "0.272875 | \n", "0.602667 | \n", "5.945508 | \n", "True | \n", "NaN | \n", "1.0 | \n", "False | \n", "False | \n", "True | \n", "False | \n", "
34 | \n", "1833-260619-1 | \n", "True | \n", "1833 | \n", "NaN | \n", "True | \n", "False | \n", "1 | \n", "NaN | \n", "False | \n", "baseline i | \n", "... | \n", "0.226452 | \n", "0.274814 | \n", "2.860048 | \n", "False | \n", "NaN | \n", "0.0 | \n", "False | \n", "True | \n", "True | \n", "False | \n", "
35 | \n", "1833-260619-1 | \n", "True | \n", "1833 | \n", "NaN | \n", "True | \n", "False | \n", "1 | \n", "NaN | \n", "False | \n", "baseline i | \n", "... | \n", "0.247266 | \n", "0.570104 | \n", "3.365674 | \n", "True | \n", "NaN | \n", "1.0 | \n", "False | \n", "False | \n", "True | \n", "False | \n", "
39 | \n", "1833-260619-1 | \n", "True | \n", "1833 | \n", "NaN | \n", "True | \n", "False | \n", "1 | \n", "NaN | \n", "False | \n", "baseline i | \n", "... | \n", "0.284542 | \n", "0.644111 | \n", "17.471520 | \n", "True | \n", "NaN | \n", "1.0 | \n", "False | \n", "False | \n", "True | \n", "False | \n", "
40 | \n", "1833-260619-1 | \n", "True | \n", "1833 | \n", "NaN | \n", "True | \n", "False | \n", "1 | \n", "NaN | \n", "False | \n", "baseline i | \n", "... | \n", "0.259920 | \n", "0.581698 | \n", "5.891739 | \n", "True | \n", "NaN | \n", "1.0 | \n", "False | \n", "False | \n", "True | \n", "False | \n", "
5 rows × 60 columns
\n", "