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


[   1    2    7    8    9   10   12   15   17   19   20   23   26  257  258
  259  260  262  263  266  267  268  269  271  272  274  276  278  279  280
  281  513  515  520  521  523  524  526  527  529  531  532  534  537  769
  771  772  773  774  777  778  780  781  783  785  786  791 1026 1029 1030
 1031 1034 1035 1038 1042 1044 1045 1046 1047 1048 1050]
71

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]:
'Principal sensory nucleus of the trigeminal'

In [86]:
print str(regionID)


7

In [87]:
ccf[str(regionID)]


Out[87]:
'Principal sensory nucleus of the trigeminal'

In [88]:
region_dict[ccf[str(regionID)]]


Out[88]:
array([[175, 337, 785,   7],
       [176, 333, 761,   7],
       [176, 335, 768,   7],
       ..., 
       [432, 347, 912,   7],
       [433, 318, 977,   7],
       [434, 332, 856,   7]])

In [92]:
region_dict['Superior colliculus']


---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-92-29e67a461298> in <module>()
----> 1 region_dict['Superior colliculus']

KeyError: 'Superior colliculus'

In [93]:
ccf['258']


Out[93]:
'Lateral septal nucleus, rostral (rostroventral) part'

In [ ]: