Exemplo n.º 1
0
                            'all', 'cad', 'lrr', 'igsf', 'nrx', 'cad_lron',
                            'non_cad_lron'
                        ],
                        help='Specify CAM choice')

    parser.add_argument('-o',
                        '--output',
                        action='store',
                        dest='fout',
                        required=False,
                        default=None,
                        help='Output file')

    params = parser.parse_args()

    ML = MatLoader()
    ML.load_lrmap()
    #nodes = sorted(ML.load_reduced_nodes())
    nodes = sorted(ML.load_all_tissue())
    neurons = sorted(ML.load_reduced_nodes()) + NODE_SCREEN

    clusters = aux.read.into_dict(TOP_CLUSTERS)
    cluster_color = aux.read.into_dict(CLUSTER_COLOR)

    e = Matrix(ML.cam, params.matrix)
    e.load_genes()
    e.load_cells(nodes)
    e.assign_expression()
    e.clean_expression()
    e.binarize()
    #M = e.E[:,idx_gene]
Exemplo n.º 2
0
            if not h.has_node(n): continue
            neigh = neigh.union(set(list(h.neighbors(n))))
        for m in neigh:
            _deg = 0
            for h in H:
                if h.has_edge(n, m):
                    _deg += 1
            if _deg >= deg:
                G.add_edge(n, m)
    return G


DOUT = './mat/consensus_graphs/consensus_%s_deg%d.graphml'

if __name__ == "__main__":
    M = MatLoader()
    M.load_left()
    M.load_right()
    M.load_lrmap()
    #M.left.remove('ASEL')
    #M.right.remove('ASER')
    N = from_db('N2U',
                adjacency=True,
                chemical=True,
                electrical=True,
                dataType='networkx')
    N.split_left_right(M.left, M.right)
    N.map_right_graphs(M.lrmap)

    J = from_db('JSH',
                adjacency=True,
Exemplo n.º 3
0
    parser.add_argument('matrix',
                        action = 'store',
                        help = 'Path to matrix file')

    parser.add_argument('deg',
                        action = 'store',
                        type= int,
                        help = 'Conserved degree')

   
    parser.add_argument('cell',action='store',help='Cell name')

    params = parser.parse_args()


    M = MatLoader()
    M.load_left()
    C = M.load_consensus_graphs(params.deg)
    S = M.load_consensus_chemical_synapse(params.deg)
    S1 = M.load_consensus_chemical_synapse(1)
    C1 = M.load_consensus_graphs(1)
    print(C.C.number_of_edges(),C1.C.number_of_edges())
    
    e = Matrix(cam,params.matrix)
    e.load_genes()
    e.load_cells(sorted(C.A.nodes()))
    e.assign_expression()
    e.binarize()
    print(len(e.gene_idx),len(e.cells_idx),e.E.shape)

    syn,neigh,cneigh = predict.get_synapse_data(S[params.cell],e,cpartners=set(C.C.neighbors(params.cell)))
Exemplo n.º 4
0
    'JSH_chem_post_synapses_right_deg%d.xml'
]
gap_left = [
    'N2U_elec_synapses_left_deg%d.xml', 'JSH_elec_synapses_left_deg%d.xml'
]
gap_right = [
    'N2U_elec_synapses_right_deg%d.xml', 'JSH_elec_synapses_right_deg%d.xml'
]

cout = din + 'all_chem_deg%d.xml'
pout = din + 'all_chem_post_deg%d.xml'
eout = din + 'all_elec_deg%d.xml'

DEG = [1, 2, 3, 4]
if __name__ == "__main__":
    M = MatLoader()
    M.load_lrmap()
    for deg in DEG:
        data = consensus.convert_xml_to_synapse(din + chem_left[0] % deg)
        tmp = consensus.convert_xml_to_synapse(din + chem_left[1] % deg)
        data = combine_data(data, tmp)

        tmp = consensus.convert_xml_to_synapse(din + chem_right[0] % deg)
        tmp = map_right_left(tmp, M.lrmap)
        data = combine_data(data, tmp)

        tmp = consensus.convert_xml_to_synapse(din + chem_right[1] % deg)
        tmp = map_right_left(tmp, M.lrmap)
        data = combine_data(data, tmp)

        tree = consensus.convert_synapse_to_xml(data)
Exemplo n.º 5
0
HUE_ORDER = ['Sp', 'Sa', 'I1', 'I2', 'HMN', 'SMN']
PALETTE = {
    'Sp': '#910000',
    'Sa': '#FE6F00',
    'I1': '#FF00FF',
    'I2': '#1700FF',
    'HMN': '#1D6500',
    'SMN': '#2aff00'
}

XSCALE = 0.09
RSCALE = 0.005

if __name__ == '__main__':
    M = MatLoader()
    M.load_left()
    M.load_right()
    nclass = M.load_nerve_ring_classes()
    con = db.connect.default(_db)
    cur = con.cursor()
    #radial = defaultdict(lambda:defaultdict(list))
    data = []
    for (k, v) in tqdm(nclass.items(), desc="Cells:"):
        if k not in M.left: continue
        if v not in remap: continue
        rv = remap[v]
        loc = db.mine.neuron_cylinder(cur, k)
        if not loc: continue
        #for l in loc: radial[v][l[2]].append(l[0])
        for l in loc:
Exemplo n.º 6
0
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument('matrix', action='store', help='Path to matrix file')

    parser.add_argument('-m',
                        '--mode',
                        action='store',
                        dest='mode',
                        choices=['pre', 'post', 'gap'],
                        default='pre',
                        required=False,
                        help='Specify pre, post or gap junction synaptic')

    params = parser.parse_args()

    M = MatLoader()
    M.load_left()
    M.load_lrmap()

    for deg in DEG:
        print('Degre: %d' % deg)
        C = M.load_consensus_graphs(deg)
        if params.mode == 'pre':
            S = M.load_consensus_chemical_synapse(deg)
        elif params.mode == 'post':
            S = M.load_consensus_chemical_post_synapse(deg)
        else:
            S = M.load_consensus_gap_junctions(deg)

        e = Matrix(cam, params.matrix)
        e.load_genes()
FOUT = 'wb_exp_matrix.csv'

if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument('cam',
                        action='store',
                        help="Path to file with cam genes")

    parser.add_argument('dout',
                        action='store',
                        help="Path to output directory")

    params = parser.parse_args()

    M = MatLoader()
    con = db.connect.default("N2U")
    cur = con.cursor()
    nodes = sorted(db.mine.get_adjacency_cells(cur))
    e = Expression(cur, params.cam, nodes)
    e.assign_expression_patterns(mode='post')

    data = e.expression_list()

    data = [d + [100] for d in data]

    fout = params.dout + FOUT

    aux.write.from_list(fout, data)
                        type=int,
                        help='Conserved degree')

    parser.add_argument('fout', action='store', help='Path to output file')

    parser.add_argument('--ie_iter',
                        dest='ie_iter',
                        action='store',
                        required=False,
                        default=1000,
                        type=int,
                        help="Number IE iterations")

    params = parser.parse_args()

    M = MatLoader()
    M.load_left()
    D = M.load_consensus_graphs(params.deg)
    S = M.load_consensus_chemical_synapse(params.deg)
    G = M.load_consensus_gap_junctions(params.deg)

    nodes = sorted(D.A.nodes())

    e = Matrix(cam, params.matrix)
    e.load_genes()
    e.load_cells(sorted(D.A.nodes()))
    e.assign_expression()
    e.binarize()
    e.difference_matrix()

    wbe = cam_lus.wbe(e, D, cells=M.left)
Exemplo n.º 9
0
                xname.text = n
            xcell.append(xcont)
        root.append(xcell)

    tree = etree.ElementTree(root)
    return tree


DEG = [3, 4]
DB = ['N2U', 'JSH']
PROCESS = [0, 0, 1, 1, 0, 0]

if __name__ == "__main__":

    for deg in DEG:
        M = MatLoader()
        M.load_left()
        M.load_right()
        M.load_lrmap()
        C = M.load_consensus_graphs(deg)

        for _db in DB:
            start, end = 0, 325
            if _db == 'JSH':
                start, end = 0, 425

            clout = './mat/consensus_synapses/%s_chem_synapses_left_deg%d.xml' % (
                _db, deg)
            crout = './mat/consensus_synapses/%s_chem_synapses_right_deg%d.xml' % (
                _db, deg)
            cplout = './mat/consensus_synapses/%s_chem_post_synapses_left_deg%d.xml' % (
Exemplo n.º 10
0
@date 09 April 2019
"""

import sys
sys.path.append('./volumetric_analysis')
sys.path.append('.')
import networkx as nx

from mat_loader import MatLoader
from connectome.load import from_db


if __name__=="__main__":
    _db = 'N2U'
    
    M = MatLoader()
    M.load_left()
    M.load_right()
    M.load_lrmap()
    C = from_db(_db,adjacency=True,chemical=True,
                electrical=True,dataType='networkx')
    C.split_left_right(M.left,M.right) 
    
    print(C.A.number_of_edges())
    print(C.Al.number_of_edges())
    print(C.Ar.number_of_edges())
    print(C.C.number_of_edges())
    print(C.Cl.number_of_edges())
    print(C.Cr.number_of_edges())
    print(C.E.number_of_edges())
    print(C.El.number_of_edges())
Exemplo n.º 11
0
if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument('matrix', action='store', help='Path to matrix file')

    #parser.add_argument('db',
    #                    action = 'store',
    #                    help = 'Database')

    #parser.add_argument('cell',action='store',help='Cell name')

    params = parser.parse_args()
    #cell = params.cell

    M = MatLoader()
    nclass = M.load_nerve_ring_classes()

    #N = from_db('N2U',adjacency=True,dataType='networkx',remove=REMOVE)
    #J = from_db('JSH',adjacency=True,dataType='networkx',remove=REMOVE)

    #nodes = sorted(set(N.A.nodes()) & set(J.A.nodes()))
    nodes = M.load_reduced_nodes()
    nrclass = [nclass[n] for n in nodes]
    print(sorted(set(nrclass)))

    e = Matrix(M.cam, params.matrix)
    e.load_genes()
    e.load_cells(nodes)
    e.assign_expression()
    e.binarize()
Exemplo n.º 12
0
                            'all', 'cad', 'lrr', 'igsf', 'nrx', 'cad_lron',
                            'non_cad_lron'
                        ],
                        help='Specify CAM choice')

    parser.add_argument('-o',
                        '--output',
                        action='store',
                        dest='fout',
                        required=False,
                        default=None,
                        help='Output file')

    params = parser.parse_args()

    ML = MatLoader()
    ML.load_lrmap()
    #nodes = sorted(ML.load_reduced_nodes())
    nodes = sorted(ML.load_all_tissue())
    neurons = sorted(ML.load_reduced_nodes())
    camclass = ML.load_cam_class(params.metric, params.camtype)

    e = Matrix(ML.cam, params.matrix)
    e.load_genes()
    e.load_cells(nodes)
    e.assign_expression()
    e.clean_expression()
    e.binarize()

    _tmp = aux.read.into_list('mat/non_cadlron_differential.txt')
    gdx = [e.genes[g].idx for g in _tmp]
Exemplo n.º 13
0
"""
import sys
sys.path.append('./volumetric_analysis')
sys.path.append('.')
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.rcParams['xtick.labelsize'] = 24
mpl.rcParams['ytick.labelsize'] = 24

from mat_loader import MatLoader

FOUT = '/home/cabrittin/Dropbox/PhD/sr_vol/figs2/fig9/cam_lr_discrepancy.png'

if __name__ == '__main__':
    M = MatLoader()
    C = M.load_consensus_graphs(3)
    M.load_left()
    M.load_lrmap()

    count = [0, 0, 0, 0]
    for n in M.left:
        if C.C.has_node(n):
            partners = set(C.C.neighbors(n))
            neighbors = set(C.A.neighbors(n))
            nonsyn = neighbors - partners
            for p in partners:
                pmap = M.lrmap[p]
                count[0] += 1
                if pmap in nonsyn:
                    print(n, p, pmap)
METRIC = 'pearsonr'
deg = 3
P = 66
Q = 100 - P

if __name__=="__main__":
    parser = argparse.ArgumentParser(description=__doc__,
                                     formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument('matrix',
                        action = 'store',
                        help = 'Path to matrix file')
 
    params = parser.parse_args()
    
    M = MatLoader()
    M.load_left()
    M.load_right()
    M.load_lrmap()

    nclass = M.load_nerve_ring_classes()
    nodes = M.load_reduced_nodes()
    single = set(nodes) - set(M.left) - set(['ASER'])

    N = from_db('N2U',adjacency=True,chemical=True,electrical=True,
            remove=REMOVE,dataType='networkx')
    Nsa = N.split_graph(N.A,single)
    Nsc = N.split_graph(N.C,single)
    Nse = N.split_graph(N.E,single)
    N.split_left_right(M.left,M.right)
    N.map_right_graphs(M.lrmap)
Exemplo n.º 15
0
mpl.rcParams['xtick.labelsize'] = 16
mpl.rcParams['xtick.labelsize'] = 14

cam_class = ['cad', 'igsf', 'lrr', 'nrx', 'all']
METRIC = 'pearsonr'
NODE_SCREEN = ['NSM', 'MC']

if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter)

    params = parser.parse_args()

    ML = MatLoader()
    ML.load_lrmap()
    #nodes = sorted(ML.load_reduced_nodes())
    nodes = sorted(ML.load_all_tissue())
    neurons = sorted(ML.load_reduced_nodes()) + NODE_SCREEN

    for c in cam_class:
        camclass = ML.load_cam_class(METRIC, c)
        k = max(camclass.values()) + 1
        num = np.zeros(k)
        den = np.zeros(k)
        for (i, j) in camclass.items():
            den[j] += 1
            if i in neurons: num[j] += 1

        p = num / den
Exemplo n.º 16
0
METHOD = 1

if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument('matrix', action='store', help='Path to matrix file')

    parser.add_argument('db', action='store', help='Database')

    #parser.add_argument('cell',action='store',help='Cell name')

    params = parser.parse_args()
    #cell = params.cell

    ML = MatLoader()
    ML.load_lrmap()
    nodes = sorted(ML.load_reduced_nodes())

    C = from_db(params.db, adjacency=True, dataType='networkx', remove=REMOVE)

    e = Matrix(ML.cam, params.matrix)
    e.load_genes()
    e.load_cells(nodes)
    e.assign_expression()
    e.binarize()
    #np.random.shuffle(e.M)

    M = e.E[:, idx_gene]

    #np.random.shuffle(M)
Exemplo n.º 17
0
import argparse
import numpy as np
from tqdm import tqdm
from random import shuffle
import matplotlib.pyplot as plt
import networkx as nx

from mat_loader import MatLoader
from cam.expression import Matrix
import cam.cam_predict as predict
import aux

DEG = [1, 2, 3, 4]
if __name__ == '__main__':

    M = MatLoader()
    M.load_left()

    for deg in DEG:
        C = M.load_consensus_graphs(deg)
        S = M.load_consensus_chemical_synapse(deg)
        pre, post = M.load_gene_sig_graph(deg)
        SCORE = [[], []]
        for cell in tqdm(M.left, desc='Cells'):
            if not C.C.has_node(cell): continue
            if cell not in S: continue
            if pre.out_degree(cell) == 0: continue
            cneighbors = set(C.C.neighbors(cell))
            k, s1, s2 = 0., 0., 0.
            for cont in S[cell]:
                partners = set(S[cell][cont]['partners'])