Compare mean, median, COV, std
In [ ]:
In [17]:
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
In [18]:
comp=pd.read_csv('C:\Users\Annie\Documents\Data\Ca_Imaging\GoodFiles\\fullpeak.csv')
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 [4]:
cfull
Out[4]:
In [19]:
colors={'160321':'r', '160421':'r', '160502':'r', '160503':'r', '160420':'r',
'160517':'b', '160525':'b', '160620':'b', '160621':'b', '160622':'b', '160626':'b',
'160330':'g', '160328':'g', '160428':'g', '160429':'g', '160325':'g', '160401':'g'}
In [20]:
cctrl=cfull[cfull.Mouse.isin(['160321','160421','160502','160503','160420'])]
hexfull=cfull[cfull.Mouse.isin(['160517', '160525', '160620', '160621', '160622', '160626'])]
msfull=cfull[cfull.Mouse.isin(['160330', '160328', '160428', '160429', '160325','160401'])]
In [21]:
cfc=composite_full[composite_full.Mouse.isin(['160321','160421','160502','160503','160420'])]
cfh=composite_full[composite_full.Mouse.isin(['160517', '160525', '160620', '160621', '160622', '160626'])]
cfm=composite_full[composite_full.Mouse.isin(['160330', '160328', '160428', '160429', '160325','160401'])]
In [22]:
odorlist=['THA', 'MS01', 'Blank', 'AP', 'MS10', 'MS05',
'IAA05', 'IAA01', 'PA', 'IAA10', 'Hexanone', 'Hexanal10',
'Hexanal01', 'Hexanal05', 'EB']
In [23]:
from scipy.stats import zscore
from scipy.stats import nanmean
from scipy.stats import nanstd
# zscore(composite_full[composite_full.Mouse==x][y])
In [34]:
zscores=pd.DataFrame([])
for x in composite_full.Mouse.unique():
tmp=pd.DataFrame([])
for y in odorlist:
v=(composite_full[composite_full.Mouse==x][y])
a=pd.DataFrame((v - nanmean(v)) / nanstd(v))
a=a.reset_index(drop=True)
a.columns=[y]
tmp=pd.concat([tmp,a],axis=1)
b=pd.DataFrame(composite_full[composite_full.Mouse==x]['Mouse'])
b=b.reset_index(drop=True)
c=pd.DataFrame(composite_full[composite_full.Mouse==x]['Group'])
c=c.reset_index(drop=True)
tmp=pd.concat([c,tmp],axis=1)
zscores=zscores.append(tmp)
In [32]:
zscores[zscores.Group=='Mint']['AP']
Out[32]:
In [42]:
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("talk", font_scale=1.8);
plt.figure(figsize=(45, 20));
sns.distplot(zscores[zscores.Group=='Control']['IAA10'].dropna(),color='r');
sns.distplot(zscores[zscores.Group=='Mint']['IAA10'].dropna(),color='g');
sns.distplot(zscores[zscores.Group=='Hexanal']['IAA10'].dropna(),color='b');
In [27]:
zmelt=pd.melt(zscores,"Group",var_name="Odor")
In [24]:
groupcolors={'Control':'r','Mint':'g','Hexanal':'b'}
In [30]:
#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=zmelt)
ax.legend_.remove()
sns.despine()
plt.ylabel('Zscore', fontsize=48);
plt.title('Zscore', fontsize=55);
plt.xlabel('Odor', fontsize=48);
In [319]:
sns.distplot(zscores[zscores.Group=='Control']['Hexanal01'], hist=False, color="r", kde_kws={"shade": True});
sns.distplot(zscores[zscores.Group=='Mint']['Hexanal01'], hist=False, color="g", kde_kws={"shade": True});
sns.distplot(zscores[zscores.Group=='Hexanal']['Hexanal01'], hist=False, color="b", kde_kws={"shade": True});
In [11]:
means=pd.DataFrame([])
for x in composite_full.Mouse.unique():
tmp=pd.DataFrame([])
for y in odorlist:
a=composite_full[composite_full.Mouse==x][y].mean()
m=pd.DataFrame({y:[a]})
tmp=pd.concat([tmp,m],axis=1)
b=pd.DataFrame({'Mouse':[x]})
c=pd.DataFrame({'Group':[composite_full[composite_full.Mouse==x]['Group'].iloc[0]]})
# c=c.reset_index(drop=True)
tmp=pd.concat([c,tmp],axis=1)
means=means.append(tmp)
In [12]:
meanmelt=pd.melt(means,"Group",var_name="Odor")
In [15]:
#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 [25]:
medians=pd.DataFrame([])
for x in composite_full.Mouse.unique():
tmp=pd.DataFrame([])
for y in odorlist:
a=composite_full[composite_full.Mouse==x][y].median()
m=pd.DataFrame({y:[a]})
tmp=pd.concat([tmp,m],axis=1)
b=pd.DataFrame({'Mouse':[x]})
c=pd.DataFrame({'Group':[composite_full[composite_full.Mouse==x]['Group'].iloc[0]]})
# c=c.reset_index(drop=True)
tmp=pd.concat([c,tmp],axis=1)
medians=medians.append(tmp)
In [26]:
medianmelt=pd.melt(medians,"Group",var_name="Odor")
In [27]:
#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 [ ]:
In [275]:
stds=pd.DataFrame([])
for x in composite_full.Mouse.unique():
tmp=pd.DataFrame([])
for y in odorlist:
a=composite_full[composite_full.Mouse==x][y].std()
m=pd.DataFrame({y:[a]})
tmp=pd.concat([tmp,m],axis=1)
b=pd.DataFrame({'Mouse':[x]})
c=pd.DataFrame({'Group':[composite_full[composite_full.Mouse==x]['Group'].iloc[0]]})
# c=c.reset_index(drop=True)
tmp=pd.concat([c,tmp],axis=1)
stds=stds.append(tmp)
In [276]:
stdmelt=pd.melt(stds,"Group",var_name="Odor")
In [277]:
#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 [ ]:
In [330]:
#Plot everything by mouse
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='Mouse',palette=colors,data=cfull)
ax.legend_.remove()
sns.despine()
plt.ylabel('Integral', fontsize=48);
plt.title('By Mouse', fontsize=55);
plt.xlabel('Odor', fontsize=48);
In [99]:
#Plot everything by mouse
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("talk", font_scale=1.8);
plt.figure(figsize=(45, 20));
ax=sns.swarmplot(x='Odor',y='value',hue='Mouse',palette=colors,data=cfull)
ax.legend_.remove()
sns.despine()
plt.ylabel('Peak DF/F', fontsize=48);
plt.title('By Mouse', fontsize=55);
plt.xlabel('Odor', fontsize=48);
In [351]:
#Plot control by mouse
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('Odor','value',hue='Mouse',data=cctrl)
ax.legend_.remove()
sns.despine()
plt.ylabel('Peak', fontsize=48);
plt.title('By Mouse - Control', fontsize=55);
plt.xlabel('Odor', fontsize=48);
In [352]:
#Plot everything by mouse - Hexanal
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('Odor','value',hue='Mouse',data=hexfull)
ax.legend_.remove()
sns.despine()
plt.ylabel('Peak', fontsize=48);
plt.title('By Mouse - Hexanal', fontsize=55);
plt.xlabel('Odor', fontsize=48);
In [353]:
#Plot everything by mouse - Mint
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('Odor','value',hue='Mouse',data=msfull)
ax.legend_.remove()
sns.despine()
plt.ylabel('Peak', fontsize=48);
plt.title('By Mouse - Mint', fontsize=55);
plt.xlabel('Odor', fontsize=48);
In [9]:
cdf=[]
for x in cfc.Mouse.unique():
cdf.append(cfc[cfc.Mouse=='%s'%x][odorlist].mean(0,skipna=True))
cmeandf=pd.concat([pd.DataFrame(cfc.Mouse.unique()),pd.DataFrame(cdf)],axis=1)
cmeandf.columns=cfc.columns
cmeanmelt=pd.melt(cmeandf,"Mouse",var_name="Odor")
mdf=[]
for x in cfm.Mouse.unique():
mdf.append(cfm[cfm.Mouse=='%s'%x][odorlist].mean(0,skipna=True))
mmeandf=pd.concat([pd.DataFrame(cfm.Mouse.unique()),pd.DataFrame(mdf)],axis=1)
mmeandf.columns=cfm.columns
hdf=[]
for x in cfh.Mouse.unique():
hdf.append(cfh[cfh.Mouse=='%s'%x][odorlist].mean(0,skipna=True))
hmeandf=pd.concat([pd.DataFrame(cfh.Mouse.unique()),pd.DataFrame(hdf)],axis=1)
hmeandf.columns=cfh.columns
full_mean=pd.melt(pd.concat([cmeandf,mmeandf,hmeandf],ignore_index=True),'Mouse',var_name='Odor')
In [10]:
full_mean
In [279]:
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('Odor','value',hue='Mouse',palette=colors,data=full_mean)
sns.despine()
plt.ylabel('Peak DF/F', fontsize=48);
plt.title('Mean, By Mouse', fontsize=55);
plt.xlabel('Odor', fontsize=48);
In [ ]:
In [178]:
In [181]:
Out[181]:
In [ ]:
In [16]:
cdf=[]
for x in cfc.Mouse.unique():
cdf.append(cfc[cfc.Mouse=='%s'%x][odorlist].median(0,skipna=True))
cmeddf=pd.concat([pd.DataFrame(cfc.Mouse.unique()),pd.DataFrame(cdf)],axis=1)
cmeddf.columns=cfc.columns
cmedmelt=pd.melt(cmeandf,"Mouse",var_name="Odor")
mdf=[]
for x in cfm.Mouse.unique():
mdf.append(cfm[cfm.Mouse=='%s'%x][odorlist].median(0,skipna=True))
mmeddf=pd.concat([pd.DataFrame(cfm.Mouse.unique()),pd.DataFrame(mdf)],axis=1)
mmeddf.columns=cfm.columns
hdf=[]
for x in cfh.Mouse.unique():
hdf.append(cfh[cfh.Mouse=='%s'%x][odorlist].median(0,skipna=True))
hmeddf=pd.concat([pd.DataFrame(cfh.Mouse.unique()),pd.DataFrame(hdf)],axis=1)
hmeddf.columns=cfh.columns
full_med=pd.melt(pd.concat([cmeddf,mmeddf,hmeddf],ignore_index=True),'Mouse',var_name='Odor')
In [281]:
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('Odor','value',hue='Mouse',palette=colors,data=full_med)
sns.despine()
plt.ylabel('Peak DF/F', fontsize=48);
plt.title('Median, By Mouse', fontsize=55);
plt.xlabel('Odor', fontsize=48);
In [289]:
Out[289]:
In [ ]:
In [ ]:
In [282]:
#Individual Animal COV
cdf=[]
for x in cfc.Mouse.unique():
cdf.append(cfc[cfc.Mouse=='%s'%x][odorlist].std(0,skipna=True))
cstddf=pd.concat([pd.DataFrame(cfc.Mouse.unique()),pd.DataFrame(cdf)],axis=1)
cstddf.columns=cfc.columns
cstdmelt=pd.melt(cmeandf,"Mouse",var_name="Odor")
mdf=[]
for x in cfm.Mouse.unique():
mdf.append(cfm[cfm.Mouse=='%s'%x][odorlist].std(0,skipna=True))
mstddf=pd.concat([pd.DataFrame(cfm.Mouse.unique()),pd.DataFrame(mdf)],axis=1)
mstddf.columns=cfm.columns
hdf=[]
for x in cfh.Mouse.unique():
hdf.append(cfh[cfh.Mouse=='%s'%x][odorlist].std(0,skipna=True))
hstddf=pd.concat([pd.DataFrame(cfh.Mouse.unique()),pd.DataFrame(hdf)],axis=1)
hstddf.columns=cfh.columns
full_std=pd.melt(pd.concat([cstddf,mstddf,hstddf],ignore_index=True),'Mouse',var_name='Odor')
full_cov=pd.concat([full_std.Mouse,full_std.Odor,full_std.value.div(full_mean.value,axis=0)],axis=1)
In [283]:
#Get Averages
c_ave=pd.DataFrame(cstddf[odorlist].div(cmeandf[odorlist]).mean())
c_ave.columns=['Control']
m_ave=pd.DataFrame(mstddf[odorlist].div(mmeandf[odorlist]).mean())
m_ave.columns=['Mint']
h_ave=pd.DataFrame(hstddf[odorlist].div(hmeandf[odorlist]).mean())
h_ave.columns=['Hexanal']
full_ave=pd.concat([c_ave,m_ave,h_ave],axis=1)
full_ave=full_ave.reset_index()
full_ave.columns=['Odor','Control','Mint','Hexanal']
avemelt=pd.melt(full_ave,'Odor')
In [284]:
#PLOT STUFF
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('Odor','value',hue='Mouse',palette=colors,data=full_cov)
sns.despine()
plt.ylabel('COV', fontsize=48);
plt.title('COV, by Mouse', fontsize=55);
plt.xlabel('Odor', fontsize=48);
In [ ]:
In [37]:
#Get Composite COV
cfc_std=pd.DataFrame(cfc[odorlist].std(0,skipna=True))
cfc_mean=pd.DataFrame(cfc[odorlist].mean(0,skipna=True))
cfc_cov=cfc_std.div(cfc_mean)
mfc_std=pd.DataFrame(cfm[odorlist].std(0,skipna=True))
mfc_mean=pd.DataFrame(cfm[odorlist].mean(0,skipna=True))
mfc_cov=mfc_std.div(mfc_mean)
hfc_std=pd.DataFrame(cfh[odorlist].std(0,skipna=True))
hfc_mean=pd.DataFrame(cfh[odorlist].mean(0,skipna=True))
hfc_cov=hfc_std.div(hfc_mean)
cfc_cov.columns=['Control']
mfc_cov.columns=['Mint']
hfc_cov.columns=['Hexanal']
full=pd.concat([cfc_cov,mfc_cov,hfc_cov],axis=1)
full=full.reset_index()
full.columns=['Odor','Control','Mint','Hexanal']
fullmelt=pd.melt(full,'Odor')
fullmelt.head()
# cstdall.columns=cfc.columns
# mdf.append(cfm[cfm.Mouse=='%s'%x][odorlist].std(0,skipna=True))
# mstddf=pd.concat([pd.DataFrame(cfm.Mouse.unique()),pd.DataFrame(mdf)],axis=1)
# mstddf.columns=cfm.columns
# hdf.append(cfh[cfh.Mouse=='%s'%x][odorlist].std(0,skipna=True))
# hstddf=pd.concat([pd.DataFrame(cfh.Mouse.unique()),pd.DataFrame(hdf)],axis=1)
# hstddf.columns=cfh.columns
# full_std=pd.melt(pd.concat([cstddf,mstddf,hstddf],ignore_index=True),'Mouse',var_name='Odor')
# full_cov=pd.concat([full_std.Mouse,full_std.Odor,full_std.value.div(full_mean.value,axis=0)],axis=1)
Out[37]:
In [382]:
In [44]:
#PLOT STUFF
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('Odor','value',hue='variable',palette={'Control':'r','Hexanal':'b','Mint':'g'},data=fullmelt)
sns.despine()
plt.ylabel('COV', fontsize=48);
plt.title('COV, Complete', fontsize=55);
plt.xlabel('Odor', fontsize=48);
In [ ]:
In [ ]:
In [ ]: