def readDataFromSpreadsheet(dir="../../", include_nonconnected_cells=False, neuron_connect=False): # reading the NeuronConnect.xls file if neuron_connect = True if neuron_connect: conns = [] cells = [] filename = dir + "NeuronConnectFormatted.xlsx" 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 = dir + "CElegansNeuronTables.xls" 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
def readMuscleDataFromSpreadsheet(): 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 readDataFromSpreadsheet(dir="../../", include_nonconnected_cells=False): conns = [] cells = [] filename = dir + "CElegansNeuronTables.xls" rb = open_workbook(filename) print "Opened Excel file: " + filename known_nonconnected_cells = ['CANL', 'CANR', 'VC6'] sheet = rb.sheet_by_index(0) for row in range(1, sheet.nrows): pre = str(sheet.cell(row, 0).value) post = str(sheet.cell(row, 1).value) syntype = sheet.cell(row, 2).value num = int(sheet.cell(row, 3).value) synclass = sheet.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
def read(self): conns = [] cells = [] rb = open_workbook(self.filename) print "Opened Excel file: "+ self.filename for row in range(2,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) # print "------------------------------------------\nConnection %i has %i from %s to %s (type: %s, synapse: %s)" %(row, num, pre, post, syntype, synclass) # print "----------------------------------------------------------------------" return cells, conns
def read(self): conns = [] cells = [] cell_names = owr.get_cells_in_model() for s in self.all_connections: pre = str(s.pre_cell().name()) post = str(s.post_cell().name()) if isinstance( s.post_cell(), P.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) logger.info("Total cells read " + str(len(cells))) logger.info("Total connections read " + str(len(conns))) P.disconnect() return cells, conns
def readDataFromSpreadsheet(dir="../../"): conns = [] cells = [] filename = dir + "CElegansNeuronTables.xls" rb = open_workbook(filename) print "Opened Excel file: " + filename for row in range(2, 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) # print "------------------------------------------\nConnection %i has %i from %s to %s (type: %s, synapse: %s)" %(row, num, pre, post, syntype, synclass) # print "----------------------------------------------------------------------" return cells, conns
def readMuscleDataFromSpreadsheet(): """ 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, 'rb') 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) or not is_body_wall_muscle(post): # Don't add connections unless pre=neuron and post=body_wall_muscle continue pre = remove_leading_index_zero(pre) post = get_old_muscle_name(post) conns.append(ConnectionInfo(pre, post, num, syntype, synclass)) #print 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 readMuscleData(self): conns = [] neurons = [] muscles = [] for s in self.muscle_connections: pre = str(s.pre_cell().name()) post = str(s.post_cell().name()) syntype = str(s.syntype()) num = int(s.number()) synclass = str(s.synclass()) conns.append(ConnectionInfo(pre, post, num, syntype, synclass)) if isinstance(s.post_cell(), P.Muscle) and post not in muscles: muscles.append(post) elif post not in neurons: neurons.append(post) if isinstance(s.pre_cell(), P.Muscle) and pre not in muscles: muscles.append(pre) elif post not in neurons: neurons.append(pre) logger.info("Total neurons connected to muscles read " + str(len(neurons))) logger.info("Total muscles connected to neurons read " + str(len(muscles))) logger.info("Total connections between neurons and muscles read " + str(len(conns))) return neurons, muscles, conns
def read(self, include_nonconnected_cells=False): conns = [] cells = [] for s in self.neuron_connections: pre = str(s.pre_cell().name()) post = str(s.post_cell().name()) syntype = str(s.syntype()) num = int(s.number()) synclass = str(s.synclass()) conns.append(ConnectionInfo(pre, post, num, syntype, synclass)) if pre not in cells: cells.append(pre) if post not in cells: cells.append(post) known_nonconnected_cells = ['CANL', 'CANR', 'VC6'] # ignore the cells unconnected if neuron_connect = True if(include_nonconnected_cells): for c in known_nonconnected_cells: # to avoid an exception: nonconnected cell becomes connected. if c not in cells: cells.append(c) logger.info("Total cells read " + str(len(cells))) logger.info("Total connections read " + str(len(conns))) return cells, conns
def read(self): conns = [] cells = [] for s in self.net.synapses(): pre = str(s[0]) post = str(s[1]) syntype = str(s[2][0]) num = int(s[2][2]) synclass = str(s[2][2]) 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
def read(self): conns = [] cells = [] for s in self.all_connections: pre = str(s.pre_cell()) post = str(s.post_cell()) syntype = str(s.syntype()) num = int(s.number()) synclass = str(s.synclass()) conns.append(ConnectionInfo(pre, post, num, syntype, synclass)) if pre not in cells: cells.append(pre) if post not in cells: cells.append(post) logger.info("Total cells read " + str(len(cells))) logger.info("Total connections read " + str(len(conns))) P.disconnect() return cells, conns
def readDataFromSpreadsheet(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_data(include_nonconnected_cells=False): print_("Initialising OpenWormReader") P.connect() net = P.Worm().get_neuron_network() all_connections = net.synapses() print_("Finished initialising OpenWormReader") 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(), P.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)) P.disconnect() if include_nonconnected_cells: return cell_names, conns else: return cells, conns