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
from scipy.stats import ks_2samp
%matplotlib
import seaborn as sns


Using matplotlib backend: Qt4Agg

In [2]:
comp=pd.read_csv('C:\Users\Annie\Documents\Data\Ca_Imaging\Analysis\Odor_Panel\Composite_MaxDF_NoP.csv')
del comp['Mouse']
comp_sorted=comp.reindex_axis(comp.mean().sort_values().index, axis=1)
comp_labels=pd.DataFrame(comp.Group)
tmp=[comp_labels,comp_sorted]
composite_full=pd.concat(tmp,axis=1)
composite_full.head()
cfull=pd.melt(composite_full,"Group",var_name="Odor")

In [3]:
MS005_full=composite_full[['Group','IAA 0.05']]
MS005df=pd.melt(MS005_full,"Group",var_name="Odor")
cg=MS005_full[MS005_full['Group']=='Control']
mg=MS005_full[MS005_full['Group']=='Mint']
hg=MS005_full[MS005_full['Group']=='Hexanal']

In [4]:
ctrlhist=np.asarray(np.histogram(cg['IAA 0.05'],bins=140,range=(-1,6))[0],dtype=np.float)
mshist=np.asarray(np.histogram(mg['IAA 0.05'],bins=140,range=(-1,6))[0],dtype=np.float)
hexhist=np.asarray(np.histogram(hg['IAA 0.05'],bins=140,range=(-1,6))[0],dtype=np.float)
bincounts=np.histogram(cg['IAA 0.05'],bins=140,range=(-1,6))[1][0:-1]

In [ ]:


In [5]:
#dataframe of bin values
colnames=['Bin','Control','Mint','Hexanal']
tmp=[pd.DataFrame(bincounts),pd.DataFrame(ctrlhist),pd.DataFrame(mshist),pd.DataFrame(hexhist)]
fullbin=pd.concat(tmp,axis=1)
fullbin.columns=colnames
#plot the bins
plt.scatter(fullbin['Bin'],fullbin['Control'],s=50,c='r');
plt.scatter(fullbin['Bin'],fullbin['Mint'],s=50,c='g');
plt.scatter(fullbin['Bin'],fullbin['Hexanal'],s=50,c='b');

In [ ]:

Normalized histograms


In [6]:
ctrlnorm=ctrlhist/(ctrlhist.sum())
msnorm=mshist/(mshist.sum())
hexnorm=hexhist/(hexhist.sum())
bincounts=np.histogram(cg['IAA 0.05'],bins=140,range=(-1,6))[1][0:-1]

In [7]:
#dataframe of bin values
colnames=['Bin','Control','Mint','Hexanal']
tmp=[pd.DataFrame(bincounts),pd.DataFrame(ctrlnorm),pd.DataFrame(msnorm),pd.DataFrame(hexnorm)]
fullnorm=pd.concat(tmp,axis=1)
fullnorm.columns=colnames

In [20]:
#plot the bins
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("talk", font_scale=1.8);
plt.figure(figsize=(30, 15));
plt.scatter(fullnorm['Bin'],fullnorm['Control'],s=80,c='r',label='Control');
plt.scatter(fullnorm['Bin'],fullnorm['Mint'],s=80,c='g',label='Mint');
plt.scatter(fullnorm['Bin'],fullnorm['Hexanal'],s=80,c='b',label='Hexanal');
plt.xlim(-0.1, 4.1)
sns.despine()
plt.ylabel('Proportion', fontsize=48);
plt.title('Normalized Histograms', fontsize=55);
plt.xlabel('Peak DF/F', fontsize=48);
plt.legend(loc=1, prop={'size': 48});

In [24]:
kruskal(fullnorm['Control'],fullnorm['Mint'],fullnorm['Hexanal'])


Out[24]:
KruskalResult(statistic=7.160661967172107, pvalue=0.027866473383399537)

In [98]:
ks_2samp(fullnorm['Mint'],fullnorm['Control'])


Out[98]:
Ks_2sampResult(statistic=0.18571428571428572, pvalue=0.013700363838126889)

In [ ]:

Hexanal


In [181]:
H005_full=composite_full[['Group','IAA 0.05']]
H005df=pd.melt(H005_full,"Group",var_name="Odor")
cg=H005_full[H005_full['Group']=='Control']
mg=H005_full[H005_full['Group']=='Mint']
hg=H005_full[H005_full['Group']=='Hexanal']

In [182]:
ctrlhist=np.asarray(np.histogram(cg['IAA 0.05'],bins=140,range=(-1,6))[0],dtype=np.float)
mshist=np.asarray(np.histogram(mg['IAA 0.05'],bins=140,range=(-1,6))[0],dtype=np.float)
hexhist=np.asarray(np.histogram(hg['IAA 0.05'],bins=140,range=(-1,6))[0],dtype=np.float)
bincounts=np.histogram(cg['IAA 0.05'],bins=140,range=(-1,6))[1][0:-1]

