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 inline
import seaborn as sns
from scipy.stats import zscore
from scipy.stats import nanmean
from scipy.stats import nanstd
from scipy.cluster.hierarchy import dendrogram, linkage
In [2]:
filename='C:\Users\Annie\Documents\Data\Ca_Imaging\Analysis\\Odor_Panel\\Odor_Trials.csv'
trials=pd.read_csv(filename)
In [3]:
z='C:\Users\Annie\Documents\Data\Ca_Imaging\GoodFiles\\fullpeak_WL.csv'
peak=pd.read_csv(z)
s='C:\Users\Annie\Documents\Data\Ca_Imaging\GoodFiles\\fullsuccess_WI.csv'
success=pd.read_csv(s)
In [4]:
melt_success=pd.melt(success,('Mouse','Group'),var_name='Odor',value_name='Reliability')
melt_peak=pd.melt(peak,('Mouse','Group'),var_name='Odor',value_name='Peak')
In [5]:
peak.head()
Out[5]:
In [6]:
success_peak=pd.concat([melt_peak,melt_success.Reliability],axis=1)
control=success_peak[success_peak['Group']=='Control']
mint=success_peak[success_peak['Group']=='Mint']
hexanal=success_peak[success_peak['Group']=='Hexanal']
In [7]:
sns.set(style='white',palette="muted", color_codes=True);
sns.set_context("paper",font_scale=2);
ax=sns.barplot(x='Reliability',y='Peak',hue='Group',data=success_peak, palette=['black',sns.xkcd_rgb['azure'],sns.xkcd_rgb['grey']],hue_order=['Control','Hexanal','Mint']);
ax.set(xlabel='Reliability', ylabel='Peak')
ax.set_xticklabels([0,0.25,0.33,0.5,0.66,0.75,1.0])
sns.despine(left=True,bottom=True);
plt.tight_layout();
plt.savefig("C:\Users\Annie\Desktop\Plasticity\Figures\Excitatory\Success_Peak.pdf")
In [42]:
sns.set(style='white',palette="muted", color_codes=True);
sns.set_context("paper",font_scale=2);
sns.barplot(x='Reliability',y='Peak',data=hexanal);
# plt.ylim(0,5)
plt.tight_layout();
In [41]:
sns.set(style='white',palette="muted", color_codes=True);
sns.set_context("paper",font_scale=2);
sns.barplot(x='Reliability',y='Peak',data=mint);
plt.xl
# plt.ylim(0,5)
plt.tight_layout();
In [33]:
sns.set(style='white',palette="muted", color_codes=True);
sns.set_context("paper",font_scale=2);
sns.jointplot('Reliability','Peak',mint).set_axis_labels("Reliability", "Peak");
# sns.jointplot('Reliability','Peak',hexanal).set_axis_labels('Reliability','Peak');
sns.despine(left=True,bottom=True);
plt.ylim(0,5)
plt.tight_layout();
In [29]:
sns.set(style='white',palette="muted", color_codes=True);
sns.set_context("paper",font_scale=2);
sns.jointplot('Reliability','Peak',hexanal).set_axis_labels('Reliability','Peak');
sns.despine(left=True,bottom=True);
plt.ylim(0,5)
plt.tight_layout();
In [30]:
sns.set(style='white',palette="muted", color_codes=True);
sns.set_context("paper",font_scale=2);
sns.jointplot('Reliability','Peak',control).set_axis_labels('Reliability','Peak');
sns.despine(left=True,bottom=True);
plt.ylim(0,5)
plt.tight_layout();
In [40]:
sns.set(style='white',palette="muted", color_codes=True);
sns.set_context("paper",font_scale=2);
sns.jointplot('Peak','Reliability',success_peak).set_axis_labels("Peak DF/F", "Baseline Fluorescence");
sns.despine(left=True,bottom=True);
plt.tight_layout();
In [8]:
import numpy as np
from kmodes import kmodes
In [9]:
import kmodes
In [ ]:
# random categorical data
data = np.random.choice(20, (100, 10))
km = kmodes.KModes(n_clusters=4, init='Huang', n_init=5, verbose=1)
clusters = km.fit_predict(data)
# Print the cluster centroids
print(km.cluster_centroids_)
In [85]:
c=peak[peak.Group=='Control'].ix[:,2:]
In [86]:
k=2
kmeans = cluster.KMeans(n_clusters=k)
kmeans.fit(c)
In [4]:
control=peak[peak['Group']=='Control']
mint=peak[peak['Group']=='Mint']
hexanal=peak[peak['Group']=='Hexanal']
In [16]:
# control.to_csv('C:\Users\Annie\Desktop\\Plasticity\\controlpeaks.csv')
# mint.to_csv('C:\Users\Annie\Desktop\\Plasticity\\mintpeaks.csv')
# hexanal.to_csv('C:\Users\Annie\Desktop\\Plasticity\\hexanalpeaks.csv')
In [5]:
c=pd.read_csv('C:\Users\Annie\Desktop\\Plasticity\\controlpeaks.csv')
m=pd.read_csv('C:\Users\Annie\Desktop\\Plasticity\\mintpeaks.csv')
h=pd.read_csv('C:\Users\Annie\Desktop\\Plasticity\\hexanalpeaks.csv')
In [6]:
c.head()
Out[6]:
In [6]:
cmelt=pd.melt(c,('Group','Mouse','Sex'),var_name='Odor',value_name='Peak')
mmelt=pd.melt(m,('Group','Mouse','Sex'),var_name='Odor',value_name='Peak')
hmelt=pd.melt(h,('Group','Mouse','Sex'),var_name='Odor',value_name='Peak')
In [13]:
cexcite=cmelt[cmelt.Peak>0]
mexcite=mmelt[mmelt.Peak>0]
hexcite=hmelt[hmelt.Peak>0]
In [32]:
allexcite=pd.concat([cexcite, mexcite, hexcite])
allexcitem=allexcite[allexcite.Sex=='M']
allexcitef=allexcite[allexcite.Sex=='F']
In [7]:
cmale=cmelt[cmelt.Sex=='M']
cfemale=cmelt[cmelt.Sex=='F']
mmale=mmelt[mmelt.Sex=='M']
mfemale=mmelt[mmelt.Sex=='F']
hmale=hmelt[hmelt.Sex=='M']
hfemale=hmelt[hmelt.Sex=='F']
In [9]:
# odor='Hexanal05'
# kruskal(cmale[cmale.Odor==odor],mmale[mmale.Odor==odor],hmale[hmale.Odor==odor])
Out[9]:
In [23]:
ecm=cmale[cmale.Peak>0]
ecf=cfemale[cfemale.Peak>0]
ecm.Peak.plot.hist(alpha=0.5);
ecf.Peak.plot.hist(alpha=0.5);
sns.set(style='white',palette="muted", color_codes=True);
sns.set_style("ticks")
plt.xlim(0,5);
plt.title('Control')
sns.despine()
plt.savefig("C:\Users\Annie\Desktop\Plasticity\Revision\SexDiff\Control.pdf")
In [9]:
emm=mmale[mmale.Peak>0]
emf=mfemale[mfemale.Peak>0]
emm.Peak.plot.hist(alpha=0.5);
emf.Peak.plot.hist(alpha=0.5);
sns.set(style='white',palette="muted", color_codes=True);
sns.set_style("ticks")
plt.title('Mint')
plt.xlim(0,5);
sns.despine()
# plt.savefig("C:\Users\Annie\Desktop\Plasticity\Revision\SexDiff\Mint.pdf")
In [10]:
ehm=hmale[hmale.Peak>0]
ehf=hfemale[hfemale.Peak>0]
ehm.Peak.plot.hist(alpha=0.5);
ehf.Peak.plot.hist(alpha=0.5);
sns.set(style='white',palette="muted", color_codes=True);
sns.set_style("ticks")
plt.xlim(0,5);
plt.title('Hexanal')
sns.despine()
# plt.savefig("C:\Users\Annie\Desktop\Plasticity\Revision\SexDiff\Hexanal.pdf")
In [87]:
mfemale.Peak.plot.hist(alpha=0.5)
# mmale.Peak.plot.hist(alpha=1)
cfemale.Peak.plot.hist(alpha=0.5)
# cmale.Peak.plot.hist(alpha=0.5)
# hfemale.Peak.plot.hist(alpha=0.5)
# hmale.Peak.plot.hist(alpha=0.5)
Out[87]:
In [61]:
kruskal(hmale.Peak,cmale.Peak.dropna())
Out[61]:
In [19]:
cat=('M','F')
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("paper", font_scale=1.3);
plt.figure(figsize=(8.5,5));
sns.boxplot(x='Odor',y='Peak',hue_order=cat,hue='Sex',data=mexcite);
# ax.legend_.remove()
sns.despine()
plt.ylabel('DF/F', fontsize=12);
plt.title('Peak DF/F, 1%, Mint', fontsize=12);
plt.xlabel('Odor', fontsize=12);
plt.ylim(-1,5)
plt.tight_layout()
plt.savefig("C:\Users\Annie\Desktop\Plasticity\Revision\SexDiff\Mint_e.pdf")
In [20]:
at=('M','F')
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("paper", font_scale=1.3);
plt.figure(figsize=(9,5));
sns.boxplot(x='Odor',y='Peak',hue_order=cat,hue='Sex',data=hexcite);
# ax.legend_.remove()
sns.despine()
plt.ylabel('DF/F', fontsize=12);
plt.title('Peak DF/F, 1%, Hexanal', fontsize=12);
plt.xlabel('Odor', fontsize=12);
plt.ylim(-1,5)
plt.tight_layout()
plt.savefig("C:\Users\Annie\Desktop\Plasticity\Revision\SexDiff\hexanal_e.pdf")
In [22]:
at=('M','F')
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("paper", font_scale=1.3);
plt.figure(figsize=(9,5));
sns.boxplot(x='Odor',y='Peak',hue_order=cat,hue='Sex',data=cexcite);
# ax.legend_.remove()
sns.despine()
plt.ylabel('DF/F', fontsize=12);
plt.title('Peak DF/F, 1%, Control', fontsize=12);
plt.xlabel('Odor', fontsize=12);
plt.ylim(-1,5)
plt.tight_layout()
plt.savefig("C:\Users\Annie\Desktop\Plasticity\Revision\SexDiff\Control_e.pdf")
In [37]:
allexcitef.tail()
Out[37]:
In [43]:
# at=('M','F')
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("paper", font_scale=1.3);
plt.figure(figsize=(9,5));
sns.boxplot(x='Odor',y='Peak',hue='Group',data=allexcitef);
# ax.legend_.remove()
sns.despine()
plt.ylabel('DF/F', fontsize=12);
plt.title('Peak DF/F, 1%, Female', fontsize=12);
plt.xlabel('Odor', fontsize=12);
plt.ylim(-1,5)
plt.tight_layout()
plt.savefig("C:\Users\Annie\Desktop\Plasticity\Revision\SexDiff\\allfemale.pdf")
In [44]:
# at=('M','F')
sns.set(style="white", palette="muted", color_codes=True);
sns.set_context("paper", font_scale=1.3);
plt.figure(figsize=(9,5));
sns.boxplot(x='Odor',y='Peak',hue='Group',data=allexcitem);
# ax.legend_.remove()
sns.despine()
plt.ylabel('DF/F', fontsize=12);
plt.title('Peak DF/F, 1%, Male', fontsize=12);
plt.xlabel('Odor', fontsize=12);
plt.ylim(-1,5)
plt.tight_layout()
plt.savefig("C:\Users\Annie\Desktop\Plasticity\Revision\SexDiff\\allmale.pdf")
In [27]:
peak.head()
Out[27]:
In [33]:
cpeak=peak[peak.Group=='Control']
mpeak=peak[peak.Group=='Mint']
hpeak=peak[peak.Group=='Hexanal']
In [34]:
X=peak[['IAA10','IAA01','AP','MS10','IAA05','Hexanal01','EB','MS01','PA','MS05','Hexanone','Hexanal10','THA','Hexanal05']]
C=cpeak[['IAA10','IAA01','AP','MS10','IAA05','Hexanal01','EB','MS01','PA','MS05','Hexanone','Hexanal10','THA','Hexanal05']]
M=mpeak[['IAA10','IAA01','AP','MS10','IAA05','Hexanal01','EB','MS01','PA','MS05','Hexanone','Hexanal10','THA','Hexanal05']]
H=hpeak[['IAA10','IAA01','AP','MS10','IAA05','Hexanal01','EB','MS01','PA','MS05','Hexanone','Hexanal10','THA','Hexanal05']]
In [35]:
Z=linkage(X)
CZ=linkage(C)
MZ=linkage(M)
HZ=linkage(H)
In [20]:
from scipy.cluster.hierarchy import cophenet
from scipy.spatial.distance import pdist
In [39]:
pd.DataFrame(HZ)
Out[39]:
In [10]:
c, coph_dists=cophenet(Z,pdist(X))
c
Out[10]:
In [30]:
pd.DataFrame(Z)
Out[30]:
In [23]:
plt.figure(figsize=(25,10))
plt.title('Hierarchical Clustering Dendrogram')
plt.xlabel('sample index')
plt.ylabel('distance')
dendrogram(Z,leaf_rotation=90., leaf_font_size=8.)
plt.show()
In [ ]: