コード例 #1
0
ファイル: network.py プロジェクト: travs/PyOpenWorm
    def _synapses_csv(self):
        """
        Get all synapses into CSV

        :returns: A generator of Connection objects
        :rtype: generator
        """
        for n,nbrs in self['nx'].adjacency_iter():
            for nbr,eattr in nbrs.items():
                yield P.Connection(n,nbr,int(eattr['weight']),eattr['synapse'],eattr['neurotransmitter'],conf=self.conf)
コード例 #2
0
    def get(self, pre_post_or_either='pre', **kwargs):
        """Get a list of connections associated with the owning neuron.

           Parameters
           ----------
           type: What kind of junction to look for.
                        0=all, 1=gap junctions only, 2=all chemical synapses
                        3=incoming chemical synapses, 4=outgoing chemical synapses
           Returns
           -------
           list of Connection
        """
        c = []
        if pre_post_or_either == 'pre':
            c.append(P.Connection(pre_cell=self.owner, **kwargs))
        elif pre_post_or_either == 'post':
            c.append(P.Connection(post_cell=self.owner, **kwargs))
        elif pre_post_or_either == 'either':
            c.append(P.Connection(pre_cell=self.owner, **kwargs))
            c.append(P.Connection(post_cell=self.owner, **kwargs))
        for x in c:
            for r in x.load():
                yield r
コード例 #3
0
    def get(self, **kwargs):
        """Get a list of neighboring neurons.

           Parameters
           ----------
           See parameters for PyOpenWorm.connection.Connection

           Returns
           -------
           list of Neuron
        """
        if len(self._conns) > 0:
            for c in self._conns:
                yield c.post_cell()
        else:
            c = P.Connection(pre_cell=self.owner, **kwargs)
            for r in c.load():
                yield r.post_cell()
コード例 #4
0
ファイル: insert_worm.py プロジェクト: hytsang/PyOpenWorm
                def add_synapse(source, target):
                    c = P.Connection(pre_cell=source,
                                     post_cell=target,
                                     number=weight,
                                     syntype=syn_type)
                    n.synapse(c)
                    e.asserts(c)

                    if isinstance(source, P.Neuron) and isinstance(
                            target, P.Neuron):
                        c.termination('neuron')
                    elif isinstance(source, P.Neuron) and isinstance(
                            target, P.Muscle):
                        c.termination('muscle')
                    elif isinstance(source, P.Muscle) and isinstance(
                            target, P.Neuron):
                        c.termination('muscle')

                    return c
コード例 #5
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()
コード例 #6
0
ファイル: insert_worm.py プロジェクト: travs/PyOpenWorm
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()
コード例 #7
0
 def set(self, other, **kwargs):
     c = P.Connection(pre_cell=self.owner, post_cell=other, **kwargs)
     self._conns.append(c)
     return c
コード例 #8
0
ファイル: shortest_path.py プロジェクト: vpomponiu/PyOpenWorm
# Start PyOpenWorm
P.connect()
try:
    # make the matrix
    try:
        # Try to load from a previous run -- the worm isn't changing
        mat = np.load("celegans.npy")
    except:
        # Get a dictionary of cell names to generated indices used to index into the matrix below
        cell_names = {
            x[1]: x[0]
            for x in enumerate({str(x.name())
                                for x in P.Neuron().load()})
        }
        # Load all of the connections between neurons
        conns = P.Connection().load()

        # initialize matrix entries to +infinity = no direct connection
        inf = float('+inf')
        mat = np.zeros((len(cell_names) + 1, len(cell_names)))
        mat.fill(inf)
        for x in conns:
            pre_cell = x.pre_cell()
            post_cell = x.post_cell()
            if isinstance(pre_cell, P.Neuron) \
                    and isinstance(post_cell, P.Neuron):
                pre_name = pre_cell.name()
                post_name = post_cell.name()
                num = x.number()
                if num is None:
                    num = 1.0
コード例 #9
0
database.
"""

import PyOpenWorm as P

P.connect()


def pp_connection(conn):
    print conn.pre_cell(), conn.post_cell(), conn.syntype(), conn.synclass(
    ), conn.number()


try:

    query_object = P.Connection(pre_cell='AVAL')
    print 'STARTING WITH AVAL'
    for x in query_object.load():
        pp_connection(x)
    print
    print 'STARTING WITH PVCL'
    query_object = P.Connection(pre_cell='PVCL')
    for x in query_object.load():
        pp_connection(x)

    print
    print 'NEURONS'
    query_object = P.Neuron()
    # sometimes a neuron object with the same name is returned more than once
    names = dict()
    for x in query_object.load():