Exploratory Data Analysis


In [35]:
# Import Necessary Libraries
from string import letters
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib
import matplotlib.pyplot as plt

%matplotlib inline

Plot Correlation Matrix

Raw Data


In [117]:
# Load data
X = np.load('/Users/Tyler/synapse_data/synapse_f0_features.npy')
channel = ('Synap0','Synap1','VGlut10','VGlut11','VGlut2','Vglut3', 'psd','glur2','nmdar1','nr2b','gad','VGAT', 'PV',\
           'Gephyr','GABAR1','GABABR','CR1','5HT1A', 'NOS','TH','VACht','Synapo','tubuli','DAPI') 
channelType = ('ex_pre','ex_pre','ex_pre','ex_pre','ex_pre','in_pre_small', 'ex_post','ex_post','ex_post','ex_post',\
               'in_pre','in_pre', 'in_pre','in_post','in_post','in_post','in_pre_small','other', 'ex_post','other',\
               'other','ex_post','none','none')
channel2type = {channel[i]: channelType[i] for i in range(len(channel))}
type2channels = {chType: [channel[i] for i in range(len(channel)) if channelType[i] == chType] for chType in\
                 set(channelType)}
type2color = {'ex_pre': '#00FF00', 'ex_post': '#008000', 'in_pre': '#FF0000', 'in_post': '#800000', 'in_pre_small':\
              '#800080', 'other': '#008080', 'none': '#0000FF'}

sns.set(style="white")

# Make dataframe
d = pd.DataFrame(data=X,
                 columns=channel)

# Compute the correlation matrix
corr = d.corr()

# Generate a mask for the upper triangle
mask = np.zeros_like(corr, dtype=np.bool)
mask[np.triu_indices_from(mask)] = True

# Set up the matplotlib figure
f, ax = plt.subplots(figsize=(20, 20))

# Generate a custom diverging colormap
cmap = sns.diverging_palette(220, 10, as_cmap=True)

# Draw the heatmap with the mask and correct aspect ratio
sns.heatmap(corr, mask=mask, cmap=cmap,
            annot=True, square=True, linewidths=.5,
            cbar_kws={"shrink": .5}, ax=ax)
ax.set_title('Integrated Brightness', fontsize=24)
cax = plt.gcf().axes[-1]
cax.tick_params(labelsize=20)
for t in ax.findobj(matplotlib.text.Text):
    if t._text in channel:
        t._color = type2color[channel2type[t._text]]
        t._rotation = 'vertical' if t._y == 0 else 'horizontal'


Log transformed


In [118]:
# Load data
X = np.load('/Users/Tyler/synapse_data/synapse_f0_features_log.npy')
channel = ('Synap0','Synap1','VGlut10','VGlut11','VGlut2','Vglut3', 'psd','glur2','nmdar1','nr2b','gad','VGAT', 'PV',\
           'Gephyr','GABAR1','GABABR','CR1','5HT1A', 'NOS','TH','VACht','Synapo','tubuli','DAPI') 
channelType = ('ex_pre','ex_pre','ex_pre','ex_pre','ex_pre','in_pre_small', 'ex_post','ex_post','ex_post','ex_post',\
               'in_pre','in_pre', 'in_pre','in_post','in_post','in_post','in_pre_small','other', 'ex_post','other',\
               'other','ex_post','none','none')
channel2type = {channel[i]: channelType[i] for i in range(len(channel))}
type2channels = {chType: [channel[i] for i in range(len(channel)) if channelType[i] == chType] for chType in\
                 set(channelType)}
type2color = {'ex_pre': '#00FF00', 'ex_post': '#008000', 'in_pre': '#FF0000', 'in_post': '#800000', 'in_pre_small':\
              '#800080', 'other': '#008080', 'none': '#0000FF'}

sns.set(style="white")

# Make dataframe
d = pd.DataFrame(data=X,
                 columns=channel)

# Compute the correlation matrix
corr = d.corr()

# Generate a mask for the upper triangle
mask = np.zeros_like(corr, dtype=np.bool)
mask[np.triu_indices_from(mask)] = True

# Set up the matplotlib figure
f, ax = plt.subplots(figsize=(20, 20))

# Generate a custom diverging colormap
cmap = sns.diverging_palette(220, 10, as_cmap=True)

# Draw the heatmap with the mask and correct aspect ratio
sns.heatmap(corr, mask=mask, cmap=cmap,
            annot=True, square=True, linewidths=.5,
            cbar_kws={"shrink": .5}, ax=ax)
ax.set_title('log(Integrated Brightness)', fontsize=24)
cax = plt.gcf().axes[-1]
cax.tick_params(labelsize=20)
for t in ax.findobj(matplotlib.text.Text):
    if t._text in channel:
        t._color = type2color[channel2type[t._text]]
        t._rotation = 'vertical' if t._y == 0 else 'horizontal'


Log Normalized


In [119]:
# Load data
X = np.load('/Users/Tyler/synapse_data/synapse_f0_features_log_normalized.npy')
channel = ('Synap0','Synap1','VGlut10','VGlut11','VGlut2','Vglut3', 'psd','glur2','nmdar1','nr2b','gad','VGAT', 'PV',\
           'Gephyr','GABAR1','GABABR','CR1','5HT1A', 'NOS','TH','VACht','Synapo','tubuli','DAPI') 
channelType = ('ex_pre','ex_pre','ex_pre','ex_pre','ex_pre','in_pre_small', 'ex_post','ex_post','ex_post','ex_post',\
               'in_pre','in_pre', 'in_pre','in_post','in_post','in_post','in_pre_small','other', 'ex_post','other',\
               'other','ex_post','none','none')
channel2type = {channel[i]: channelType[i] for i in range(len(channel))}
type2channels = {chType: [channel[i] for i in range(len(channel)) if channelType[i] == chType] for chType in\
                 set(channelType)}
type2color = {'ex_pre': '#00FF00', 'ex_post': '#008000', 'in_pre': '#FF0000', 'in_post': '#800000', 'in_pre_small':\
              '#800080', 'other': '#008080', 'none': '#0000FF'}

sns.set(style="white")

# Make dataframe
d = pd.DataFrame(data=X,
                 columns=channel)

# Compute the correlation matrix
corr = d.corr()

# Generate a mask for the upper triangle
mask = np.zeros_like(corr, dtype=np.bool)
mask[np.triu_indices_from(mask)] = True

# Set up the matplotlib figure
f, ax = plt.subplots(figsize=(20, 20))

# Generate a custom diverging colormap
cmap = sns.diverging_palette(220, 10, as_cmap=True)

# Draw the heatmap with the mask and correct aspect ratio
sns.heatmap(corr, mask=mask, cmap=cmap, annot=True,
            square=True, linewidths=.5,
            cbar_kws={"shrink": .5}, ax=ax)
ax.set_title('log(Normalized Integrated Brightness)', fontsize=24)
cax = plt.gcf().axes[-1]
cax.tick_params(labelsize=20)
for t in ax.findobj(matplotlib.text.Text):
    if t._text in channel:
        t._color = type2color[channel2type[t._text]]
        t._rotation = 'vertical' if t._y == 0 else 'horizontal'
        t._rotation = 'vertical' if t._y == 0 else 'horizontal'


Sqrt Transformed


In [120]:
# Load data
X = np.load('/Users/Tyler/synapse_data/synapse_f0_features_sqrt.npy')
channel = ('Synap0','Synap1','VGlut10','VGlut11','VGlut2','Vglut3', 'psd','glur2','nmdar1','nr2b','gad','VGAT', 'PV',\
           'Gephyr','GABAR1','GABABR','CR1','5HT1A', 'NOS','TH','VACht','Synapo','tubuli','DAPI') 
channelType = ('ex_pre','ex_pre','ex_pre','ex_pre','ex_pre','in_pre_small', 'ex_post','ex_post','ex_post','ex_post',\
               'in_pre','in_pre', 'in_pre','in_post','in_post','in_post','in_pre_small','other', 'ex_post','other',\
               'other','ex_post','none','none')
channel2type = {channel[i]: channelType[i] for i in range(len(channel))}
type2channels = {chType: [channel[i] for i in range(len(channel)) if channelType[i] == chType] for chType in\
                 set(channelType)}
type2color = {'ex_pre': '#00FF00', 'ex_post': '#008000', 'in_pre': '#FF0000', 'in_post': '#800000', 'in_pre_small':\
              '#800080', 'other': '#008080', 'none': '#0000FF'}

sns.set(style="white")

# Make dataframe
d = pd.DataFrame(data=X,
                 columns=channel)

# Compute the correlation matrix
corr = d.corr()

# Generate a mask for the upper triangle
mask = np.zeros_like(corr, dtype=np.bool)
mask[np.triu_indices_from(mask)] = True

# Set up the matplotlib figure
f, ax = plt.subplots(figsize=(20, 20))

# Generate a custom diverging colormap
cmap = sns.diverging_palette(220, 10, as_cmap=True)

# Draw the heatmap with the mask and correct aspect ratio
sns.heatmap(corr, mask=mask, cmap=cmap, annot=True,
            square=True, linewidths=.5,
            cbar_kws={"shrink": .5}, ax=ax)
ax.set_title('sqrt(Integrated Brightness)', fontsize=24)
cax = plt.gcf().axes[-1]
cax.tick_params(labelsize=20)
for t in ax.findobj(matplotlib.text.Text):
    if t._text in channel:
        t._color = type2color[channel2type[t._text]]
        t._rotation = 'vertical' if t._y == 0 else 'horizontal'
        t._rotation = 'vertical' if t._y == 0 else 'horizontal'


Sqrt Normalized


In [121]:
# Load data
X = np.load('/Users/Tyler/synapse_data/synapse_f0_features_sqrt_normalized.npy')
channel = ('Synap0','Synap1','VGlut10','VGlut11','VGlut2','Vglut3', 'psd','glur2','nmdar1','nr2b','gad','VGAT', 'PV',\
           'Gephyr','GABAR1','GABABR','CR1','5HT1A', 'NOS','TH','VACht','Synapo','tubuli','DAPI') 
channelType = ('ex_pre','ex_pre','ex_pre','ex_pre','ex_pre','in_pre_small', 'ex_post','ex_post','ex_post','ex_post',\
               'in_pre','in_pre', 'in_pre','in_post','in_post','in_post','in_pre_small','other', 'ex_post','other',\
               'other','ex_post','none','none')
channel2type = {channel[i]: channelType[i] for i in range(len(channel))}
type2channels = {chType: [channel[i] for i in range(len(channel)) if channelType[i] == chType] for chType in\
                 set(channelType)}
type2color = {'ex_pre': '#00FF00', 'ex_post': '#008000', 'in_pre': '#FF0000', 'in_post': '#800000', 'in_pre_small':\
              '#800080', 'other': '#008080', 'none': '#0000FF'}

sns.set(style="white")

# Make dataframe
d = pd.DataFrame(data=X,
                 columns=channel)

# Compute the correlation matrix
corr = d.corr()

# Generate a mask for the upper triangle
mask = np.zeros_like(corr, dtype=np.bool)
mask[np.triu_indices_from(mask)] = True

# Set up the matplotlib figure
f, ax = plt.subplots(figsize=(20, 20))

# Generate a custom diverging colormap
cmap = sns.diverging_palette(220, 10, as_cmap=True)

# Draw the heatmap with the mask and correct aspect ratio
sns.heatmap(corr, mask=mask, cmap=cmap, annot=True,
            square=True, linewidths=.5,
            cbar_kws={"shrink": .5}, ax=ax)
ax.set_title('sqrt(Normalized Integrated Brightness)', fontsize=24)
cax = plt.gcf().axes[-1]
cax.tick_params(labelsize=20)
for t in ax.findobj(matplotlib.text.Text):
    if t._text in channel:
        t._color = type2color[channel2type[t._text]]
        t._rotation = 'vertical' if t._y == 0 else 'horizontal'
        t._rotation = 'vertical' if t._y == 0 else 'horizontal'



In [ ]: