{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import os\n", "import pathlib\n", "import numpy as np\n", "import matplotlib\n", "import matplotlib.pyplot as plt\n", "import re\n", "import shutil\n", "import pandas as pd\n", "import scipy.stats\n", "from functools import reduce\n", "import statsmodels\n", "import seaborn as sns\n", "import exdir\n", "import expipe\n", "from distutils.dir_util import copy_tree\n", "import septum_mec\n", "import spatial_maps as sp\n", "import head_direction.head as head\n", "import septum_mec.analysis.data_processing as dp\n", "import septum_mec.analysis.registration\n", "from septum_mec.analysis.plotting import violinplot, savefig, despine\n", "\n", "from septum_mec.analysis.statistics import load_data_frames, make_paired_tables, make_statistics_table" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "project_path = dp.project_path()\n", "project = expipe.get_project(project_path)\n", "actions = project.actions\n", "\n", "output_path = pathlib.Path(\"output\") / \"comparisons-allcells\"\n", "(output_path / \"statistics\").mkdir(exist_ok=True, parents=True)\n", "(output_path / \"figures\").mkdir(exist_ok=True, parents=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Load cell statistics and shuffling quantiles" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of sessions above threshold 194\n", "Number of animals 4\n", "Number of individual gridcells 139\n", "Number of gridcell recordings 230\n" ] } ], "source": [ "data, labels, colors, queries = load_data_frames()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['action', 'baseline', 'entity', 'frequency', 'i', 'ii', 'session',\n", " 'stim_location', 'stimulated', 'tag', 'date', 'entity_date', 'Hz11',\n", " 'Hz30', 'channel_group', 'max_depth_delta', 'max_dissimilarity',\n", " 'unit_id', 'unit_idnum', 'unit_name', 'average_rate', 'speed_score',\n", " 'out_field_mean_rate', 'in_field_mean_rate', 'max_field_mean_rate',\n", " 'max_rate', 'sparsity', 'selectivity', 'interspike_interval_cv',\n", " 'burst_event_ratio', 'bursty_spike_ratio', 'gridness', 'border_score',\n", " 'information_rate', 'information_specificity', 'head_mean_ang',\n", " 'head_mean_vec_len', 'spacing', 'orientation', 'field_area',\n", " 'theta_score', 'unit_day', 't_e_peak', 'p_e_peak', 't_i_peak',\n", " 'p_i_peak', 'border_score_threshold', 'gridness_threshold',\n", " 'head_mean_ang_threshold', 'head_mean_vec_len_threshold',\n", " 'information_rate_threshold', 'speed_score_threshold', 'specificity',\n", " 'half_width', 'peak_to_trough', 'average_firing_rate', 'bs', 'bs_stim',\n", " 'bs_ctrl', 'ns_inhibited', 'ns_not_inhibited', 'gridcell',\n", " 'bs_not_gridcell', 'label', 'label_num', 'query', 'color', 'cell_type'],\n", " dtype='object')" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data.keys()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Calculate statistics" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "columns = [\n", " 'average_rate', \n", "# 'spatial_average_rate',\n", " 'gridness', \n", " 'sparsity', \n", " 'selectivity',\n", " 'information_rate',\n", " 'information_specificity',\n", " 'max_rate', \n", " 'interspike_interval_cv', \n", " 'burst_event_ratio', \n", " 'in_field_mean_rate', \n", " 'out_field_mean_rate',\n", " 'max_field_mean_rate',\n", " 'specificity', \n", " 'speed_score', \n", " 'spacing', \n", " 'field_area', \n", " 'head_mean_vec_len', \n", " 'border_score'\n", "]" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "results, labels = make_paired_tables(data, columns)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | entity | \n", "unit_idnum | \n", "channel_group | \n", "date | \n", "Baseline I | \n", "11 Hz | \n", "Baseline II | \n", "30 Hz | \n", "
---|---|---|---|---|---|---|---|---|
51 | \n", "1833 | \n", "8 | \n", "0 | \n", "20719 | \n", "7.900527 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
85 | \n", "1833 | \n", "13 | \n", "0 | \n", "20719 | \n", "NaN | \n", "5.415361 | \n", "6.456882 | \n", "9.526984 | \n", "
86 | \n", "1833 | \n", "14 | \n", "0 | \n", "20719 | \n", "NaN | \n", "16.681112 | \n", "16.498883 | \n", "NaN | \n", "
58 | \n", "1833 | \n", "23 | \n", "0 | \n", "200619 | \n", "16.171078 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
127 | \n", "1833 | \n", "26 | \n", "0 | \n", "200619 | \n", "NaN | \n", "NaN | \n", "6.990117 | \n", "6.953565 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
139 | \n", "1849 | \n", "835 | \n", "4 | \n", "150319 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "3.680061 | \n", "
43 | \n", "1849 | \n", "851 | \n", "5 | \n", "60319 | \n", "23.736187 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
65 | \n", "1849 | \n", "932 | \n", "7 | \n", "280219 | \n", "5.661950 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
74 | \n", "1849 | \n", "937 | \n", "7 | \n", "280219 | \n", "NaN | \n", "9.485790 | \n", "NaN | \n", "NaN | \n", "
105 | \n", "1849 | \n", "939 | \n", "7 | \n", "280219 | \n", "NaN | \n", "NaN | \n", "12.721755 | \n", "NaN | \n", "
137 rows × 8 columns
\n", "\n", " | Baseline I | \n", "11 Hz | \n", "Baseline II | \n", "30 Hz | \n", "LMM Baseline I - 11 Hz | \n", "LMM Baseline I - Baseline II | \n", "LMM Baseline I - 30 Hz | \n", "LMM 11 Hz - Baseline II | \n", "LMM 11 Hz - 30 Hz | \n", "LMM Baseline II - 30 Hz | \n", "
---|---|---|---|---|---|---|---|---|---|---|
Average rate | \n", "9.8e+00 ± 9.3e-01 (63) | \n", "1.1e+01 ± 1.0e+00 (56) | \n", "1.0e+01 ± 1.0e+00 (46) | \n", "8.5e+00 ± 1.1e+00 (35) | \n", "6.9e-01, -6.0e-01 | \n", "8.2e-01, 3.1e-01 | \n", "8.4e-01, 3.3e-01 | \n", "5.1e-01, 5.9e-01 | \n", "6.2e-01, -1.2e+00 | \n", "6.8e-01, -5.1e-01 | \n", "
Gridness | \n", "3.7e-01 ± 5.6e-02 (63) | \n", "4.0e-01 ± 5.1e-02 (56) | \n", "5.3e-01 ± 3.7e-02 (46) | \n", "5.7e-01 ± 4.9e-02 (35) | \n", "8.5e-01, -2.8e-02 | \n", "NaN | \n", "4.1e-01, -1.5e-01 | \n", "2.2e-01, 1.5e-01 | \n", "3.2e-01, 1.2e-01 | \n", "8.6e-01, -2.7e-02 | \n", "
Sparsity | \n", "6.6e-01 ± 2.4e-02 (63) | \n", "7.1e-01 ± 3.1e-02 (56) | \n", "6.6e-01 ± 3.2e-02 (46) | \n", "6.4e-01 ± 3.7e-02 (35) | \n", "2.5e-01, -2.6e-02 | \n", "9.3e-01, -5.2e-03 | \n", "5.0e-01, -4.1e-02 | \n", "7.5e-02, -2.5e-02 | \n", "NaN | \n", "5.8e-01, -1.9e-02 | \n", "
Selectivity | \n", "5.3e+00 ± 4.3e-01 (63) | \n", "5.4e+00 ± 5.9e-01 (56) | \n", "6.2e+00 ± 6.7e-01 (46) | \n", "6.8e+00 ± 6.7e-01 (35) | \n", "4.1e-01, 1.9e-01 | \n", "6.6e-01, 6.6e-01 | \n", "5.5e-01, -9.3e-01 | \n", "3.8e-01, 3.7e-01 | \n", "1.6e-01, 1.1e+00 | \n", "9.3e-01, 4.1e-02 | \n", "
Information rate | \n", "1.4e+00 ± 8.6e-02 (63) | \n", "9.3e-01 ± 6.9e-02 (56) | \n", "1.3e+00 ± 1.0e-01 (46) | \n", "1.1e+00 ± 1.1e-01 (35) | \n", "1.7e-02, 4.0e-01 | \n", "4.3e-02, -9.7e-02 | \n", "4.3e-06, 3.0e-01 | \n", "1.0e-01, 3.3e-01 | \n", "1.6e-01, 2.5e-01 | \n", "9.5e-01, 2.7e-02 | \n", "
Information specificity | \n", "2.5e-01 ± 3.4e-02 (63) | \n", "2.2e-01 ± 4.5e-02 (56) | \n", "2.3e-01 ± 3.4e-02 (46) | \n", "2.4e-01 ± 3.8e-02 (35) | \n", "NaN | \n", "2.3e-01, -3.0e-02 | \n", "6.4e-01, 2.0e-02 | \n", "3.2e-01, 5.6e-02 | \n", "2.2e-01, 5.6e-02 | \n", "3.3e-01, 2.0e-02 | \n", "
Max rate | \n", "3.6e+01 ± 2.1e+00 (63) | \n", "3.6e+01 ± 2.2e+00 (56) | \n", "4.2e+01 ± 2.4e+00 (46) | \n", "3.7e+01 ± 2.5e+00 (35) | \n", "7.6e-01, 1.3e+00 | \n", "3.4e-01, 3.3e+00 | \n", "7.8e-01, 1.9e+00 | \n", "1.7e-01, 5.5e+00 | \n", "9.6e-02, 6.5e+00 | \n", "7.2e-01, 1.7e+00 | \n", "
Interspike interval cv | \n", "2.2e+00 ± 8.9e-02 (63) | \n", "2.0e+00 ± 1.4e-01 (56) | \n", "2.2e+00 ± 8.0e-02 (46) | \n", "2.3e+00 ± 1.1e-01 (35) | \n", "8.3e-02, 1.7e-01 | \n", "NaN | \n", "8.3e-01, 5.5e-02 | \n", "NaN | \n", "9.4e-02, 4.1e-01 | \n", "9.6e-01, 1.4e-02 | \n", "
Burst event ratio | \n", "2.3e-01 ± 1.1e-02 (63) | \n", "2.3e-01 ± 1.2e-02 (56) | \n", "2.3e-01 ± 1.1e-02 (46) | \n", "1.8e-01 ± 1.2e-02 (35) | \n", "7.7e-01, -4.8e-03 | \n", "7.4e-01, -1.1e-02 | \n", "4.7e-03, 5.7e-02 | \n", "7.7e-01, 3.5e-03 | \n", "NaN | \n", "1.3e-02, 3.9e-02 | \n", "
In-field mean rate | \n", "1.5e+01 ± 1.2e+00 (63) | \n", "1.6e+01 ± 1.3e+00 (56) | \n", "1.7e+01 ± 1.2e+00 (46) | \n", "1.3e+01 ± 1.3e+00 (35) | \n", "9.7e-01, -6.9e-02 | \n", "7.5e-01, 4.7e-01 | \n", "3.6e-01, 1.8e+00 | \n", "4.6e-01, 1.2e+00 | \n", "6.9e-01, -9.9e-01 | \n", "6.7e-01, 5.9e-01 | \n", "
Out-field mean rate | \n", "7.3e+00 ± 7.9e-01 (63) | \n", "8.8e+00 ± 9.0e-01 (56) | \n", "7.8e+00 ± 8.6e-01 (46) | \n", "6.0e+00 ± 8.7e-01 (35) | \n", "5.1e-01, -7.0e-01 | \n", "7.3e-01, 3.3e-01 | \n", "6.5e-01, 6.8e-01 | \n", "7.3e-01, 2.2e-01 | \n", "3.1e-01, -1.9e+00 | \n", "9.1e-01, 9.4e-02 | \n", "
Max-field mean rate | \n", "1.2e+01 ± 1.3e+00 (35) | \n", "1.1e+01 ± 1.6e+00 (31) | \n", "1.7e+01 ± 2.6e+00 (33) | \n", "7.8e+00 ± 1.2e+00 (19) | \n", "2.6e-01, 4.1e+00 | \n", "8.9e-01, 1.3e+00 | \n", "1.0e+00, -1.6e-02 | \n", "3.8e-01, 5.3e+00 | \n", "NaN | \n", "9.8e-01, -2.2e-01 | \n", "
Specificity | \n", "4.2e-01 ± 2.9e-02 (63) | \n", "3.9e-01 ± 3.5e-02 (56) | \n", "4.3e-01 ± 3.1e-02 (46) | \n", "4.7e-01 ± 4.0e-02 (35) | \n", "2.0e-01, 2.6e-02 | \n", "9.3e-01, -1.0e-02 | \n", "5.5e-01, 4.1e-02 | \n", "5.9e-01, 2.4e-02 | \n", "4.2e-01, 4.5e-02 | \n", "7.6e-01, -1.5e-02 | \n", "
Speed score | \n", "1.1e-01 ± 1.1e-02 (63) | \n", "9.4e-02 ± 1.2e-02 (56) | \n", "8.7e-02 ± 8.0e-03 (46) | \n", "7.4e-02 ± 9.9e-03 (35) | \n", "5.4e-01, 1.3e-02 | \n", "6.8e-01, 9.4e-03 | \n", "5.6e-01, 3.3e-02 | \n", "1.5e-01, 3.6e-02 | \n", "8.4e-01, 1.7e-02 | \n", "NaN | \n", "
Spacing | \n", "5.6e-01 ± 2.0e-02 (63) | \n", "5.4e-01 ± 2.0e-02 (56) | \n", "5.2e-01 ± 1.6e-02 (46) | \n", "4.9e-01 ± 1.5e-02 (35) | \n", "3.0e-01, 3.5e-02 | \n", "4.4e-01, -2.9e-02 | \n", "2.2e-01, 6.5e-02 | \n", "7.1e-01, 8.8e-03 | \n", "1.7e-01, -4.1e-02 | \n", "1.5e-01, 2.5e-02 | \n", "
Field area | \n", "4.5e-01 ± 7.6e-03 (63) | \n", "4.3e-01 ± 7.8e-03 (56) | \n", "4.4e-01 ± 8.6e-03 (46) | \n", "4.4e-01 ± 9.3e-03 (35) | \n", "2.3e-01, 1.5e-02 | \n", "6.6e-01, -7.3e-03 | \n", "7.8e-01, -6.6e-03 | \n", "4.5e-01, 2.2e-03 | \n", "8.6e-01, -2.6e-03 | \n", "9.0e-01, 1.2e-03 | \n", "
Head mean vec len | \n", "8.7e-02 ± 8.5e-03 (63) | \n", "7.7e-02 ± 8.6e-03 (56) | \n", "6.7e-02 ± 7.1e-03 (46) | \n", "8.8e-02 ± 7.9e-03 (35) | \n", "7.5e-01, 6.8e-03 | \n", "8.2e-04, -1.3e-02 | \n", "6.7e-01, -6.8e-03 | \n", "2.4e-01, -2.8e-02 | \n", "8.7e-01, 2.3e-03 | \n", "5.6e-01, -9.6e-03 | \n", "
Border score | \n", "2.1e-01 ± 1.3e-02 (63) | \n", "2.1e-01 ± 1.2e-02 (56) | \n", "1.8e-01 ± 1.3e-02 (46) | \n", "1.9e-01 ± 1.5e-02 (35) | \n", "9.5e-01, -2.4e-03 | \n", "4.9e-01, -2.9e-02 | \n", "5.8e-01, 2.0e-02 | \n", "5.2e-08, -3.7e-02 | \n", "9.5e-01, -2.1e-03 | \n", "5.8e-01, -3.6e-02 | \n", "