{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import os\n",
    "import vbn_utils as vbn\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from matplotlib import pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Paths to all of the useful supplemental tables and tensors\n",
    "stim_table_file = \"/Volumes/programs/mindscope/workgroups/np-behavior/vbn_data_release/supplemental_tables/master_stim_table_no_filter.csv\"\n",
    "unit_table_file = \"/Volumes/programs/mindscope/workgroups/np-behavior/vbn_data_release/supplemental_tables/master_units_with_responsiveness.csv\"\n",
    "\n",
    "sessions_table_file = \"/Volumes/programs/mindscope/workgroups/np-behavior/vbn_data_release/supplemental_tables/master_sessions_table.csv\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "sessions = pd.read_csv(sessions_table_file)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Assessing whether mice in this dataset are more disposed to using a visual strategy (as opposed to timing) compared to mice in the companion 2-photon visual behavior dataset (Piet et al, Neuron 2024)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "vbo_beh_model_summary = pd.read_pickle(\"/Volumes/programs/braintv/workgroups/nc-ophys/alex.piet/behavior/psy_fits_v21/summary_data/_summary_table.pkl\")\n",
    "vbn_beh_model_summary = pd.read_pickle(\"/Volumes/programs/braintv/workgroups/nc-ophys/alex.piet/NP/behavior/psy_fits_v100/summary_data/_summary_table.pkl\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print('timing', np.sum(vbo_beh_model_summary['strategy_dropout_index']<0)/len(vbo_beh_model_summary), np.sum(vbn_beh_model_summary['strategy_dropout_index']<0)/len(vbn_beh_model_summary))\n",
    "print('visual', np.sum(vbo_beh_model_summary['strategy_dropout_index']>0)/len(vbo_beh_model_summary), np.sum(vbn_beh_model_summary['strategy_dropout_index']>0)/len(vbn_beh_model_summary))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "vbn_beh_model_summary['strategy_dropout_index'].hist(density=True, bins=25, alpha=0.5, label='VBN')\n",
    "vbo_beh_model_summary['strategy_dropout_index'].hist(density=True, bins=25, alpha=0.5, label='VBO')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Plot the strategy scores for mice in both datasets. A positive score indicates heavier reliance on a visual strategy. Negative indicates reliance on a timing strategy."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig, ax = plt.subplots()\n",
    "plt.rcParams['font.size'] = 18\n",
    "for id, dataset in enumerate([vbn_beh_model_summary, vbo_beh_model_summary]):\n",
    "    plt.boxplot(dataset['strategy_dropout_index'], positions=[id], widths=0.5, patch_artist=True, boxprops=dict(facecolor='gray', color='black'), \n",
    "                medianprops=dict(color='black'), whiskerprops=dict(color='black'), capprops=dict(color='black'), notch=True, showfliers=False)\n",
    "vbn.formatFigure(fig, ax, xLabel='Dataset', yLabel='Strategy dropout index', title='Figure S14', legend=False)\n",
    "ax.set_xticklabels(['VBN', 'VBO'])\n",
    "ax.axhline(0, color='k', ls='dotted')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import scipy.stats\n",
    "\n",
    "vbn_beh_model_summary['strategy_dropout_index'].mean(), vbn_beh_model_summary['strategy_dropout_index'].sem(), vbo_beh_model_summary['strategy_dropout_index'].mean(), vbo_beh_model_summary['strategy_dropout_index'].sem(), scipy.stats.ranksums(vbn_beh_model_summary['strategy_dropout_index'], vbo_beh_model_summary['strategy_dropout_index'])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "vbn_manuscript",
   "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.8.20"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
