Beispiel #1
0
def upload_neurons():
    try:
        conn = sqlite3.connect(SQLITE_DB_LOC)
        cur = conn.cursor()
        ev = P.Evidence(title="C. elegans sqlite database")
        w = P.Worm()
        n = P.Network()
        w.neuron_network(n)
        # insert neurons.
        # save
        cur.execute("""
        SELECT DISTINCT a.Entity FROM tblrelationship, tblentity a, tblentity b
        where EnID1=a.id and Relation = '1515' and EnID2='1'
        """)
        for r in cur.fetchall():
            neuron_name = str(r[0])
            n.neuron(P.Neuron(name=neuron_name))
        ev.asserts(n)
        ev.save()
        #second step, get the relationships between them and add them to the graph
        print("uploaded neurons")
    except Exception:
        traceback.print_exc()
    finally:
        conn.close()
Beispiel #2
0
def do_insert(config="default.conf", logging=False):
    if config:
        if isinstance(config, P.Configure):
            pass
        elif isinstance(config, str):
            config = P.Configure.open(config)
        elif isinstance(config, dict):
            config = P.Configure().copy(config)
        else:
            raise Exception("Invalid configuration object " + str(config))

    P.connect(conf=config, do_logging=logging)
    try:
        w = P.Worm()
        net = P.Network()
        w.neuron_network(net)
        w.save()

        upload_neurons()
        upload_muscles()
        upload_lineage_and_descriptions()
        upload_synapses()
        upload_receptors_and_innexins()
        upload_types()
        serialize_as_n3()
        #infer()
    except:
        traceback.print_exc()
    finally:
        P.disconnect()
Beispiel #3
0
def main():
    c = Configure()
    c['neuronscsv'] = 'https://raw.github.com/openworm/data-viz/master/HivePlots/neurons.csv'
    c['connectomecsv'] = 'https://raw.github.com/openworm/data-viz/master/HivePlots/connectome.csv'
    c['sqldb'] = '/home/markw/work/openworm/PyOpenWorm/db/celegans.db'
    c = Data(c)
    net = PyOpenWorm.Network(c)
    nml_doc = NeuroMLDocument(id="IafNet")
    ns = net.neurons()

    nml_net = neuroml.Network(id="IafNet")
    nml_doc.networks.append(nml_net)

    for n in [net.aneuron_nocheck(n) for n in ns]:
        s(nml_doc, nml_net, n)

    syn0 = ExpOneSynapse(id="syn0", gbase="65nS", erev="0mV", tau_decay="3ms")
    for k in net.synapses():
        n1 = net.aneuron_nocheck(k[0])
        n2 = net.aneuron_nocheck(k[1])
        connect(nml_net, n1, n2, 'syn0')

    f = "test.nml"
    writers.NeuroMLWriter.write(nml_doc, f)
    v(f)
Beispiel #4
0
 def get_neuron_network(self):
     """
     Get the network object
         
     :returns: An object to work with the network of the worm
     :rtype: PyOpenWorm.Network
    """
     return PyOpenWorm.Network()
Beispiel #5
0
def upload_receptors_and_innexins():
    try:
        conn = sqlite3.connect(SQLITE_DB_LOC)
        cur = conn.cursor()
        w = P.Worm()
        n = P.Network()
        w.neuron_network(n)
        # insert neurons.
        # save
        # get the receptor (354) and innexin (355)
        cur.execute("""
        SELECT DISTINCT a.Entity, b.Entity
        FROM
        tblrelationship q,
        tblrelationship r,
        tblentity a,
        tblentity b
        where q.EnID1=a.id and q.Relation = '1515' and q.EnID2='1'
        and   r.EnID1=a.id and r.Relation = '354'  and r.EnID2=b.id
        """)
        for r in cur.fetchall():
            neuron_name = str(r[0])
            receptor = str(r[1])
            neur = P.Neuron(name=neuron_name)
            neur.receptor(receptor)
            n.neuron(neur)
        cur.execute("""
        SELECT DISTINCT a.Entity, b.Entity
        FROM
        tblrelationship q,
        tblrelationship r,
        tblentity a,
        tblentity b
        where q.EnID1=a.id and q.Relation = '1515' and q.EnID2='1'
        and   r.EnID1=a.id and r.Relation = '355'  and r.EnID2=b.id
        """)
        for r in cur.fetchall():
            neuron_name = str(r[0])
            innexin = str(r[1])
            neur = P.Neuron(name=neuron_name)
            neur.innexin(innexin)
            n.neuron(neur)
        n.save()
        #second step, get the relationships between them and add them to the graph
    except Exception:
        traceback.print_exc()
    finally:
        conn.close()
Beispiel #6
0
def do_insert(config="default.conf", logging=False):
    global SQLITE_EVIDENCE
    global WORM
    global NETWORK

    if config:
        if isinstance(config, P.Configure):
            pass
        elif isinstance(config, str):
            config = P.Configure.open(config)
        elif isinstance(config, dict):
            config = P.Configure().copy(config)
        else:
            raise Exception("Invalid configuration object " + str(config))

    P.connect(conf=config, do_logging=logging)
    SQLITE_EVIDENCE = P.Evidence(key="C_elegans_SQLite_DB",
                                 title="C. elegans sqlite database")
    try:
        WORM = P.Worm()
        NETWORK = P.Network()
        WORM.neuron_network(NETWORK)
        NETWORK.worm(WORM)

        upload_neurons()
        upload_muscles()
        upload_lineage_and_descriptions()
        upload_connections()
        upload_receptors_types_neurotransmitters_neuropeptides_innexins()
        upload_additional_receptors_neurotransmitters_neuropeptides_innexins()

        print("Saving...")
        WORM.save()

        #infer()
        print("Serializing...")
        serialize_as_n3()

    except Exception:
        traceback.print_exc()
    finally:
        P.disconnect()
Beispiel #7
0
def upload_synapses():
    try:
        conn = sqlite3.connect(SQLITE_DB_LOC)
        cur = conn.cursor()
        w = P.Worm()
        n = P.Network()
        w.neuron_network(n)
        #second step, get the relationships between them and add them to the graph
        cur.execute("SELECT DISTINCT a.Entity, b.Entity, Weight, Relation FROM tblrelationship, tblentity a, tblentity b where EnID1=a.id and EnID2=b.id and (Relation = '356' OR Relation = '357')")

        for r in cur.fetchall():
            #all items are numbers -- need to be converted to a string
            first = str(r[0])
            second = str(r[1])
            third = str(r[2])
            syntype = str(r[3])
            if syntype == '356':
                syntype = 'send'
            else:
                syntype = 'gapjunction'
            try:
                weight = int(third)
                # NMJs have negative weights. we only want the synaptic connections
                if weight < 0:
                    syntype = 'gapjunction'
                    weight = -1 * weight

            except:
                weight = None

            if weight:
                c = P.Connection(pre_cell=first, post_cell=second, number=weight, syntype=syntype)
                n.synapse(c)
        e = P.Evidence(author='*****@*****.**')
        e.asserts(w)
        e.save()
    except Exception, e:
        traceback.print_exc()
Beispiel #8
0
 def test_network_as_networkx(self):
     self.assertTrue(
         isinstance(PyOpenWorm.Network().as_networkx(), networkx.DiGraph))
Beispiel #9
0
 def test_neuron_Syn_degree(self):
     self.assertEquals(PyOpenWorm.Network().aneuron('AVAL').Syn_degree(),
                       74)
Beispiel #10
0
 def test_neuron_name(self):
     self.assertEquals(PyOpenWorm.Network().aneuron('AVAL').name(), 'AVAL')
     self.assertEquals(PyOpenWorm.Network().aneuron('AVAR').name(), 'AVAR')
Beispiel #11
0
 def test_neuron_type(self):
     self.assertEquals(PyOpenWorm.Network().aneuron('AVAL').type(),
                       'interneuron')
     self.assertEquals(PyOpenWorm.Network().aneuron('DD5').type(), 'motor')
     self.assertEquals(PyOpenWorm.Network().aneuron('PHAL').type(),
                       'sensory')
Beispiel #12
0
 def test_network_neurons(self):
     self.assertTrue('AVAL' in PyOpenWorm.Network().neurons())
     self.assertTrue('DD5' in PyOpenWorm.Network().neurons())
     self.assertEquals(len(PyOpenWorm.Network().neurons()), 302)
Beispiel #13
0
 def test_network_aneuron(self):
     self.assertTrue(
         isinstance(PyOpenWorm.Network().aneuron('AVAL'),
                    PyOpenWorm.Neuron))
Beispiel #14
0
 def test_network(self):
     self.assertTrue(isinstance(PyOpenWorm.Network(), PyOpenWorm.Network))
Beispiel #15
0
def upload_synapses():

    import re
    search_string = re.compile(r'\w+[0]+[1-9]+')
    replace_string = re.compile(r'[0]+')

    def normalize(name):
        # normalize neuron names to match those used at other points
        # see #137 for elaboration
        # if there are zeroes in the middle of a name, remove them
        if re.match(search_string, name):
            name = replace_string.sub('', name)
        return name

    import xlrd

    try:
        w = P.Worm()
        n = P.Network()
        w.neuron_network(n)
        combining_dict = {}
        # Get synapses and gap junctions and add them to the graph
        s = xlrd.open_workbook('../aux_data/NeuronConnect.xls').sheets()[0]
        for row in range(1, s.nrows):
            if s.cell(row, 2).value in ('S', 'Sp', 'EJ'):
                #We're not going to include 'receives' ('R', 'Rp') since they're just the inverse of 'sends'
                #Also omitting 'NMJ' for the time being (no model in db)
                pre = normalize(s.cell(row, 0).value)
                post = normalize(s.cell(row, 1).value)
                num = int(s.cell(row, 3).value)
                if s.cell(row, 2).value == 'EJ':
                    syntype = 'gapJunction'
                elif s.cell(row, 2).value in ('S', 'Sp'):
                    syntype = 'send'

                # Add them to a dict to make sure Sends ('S') and Send-polys ('Sp') are summed.
                # keying by connection pairs as a string (e.g. 'SDQL,AVAL,send').
                # values are lists of the form [pre, post, number, syntype].
                string_key = '{},{},{}'.format(pre, post, syntype)
                if string_key in combining_dict.keys():
                    # if key already there, add to number
                    num += combining_dict[string_key][2]

                combining_dict[string_key] = [pre, post, num, syntype]

        for entry in combining_dict:
            pre, post, num, syntype = combining_dict[entry]
            c = P.Connection(pre_cell=pre,
                             post_cell=post,
                             number=num,
                             syntype=syntype)
            n.synapse(c)

        e = P.Evidence(
            uri='http://www.wormatlas.org/neuronalwiring.html#Connectivitydata'
        )
        e.asserts(n)
        e.save()
        print('uploaded synapses')
    except Exception, e:
        traceback.print_exc()
Beispiel #16
0
# n.neighbor(b) # Otherwise, the neuron (b) in the connected class on the same side as
#               # n (i.e., the one for which the last character in its name matches the
#               # last in n's name) in the neighbor
# n.name()[:-1] == nc.name()

#
# Setting up the data
#

ev = P.Evidence(
    title=
    "A Hub-and-Spoke Circuit Drives Pheromone Attraction and Social Behavior in C. elegans",
    uri="http://www.ncbi.nlm.nih.gov/pmc/articles/PMC2760495/",
    year=2009)
w = P.Worm("C. elegans")
net = P.Network()
w.neuron_network(net)

ev.asserts(w)


def setup(name, type):
    n = NeuronClass(name)
    n.type(type)
    n.member(P.Neuron(name + "R"))
    n.member(P.Neuron(name + "L"))
    net.neuron(n)
    return n


rmg = setup("RMG", 'interneuron')