Example #1
0
def read_data(include_nonconnected_cells=False, neuron_connect=False):



# reading the NeuronConnect.xls file if neuron_connect = True
    if neuron_connect:
        conns = []
        cells = []
        filename = "%sNeuronConnectFormatted.xlsx"%spreadsheet_location
        rb = open_workbook(filename)
        print_("Opened Excel file: " + filename)

        for row in range(1,rb.sheet_by_index(0).nrows):
            pre = str(rb.sheet_by_index(0).cell(row,0).value)
            post = str(rb.sheet_by_index(0).cell(row,1).value)
            syntype = rb.sheet_by_index(0).cell(row,2).value
            num = int(rb.sheet_by_index(0).cell(row,3).value)
            synclass = 'Generic_GJ' if 'EJ' in syntype else 'Chemical_Synapse'

            conns.append(ConnectionInfo(pre, post, num, syntype, synclass))
            if pre not in cells:
                cells.append(pre)
            if post not in cells:
                cells.append(post)

        return cells, conns

    else:
        conns = []
        cells = []
        filename = "%sCElegansNeuronTables.xls"%spreadsheet_location
        rb = open_workbook(filename)

        print_("Opened Excel file: " + filename)

        known_nonconnected_cells = ['CANL', 'CANR', 'VC6']


        for row in range(1,rb.sheet_by_index(0).nrows):
            pre = str(rb.sheet_by_index(0).cell(row,0).value)
            post = str(rb.sheet_by_index(0).cell(row,1).value)
            syntype = rb.sheet_by_index(0).cell(row,2).value
            num = int(rb.sheet_by_index(0).cell(row,3).value)
            synclass = rb.sheet_by_index(0).cell(row,4).value

            conns.append(ConnectionInfo(pre, post, num, syntype, synclass))
            if pre not in cells:
                cells.append(pre)
            if post not in cells:
                cells.append(post)

        if include_nonconnected_cells:
            for c in known_nonconnected_cells: cells.append(c)

        return cells, conns
Example #2
0
def read_muscle_data():

    conns = []
    neurons = []
    muscles = []

    filename = "%sCElegansNeuronTables.xls"%spreadsheet_location
    rb = open_workbook(filename)

    print_("Opened Excel file: "+ filename)

    sheet = rb.sheet_by_index(1)

    for row in range(1,sheet.nrows):
        pre = str(sheet.cell(row,0).value)
        post = str(sheet.cell(row,1).value)
        syntype = 'Send'
        num = int(sheet.cell(row,2).value)
        synclass = sheet.cell(row,3).value.replace(',', 'plus').replace(' ', '_')

        conns.append(ConnectionInfo(pre, post, num, syntype, synclass))
        if pre not in neurons:
            neurons.append(pre)
        if post not in muscles:
            muscles.append(post)


    return neurons, muscles, conns
def read_data(include_nonconnected_cells=False):
    """
    Args:
        include_nonconnected_cells (bool): Also append neurons without known connections to other neurons to the 'cells' list. True if they should get appended, False otherwise.
    Returns:
        cells (:obj:`list` of :obj:`str`): List of neurons
        conns (:obj:`list` of :obj:`ConnectionInfo`): List of connections from neuron to neuron
    """

    conns = []
    cells = []

    with open(filename, 'r') as f:
        reader = csv.DictReader(f)
        print_("Opened file: " + filename)

        known_nonconnected_cells = ['CANL', 'CANR']

        for row in reader:
            pre, post, num, syntype, synclass = parse_row(row)

            if not is_neuron(pre) or not is_neuron(post):
                continue  # pre or post is not a neuron

            pre = remove_leading_index_zero(pre)
            post = remove_leading_index_zero(post)

            conns.append(ConnectionInfo(pre, post, num, syntype, synclass))
            #print ConnectionInfo(pre, post, num, syntype, synclass)
            if pre not in cells:
                cells.append(pre)
            if post not in cells:
                cells.append(post)

        if include_nonconnected_cells:
            for c in known_nonconnected_cells:
                if c not in cells:
                    cells.append(c)

    return cells, conns
def read_muscle_data():
    """
    Returns:
        neurons (:obj:`list` of :obj:`str`): List of motor neurons. Each neuron has at least one connection with a post-synaptic muscle cell.
        muscles (:obj:`list` of :obj:`str`): List of muscle cells.
        conns (:obj:`list` of :obj:`ConnectionInfo`): List of neuron-muscle connections.
    """

    neurons = []
    muscles = []
    conns = []

    with open(filename, 'r') as f:
        reader = csv.DictReader(f)
        print_("Opened file: " + filename)

        for row in reader:
            pre, post, num, syntype, synclass = parse_row(row)

            if (not is_neuron(pre) and not is_body_wall_muscle(pre)
                ) or not is_body_wall_muscle(post):
                # Don't add connections unless pre=neuron and post=body_wall_muscle
                continue

            if is_neuron(pre):
                pre = remove_leading_index_zero(pre)
            else:
                pre = get_old_muscle_name(pre)
            post = get_old_muscle_name(post)

            conns.append(ConnectionInfo(pre, post, num, syntype, synclass))
            #print ConnectionInfo(pre, post, num, syntype, synclass)
            if is_neuron(pre) and pre not in neurons:
                neurons.append(pre)
            elif is_body_wall_muscle(pre) and pre not in muscles:
                muscles.append(pre)
            if post not in muscles:
                muscles.append(post)

    return neurons, muscles, conns
Example #5
0
def read_data(include_nonconnected_cells=False):
    print_("Initialising OpenWormReader")

    with pyopenworm_connect() as conn:
        ctx = Context(ident="http://openworm.org/data", conf=conn.conf).stored
        #Extract the network object from the worm object.
        net = ctx(Worm)().neuron_network()
        all_connections = net.synapses()

        conns = []
        cells = []

        cell_names = get_cells_in_model(net)

        for s in all_connections:
            pre = str(s.pre_cell().name())
            post = str(s.post_cell().name())

            if isinstance(s.post_cell(),
                          Neuron) and pre in cell_names and post in cell_names:
                syntype = str(s.syntype())
                syntype = syntype[0].upper() + syntype[1:]
                num = int(s.number())
                synclass = str(s.synclass())
                ci = ConnectionInfo(pre, post, num, syntype, synclass)
                conns.append(ci)
                if pre not in cells:
                    cells.append(pre)
                if post not in cells:
                    cells.append(post)

        print_("Total cells %i (%i with connections)" %
               (len(cell_names), len(cells)))
        print_("Total connections found %i " % len(conns))

        if include_nonconnected_cells:
            return cell_names, conns
        else:
            return cells, conns
Example #6
0
    def _read_connections(self, termination=None):
        if not self.cached:
            with Bundle('openworm/owmeta-data', version=6) as bnd:
                ctx = bnd(Context)(ident="http://openworm.org/data").stored
                # Extract the network object from the worm object.
                net = ctx(Worm).query().neuron_network()

                syn = net.synapse.expr
                pre = syn.pre_cell
                post = syn.post_cell

                (pre | post).rdf_type(multiple=True)

                (pre | post).name()
                pre()
                post()
                syn.syntype()
                syn.synclass()
                syn.number()
                self.connlist = syn.to_objects()

                self.cell_names = self.get_cells_in_model(net)
            self.cached = True

        if termination == 'neuron':
            term_type = set([Neuron.rdf_type])
        elif termination == 'muscle':
            term_type = set([BodyWallMuscle.rdf_type])
        else:
            term_type = set([Neuron.rdf_type, BodyWallMuscle.rdf_type])

        conns = []
        pre_cell_names = set()
        post_cell_names = set()
        for conn in self.connlist:
            if (Neuron.rdf_type in conn.pre_cell.rdf_type and
                    term_type & set(conn.post_cell.rdf_type)):
                num = conn.number
                syntype = conn.syntype or ''
                synclass = conn.synclass or ''
                pre_name = conn.pre_cell.name
                post_name = conn.post_cell.name
                if BodyWallMuscle.rdf_type in conn.post_cell.rdf_type:
                    post_name = format_muscle_name(post_name)

                if not synclass:
                    # Hack/guess
                    if syntype and syntype.lower() == "gapjunction":
                        synclass = "Generic_GJ"
                    else:
                        if pre_name.startswith("DD") or pre_name.startswith("VD"):
                            synclass = "GABA"
                        synclass = "Acetylcholine"
                conns.append(ConnectionInfo(pre_name, post_name, num, syntype, synclass))

                pre_cell_names.add(pre_name)
                post_cell_names.add(post_name)

        print_("Total cells %i (%i with connections)" % (
            len(self.cell_names | pre_cell_names | post_cell_names),
            len(pre_cell_names | post_cell_names)))
        print_("Total connections found %i " % len(conns))

        return list(self.cell_names), pre_cell_names, post_cell_names, conns