Skip to content

Commit ebdaf4e

Browse files
author
Elisabetta Iavarone
committed
First draft of exercise notebook
1 parent 2e86f3b commit ebdaf4e

30 files changed

Lines changed: 32574 additions & 0 deletions

FENS2016/exercise/Sst-IRES-Cre_Ai14_IVSCC_-183332.05.02.01_486041253_m.swc

Lines changed: 2221 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
"""Run simple cell optimisation"""
2+
3+
"""
4+
Copyright (c) 2016, EPFL/Blue Brain Project
5+
This file is part of BluePyOpt <https://github.com/BlueBrain/BluePyOpt>
6+
This library is free software; you can redistribute it and/or modify it under
7+
the terms of the GNU Lesser General Public License version 3.0 as published
8+
by the Free Software Foundation.
9+
This library is distributed in the hope that it will be useful, but WITHOUT
10+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11+
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12+
details.
13+
You should have received a copy of the GNU Lesser General Public License
14+
along with this library; if not, write to the Free Software Foundation, Inc.,
15+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16+
"""
17+
# pylint: disable=R0914
18+
19+
import os
20+
import json
21+
22+
#import l5pc_model # NOQA
23+
24+
import bluepyopt.ephys as ephys
25+
26+
script_dir = os.path.dirname(__file__)
27+
config_dir = os.path.join(script_dir, 'config')
28+
29+
# TODO store definition dicts in json
30+
# TODO rename 'score' into 'objective'
31+
# TODO add functionality to read settings of every object from config format
32+
33+
def define_protocols():
34+
"""Define protocols"""
35+
36+
protocol_definitions = json.load(
37+
open(
38+
os.path.join(
39+
config_dir,
40+
'protocols.json')))
41+
42+
protocols = {}
43+
44+
soma_loc = ephys.locations.NrnSeclistCompLocation(
45+
name='soma',
46+
seclist_name='somatic',
47+
sec_index=0,
48+
comp_x=0.5)
49+
50+
for protocol_name, protocol_definition in protocol_definitions.iteritems():
51+
# By default include somatic recording
52+
somav_recording = ephys.recordings.CompRecording(
53+
name='%s.soma.v' %
54+
protocol_name,
55+
location=soma_loc,
56+
variable='v')
57+
58+
recordings = [somav_recording]
59+
60+
if 'extra_recordings' in protocol_definition:
61+
for recording_definition in protocol_definition['extra_recordings']:
62+
if recording_definition['type'] == 'somadistance':
63+
location = ephys.locations.NrnSomaDistanceCompLocation(
64+
name=recording_definition['name'],
65+
soma_distance=recording_definition['somadistance'],
66+
seclist_name=recording_definition['seclist_name'])
67+
var = recording_definition['var']
68+
recording = ephys.recordings.CompRecording(
69+
name='%s.%s.%s' % (protocol_name, location.name, var),
70+
location=location,
71+
variable=recording_definition['var'])
72+
73+
recordings.append(recording)
74+
else:
75+
raise Exception(
76+
'Recording type %s not supported' %
77+
recording_definition['type'])
78+
79+
stimuli = []
80+
for stimulus_definition in protocol_definition['stimuli']:
81+
stimuli.append(ephys.stimuli.NrnSquarePulse(
82+
step_amplitude=stimulus_definition['amp'],
83+
step_delay=stimulus_definition['delay'],
84+
step_duration=stimulus_definition['duration'],
85+
location=soma_loc,
86+
total_duration=stimulus_definition['totduration']))
87+
88+
protocols[protocol_name] = ephys.protocols.SweepProtocol(
89+
protocol_name,
90+
stimuli,
91+
recordings)
92+
93+
return protocols
94+
95+
96+
def define_fitness_calculator(protocols):
97+
"""Define fitness calculator"""
98+
99+
feature_definitions = json.load(
100+
open(
101+
os.path.join(
102+
config_dir,
103+
'features.json')))
104+
105+
# TODO: add bAP stimulus
106+
objectives = []
107+
108+
for protocol_name, locations in feature_definitions.iteritems():
109+
for location, features in locations.iteritems():
110+
for efel_feature_name, meanstd in features.iteritems():
111+
feature_name = '%s.%s.%s' % (
112+
protocol_name, location, efel_feature_name)
113+
recording_names = {'': '%s.%s.v' % (protocol_name, location)}
114+
stimulus = protocols[protocol_name].stimuli[0]
115+
116+
stim_start = stimulus.step_delay
117+
118+
if location == 'soma':
119+
threshold = -20
120+
elif 'dend' in location:
121+
threshold = -55
122+
123+
if protocol_name == 'bAP':
124+
stim_end = stimulus.total_duration
125+
else:
126+
stim_end = stimulus.step_delay + stimulus.step_duration
127+
128+
feature = ephys.efeatures.eFELFeature(
129+
feature_name,
130+
efel_feature_name=efel_feature_name,
131+
recording_names=recording_names,
132+
stim_start=stim_start,
133+
stim_end=stim_end,
134+
exp_mean=meanstd[0],
135+
exp_std=meanstd[1],
136+
threshold=threshold)
137+
objective = ephys.objectives.SingletonObjective(
138+
feature_name,
139+
feature)
140+
objectives.append(objective)
141+
142+
fitcalc = ephys.objectivescalculators.ObjectivesCalculator(objectives)
143+
144+
return fitcalc
145+
146+
147+
# def create():
148+
# """Setup"""
149+
150+
# l5pc_cell = l5pc_model.create()
151+
152+
# fitness_protocols = define_protocols()
153+
# fitness_calculator = define_fitness_calculator(fitness_protocols)
154+
155+
# param_names = [param.name
156+
# for param in l5pc_cell.params.values()
157+
# if not param.frozen]
158+
159+
# sim = ephys.simulators.NrnSimulator()
160+
161+
# return ephys.evaluators.CellEvaluator(
162+
# cell_model=l5pc_cell,
163+
# param_names=param_names,
164+
# fitness_protocols=fitness_protocols,
165+
# fitness_calculator=fitness_calculator,
166+
# sim=sim)

FENS2016/exercise/cell_model.py

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
"""Run simple cell optimisation"""
2+
3+
"""
4+
Copyright (c) 2016, EPFL/Blue Brain Project
5+
This file is part of BluePyOpt <https://github.com/BlueBrain/BluePyOpt>
6+
This library is free software; you can redistribute it and/or modify it under
7+
the terms of the GNU Lesser General Public License version 3.0 as published
8+
by the Free Software Foundation.
9+
This library is distributed in the hope that it will be useful, but WITHOUT
10+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11+
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12+
details.
13+
You should have received a copy of the GNU Lesser General Public License
14+
along with this library; if not, write to the Free Software Foundation, Inc.,
15+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16+
"""
17+
# pylint: disable=R0914
18+
19+
import os
20+
import json
21+
22+
import bluepyopt.ephys as ephys
23+
24+
script_dir = os.path.dirname(__file__)
25+
config_dir = os.path.join(script_dir, 'config')
26+
27+
# TODO store definition dicts in json
28+
# TODO rename 'score' into 'objective'
29+
# TODO add functionality to read settings of every object from config format
30+
31+
32+
def define_mechanisms():
33+
"""Define mechanisms"""
34+
35+
mech_definitions = json.load(
36+
open(
37+
os.path.join(
38+
config_dir,
39+
'mechanisms.json')))
40+
41+
mechanisms = []
42+
for sectionlist, channels in mech_definitions.iteritems():
43+
seclist_loc = ephys.locations.NrnSeclistLocation(
44+
sectionlist,
45+
seclist_name=sectionlist)
46+
for channel in channels:
47+
mechanisms.append(ephys.mechanisms.NrnMODMechanism(
48+
name='%s.%s' % (channel, sectionlist),
49+
mod_path=None,
50+
prefix=channel,
51+
locations=[seclist_loc],
52+
preloaded=True))
53+
54+
return mechanisms
55+
56+
57+
def define_parameters():
58+
"""Define parameters"""
59+
60+
param_configs = json.load(open(os.path.join(config_dir, 'parameters.json')))
61+
parameters = []
62+
63+
for param_config in param_configs:
64+
if 'value' in param_config:
65+
frozen = True
66+
value = param_config['value']
67+
bounds = None
68+
elif 'bounds':
69+
frozen = False
70+
bounds = param_config['bounds']
71+
value = None
72+
else:
73+
raise Exception(
74+
'Parameter config has to have bounds or value: %s'
75+
% param_config)
76+
77+
if param_config['type'] == 'global':
78+
parameters.append(
79+
ephys.parameters.NrnGlobalParameter(
80+
name=param_config['param_name'],
81+
param_name=param_config['param_name'],
82+
frozen=frozen,
83+
bounds=bounds,
84+
value=value))
85+
elif param_config['type'] in ['section', 'range']:
86+
if param_config['dist_type'] == 'uniform':
87+
scaler = ephys.parameterscalers.NrnSegmentLinearScaler()
88+
elif param_config['dist_type'] == 'exp':
89+
scaler = ephys.parameterscalers.NrnSegmentSomaDistanceScaler(
90+
distribution=param_config['dist'])
91+
seclist_loc = ephys.locations.NrnSeclistLocation(
92+
param_config['sectionlist'],
93+
seclist_name=param_config['sectionlist'])
94+
95+
name = '%s.%s' % (param_config['param_name'],
96+
param_config['sectionlist'])
97+
98+
if param_config['type'] == 'section':
99+
parameters.append(
100+
ephys.parameters.NrnSectionParameter(
101+
name=name,
102+
param_name=param_config['param_name'],
103+
value_scaler=scaler,
104+
value=value,
105+
frozen=frozen,
106+
bounds=bounds,
107+
locations=[seclist_loc]))
108+
elif param_config['type'] == 'range':
109+
parameters.append(
110+
ephys.parameters.NrnRangeParameter(
111+
name=name,
112+
param_name=param_config['param_name'],
113+
value_scaler=scaler,
114+
value=value,
115+
frozen=frozen,
116+
bounds=bounds,
117+
locations=[seclist_loc]))
118+
else:
119+
raise Exception(
120+
'Param config type has to be global, section or range: %s' %
121+
param_config)
122+
123+
return parameters
124+
125+
126+
# def define_morphology():
127+
# """Define morphology"""
128+
129+
# return ephys.morphologies.NrnFileMorphology(
130+
# os.path.join(
131+
# script_dir,
132+
# 'morphology/C060114A7.asc'),
133+
# do_replace_axon=True)
134+
135+
136+
def create():
137+
"""Create cell model"""
138+
139+
cell = ephys.models.CellModel(
140+
'abi_cell',
141+
morph=define_morphology(),
142+
mechs=define_mechanisms(),
143+
params=define_parameters())
144+
145+
return cell

0 commit comments

Comments
 (0)