{ "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", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
entityunit_idnumchannel_groupdateBaseline I11 HzBaseline II30 Hz
51183380207197.900527NaNNaNNaN
85183313020719NaN5.4153616.4568829.526984
86183314020719NaN16.68111216.498883NaN
58183323020061916.171078NaNNaNNaN
1271833260200619NaNNaN6.9901176.953565
...........................
13918498354150319NaNNaNNaN3.680061
43184985156031923.736187NaNNaNNaN
65184993272802195.661950NaNNaNNaN
7418499377280219NaN9.485790NaNNaN
10518499397280219NaNNaN12.721755NaN
\n", "

137 rows × 8 columns

\n", "
" ], "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Baseline I11 HzBaseline II30 HzLMM Baseline I - 11 HzLMM Baseline I - Baseline IILMM Baseline I - 30 HzLMM 11 Hz - Baseline IILMM 11 Hz - 30 HzLMM Baseline II - 30 Hz
Average rate9.8e+00 ± 9.3e-01 (63)1.1e+01 ± 1.0e+00 (56)1.0e+01 ± 1.0e+00 (46)8.5e+00 ± 1.1e+00 (35)6.9e-01, -6.0e-018.2e-01, 3.1e-018.4e-01, 3.3e-015.1e-01, 5.9e-016.2e-01, -1.2e+006.8e-01, -5.1e-01
Gridness3.7e-01 ± 5.6e-02 (63)4.0e-01 ± 5.1e-02 (56)5.3e-01 ± 3.7e-02 (46)5.7e-01 ± 4.9e-02 (35)8.5e-01, -2.8e-02NaN4.1e-01, -1.5e-012.2e-01, 1.5e-013.2e-01, 1.2e-018.6e-01, -2.7e-02
Sparsity6.6e-01 ± 2.4e-02 (63)7.1e-01 ± 3.1e-02 (56)6.6e-01 ± 3.2e-02 (46)6.4e-01 ± 3.7e-02 (35)2.5e-01, -2.6e-029.3e-01, -5.2e-035.0e-01, -4.1e-027.5e-02, -2.5e-02NaN5.8e-01, -1.9e-02
Selectivity5.3e+00 ± 4.3e-01 (63)5.4e+00 ± 5.9e-01 (56)6.2e+00 ± 6.7e-01 (46)6.8e+00 ± 6.7e-01 (35)4.1e-01, 1.9e-016.6e-01, 6.6e-015.5e-01, -9.3e-013.8e-01, 3.7e-011.6e-01, 1.1e+009.3e-01, 4.1e-02
Information rate1.4e+00 ± 8.6e-02 (63)9.3e-01 ± 6.9e-02 (56)1.3e+00 ± 1.0e-01 (46)1.1e+00 ± 1.1e-01 (35)1.7e-02, 4.0e-014.3e-02, -9.7e-024.3e-06, 3.0e-011.0e-01, 3.3e-011.6e-01, 2.5e-019.5e-01, 2.7e-02
Information specificity2.5e-01 ± 3.4e-02 (63)2.2e-01 ± 4.5e-02 (56)2.3e-01 ± 3.4e-02 (46)2.4e-01 ± 3.8e-02 (35)NaN2.3e-01, -3.0e-026.4e-01, 2.0e-023.2e-01, 5.6e-022.2e-01, 5.6e-023.3e-01, 2.0e-02
Max rate3.6e+01 ± 2.1e+00 (63)3.6e+01 ± 2.2e+00 (56)4.2e+01 ± 2.4e+00 (46)3.7e+01 ± 2.5e+00 (35)7.6e-01, 1.3e+003.4e-01, 3.3e+007.8e-01, 1.9e+001.7e-01, 5.5e+009.6e-02, 6.5e+007.2e-01, 1.7e+00
Interspike interval cv2.2e+00 ± 8.9e-02 (63)2.0e+00 ± 1.4e-01 (56)2.2e+00 ± 8.0e-02 (46)2.3e+00 ± 1.1e-01 (35)8.3e-02, 1.7e-01NaN8.3e-01, 5.5e-02NaN9.4e-02, 4.1e-019.6e-01, 1.4e-02
Burst event ratio2.3e-01 ± 1.1e-02 (63)2.3e-01 ± 1.2e-02 (56)2.3e-01 ± 1.1e-02 (46)1.8e-01 ± 1.2e-02 (35)7.7e-01, -4.8e-037.4e-01, -1.1e-024.7e-03, 5.7e-027.7e-01, 3.5e-03NaN1.3e-02, 3.9e-02
In-field mean rate1.5e+01 ± 1.2e+00 (63)1.6e+01 ± 1.3e+00 (56)1.7e+01 ± 1.2e+00 (46)1.3e+01 ± 1.3e+00 (35)9.7e-01, -6.9e-027.5e-01, 4.7e-013.6e-01, 1.8e+004.6e-01, 1.2e+006.9e-01, -9.9e-016.7e-01, 5.9e-01
Out-field mean rate7.3e+00 ± 7.9e-01 (63)8.8e+00 ± 9.0e-01 (56)7.8e+00 ± 8.6e-01 (46)6.0e+00 ± 8.7e-01 (35)5.1e-01, -7.0e-017.3e-01, 3.3e-016.5e-01, 6.8e-017.3e-01, 2.2e-013.1e-01, -1.9e+009.1e-01, 9.4e-02
Max-field mean rate1.2e+01 ± 1.3e+00 (35)1.1e+01 ± 1.6e+00 (31)1.7e+01 ± 2.6e+00 (33)7.8e+00 ± 1.2e+00 (19)2.6e-01, 4.1e+008.9e-01, 1.3e+001.0e+00, -1.6e-023.8e-01, 5.3e+00NaN9.8e-01, -2.2e-01
Specificity4.2e-01 ± 2.9e-02 (63)3.9e-01 ± 3.5e-02 (56)4.3e-01 ± 3.1e-02 (46)4.7e-01 ± 4.0e-02 (35)2.0e-01, 2.6e-029.3e-01, -1.0e-025.5e-01, 4.1e-025.9e-01, 2.4e-024.2e-01, 4.5e-027.6e-01, -1.5e-02
Speed score1.1e-01 ± 1.1e-02 (63)9.4e-02 ± 1.2e-02 (56)8.7e-02 ± 8.0e-03 (46)7.4e-02 ± 9.9e-03 (35)5.4e-01, 1.3e-026.8e-01, 9.4e-035.6e-01, 3.3e-021.5e-01, 3.6e-028.4e-01, 1.7e-02NaN
Spacing5.6e-01 ± 2.0e-02 (63)5.4e-01 ± 2.0e-02 (56)5.2e-01 ± 1.6e-02 (46)4.9e-01 ± 1.5e-02 (35)3.0e-01, 3.5e-024.4e-01, -2.9e-022.2e-01, 6.5e-027.1e-01, 8.8e-031.7e-01, -4.1e-021.5e-01, 2.5e-02
Field area4.5e-01 ± 7.6e-03 (63)4.3e-01 ± 7.8e-03 (56)4.4e-01 ± 8.6e-03 (46)4.4e-01 ± 9.3e-03 (35)2.3e-01, 1.5e-026.6e-01, -7.3e-037.8e-01, -6.6e-034.5e-01, 2.2e-038.6e-01, -2.6e-039.0e-01, 1.2e-03
Head mean vec len8.7e-02 ± 8.5e-03 (63)7.7e-02 ± 8.6e-03 (56)6.7e-02 ± 7.1e-03 (46)8.8e-02 ± 7.9e-03 (35)7.5e-01, 6.8e-038.2e-04, -1.3e-026.7e-01, -6.8e-032.4e-01, -2.8e-028.7e-01, 2.3e-035.6e-01, -9.6e-03
Border score2.1e-01 ± 1.3e-02 (63)2.1e-01 ± 1.2e-02 (56)1.8e-01 ± 1.3e-02 (46)1.9e-01 ± 1.5e-02 (35)9.5e-01, -2.4e-034.9e-01, -2.9e-025.8e-01, 2.0e-025.2e-08, -3.7e-029.5e-01, -2.1e-035.8e-01, -3.6e-02
\n", "
" ], "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 }