In [183]:
#dataframe of bin values
colnames=['Bin','Control','Mint','Hexanal']
tmp=[pd.DataFrame(bincounts),pd.DataFrame(ctrlhist),pd.DataFrame(mshist),pd.DataFrame(hexhist)]
fullbin=pd.concat(tmp,axis=1)
fullbin.columns=colnames
#plot the bins
plt.scatter(fullbin['Bin'],fullbin['Control'],s=50,c='r');
plt.scatter(fullbin['Bin'],fullbin['Mint'],s=50,c='g');
plt.scatter(fullbin['Bin'],fullbin['Hexanal'],s=50,c='b');

In [ ]:

Normalized histograms


In [184]:
ctrlnorm=ctrlhist/(ctrlhist.sum())
msnorm=mshist/(mshist.sum())
hexnorm=hexhist/(hexhist.sum())
bincounts=np.histogram(cg['IAA 0.05'],bins=140,range=(-1,6))[1][0:-1]

In [185]:
#dataframe of bin values
colnames=['Bin','Control','Mint','Hexanal']
tmp=[pd.DataFrame(bincounts),pd.DataFrame(ctrlnorm),pd.DataFrame(msnorm),pd.DataFrame(hexnorm)]
fullnorm=pd.concat(tmp,axis=1)
fullnorm.columns=colnames
#plot the bins
plt.scatter(fullnorm['Bin'],fullnorm['Control'],s=50,c='r');
plt.scatter(fullnorm['Bin'],fullnorm['Mint'],s=50,c='g');
plt.scatter(fullnorm['Bin'],fullnorm['Hexanal'],s=50,c='b');

In [188]:
ks(fullnorm['Mint'],fullnorm['Hexanal'])


Out[188]:
KruskalResult(statistic=4.3987056899553743, pvalue=0.035966217000932457)

In [ ]:

Digitize


In [99]:
MS005_full=composite_full[['Group','MS 0.05']]
MS005df=pd.melt(MS005_full,"Group",var_name="Odor")
cg=MS005_full[MS005_full['Group']=='Control']
mg=MS005_full[MS005_full['Group']=='Mint']
mg=mg.reset_index(drop=True)
hg=MS005_full[MS005_full['Group']=='Hexanal']
hg=hg.reset_index(drop=True)

In [100]:
ctrlbin=pd.DataFrame(np.digitize(cg['MS 0.05'],bincounts)*0.05)
msbin=pd.DataFrame(np.digitize(mg['MS 0.05'],bincounts)*0.05)
hexbin=pd.DataFrame(np.digitize(hg['MS 0.05'],bincounts)*0.05)
binnums=np.arange(-1,6,0.05)

In [101]:
ctrlcn=['Control Bins','Control']
ctrlt=[ctrlbin,cg['MS 0.05']]
ctrldf=pd.concat(ctrlt,axis=1)
ctrldf.columns=ctrlcn

mscn=['Mint Bins','Mint']
mst=[msbin,mg['MS 0.05']]
msdf=pd.concat(mst,axis=1)
msdf.columns=mscn

hcn=['Hexanal Bins','Hexanal']
ht=[hexbin,hg['MS 0.05']]
hdf=pd.concat(ht,axis=1)
hdf.columns=hcn

In [102]:
from scipy.stats import binned_statistic

In [104]:
c_bin_full=pd.melt(ctrldf,"Control Bins",var_name="Control")
#by binning data into df/f can compare means within each bin across groups
sns.stripplot(x='Control Bins',y='value',data=c_bin_full,palette='Reds_d',size=10)


Out[104]:
<matplotlib.axes._subplots.AxesSubplot at 0x11e1ab38>

In [105]:
m_bin_full=pd.melt(msdf,'Mint Bins',var_name='Mint')
#by binning data into df/f can compare means within each bin across groups
sns.stripplot(x='Mint Bins',y='value',data=m_bin_full,palette='Greens_d',size=10)


Out[105]:
<matplotlib.axes._subplots.AxesSubplot at 0x11e1ab38>

In [106]:
h_bin_full=pd.melt(hdf,'Hexanal Bins',var_name='Hexanal')
#by binning data into df/f can compare means within each bin across groups
sns.stripplot(x='Hexanal Bins',y='value',data=h_bin_full,palette='Blues_d',size=10)


Out[106]:
<matplotlib.axes._subplots.AxesSubplot at 0x11e1ab38>

In [ ]: