septum-mec/actions/comparisons-allcells/data/20_comparisons_allcells.ipynb

1086 lines
40 KiB
Plaintext
Raw Normal View History

2021-03-10 12:56:16 +00:00
{
"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": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>entity</th>\n",
" <th>unit_idnum</th>\n",
" <th>channel_group</th>\n",
" <th>date</th>\n",
" <th>Baseline I</th>\n",
" <th>11 Hz</th>\n",
" <th>Baseline II</th>\n",
" <th>30 Hz</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>51</th>\n",
" <td>1833</td>\n",
" <td>8</td>\n",
" <td>0</td>\n",
" <td>20719</td>\n",
" <td>7.900527</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>85</th>\n",
" <td>1833</td>\n",
" <td>13</td>\n",
" <td>0</td>\n",
" <td>20719</td>\n",
" <td>NaN</td>\n",
" <td>5.415361</td>\n",
" <td>6.456882</td>\n",
" <td>9.526984</td>\n",
" </tr>\n",
" <tr>\n",
" <th>86</th>\n",
" <td>1833</td>\n",
" <td>14</td>\n",
" <td>0</td>\n",
" <td>20719</td>\n",
" <td>NaN</td>\n",
" <td>16.681112</td>\n",
" <td>16.498883</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>58</th>\n",
" <td>1833</td>\n",
" <td>23</td>\n",
" <td>0</td>\n",
" <td>200619</td>\n",
" <td>16.171078</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>127</th>\n",
" <td>1833</td>\n",
" <td>26</td>\n",
" <td>0</td>\n",
" <td>200619</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>6.990117</td>\n",
" <td>6.953565</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>139</th>\n",
" <td>1849</td>\n",
" <td>835</td>\n",
" <td>4</td>\n",
" <td>150319</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>3.680061</td>\n",
" </tr>\n",
" <tr>\n",
" <th>43</th>\n",
" <td>1849</td>\n",
" <td>851</td>\n",
" <td>5</td>\n",
" <td>60319</td>\n",
" <td>23.736187</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>65</th>\n",
" <td>1849</td>\n",
" <td>932</td>\n",
" <td>7</td>\n",
" <td>280219</td>\n",
" <td>5.661950</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>74</th>\n",
" <td>1849</td>\n",
" <td>937</td>\n",
" <td>7</td>\n",
" <td>280219</td>\n",
" <td>NaN</td>\n",
" <td>9.485790</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>105</th>\n",
" <td>1849</td>\n",
" <td>939</td>\n",
" <td>7</td>\n",
" <td>280219</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>12.721755</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>137 rows × 8 columns</p>\n",
"</div>"
],
"text/plain": [
" entity unit_idnum channel_group date Baseline I 11 Hz \\\n",
"51 1833 8 0 20719 7.900527 NaN \n",
"85 1833 13 0 20719 NaN 5.415361 \n",
"86 1833 14 0 20719 NaN 16.681112 \n",
"58 1833 23 0 200619 16.171078 NaN \n",
"127 1833 26 0 200619 NaN NaN \n",
".. ... ... ... ... ... ... \n",
"139 1849 835 4 150319 NaN NaN \n",
"43 1849 851 5 60319 23.736187 NaN \n",
"65 1849 932 7 280219 5.661950 NaN \n",
"74 1849 937 7 280219 NaN 9.485790 \n",
"105 1849 939 7 280219 NaN NaN \n",
"\n",
" Baseline II 30 Hz \n",
"51 NaN NaN \n",
"85 6.456882 9.526984 \n",
"86 16.498883 NaN \n",
"58 NaN NaN \n",
"127 6.990117 6.953565 \n",
".. ... ... \n",
"139 NaN 3.680061 \n",
"43 NaN NaN \n",
"65 NaN NaN \n",
"74 NaN NaN \n",
"105 12.721755 NaN \n",
"\n",
"[137 rows x 8 columns]"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"results['gridcell']['average_rate']"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"# TODO: control for information rate"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Create nice table"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"stat = {}\n",
"stat_values = {}\n",
"for cell_type, result in results.items():\n",
" stat[cell_type], stat_values[cell_type] = make_statistics_table(result, labels)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Baseline I</th>\n",
" <th>11 Hz</th>\n",
" <th>Baseline II</th>\n",
" <th>30 Hz</th>\n",
" <th>LMM Baseline I - 11 Hz</th>\n",
" <th>LMM Baseline I - Baseline II</th>\n",
" <th>LMM Baseline I - 30 Hz</th>\n",
" <th>LMM 11 Hz - Baseline II</th>\n",
" <th>LMM 11 Hz - 30 Hz</th>\n",
" <th>LMM Baseline II - 30 Hz</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Average rate</th>\n",
" <td>9.8e+00 ± 9.3e-01 (63)</td>\n",
" <td>1.1e+01 ± 1.0e+00 (56)</td>\n",
" <td>1.0e+01 ± 1.0e+00 (46)</td>\n",
" <td>8.5e+00 ± 1.1e+00 (35)</td>\n",
" <td>6.9e-01, -6.0e-01</td>\n",
" <td>8.2e-01, 3.1e-01</td>\n",
" <td>8.4e-01, 3.3e-01</td>\n",
" <td>5.1e-01, 5.9e-01</td>\n",
" <td>6.2e-01, -1.2e+00</td>\n",
" <td>6.8e-01, -5.1e-01</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Gridness</th>\n",
" <td>3.7e-01 ± 5.6e-02 (63)</td>\n",
" <td>4.0e-01 ± 5.1e-02 (56)</td>\n",
" <td>5.3e-01 ± 3.7e-02 (46)</td>\n",
" <td>5.7e-01 ± 4.9e-02 (35)</td>\n",
" <td>8.5e-01, -2.8e-02</td>\n",
" <td>NaN</td>\n",
" <td>4.1e-01, -1.5e-01</td>\n",
" <td>2.2e-01, 1.5e-01</td>\n",
" <td>3.2e-01, 1.2e-01</td>\n",
" <td>8.6e-01, -2.7e-02</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Sparsity</th>\n",
" <td>6.6e-01 ± 2.4e-02 (63)</td>\n",
" <td>7.1e-01 ± 3.1e-02 (56)</td>\n",
" <td>6.6e-01 ± 3.2e-02 (46)</td>\n",
" <td>6.4e-01 ± 3.7e-02 (35)</td>\n",
" <td>2.5e-01, -2.6e-02</td>\n",
" <td>9.3e-01, -5.2e-03</td>\n",
" <td>5.0e-01, -4.1e-02</td>\n",
" <td>7.5e-02, -2.5e-02</td>\n",
" <td>NaN</td>\n",
" <td>5.8e-01, -1.9e-02</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Selectivity</th>\n",
" <td>5.3e+00 ± 4.3e-01 (63)</td>\n",
" <td>5.4e+00 ± 5.9e-01 (56)</td>\n",
" <td>6.2e+00 ± 6.7e-01 (46)</td>\n",
" <td>6.8e+00 ± 6.7e-01 (35)</td>\n",
" <td>4.1e-01, 1.9e-01</td>\n",
" <td>6.6e-01, 6.6e-01</td>\n",
" <td>5.5e-01, -9.3e-01</td>\n",
" <td>3.8e-01, 3.7e-01</td>\n",
" <td>1.6e-01, 1.1e+00</td>\n",
" <td>9.3e-01, 4.1e-02</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Information rate</th>\n",
" <td>1.4e+00 ± 8.6e-02 (63)</td>\n",
" <td>9.3e-01 ± 6.9e-02 (56)</td>\n",
" <td>1.3e+00 ± 1.0e-01 (46)</td>\n",
" <td>1.1e+00 ± 1.1e-01 (35)</td>\n",
" <td>1.7e-02, 4.0e-01</td>\n",
" <td>4.3e-02, -9.7e-02</td>\n",
" <td>4.3e-06, 3.0e-01</td>\n",
" <td>1.0e-01, 3.3e-01</td>\n",
" <td>1.6e-01, 2.5e-01</td>\n",
" <td>9.5e-01, 2.7e-02</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Information specificity</th>\n",
" <td>2.5e-01 ± 3.4e-02 (63)</td>\n",
" <td>2.2e-01 ± 4.5e-02 (56)</td>\n",
" <td>2.3e-01 ± 3.4e-02 (46)</td>\n",
" <td>2.4e-01 ± 3.8e-02 (35)</td>\n",
" <td>NaN</td>\n",
" <td>2.3e-01, -3.0e-02</td>\n",
" <td>6.4e-01, 2.0e-02</td>\n",
" <td>3.2e-01, 5.6e-02</td>\n",
" <td>2.2e-01, 5.6e-02</td>\n",
" <td>3.3e-01, 2.0e-02</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Max rate</th>\n",
" <td>3.6e+01 ± 2.1e+00 (63)</td>\n",
" <td>3.6e+01 ± 2.2e+00 (56)</td>\n",
" <td>4.2e+01 ± 2.4e+00 (46)</td>\n",
" <td>3.7e+01 ± 2.5e+00 (35)</td>\n",
" <td>7.6e-01, 1.3e+00</td>\n",
" <td>3.4e-01, 3.3e+00</td>\n",
" <td>7.8e-01, 1.9e+00</td>\n",
" <td>1.7e-01, 5.5e+00</td>\n",
" <td>9.6e-02, 6.5e+00</td>\n",
" <td>7.2e-01, 1.7e+00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Interspike interval cv</th>\n",
" <td>2.2e+00 ± 8.9e-02 (63)</td>\n",
" <td>2.0e+00 ± 1.4e-01 (56)</td>\n",
" <td>2.2e+00 ± 8.0e-02 (46)</td>\n",
" <td>2.3e+00 ± 1.1e-01 (35)</td>\n",
" <td>8.3e-02, 1.7e-01</td>\n",
" <td>NaN</td>\n",
" <td>8.3e-01, 5.5e-02</td>\n",
" <td>NaN</td>\n",
" <td>9.4e-02, 4.1e-01</td>\n",
" <td>9.6e-01, 1.4e-02</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Burst event ratio</th>\n",
" <td>2.3e-01 ± 1.1e-02 (63)</td>\n",
" <td>2.3e-01 ± 1.2e-02 (56)</td>\n",
" <td>2.3e-01 ± 1.1e-02 (46)</td>\n",
" <td>1.8e-01 ± 1.2e-02 (35)</td>\n",
" <td>7.7e-01, -4.8e-03</td>\n",
" <td>7.4e-01, -1.1e-02</td>\n",
" <td>4.7e-03, 5.7e-02</td>\n",
" <td>7.7e-01, 3.5e-03</td>\n",
" <td>NaN</td>\n",
" <td>1.3e-02, 3.9e-02</td>\n",
" </tr>\n",
" <tr>\n",
" <th>In-field mean rate</th>\n",
" <td>1.5e+01 ± 1.2e+00 (63)</td>\n",
" <td>1.6e+01 ± 1.3e+00 (56)</td>\n",
" <td>1.7e+01 ± 1.2e+00 (46)</td>\n",
" <td>1.3e+01 ± 1.3e+00 (35)</td>\n",
" <td>9.7e-01, -6.9e-02</td>\n",
" <td>7.5e-01, 4.7e-01</td>\n",
" <td>3.6e-01, 1.8e+00</td>\n",
" <td>4.6e-01, 1.2e+00</td>\n",
" <td>6.9e-01, -9.9e-01</td>\n",
" <td>6.7e-01, 5.9e-01</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Out-field mean rate</th>\n",
" <td>7.3e+00 ± 7.9e-01 (63)</td>\n",
" <td>8.8e+00 ± 9.0e-01 (56)</td>\n",
" <td>7.8e+00 ± 8.6e-01 (46)</td>\n",
" <td>6.0e+00 ± 8.7e-01 (35)</td>\n",
" <td>5.1e-01, -7.0e-01</td>\n",
" <td>7.3e-01, 3.3e-01</td>\n",
" <td>6.5e-01, 6.8e-01</td>\n",
" <td>7.3e-01, 2.2e-01</td>\n",
" <td>3.1e-01, -1.9e+00</td>\n",
" <td>9.1e-01, 9.4e-02</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Max-field mean rate</th>\n",
" <td>1.2e+01 ± 1.3e+00 (35)</td>\n",
" <td>1.1e+01 ± 1.6e+00 (31)</td>\n",
" <td>1.7e+01 ± 2.6e+00 (33)</td>\n",
" <td>7.8e+00 ± 1.2e+00 (19)</td>\n",
" <td>2.6e-01, 4.1e+00</td>\n",
" <td>8.9e-01, 1.3e+00</td>\n",
" <td>1.0e+00, -1.6e-02</td>\n",
" <td>3.8e-01, 5.3e+00</td>\n",
" <td>NaN</td>\n",
" <td>9.8e-01, -2.2e-01</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Specificity</th>\n",
" <td>4.2e-01 ± 2.9e-02 (63)</td>\n",
" <td>3.9e-01 ± 3.5e-02 (56)</td>\n",
" <td>4.3e-01 ± 3.1e-02 (46)</td>\n",
" <td>4.7e-01 ± 4.0e-02 (35)</td>\n",
" <td>2.0e-01, 2.6e-02</td>\n",
" <td>9.3e-01, -1.0e-02</td>\n",
" <td>5.5e-01, 4.1e-02</td>\n",
" <td>5.9e-01, 2.4e-02</td>\n",
" <td>4.2e-01, 4.5e-02</td>\n",
" <td>7.6e-01, -1.5e-02</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Speed score</th>\n",
" <td>1.1e-01 ± 1.1e-02 (63)</td>\n",
" <td>9.4e-02 ± 1.2e-02 (56)</td>\n",
" <td>8.7e-02 ± 8.0e-03 (46)</td>\n",
" <td>7.4e-02 ± 9.9e-03 (35)</td>\n",
" <td>5.4e-01, 1.3e-02</td>\n",
" <td>6.8e-01, 9.4e-03</td>\n",
" <td>5.6e-01, 3.3e-02</td>\n",
" <td>1.5e-01, 3.6e-02</td>\n",
" <td>8.4e-01, 1.7e-02</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Spacing</th>\n",
" <td>5.6e-01 ± 2.0e-02 (63)</td>\n",
" <td>5.4e-01 ± 2.0e-02 (56)</td>\n",
" <td>5.2e-01 ± 1.6e-02 (46)</td>\n",
" <td>4.9e-01 ± 1.5e-02 (35)</td>\n",
" <td>3.0e-01, 3.5e-02</td>\n",
" <td>4.4e-01, -2.9e-02</td>\n",
" <td>2.2e-01, 6.5e-02</td>\n",
" <td>7.1e-01, 8.8e-03</td>\n",
" <td>1.7e-01, -4.1e-02</td>\n",
" <td>1.5e-01, 2.5e-02</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Field area</th>\n",
" <td>4.5e-01 ± 7.6e-03 (63)</td>\n",
" <td>4.3e-01 ± 7.8e-03 (56)</td>\n",
" <td>4.4e-01 ± 8.6e-03 (46)</td>\n",
" <td>4.4e-01 ± 9.3e-03 (35)</td>\n",
" <td>2.3e-01, 1.5e-02</td>\n",
" <td>6.6e-01, -7.3e-03</td>\n",
" <td>7.8e-01, -6.6e-03</td>\n",
" <td>4.5e-01, 2.2e-03</td>\n",
" <td>8.6e-01, -2.6e-03</td>\n",
" <td>9.0e-01, 1.2e-03</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Head mean vec len</th>\n",
" <td>8.7e-02 ± 8.5e-03 (63)</td>\n",
" <td>7.7e-02 ± 8.6e-03 (56)</td>\n",
" <td>6.7e-02 ± 7.1e-03 (46)</td>\n",
" <td>8.8e-02 ± 7.9e-03 (35)</td>\n",
" <td>7.5e-01, 6.8e-03</td>\n",
" <td>8.2e-04, -1.3e-02</td>\n",
" <td>6.7e-01, -6.8e-03</td>\n",
" <td>2.4e-01, -2.8e-02</td>\n",
" <td>8.7e-01, 2.3e-03</td>\n",
" <td>5.6e-01, -9.6e-03</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Border score</th>\n",
" <td>2.1e-01 ± 1.3e-02 (63)</td>\n",
" <td>2.1e-01 ± 1.2e-02 (56)</td>\n",
" <td>1.8e-01 ± 1.3e-02 (46)</td>\n",
" <td>1.9e-01 ± 1.5e-02 (35)</td>\n",
" <td>9.5e-01, -2.4e-03</td>\n",
" <td>4.9e-01, -2.9e-02</td>\n",
" <td>5.8e-01, 2.0e-02</td>\n",
" <td>5.2e-08, -3.7e-02</td>\n",
" <td>9.5e-01, -2.1e-03</td>\n",
" <td>5.8e-01, -3.6e-02</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Baseline I 11 Hz \\\n",
"Average rate 9.8e+00 ± 9.3e-01 (63) 1.1e+01 ± 1.0e+00 (56) \n",
"Gridness 3.7e-01 ± 5.6e-02 (63) 4.0e-01 ± 5.1e-02 (56) \n",
"Sparsity 6.6e-01 ± 2.4e-02 (63) 7.1e-01 ± 3.1e-02 (56) \n",
"Selectivity 5.3e+00 ± 4.3e-01 (63) 5.4e+00 ± 5.9e-01 (56) \n",
"Information rate 1.4e+00 ± 8.6e-02 (63) 9.3e-01 ± 6.9e-02 (56) \n",
"Information specificity 2.5e-01 ± 3.4e-02 (63) 2.2e-01 ± 4.5e-02 (56) \n",
"Max rate 3.6e+01 ± 2.1e+00 (63) 3.6e+01 ± 2.2e+00 (56) \n",
"Interspike interval cv 2.2e+00 ± 8.9e-02 (63) 2.0e+00 ± 1.4e-01 (56) \n",
"Burst event ratio 2.3e-01 ± 1.1e-02 (63) 2.3e-01 ± 1.2e-02 (56) \n",
"In-field mean rate 1.5e+01 ± 1.2e+00 (63) 1.6e+01 ± 1.3e+00 (56) \n",
"Out-field mean rate 7.3e+00 ± 7.9e-01 (63) 8.8e+00 ± 9.0e-01 (56) \n",
"Max-field mean rate 1.2e+01 ± 1.3e+00 (35) 1.1e+01 ± 1.6e+00 (31) \n",
"Specificity 4.2e-01 ± 2.9e-02 (63) 3.9e-01 ± 3.5e-02 (56) \n",
"Speed score 1.1e-01 ± 1.1e-02 (63) 9.4e-02 ± 1.2e-02 (56) \n",
"Spacing 5.6e-01 ± 2.0e-02 (63) 5.4e-01 ± 2.0e-02 (56) \n",
"Field area 4.5e-01 ± 7.6e-03 (63) 4.3e-01 ± 7.8e-03 (56) \n",
"Head mean vec len 8.7e-02 ± 8.5e-03 (63) 7.7e-02 ± 8.6e-03 (56) \n",
"Border score 2.1e-01 ± 1.3e-02 (63) 2.1e-01 ± 1.2e-02 (56) \n",
"\n",
" Baseline II 30 Hz \\\n",
"Average rate 1.0e+01 ± 1.0e+00 (46) 8.5e+00 ± 1.1e+00 (35) \n",
"Gridness 5.3e-01 ± 3.7e-02 (46) 5.7e-01 ± 4.9e-02 (35) \n",
"Sparsity 6.6e-01 ± 3.2e-02 (46) 6.4e-01 ± 3.7e-02 (35) \n",
"Selectivity 6.2e+00 ± 6.7e-01 (46) 6.8e+00 ± 6.7e-01 (35) \n",
"Information rate 1.3e+00 ± 1.0e-01 (46) 1.1e+00 ± 1.1e-01 (35) \n",
"Information specificity 2.3e-01 ± 3.4e-02 (46) 2.4e-01 ± 3.8e-02 (35) \n",
"Max rate 4.2e+01 ± 2.4e+00 (46) 3.7e+01 ± 2.5e+00 (35) \n",
"Interspike interval cv 2.2e+00 ± 8.0e-02 (46) 2.3e+00 ± 1.1e-01 (35) \n",
"Burst event ratio 2.3e-01 ± 1.1e-02 (46) 1.8e-01 ± 1.2e-02 (35) \n",
"In-field mean rate 1.7e+01 ± 1.2e+00 (46) 1.3e+01 ± 1.3e+00 (35) \n",
"Out-field mean rate 7.8e+00 ± 8.6e-01 (46) 6.0e+00 ± 8.7e-01 (35) \n",
"Max-field mean rate 1.7e+01 ± 2.6e+00 (33) 7.8e+00 ± 1.2e+00 (19) \n",
"Specificity 4.3e-01 ± 3.1e-02 (46) 4.7e-01 ± 4.0e-02 (35) \n",
"Speed score 8.7e-02 ± 8.0e-03 (46) 7.4e-02 ± 9.9e-03 (35) \n",
"Spacing 5.2e-01 ± 1.6e-02 (46) 4.9e-01 ± 1.5e-02 (35) \n",
"Field area 4.4e-01 ± 8.6e-03 (46) 4.4e-01 ± 9.3e-03 (35) \n",
"Head mean vec len 6.7e-02 ± 7.1e-03 (46) 8.8e-02 ± 7.9e-03 (35) \n",
"Border score 1.8e-01 ± 1.3e-02 (46) 1.9e-01 ± 1.5e-02 (35) \n",
"\n",
" LMM Baseline I - 11 Hz LMM Baseline I - Baseline II \\\n",
"Average rate 6.9e-01, -6.0e-01 8.2e-01, 3.1e-01 \n",
"Gridness 8.5e-01, -2.8e-02 NaN \n",
"Sparsity 2.5e-01, -2.6e-02 9.3e-01, -5.2e-03 \n",
"Selectivity 4.1e-01, 1.9e-01 6.6e-01, 6.6e-01 \n",
"Information rate 1.7e-02, 4.0e-01 4.3e-02, -9.7e-02 \n",
"Information specificity NaN 2.3e-01, -3.0e-02 \n",
"Max rate 7.6e-01, 1.3e+00 3.4e-01, 3.3e+00 \n",
"Interspike interval cv 8.3e-02, 1.7e-01 NaN \n",
"Burst event ratio 7.7e-01, -4.8e-03 7.4e-01, -1.1e-02 \n",
"In-field mean rate 9.7e-01, -6.9e-02 7.5e-01, 4.7e-01 \n",
"Out-field mean rate 5.1e-01, -7.0e-01 7.3e-01, 3.3e-01 \n",
"Max-field mean rate 2.6e-01, 4.1e+00 8.9e-01, 1.3e+00 \n",
"Specificity 2.0e-01, 2.6e-02 9.3e-01, -1.0e-02 \n",
"Speed score 5.4e-01, 1.3e-02 6.8e-01, 9.4e-03 \n",
"Spacing 3.0e-01, 3.5e-02 4.4e-01, -2.9e-02 \n",
"Field area 2.3e-01, 1.5e-02 6.6e-01, -7.3e-03 \n",
"Head mean vec len 7.5e-01, 6.8e-03 8.2e-04, -1.3e-02 \n",
"Border score 9.5e-01, -2.4e-03 4.9e-01, -2.9e-02 \n",
"\n",
" LMM Baseline I - 30 Hz LMM 11 Hz - Baseline II \\\n",
"Average rate 8.4e-01, 3.3e-01 5.1e-01, 5.9e-01 \n",
"Gridness 4.1e-01, -1.5e-01 2.2e-01, 1.5e-01 \n",
"Sparsity 5.0e-01, -4.1e-02 7.5e-02, -2.5e-02 \n",
"Selectivity 5.5e-01, -9.3e-01 3.8e-01, 3.7e-01 \n",
"Information rate 4.3e-06, 3.0e-01 1.0e-01, 3.3e-01 \n",
"Information specificity 6.4e-01, 2.0e-02 3.2e-01, 5.6e-02 \n",
"Max rate 7.8e-01, 1.9e+00 1.7e-01, 5.5e+00 \n",
"Interspike interval cv 8.3e-01, 5.5e-02 NaN \n",
"Burst event ratio 4.7e-03, 5.7e-02 7.7e-01, 3.5e-03 \n",
"In-field mean rate 3.6e-01, 1.8e+00 4.6e-01, 1.2e+00 \n",
"Out-field mean rate 6.5e-01, 6.8e-01 7.3e-01, 2.2e-01 \n",
"Max-field mean rate 1.0e+00, -1.6e-02 3.8e-01, 5.3e+00 \n",
"Specificity 5.5e-01, 4.1e-02 5.9e-01, 2.4e-02 \n",
"Speed score 5.6e-01, 3.3e-02 1.5e-01, 3.6e-02 \n",
"Spacing 2.2e-01, 6.5e-02 7.1e-01, 8.8e-03 \n",
"Field area 7.8e-01, -6.6e-03 4.5e-01, 2.2e-03 \n",
"Head mean vec len 6.7e-01, -6.8e-03 2.4e-01, -2.8e-02 \n",
"Border score 5.8e-01, 2.0e-02 5.2e-08, -3.7e-02 \n",
"\n",
" LMM 11 Hz - 30 Hz LMM Baseline II - 30 Hz \n",
"Average rate 6.2e-01, -1.2e+00 6.8e-01, -5.1e-01 \n",
"Gridness 3.2e-01, 1.2e-01 8.6e-01, -2.7e-02 \n",
"Sparsity NaN 5.8e-01, -1.9e-02 \n",
"Selectivity 1.6e-01, 1.1e+00 9.3e-01, 4.1e-02 \n",
"Information rate 1.6e-01, 2.5e-01 9.5e-01, 2.7e-02 \n",
"Information specificity 2.2e-01, 5.6e-02 3.3e-01, 2.0e-02 \n",
"Max rate 9.6e-02, 6.5e+00 7.2e-01, 1.7e+00 \n",
"Interspike interval cv 9.4e-02, 4.1e-01 9.6e-01, 1.4e-02 \n",
"Burst event ratio NaN 1.3e-02, 3.9e-02 \n",
"In-field mean rate 6.9e-01, -9.9e-01 6.7e-01, 5.9e-01 \n",
"Out-field mean rate 3.1e-01, -1.9e+00 9.1e-01, 9.4e-02 \n",
"Max-field mean rate NaN 9.8e-01, -2.2e-01 \n",
"Specificity 4.2e-01, 4.5e-02 7.6e-01, -1.5e-02 \n",
"Speed score 8.4e-01, 1.7e-02 NaN \n",
"Spacing 1.7e-01, -4.1e-02 1.5e-01, 2.5e-02 \n",
"Field area 8.6e-01, -2.6e-03 9.0e-01, 1.2e-03 \n",
"Head mean vec len 8.7e-01, 2.3e-03 5.6e-01, -9.6e-03 \n",
"Border score 9.5e-01, -2.1e-03 5.8e-01, -3.6e-02 "
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"stat['gridcell'].T"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"for cell_type, sta in stat.items():\n",
" sta.to_latex(output_path / \"statistics\" / f\"statistics_{cell_type}.tex\")\n",
" sta.to_csv(output_path / \"statistics\" / f\"statistics_{cell_type}.csv\")"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"for cell_type, cell_results in results.items():\n",
" for key, result in cell_results.items():\n",
" result.to_latex(output_path / \"statistics\" / f\"values_{cell_type}_{key}.tex\")\n",
" result.to_csv(output_path / \"statistics\" / f\"values_{cell_type}_{key}.csv\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Cumulative density plots"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"title_xlabel = {\n",
" 'information_rate': ('Spatial information','bits/s'),\n",
" 'information_specificity': (\"Spatial information specificity\",\"bits/spike\"),\n",
" 'specificity': (\"Spatial specificity\", \"\"),\n",
" 'average_rate': (\"Average rate\", \"spikes/s\"),\n",
"# 'spatial_average_rate': (\"Spatial average rate\", \"spikes/s\"),\n",
" 'max_rate': (\"Max rate\", \"spikes/s\"),\n",
" 'interspike_interval_cv': (\"ISI CV\", \"Coefficient of variation\"),\n",
" 'in_field_mean_rate': (\"In-field rate\", \"spikes/s\"),\n",
" 'out_field_mean_rate': (\"Out-of-field rate\", \"spikes/s\"),\n",
" 'burst_event_ratio': (\"Bursting ratio\", \"\"),\n",
" 'gridness': (\"Gridness\", \"Gridness\"),\n",
" 'speed_score': (\"Speed score\", \"Speed score\"),\n",
" 'spacing': ('Field spacing', 'cm'),\n",
" 'field_area': ('Field area', 'cm$^2$'),\n",
" 'border_score': ('Border Score', ''),\n",
" 'head_mean_vec_len': ('Head direction score', ''),\n",
" 'max_field_mean_rate': ('Max field mean rate', 'spike/s'),\n",
" 'selectivity': ('Selectivity', ''),\n",
" 'sparsity': ('Sparsity', '')\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"set()"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"set(columns) - set(title_xlabel.keys()).intersection(set(columns))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"plt.rc('axes', titlesize=12)\n",
"plt.rcParams.update({\n",
" 'font.size': 12, \n",
" 'figure.figsize': (3.7, 2.2), \n",
" 'figure.dpi': 150\n",
"})"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for cell_type, cell_results in results.items():\n",
" for key, result in cell_results.items():\n",
" if key not in title_xlabel:\n",
" continue\n",
" fig = plt.figure()\n",
" plt.suptitle(cell_type + ' ' + title_xlabel[key][0])\n",
" legend_lines = []\n",
" for color, label in zip(colors, labels):\n",
" legend_lines.append(matplotlib.lines.Line2D([0], [0], color=color, label=label))\n",
" sns.kdeplot(data=result.loc[:,labels], cumulative=True, legend=False, palette=colors, common_norm=False)\n",
" plt.xlabel(title_xlabel[key][1])\n",
" plt.legend(\n",
" handles=legend_lines,\n",
" bbox_to_anchor=(1.04,1), borderaxespad=0, frameon=False)\n",
" plt.tight_layout()\n",
" plt.grid(False)\n",
" despine()\n",
" savefig(output_path / \"figures\" / f'{cell_type}_{key}')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Violinplot"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"plt.rc('axes', titlesize=12)\n",
"plt.rcParams.update({\n",
" 'font.size': 12, \n",
" 'figure.figsize': (1.7*3, 3), \n",
" 'figure.dpi': 150\n",
"})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Information rate"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def violinplot(df, labels, colors, statistics=None):\n",
" data = np.array([df.loc[:,label].dropna().to_numpy() for label in labels])\n",
" pos = np.array([i * 0.6 for i in range(len(data))])\n",
" labels = np.array(labels)\n",
"# print(pos)\n",
" violins = plt.violinplot(data, pos, showmedians=True, showextrema=False)\n",
" \n",
" for i, b in enumerate(violins['bodies']):\n",
" b.set_color(colors[i])\n",
" b.set_alpha (0.8)\n",
"\n",
" # for i, body in enumerate(violins['cbars']):\n",
" # body.set_color('C{}'.format(i))\n",
"\n",
" for category in ['cbars', 'cmins', 'cmaxes', 'cmedians']:\n",
" if category in violins:\n",
" violins[category].set_color(['k', 'k'])\n",
" violins[category].set_linewidth(2.0)\n",
" plt.xticks(pos, labels, rotation=45)\n",
" plt.gca().spines['top'].set_visible(False)\n",
" plt.gca().spines['right'].set_visible(False)\n",
"\n",
" \n",
" if statistics is not None:\n",
" tests = [[0,1], [2,3], [0,2]]\n",
" ds = [0,0,1]\n",
" for test, d in zip(tests, ds):\n",
" pvalue = statistics.loc[' - '.join(labels[test])]\n",
" # significance\n",
" if pvalue < 0.0001:\n",
" significance = \"****\"\n",
" elif pvalue < 0.001:\n",
" significance = \"***\"\n",
" elif pvalue < 0.01:\n",
" significance = \"**\"\n",
" elif pvalue < 0.05:\n",
" significance = \"*\"\n",
" else:\n",
" significance = \"ns\"\n",
"\n",
" x1, x2 = pos[test]\n",
" data_max = np.max([a.max() for a in data[test]])\n",
" data_min = np.min([a.min() for a in data[test]])\n",
" y = (data_max * 1.05)\n",
" h = 0.025 * (data_max - data_min)\n",
" d_ = d * 0.15 * (data_max - data_min)\n",
" plt.plot([x1, x1, x2, x2], np.array([y - h, y, y, y - h]) + d_, c='k')\n",
" plt.text((x1 + x2) / 2, y + h + d_, significance, ha='center', va='bottom')\n",
" \n",
" \n",
" \n",
"# plt.gca().spines['top'].set_visible(False)\n",
"# plt.gca().spines['right'].set_visible(False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for cell_type, cell_results in results.items():\n",
" for key, result in cell_results.items():\n",
" if key not in title_xlabel:\n",
" continue\n",
" fig = plt.figure()\n",
" plt.suptitle(cell_type + ' ' + title_xlabel[key][0])\n",
" violinplot(result, labels=labels, colors=colors, statistics=stat_values[cell_type][key])\n",
" plt.ylabel(title_xlabel[key][1])\n",
"# plt.tight_layout()\n",
" plt.grid(False)\n",
" despine()\n",
" savefig(output_path / \"figures\" / f'{cell_type}_violin_{key}')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Register in Expipe"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"action = project.require_action(\"comparisons-allcells\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"copy_tree(output_path, str(action.data_path()))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"septum_mec.analysis.registration.store_notebook(action, \"20_comparisons_allcells.ipynb\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 4
}