def populate(infile, outfile): dbmodel.db.connect() dbmodel.create_db() from dbmodel import Cells, Synapses # load the individual neurons indata = pickle.load(open(infile, 'r')) neurons = indata['neurons'] for neuron_name, nd in neurons.iterrows(): nt = nd['neurotransmitters'] if type(nt) == float: nt = None role = nd['role'] if type(role)==float: role = None Cells.create(cell_name =neuron_name, cell_class= nd['class'], soma_pos = nd['soma_pos'], neurotransmitters=nt, role = role) connections = indata['connections'] for n1 in neurons.index.values: for n2 in neurons.index.values: c1 = Cells.get(Cells.cell_name == n1) c2 = Cells.get(Cells.cell_name == n2) c = (n1, n2) if c in connections: for synapse_type, nbr in connections[c]: code = synapse_type[0] st_short = None # note this dataset includes entries for both A sends to B (type S) and B receives from A (type R) if code == "Sp" or code == 'S': st_short = 'C' elif code == 'E': st_short = 'E' elif code == 'R' or code == 'Rp': pass else: raise Exception("code %s not understood" % code) if st_short: s = Synapses.select().where(Synapses.from_id == c1, Synapses.to_id == c2, Synapses.synapse_type == st_short).count() if s == 0: Synapses.create(from_id = c1, to_id = c2, synapse_type = st_short, count = nbr) else: Synapses.update(count = Synapses.count + nbr).where(Synapses.from_id == c1, Synapses.to_id == c2, synapse_type == st_short) dbmodel.db.close()
def populate(infile, outfile): dbmodel.db.connect() dbmodel.create_db() from dbmodel import Cells, Synapses # load the individual neurons indata = pickle.load(open(infile, 'r')) neurons = indata['neurons'] for neuron_name, nd in neurons.iterrows(): nt = nd['neurotransmitters'] if type(nt) == float: nt = None role = nd['role'] if type(role) == float: role = None Cells.create(cell_name=neuron_name, cell_class=nd['class'], soma_pos=nd['soma_pos'], neurotransmitters=nt, role=role) connections = indata['connections'] for n1 in neurons.index.values: for n2 in neurons.index.values: c1 = Cells.get(Cells.cell_name == n1) c2 = Cells.get(Cells.cell_name == n2) c = (n1, n2) if c in connections: for synapse_type, nbr in connections[c]: code = synapse_type[0] st_short = None # note this dataset includes entries for both A sends to B (type S) and B receives from A (type R) if code == "Sp" or code == 'S': st_short = 'C' elif code == 'E': st_short = 'E' elif code == 'R' or code == 'Rp': pass else: raise Exception("code %s not understood" % code) if st_short: s = Synapses.select().where( Synapses.from_id == c1, Synapses.to_id == c2, Synapses.synapse_type == st_short).count() if s == 0: Synapses.create(from_id=c1, to_id=c2, synapse_type=st_short, count=nbr) else: Synapses.update(count=Synapses.count + nbr).where( Synapses.from_id == c1, Synapses.to_id == c2, synapse_type == st_short) dbmodel.db.close()
def populate_db(infile, outfile): dbmodel.db.connect() from dbmodel import Types, Cells, SomaPositions, Contacts with dbmodel.db.transaction(): types_df = pickle.load(open('type_metadata.pickle', 'r'))['type_metadata'] for r_id, r in types_df.iterrows(): print "rid=", r_id t = Types.create(type_id = int(r_id), designation = r['desig'], volgyi_type = r['volgyi'], macneil_type = r['macneil'], certainty = r['certainty'], coarse = r['coarse']) t.save() # create the additional types, because... this data is noisy for i in range(72, 79): t = Types.create(type_id = i) cell_types = pickle.load(open('xlsxdata.pickle', 'r'))['types'] for c_i, c_t in cell_types.iteritems(): c = Cells.create(cell_id = c_i, type_id = Types.get(Types.type_id == c_t)) c.save() pos = pickle.load(open("soma.positions.pickle", 'r')) for k, v in pos['pos'].iteritems(): p = SomaPositions.create(cell_id = Cells.get(Cells.cell_id ==k), x = v[0], y =v[1], z=v[2]) p.save() s = pickle.load(open("synapses.pickle", 'r')) for r_id, r in s['synapsedf'].iterrows(): for from_id in Cells.select().where(Cells.cell_id == r['from_id']): for to_id in Cells.select().where(Cells.cell_id == r['to_id']): # WE ARE INTENTIONALLY THROWING OUT ALL THE CONTACTS # that have cell_ids that don't map to known cells. Contacts.create(from_id = from_id, to_id = to_id, x = r['x'], y=r['y'], z=r['z'], area = r['area']).save() dbmodel.db.close() open(outfile, 'w').write(" ")