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
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','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']
hg=MS005_full[MS005_full['Group']=='Hexanal']
In [117]:
ctrlhist=np.asarray(np.histogram(cg['MS 0.05'],bins=140,range=(-1,6))[0],dtype=np.float)
mshist=np.asarray(np.histogram(mg['MS 0.05'],bins=140,range=(-1,6))[0],dtype=np.float)
hexhist=np.asarray(np.histogram(hg['MS 0.05'],bins=140,range=(-1,6))[0],dtype=np.float)
bincounts=np.histogram(cg['MS 0.05'],bins=140,range=(-1,6))[1][0:-1]
In [119]:
#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 [ ]:
In [120]:
ctrlnorm=ctrlhist/(ctrlhist.sum())
msnorm=mshist/(mshist.sum())
hexnorm=hexhist/(hexhist.sum())
bincounts=np.histogram(cg['MS 0.05'],bins=140,range=(-1,6))[1][0:-1]
In [121]:
#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 [124]:
kruskal(fullnorm['Hexanal'],fullnorm['Mint'])
Out[124]:
In [ ]:
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 [ ]:
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]:
kruskal(fullnorm['Mint'],fullnorm['Hexanal'])
Out[188]:
In [ ]:
In [260]:
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 [261]:
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 [277]:
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 [263]:
from scipy.stats import binned_statistic
In [311]:
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[311]:
In [312]:
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[312]:
In [314]:
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[314]:
In [ ]: