In [1]:
drive_path = 'c:/'
import numpy as np
import pandas as pd
import os
import sys
import matplotlib.pyplot as plt
from scipy.stats import ks_2samp
from scipy.stats import anderson_ksamp
from scipy.stats import kruskal
from scipy.stats import variation
%matplotlib
import seaborn as sns
from scipy.stats import zscore
from scipy.stats import nanmean
from scipy.stats import nanstd
In [15]:
filename='C:\Users\Annie\Documents\Data\Ca_Imaging\GoodFiles\\fullintegral.csv'
comp=pd.read_csv(filename)
comp_sorted=comp.reindex_axis(comp.mean().sort_values().index, axis=1)
comp_labels=pd.DataFrame(comp.Mouse)
comp_group=pd.DataFrame(comp.Group)
tmp=[comp_group,comp_labels,comp_sorted]
composite_full=pd.concat(tmp,axis=1)
cfull=pd.melt(composite_full,['Group','Mouse'],var_name="Odor")
# cfull['Mouse'] = cfull['Mouse'].apply(lambda x: x.split('_')[0])
# composite_full['Mouse']=composite_full['Mouse'].apply(lambda x:x.split('_')[0])
In [ ]:
In [49]:
# for x in composite_full.index:
a=0
b=0
for value in composite_full.iloc[x][2:]:
if value>0:
a=a+1
elif value<0:
b=b+1
In [50]:
c=pd.DataFrame(composite_full.iloc[x][['Group','Mouse']]).T
c=c.reset_index()
pd.concat([c,pd.DataFrame({'E':[a]}),pd.DataFrame({'I':[b]})],axis=1)
Out[50]:
In [ ]:
In [16]:
#Make separate excitatory and inhibitory dataframes
mindf=pd.DataFrame([])
maxdf=pd.DataFrame([])
zdf=pd.DataFrame([])
for x in cfull.index:
if cfull.value[x]>0:
a=pd.DataFrame(cfull.iloc[x]).T
maxdf=maxdf.append(a,ignore_index=True)
elif cfull.value[x]<0:
a=pd.DataFrame(cfull.iloc[x]).T
mindf=mindf.append(a,ignore_index=True)
else:
a=pd.DataFrame(cfull.iloc[x]).T
zdf=zdf.append(a,ignore_index=True)
In [17]:
groupcolors={'Control':'r','Mint':'g','Hexanal':'b'}
In [52]:
#Plot Excitatory by group
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("talk", font_scale=1.8);
plt.figure(figsize=(45, 20));
sns.boxplot(x='Odor',y='value',hue='Group',palette=groupcolors,data=maxdf[['Group','Odor','value']]);
sns.despine()
plt.ylabel('Integral', fontsize=48);
plt.title('Excitatory responses', fontsize=55);
plt.xlabel('Odor', fontsize=48);
In [53]:
#Plot Inhibitory by group
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("talk", font_scale=1.8);
plt.figure(figsize=(45, 20));
sns.boxplot(x='Odor',y='value',hue='Group',palette=groupcolors,data=mindf[['Group','Odor','value']]);
sns.despine()
plt.ylabel('Integral', fontsize=48);
plt.title('Inhibitory responses', fontsize=55);
plt.xlabel('Odor', fontsize=48);
In [120]:
#All responses
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("talk", font_scale=1.8);
plt.figure(figsize=(45, 20));
sns.boxplot(x='Odor',y='value',hue='Group',palette=groupcolors,data=mindf[['Group','Odor','value']]);
ax=sns.boxplot(x='Odor',y='value',hue='Group',palette=groupcolors,data=maxdf[['Group','Odor','value']]);
ax.legend_.remove()
sns.despine()
plt.ylabel('Peak', fontsize=48);
plt.title('All responses', fontsize=55);
plt.xlabel('Odor', fontsize=48);
In [18]:
#EI ratio, of number
eibdf=pd.DataFrame([])
for x in maxdf.Group.unique():
for y in maxdf.Odor.unique():
a=float(len(mindf[(mindf.Group==x) & (mindf.Odor==y)]['value']))
b=float(len(maxdf[(maxdf.Group==x) & (maxdf.Odor==y)]['value']))
EIB=a/b
eibdf=eibdf.append(pd.DataFrame({'Group':[x],'Odor':[y],'EIB':[EIB]}))
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("talk", font_scale=1.8);
plt.figure(figsize=(45, 20));
sns.pointplot(x='Odor',y='EIB',hue='Group',palette=groupcolors,data=eibdf);
sns.despine()
plt.ylabel('Inhibition/Excitation Ratio', fontsize=48);
plt.title('Inhibition/Excitation', fontsize=55);
plt.xlabel('Odor', fontsize=48);
In [12]:
float(a)/float(b)
Out[12]:
In [ ]:
In [ ]:
In [265]:
#EI balance (comparison of summed I/E)
eibdf=pd.DataFrame([])
for x in maxdf.Group.unique():
for y in maxdf.Odor.unique():
a=mindf[(mindf.Group==x) & (mindf.Odor==y)]['value'].sum()
b=maxdf[(maxdf.Group==x) & (maxdf.Odor==y)]['value'].sum()
EIB=abs(a/b)
eibdf=eibdf.append(pd.DataFrame({'Group':[x],'Odor':[y],'EIB':[EIB]}))
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("talk", font_scale=1.8);
plt.figure(figsize=(45, 20));
sns.pointplot(x='Odor',y='EIB',hue='Group',palette=groupcolors,data=eibdf);
sns.despine()
plt.ylabel('EIB', fontsize=48);
plt.title('Excitation-Inhibition Balance', fontsize=55);
plt.xlabel('Odor', fontsize=48);
In [266]:
ks_2samp(eibdf[(eibdf.Group=='Control')]['EIB'],eibdf[(eibdf.Group=='Mint')]['EIB'])
Out[266]:
In [270]:
zscores=pd.DataFrame([])
df=maxdf
for x in df.Mouse.unique():
tmp=pd.DataFrame([])
for y in df.Odor.unique():
v=df[(df.Mouse==x)& (df.Odor==y)]['value']
a=pd.DataFrame((v - np.nanmean(v)) / np.nanstd(v))
a=pd.concat([df[(df.Mouse==x)& (df.Odor==y)][['Group','Mouse','Odor']],a],axis=1)
tmp=tmp.append(a)
zscores=zscores.append(tmp)
In [271]:
#Plot everything by group
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("talk", font_scale=1.8);
plt.figure(figsize=(45, 20));
ax=sns.boxplot(x='Odor',y='value',hue='Group',palette=groupcolors,data=zscores)
ax.legend_.remove()
sns.despine()
plt.ylabel('Zscore', fontsize=48);
plt.title('Zscore', fontsize=55);
plt.xlabel('Odor', fontsize=48);
In [215]:
o='Hexanone'
sns.distplot(zscores[(zscores.Group=='Control')&(zscores.Odor==o)]['value'], hist=False, color="r", kde_kws={"shade": True});
sns.distplot(zscores[(zscores.Group=='Mint')&(zscores.Odor==o)]['value'], hist=False, color="g", kde_kws={"shade": True});
sns.distplot(zscores[(zscores.Group=='Hexanal')&(zscores.Odor==o)]['value'], hist=False, color="b", kde_kws={"shade": True});
In [236]:
kruskal(zscores[(zscores.Group=='Control')&(zscores.Odor==o)]['value'],zscores[(zscores.Group=='Mint')&(zscores.Odor==o)]['value'],zscores[(zscores.Group=='Hexanal')&(zscores.Odor==o)]['value'])
Out[236]:
In [273]:
means=pd.DataFrame([])
df=maxdf
for x in df.Mouse.unique():
tmp=pd.DataFrame([])
for y in df.Odor.unique():
a=(df[(df.Mouse==x)&(df.Odor==y)]['value']).dropna().mean()
m=pd.DataFrame({y:[a]})
tmp=pd.concat([tmp,m],axis=1)
b=pd.DataFrame({'Mouse':[x]})
c=pd.DataFrame({'Group':[df[df.Mouse==x]['Group'].iloc[0]]})
# c=c.reset_index(drop=True)
tmp=pd.concat([c,tmp],axis=1)
means=means.append(tmp)
meanmelt=pd.melt(means,"Group",var_name="Odor")
#Plot everything by group
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("talk", font_scale=1.8);
plt.figure(figsize=(45, 20));
ax=sns.boxplot(x='Odor',y='value',hue='Group',palette=groupcolors,data=meanmelt)
ax.legend_.remove()
sns.despine()
plt.ylabel('Mean', fontsize=48);
plt.title('Mean', fontsize=55);
plt.xlabel('Odor', fontsize=48);
In [323]:
#POINTPLOTS
means=pd.DataFrame([])
df=maxdf
for x in df.Group.unique():
tmp=pd.DataFrame([])
for y in df.Odor.unique():
a=(df[(df.Group==x)&(df.Odor==y)]['value']).dropna().std()
m=pd.DataFrame({y:[a]})
tmp=pd.concat([tmp,m],axis=1)
b=pd.DataFrame({'Group':[x]})
# c=pd.DataFrame({'Group':[df[df.Mouse==x]['Group'].iloc[0]]})
# c=c.reset_index(drop=True)
tmp=pd.concat([b,tmp],axis=1)
means=means.append(tmp)
meanmelt=pd.melt(means,"Group",var_name="Odor")
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("talk", font_scale=1.8);
plt.figure(figsize=(45, 20));
ax=sns.pointplot(x='Odor',y='value',hue='Group',palette=groupcolors,data=meanmelt)
ax.legend_.remove()
sns.despine()
plt.ylabel('STD', fontsize=48);
plt.title('STD', fontsize=55);
plt.xlabel('Odor', fontsize=48);
In [277]:
#MEDIANS
medians=pd.DataFrame([])
df=mindf
for x in df.Mouse.unique():
tmp=pd.DataFrame([])
for y in df.Odor.unique():
a=df[(df.Mouse==x)&(df.Odor==y)]['value'].dropna().median()
m=pd.DataFrame({y:[a]})
tmp=pd.concat([tmp,m],axis=1)
b=pd.DataFrame({'Mouse':[x]})
c=pd.DataFrame({'Group':[df[df.Mouse==x]['Group'].iloc[0]]})
# c=c.reset_index(drop=True)
tmp=pd.concat([c,tmp],axis=1)
medians=medians.append(tmp)
medianmelt=pd.melt(medians,"Group",var_name="Odor")
#Plot everything by group
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("talk", font_scale=1.8);
plt.figure(figsize=(45, 20));
ax=sns.boxplot(x='Odor',y='value',hue='Group',palette=groupcolors,data=medianmelt)
ax.legend_.remove()
sns.despine()
plt.ylabel('Median', fontsize=48);
plt.title('Median', fontsize=55);
plt.xlabel('Odor', fontsize=48);
In [276]:
stds=pd.DataFrame([])
df=maxdf
for x in df.Mouse.unique():
tmp=pd.DataFrame([])
for y in df.Odor.unique():
a=df[(df.Mouse==x)&(df.Odor==y)]['value'].dropna().std()
m=pd.DataFrame({y:[a]})
tmp=pd.concat([tmp,m],axis=1)
b=pd.DataFrame({'Mouse':[x]})
c=pd.DataFrame({'Group':[df[df.Mouse==x]['Group'].iloc[0]]})
# c=c.reset_index(drop=True)
tmp=pd.concat([c,tmp],axis=1)
stds=stds.append(tmp)
stdmelt=pd.melt(stds,"Group",var_name="Odor")
#Plot everything by group
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("talk", font_scale=1.8);
plt.figure(figsize=(45, 20));
ax=sns.boxplot(x='Odor',y='value',hue='Group',palette=groupcolors,data=stdmelt)
ax.legend_.remove()
sns.despine()
plt.ylabel('STD', fontsize=48);
plt.title('STD', fontsize=55);
plt.xlabel('Odor', fontsize=48);
In [ ]: