In [1]:
%matplotlib inline
In [49]:
import pandas as pd
import numpy as np
import seaborn as sns
from matplotlib import pyplot as plt
In [50]:
sns.set(style='whitegrid')
In [11]:
mean_xyz = pd.read_csv('no_over_3mm_mean/roi_MeanXYZ', header=None, names= ['x','y','z'], sep='\t')
mean_xyz.head()
Out[11]:
In [34]:
range(10)[:3]
Out[34]:
In [76]:
def activity_for(file):
answer = []
with open(file) as f:
for line in f.readlines():
values = line.split('\t')
answer.append([float(x) for x in values[:3]] + [len(values) - 3])
return pd.DataFrame(answer, columns=['x', 'y', 'z', 'total'])
In [91]:
def inputs_and_regions_for(energy_name):
inputData = pd.read_csv('SampleLogs/{}_Input.csv'.format(energy_name), index_col='time', \
names= ['time', 'source', 'destination', 'inhibitor'])
regions = pd.read_csv('SampleLogs/{}_Region.csv'.format(energy_name), index_col='neuron', \
names=['neuron', 'region'])
lowerLimit = pd.to_datetime(5, unit='s')
inputData.index = pd.to_datetime(inputData.index, unit='ms')
inputData = inputData[lowerLimit:]
inputs_and_regions = inputData.join(regions, \
on='source').join(regions, \
on= 'destination', lsuffix='_src', rsuffix='_dst')
inputs_and_regions['efective_input'] = 1*(1-inputs_and_regions.inhibitor) -1*inputs_and_regions.inhibitor
answer = inputs_and_regions.groupby([inputs_and_regions.region_src == inputs_and_regions.region_dst, 'region_src']).\
efective_input.count().unstack().T
answer['total'] = answer.sum(axis=1)
answer = answer.rename(columns={True: 'within_regions', False:'between_regions'})
return answer
In [77]:
gluco = activity_for('3_data/reno_over_3mm_meaninvitationtocollaborate/3mm_mean-GLUCO_XYZspikeTrain.txt')
In [78]:
hypo = activity_for('3_data/reno_over_3mm_meaninvitationtocollaborate/3mm_mean-hypo_XYZspikeTrain.txt')
In [79]:
keto = activity_for('3_data/reno_over_3mm_meaninvitationtocollaborate/3mm_mean-KETO_XYZspikeTrain.txt')
In [80]:
gluco.total.hist(alpha=0.5, bins=20, label='gluco')
keto.total.hist(alpha=0.5, bins=20, label='keto')
hypo.total.hist(alpha=0.5, bins=20, label='hypo')
plt.legend()
Out[80]:
In [81]:
region_location = pd.read_csv('../static/models/regions.obj', header=None, sep=' ')
region_location.index = range(1, len(region_location)+1)
region_location = region_location.drop(0, axis=1)
region_location.columns = ['x', 'y', 'z']
In [82]:
region_location.shape
Out[82]:
In [83]:
min_sqrt = lambda serie: ((serie.x-region_location.x)**2 + (serie.y-region_location.y)**2 \
+ (serie.z-region_location.z)**2).argmin()
In [84]:
gluco['region'] = gluco.apply(min_sqrt, axis=1)
hypo['region'] = hypo.apply(min_sqrt, axis=1)
keto['region'] = keto.apply(min_sqrt, axis=1)
In [85]:
gluco.index = gluco.region
hypo.index = hypo.region
keto.index = keto.region
In [86]:
gluco.region.value_counts().hist()
Out[86]:
In [87]:
region_names = pd.read_csv('1013090_DTI_region_names_full_file.txt')
region_names.head()
Out[87]:
In [88]:
region_names.index = region_names.index+1
In [92]:
medium = inputs_and_regions_for('MediumConst')
low = inputs_and_regions_for('LowConst')
high = inputs_and_regions_for('HighConst')
In [135]:
mapping = {k:v.groupby('region').aggregate(np.sum) for k, v in \
{'gluco': gluco, 'hypo': hypo, 'keto' : keto}.iteritems()}
mapping.update({'medium': medium, 'low': low, 'high': high})
df = pd.DataFrame.from_dict({k:pd.Series(v.sort_values('total', ascending=False).index) for k,v in mapping.iteritems()})
In [136]:
df = df.fillna(0)
In [138]:
df.corr(method='kendall')
Out[138]:
In [169]:
def sorting_and_naming(df):
values = df.join(region_names).sort_values('total', ascending=False)['Brain-Stem'].values
return pd.Series(values)
In [162]:
df = pd.DataFrame.from_dict({k: sorting_and_naming(v)\
for k,v in mapping.iteritems()})
In [174]:
df.head()
Out[174]:
In [177]:
(df.gluco == df.high).mean()
Out[177]:
In [178]:
(df.gluco == df.hypo).mean()
Out[178]:
In [179]:
(df.gluco == df.keto).mean()
Out[179]:
In [180]:
(df.gluco == df.medium).mean()
Out[180]:
In [181]:
(df.high == df.low).mean()
Out[181]:
In [182]:
(df.high == df.medium).mean()
Out[182]:
In [183]:
(df.high == df.hypo).mean()
Out[183]:
In [184]:
(df.medium == df.low).mean()
Out[184]:
In [201]:
index = mapping['gluco'].index
In [205]:
sns.jointplot(mapping['gluco'].ix[index].total, mapping['low'].ix[index].total)
Out[205]:
In [206]:
sns.jointplot(mapping['keto'].ix[index].total, mapping['low'].ix[index].total)
Out[206]:
In [207]:
sns.jointplot(mapping['hypo'].ix[index].total, mapping['low'].ix[index].total)
Out[207]:
In [209]:
sns.jointplot(mapping['gluco'].ix[index].total, mapping['high'].ix[index].total)
Out[209]:
In [ ]: