In [ ]:
## Plotting just the "Basic cell groups and regions" by itself
In [1]:
from plotly.offline import download_plotlyjs
from plotly.graph_objs import *
from plotly import tools
import plotly
import os
#os.chdir('C:/Users/L/Documents/Homework/BME/Neuro Data I/Data/')
import csv,gc # garbage memory collection :)
import numpy as np
# import matplotlib.pyplot as plt
# from mpl_toolkits.mplot3d import axes3d
# from mpl_toolkits.mplot3d import axes3d
# from collections import namedtuple
import csv
import re
import matplotlib
import time
import seaborn as sns
from collections import OrderedDict
In [2]:
token = 'Aut1367'
In [3]:
"""Script for generating the color coded atlas region graphs"""
path1 = os.getcwd() + '/../ccrf/'
path2 = os.getcwd() + '/../ccf/'
data_txt = path1 + 'Aut1367reorient_atlas.region.csv'
ccf_txt = path2 + 'natureCCFOhedited.csv'
data = np.genfromtxt(data_txt, delimiter=',', dtype='int', usecols = (0,1,2,4), names=['x','y','z','region'])
In [4]:
ccf = {}
In [5]:
with open(ccf_txt, 'rU') as csvfile:
csvreader = csv.reader(csvfile)
for row in csvreader:
# row[0] is ccf atlas index, row[4] is string of full name
ccf[row[0]] = row[4];
#print row[0]
#print row[4]
#print ', '.join(row)
In [6]:
# Find all unique regions of brightest points
unique = [];
for l in data:
unique.append(l[3])
uniqueNP = np.asarray(unique)
allUnique = np.unique(uniqueNP)
numRegionsA = len(allUnique)
print allUnique
print numRegionsA ## number of regions
In [63]:
def generate_atlas_specific_region_graph(data, regionID, path=None, numRegions = 1):
font = {'weight' : 'bold',
'size' : 18}
matplotlib.rc('font', **font)
region_dict = OrderedDict()
for l in data:
trace = ccf[str(l[3])]
#trace = 'trace' + str(l[3])
if trace not in region_dict:
region_dict[trace] = np.array([[l[0], l[1], l[2], l[3]]])
#print 'yay'
else:
tmp = np.array([[l[0], l[1], l[2], l[3]]])
region_dict[trace] = np.concatenate((region_dict.get(trace, np.zeros((1,4))), tmp), axis=0)
#print 'nay'
current_palette = sns.color_palette("husl", numRegions)
# print current_palette
data = []
key = ccf[str(regionID)];
trace = region_dict[key]
tmp_col = current_palette[0]
tmp_col_lit = 'rgb' + str(tmp_col)
temp = str(np.unique(trace[:,3])).replace("[", "")
final = temp.replace("]", "")
trace_scatter = Scatter3d(
x = trace[:,0],
y = trace[:,1],
z = trace[:,2],
mode='markers',
name=ccf[final],
marker=dict(
size=1.2,
color=tmp_col_lit, #'purple', # set color to an array/list of desired values
colorscale='Viridis', # choose a colorscale
opacity=0.3
)
)
data.append(trace_scatter)
layout = Layout(
margin=dict(
l=0,
r=0,
b=0,
t=0
),
paper_bgcolor='rgb(0,0,0)',
plot_bgcolor='rgb(0,0,0)'
)
fig = Figure(data=data, layout=layout)
plotly.offline.plot(fig, filename= 'Aut1367' + ccf[str(regionID)] + ".html")
In [95]:
generate_atlas_specific_region_graph(data, regionID = 8, path=None, numRegions = 1);
In [35]:
region_dict = OrderedDict()
for l in data:
trace = ccf[str(l[3])]
#trace = 'trace' + str(l[3])
if trace not in region_dict:
region_dict[trace] = np.array([[l[0], l[1], l[2], l[3]]])
#print 'yay'
else:
tmp = np.array([[l[0], l[1], l[2], l[3]]])
region_dict[trace] = np.concatenate((region_dict.get(trace, np.zeros((1,4))), tmp), axis=0)
#print 'nay'
In [84]:
regionID = 7
In [85]:
ccf['7']
Out[85]:
In [86]:
print str(regionID)
In [87]:
ccf[str(regionID)]
Out[87]:
In [88]:
region_dict[ccf[str(regionID)]]
Out[88]:
In [92]:
region_dict['Superior colliculus']
In [93]:
ccf['258']
Out[93]:
In [ ]: