Exemple #1
0
def createconnectogram(num_out_lbl, heatmap, annot_csv, uniq_lbls, targ, dic):
    """ Generates & saves the connectome graph of the connectiviy matrix
    """

    print(
        "\n Computing & saving the interactive connectivity graph (connectogram) "
    )

    lgn = Lightning(ipython=True, local=True)

    # create circle connectome
    connections = np.zeros(((2 * num_out_lbl) + 1, (2 * num_out_lbl) + 1))

    connections[1:(num_out_lbl + 1), 0] = uniq_lbls.T
    connections[num_out_lbl + 1:, 0] = targ.T

    connections[0, 1:(num_out_lbl + 1)] = uniq_lbls.T
    connections[0, (num_out_lbl + 1):] = targ.T

    # propagate connections

    alllbls = connections[1:, 0]

    for l, lbl in enumerate(alllbls):

        for t, tart in enumerate(alllbls):
            iind = heatmap[:-1, 0] == lbl
            jind = heatmap[num_out_lbl, :] == tart
            val = heatmap[np.where(iind == True), np.where(jind == True)]

            connections[l + 1, t + 1] = val if val > 0 else 0

    # threshold connections
    thr = 0.1
    connections[connections < thr] = 0

    # lbls abrv
    alllbls_abrv = pd.DataFrame(alllbls)
    alllbls_abrv = alllbls_abrv.replace(dic)
    alllbls_abrv = np.array(alllbls_abrv[0])

    # get grand parents ids for groups
    ggp_parents = np.array([
        annot_csv['parent_structure_id'][annot_csv['id'] == lbl].item()
        for l, lbl in enumerate(alllbls)
    ])

    parent_grps = ggp_parents

    for i in range(2):
        parent_grps = np.array([
            annot_csv['parent_structure_id'][annot_csv['id'] == lbl].item() if
            (lbl != 997) else 997 for l, lbl in enumerate(parent_grps)
        ])

    # make dic
    repl = np.unique(ggp_parents)
    np.place(repl, repl > 0, range(len(repl)))
    uniq_parents = np.unique(ggp_parents)
    parents_dic = dict(zip(uniq_parents, repl))

    # replace
    ggp_parents = pd.DataFrame(ggp_parents)
    groups = ggp_parents.replace(parents_dic)
    groups = np.array(groups[0])

    # make dic
    repl2 = np.unique(parent_grps)
    np.place(repl2, repl2 > 0, range(len(repl2)))
    uniq_parents2 = np.unique(parent_grps)
    parents_dic2 = dict(zip(uniq_parents2, repl2))

    parent_grps = pd.DataFrame(parent_grps)
    parent_groups = parent_grps.replace(parents_dic2)
    parent_groups = np.array(parent_groups[0])

    justconn = connections[1:, 1:]

    c = lgn.circle(justconn,
                   labels=alllbls_abrv,
                   group=[parent_groups, groups],
                   width=1000,
                   height=1000)

    c.save_html('connectogram_grouped_by_parent_id_%d_labels.html' %
                num_out_lbl,
                overwrite=True)
Exemple #2
0
from lightning import Lightning
from numpy import random

lgn = Lightning()

connections = random.rand(50,50)
connections[connections<0.98] = 0

g1 = (random.rand(50) * 3).astype('int')
g2 = (random.rand(50) * 3).astype('int')
group = [g2, g1]

lgn.circle(connections, group=group)
from lightning import Lightning
from numpy import random

lgn = Lightning()

connections = random.rand(50, 50)
connections[connections < 0.98] = 0

g1 = (random.rand(50) * 3).astype('int')
g2 = (random.rand(50) * 3).astype('int')
group = [g2, g1]

lgn.circle(connections, group=group)
Exemple #4
0
import numpy as np
from lightning import Lightning
lgn = Lightning(local=True)
connections = np.matrix("0 0 0 1;0 0 0 0;0 0 0 0;0 0 0 0")
lgn.circle(connections)