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 create_db(_, outfile): dbmodel.db.connect() dbmodel.create_db()