|
@@ -5,6 +5,9 @@
|
|
|
|
|
|
# In[14]:
|
|
|
|
|
|
+#import matplotlib.pyplot as plt
|
|
|
+#plt.rcParams["figure.figsize"] = (20,3)
|
|
|
+
|
|
|
|
|
|
database_path = '/media/andrey/My Passport/GIN/Anesthesia_CA1/meta_data/meta_recordings - anesthesia.xlsx'
|
|
|
|
|
@@ -25,6 +28,8 @@ import numpy as np
|
|
|
import numpy.ma as ma
|
|
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
+import matplotlib.ticker as ticker
|
|
|
+
|
|
|
import pandas as pd
|
|
|
import seaborn as sns
|
|
|
import pickle
|
|
@@ -57,9 +62,8 @@ custom_palette ={'keta':color_keta, 'iso':color_iso,'fenta':color_mmf,'awa':colo
|
|
|
from capipeline import *
|
|
|
|
|
|
|
|
|
-
|
|
|
# ### Run the analysis
|
|
|
-#
|
|
|
+# /media/andrey/My Passport/GIN/Anesthesia_CA1/validation/calcium_imaging
|
|
|
# It creates a data frame *df_estimators* that contains basic information regarding stability of the recordings, such as
|
|
|
#
|
|
|
# - total number of identified neurons,
|
|
@@ -73,6 +77,7 @@ from capipeline import *
|
|
|
|
|
|
|
|
|
df_estimators = pd.DataFrame()
|
|
|
+'''
|
|
|
|
|
|
for r in rec:
|
|
|
|
|
@@ -95,7 +100,7 @@ for r in rec:
|
|
|
|
|
|
baseline = np.quantile(Traces,0.25,axis=1)
|
|
|
|
|
|
- recording_length = int(Traces.shape[1])
|
|
|
+ recording_length = int(Traces.shape[1])
|
|
|
|
|
|
half = int(recording_length/2)
|
|
|
|
|
@@ -133,8 +138,8 @@ for r in rec:
|
|
|
|
|
|
print("*****")
|
|
|
|
|
|
-
|
|
|
-#df_estimators['neuronID'] = df_estimators.index
|
|
|
+'''
|
|
|
+
|
|
|
|
|
|
|
|
|
# ### Save the result of the analysis
|
|
@@ -142,7 +147,7 @@ for r in rec:
|
|
|
# In[7]:
|
|
|
|
|
|
|
|
|
-df_estimators.to_pickle("./calcium_imaging_stability_validation.pkl")
|
|
|
+#df_estimators.to_pickle("./calcium_imaging_stability_validation.pkl")
|
|
|
|
|
|
|
|
|
# ### Load the result of the analysis
|
|
@@ -151,6 +156,9 @@ df_estimators.to_pickle("./calcium_imaging_stability_validation.pkl")
|
|
|
|
|
|
|
|
|
df_estimators = pd.read_pickle("./calcium_imaging_stability_validation.pkl")
|
|
|
+df_estimators['neuronID'] = df_estimators.index
|
|
|
+
|
|
|
+df_estimators["animal_cat"] = df_estimators["animal"].astype("category")
|
|
|
|
|
|
|
|
|
# ### Plot
|
|
@@ -159,42 +167,66 @@ df_estimators = pd.read_pickle("./calcium_imaging_stability_validation.pkl")
|
|
|
|
|
|
|
|
|
parameters = ["animal",'number.neurons','baseline.quantile.25','traces.median','traces.skewness','median.stability']
|
|
|
-labels = ["Animal ID",'Extracted ROIs','Baseline, A.U.','Traces Median, A.U.','Traces Skewness','Stability, %']
|
|
|
+labels = ["Animal \n ID",'Extracted \n ROIs','Baseline, \n A.U.','Median, \n A.U.','Skewness','Stability, \n %']
|
|
|
number_subplots = len(parameters)
|
|
|
-recordings_ranges = [[0,31],[32,55],[56,95],[96,133],[134,160],[161,188]]
|
|
|
-#recordings_ranges = [[1,2]] #test
|
|
|
+#recordings_ranges = [[0,31],[32,55],[56,95],[96,133],[134,160],[161,188]]
|
|
|
+#recordings_ranges = [[0,55],[56,133],[134,188]]
|
|
|
+#recordings_ranges = [[0,133],[134,188]] #test
|
|
|
+recordings_ranges = [[0,188]]
|
|
|
|
|
|
for rmin,rmax in recordings_ranges:
|
|
|
|
|
|
- f, axes = plt.subplots(number_subplots, 1, figsize=(32, 24)) # sharex=Truerex=True
|
|
|
+ f, axes = plt.subplots(number_subplots, 1, figsize=(8, 6)) # sharex=Truerex=True
|
|
|
sns.despine(left=True)
|
|
|
|
|
|
for i, param in enumerate(parameters):
|
|
|
|
|
|
lw = 3
|
|
|
- if i > 4:
|
|
|
- lw = 10
|
|
|
-
|
|
|
- sns.boxplot(x='recording', y=param, data=df_estimators[(df_estimators.recording>=rmin)&(df_estimators.recording<=rmax)], hue='condition', palette=custom_palette,ax=axes[i],linewidth=lw)
|
|
|
-
|
|
|
+ if (i == 5)|(i == 0)|(i == 1):
|
|
|
+ lw = 1
|
|
|
+ else:
|
|
|
+ lw = 1
|
|
|
+
|
|
|
+
|
|
|
+ #else:
|
|
|
+ sns.boxplot(x='recording', y=param, data=df_estimators[(df_estimators.recording>=rmin)&(df_estimators.recording<=rmax)], width=0.9, dodge=False, showfliers = False,hue='condition', palette=custom_palette,ax=axes[i],linewidth=lw)
|
|
|
+ if (i == 0):
|
|
|
+ param = "animal_cat"
|
|
|
+ print(np.unique(df_estimators[param]))
|
|
|
+ axes[i].set_yticks(np.unique(df_estimators[param]))
|
|
|
+
|
|
|
+ sns.swarmplot(x='recording', y=param, data=df_estimators[(df_estimators.recording>=rmin)&(df_estimators.recording<=rmax)&(df_estimators['neuronID'] == 0)],dodge=False, s=1, edgecolor='black', linewidth=1, hue='condition', palette=custom_palette, ax=axes[i])
|
|
|
+ #ax.set(ylabel="")
|
|
|
+
|
|
|
if i > 1:
|
|
|
- axes[i].set_ylim([0.0,3000.0])
|
|
|
+ axes[i].set_ylim([0.0,2000.0])
|
|
|
if i > 3:
|
|
|
axes[i].set_ylim([0.0,10.0])
|
|
|
if i > 4:
|
|
|
axes[i].set_ylim([80,120])
|
|
|
+ axes[i].get_xaxis().set_visible(True)
|
|
|
+ else:
|
|
|
+ axes[i].get_xaxis().set_visible(False)
|
|
|
+
|
|
|
if i < number_subplots-1:
|
|
|
axes[i].xaxis.label.set_visible(False)
|
|
|
if i==0:
|
|
|
- axes[i].set_title("Validation: stability check (recordings #%d-#%d)" % (rmin,rmax), fontsize=35)
|
|
|
- axes[i].set_ylabel(labels[i], fontsize=20,labelpad=55)
|
|
|
- axes[i].set_xlabel("Recording", fontsize=25,labelpad=55)
|
|
|
- axes[i].xaxis.set_tick_params(labelsize=20)
|
|
|
- axes[i].yaxis.set_tick_params(labelsize=20)
|
|
|
+ axes[i].set_title("Validation: stability check (recordings #%d-#%d)" % (rmin,rmax), fontsize=9, pad=20)
|
|
|
+ axes[i].set_ylabel(labels[i], fontsize=9,labelpad=5)
|
|
|
+ axes[i].set_xlabel("Recording", fontsize=9,labelpad=5)
|
|
|
+ #axes[i].axis('off')
|
|
|
+
|
|
|
+ axes[i].xaxis.set_tick_params(labelsize=9)
|
|
|
+ axes[i].yaxis.set_tick_params(labelsize=9)
|
|
|
+
|
|
|
axes[i].get_legend().remove()
|
|
|
+ axes[i].xaxis.set_major_locator(ticker.MultipleLocator(20))
|
|
|
+ axes[i].xaxis.set_major_formatter(ticker.ScalarFormatter())
|
|
|
|
|
|
- plt.legend(loc='upper right',fontsize=25)
|
|
|
- plt.savefig("Validation_stability_check_rec_#%d-#%d).png" % (rmin,rmax))
|
|
|
+ #plt.legend(loc='upper right',fontsize=8)
|
|
|
+ #plt.legend(bbox_to_anchor=(1.01, 1), loc=2, borderaxespad=0.,fontsize=9)
|
|
|
+ plt.savefig("Validation_stability_check_rec_#%d-#%d).png" % (rmin,rmax),dpi=300)
|
|
|
+ plt.savefig("Validation_stability_check_rec_#%d-#%d).svg" % (rmin,rmax))
|
|
|
#plt.show()
|
|
|
|
|
|
|
|
@@ -203,8 +235,8 @@ for rmin,rmax in recordings_ranges:
|
|
|
|
|
|
sns.displot(data=df_estimators, x="median.stability", hue = 'condition',palette=custom_palette, kind="kde")
|
|
|
plt.xlim([80,120])
|
|
|
-plt.xlabel("Stability, %", fontsize = 15)
|
|
|
-plt.title("Validation: summary on stability (recordings #%d-#%d)" % (min(rec),max(rec)), fontsize = 10)
|
|
|
+plt.xlabel("Stability, %", fontsize = 25)
|
|
|
+plt.title("Validation: summary on stability (recordings #%d-#%d)" % (min(rec),max(rec)), fontsize = 20, pad=20)
|
|
|
plt.grid(False)
|
|
|
plt.savefig("Validation_summary_stability_recordings_#%d-#%d)" % (min(rec),max(rec)))
|
|
|
#plt.show()
|