def __init__(self, analyzer_mode): s = db.session() self._signalHandler = SignalHandler() self.sigOutputChanged = self._signalHandler.sigOutputChanged self.analyzer_mode = analyzer_mode self.pairs = None self.acsf = None projects = s.query(db.Experiment.project_name).distinct().all() projects = [project[0] for project in projects if project[0] is not None or ''] acsfs = s.query(db.Experiment.acsf).distinct().all() acsfs = [acsf[0] for acsf in acsfs if acsf[0] is not None or ''] acsf_expand = False internals = s.query(db.Experiment.internal).distinct().all() internals = [internal[0] for internal in internals if internal[0] is not None or ''] internal_expand = False if self.analyzer_mode == 'external': self.project_keys = {'Mouse': ['mouse V1 pre-production', 'mouse V1 coarse matrix'], 'Human': ['human coarse matrix']} projects = self.project_keys.keys() self.internal_keys = {'0.3mM EGTA': ['Standard K-Gluc'], '1mM EGTA': ['K-Gluc 1uM EGTA', ' K-Gluc 1uM EGTA'], 'No EGTA': ['K-Gluc -EGTA']} internals = self.internal_keys.keys() self.acsf_keys = {'1.3mM': ['1.3mM Ca & 1mM Mg'], '2mM': ['2mM Ca & Mg']} acsfs = self.acsf_keys.keys() acsf_expand = True internal_expand = True project_list = [{'name': str(project), 'type': 'bool'} for project in projects] acsf_list = [{'name': str(acsf), 'type': 'bool'} for acsf in acsfs] internal_list = [{'name': str(internal), 'type': 'bool'} for internal in internals] self.params = Parameter.create(name='Data Filters', type='group', children=[ {'name': 'Projects', 'type': 'group', 'children':project_list}, {'name': 'ACSF [Ca2+]', 'type': 'group', 'children':acsf_list, 'expanded': acsf_expand}, {'name': 'Internal [EGTA]', 'type': 'group', 'children': internal_list, 'expanded': internal_expand}, ]) self.params.sigTreeStateChanged.connect(self.invalidate_output)
def __init__(self): pg.QtCore.QObject.__init__(self) # global session for querying from DB self.session = db.session() win = pg.QtGui.QSplitter() win.setOrientation(pg.QtCore.Qt.Horizontal) win.resize(1000, 800) win.show() b = ExperimentBrowser() b.populate() win.addWidget(b) rs_plots = ResponseStrengthPlots(self.session) win.addWidget(rs_plots) b.itemSelectionChanged.connect(self._selected) b.doubleClicked.connect(self._dbl_clicked) self.win = win self.rs_plots = rs_plots self.browser = b self.nwb_viewer = MultipatchNwbViewer()
def populate(self, experiments=None): self.items_by_pair_id = {} self.session = db.session() if experiments is None: experiments = db.list_experiments(session=self.session) # preload all cells,pairs so they are not queried individually later on pairs = self.session.query(db.Pair, db.Experiment, db.Cell, db.Slice).join(db.Experiment, db.Pair.experiment_id==db.Experiment.id).join(db.Cell, db.Cell.id==db.Pair.pre_cell_id).join(db.Slice).all() experiments.sort(key=lambda e: e.acq_timestamp) for expt in experiments: date = expt.acq_timestamp date_str = datetime.fromtimestamp(date).strftime('%Y-%m-%d') slice = expt.slice expt_item = pg.TreeWidgetItem(map(str, [date_str, '%0.3f'%expt.acq_timestamp, expt.rig_name, slice.species, expt.project_name, expt.target_region, slice.genotype, expt.acsf])) expt_item.expt = expt self.addTopLevelItem(expt_item) for pair in expt.pair_list: # if pair.n_ex_test_spikes == 0 and pair.n_in_test_spikes == 0: # continue cells = '%s => %s' % (pair.pre_cell.ext_id, pair.post_cell.ext_id) conn = {True:"syn", False:"-", None:"?"}[pair.has_synapse] types = 'L%s %s => L%s %s' % (pair.pre_cell.target_layer or "?", pair.pre_cell.cre_type, pair.post_cell.target_layer or "?", pair.post_cell.cre_type) pair_item = pg.TreeWidgetItem([cells, conn, types]) expt_item.addChild(pair_item) pair_item.pair = pair pair_item.expt = expt self.items_by_pair_id[pair.id] = pair_item # also allow select by ext id self.items_by_pair_id[(expt.acq_timestamp, pair.pre_cell.ext_id, pair.post_cell.ext_id)] = pair_item self.verticalScrollBar().setValue(self.verticalScrollBar().maximum())
from multipatch_analysis.database import default_db as db from multipatch_analysis.data import Analyzer, PulseStimAnalyzer, MultiPatchProbe import pyqtgraph as pg pg.dbg() # for inspecting exception stack expt_id = float(sys.argv[1]) cell_id = int(sys.argv[2]) ui = SpikeDetectUI() skip_btn = pg.QtGui.QPushButton('skip') ui.widget.addWidget(skip_btn) save_btn = pg.QtGui.QPushButton('save') ui.widget.addWidget(save_btn) session = db.session() def iter_pulses(): """Generator that yields all selected pulses one at a time. """ # look up experiment from database and load the NWB file expt = db.experiment_from_timestamp(expt_id) cell = expt.cells[cell_id] channel = cell.electrode.device_id sweeps = expt.data.contents for sweep in sweeps: # Ignore sweep if it doesn't have the requested channel, or the correct stimulus try: pre_rec = sweep[channel]
def query_all_pairs(classifier=None): columns = [ "synapse_prediction.*", "experiment.id as experiment_id", "experiment.acq_timestamp as acq_timestamp", "experiment.rig_name", "experiment.acsf", "slice.species as donor_species", "slice.genotype as donor_genotype", "slice.age as donor_age", "slice.sex as donor_sex", "slice.quality as slice_quality", "slice.weight as donor_weight", "slice.slice_time", "pre_cell.ext_id as pre_cell_id", "pre_cell.cre_type as pre_cre_type", "pre_cell.target_layer as pre_target_layer", "pre_morphology.pyramidal as pre_pyramidal", "post_cell.ext_id as post_cell_id", "post_cell.cre_type as post_cre_type", "post_cell.target_layer as post_target_layer", "post_morphology.pyramidal as post_pyramidal", "pair.has_synapse", "pair.distance", "pair.crosstalk_artifact", # "abs(post_cell.ext_id - pre_cell.ext_id) as electrode_distance", ] # columns.extend([ # "detection_limit.minimum_amplitude", # ]) joins = [ "join pair on synapse_prediction.pair_id=pair.id", "join cell pre_cell on pair.pre_cell_id=pre_cell.id", "join cell post_cell on pair.post_cell_id=post_cell.id", "join morphology pre_morphology on pre_morphology.cell_id=pre_cell.id", "join morphology post_morphology on post_morphology.cell_id=post_cell.id", "join experiment on pair.experiment_id=experiment.id", "join slice on experiment.slice_id=slice.id", ] # joins.extend([ # "left join detection_limit on detection_limit.pair_id=pair.id", # ]) query = (""" select {columns} from synapse_prediction {joins} order by acq_timestamp """).format( columns=", ".join(columns), joins=" ".join(joins), ) session = db.session() df = pandas.read_sql(query, session.bind) recs = df.to_records() if classifier is None: return recs # Fit classifier and add results of classifier prediction in to records classifier.fit(recs) prediction = classifier.predict(recs) recs = join_struct_arrays([recs, prediction]) return recs
def __init__(self, expt_browser=None): if expt_browser is None: expt_browser = ExperimentBrowser() self.expt_browser = expt_browser expt_browser.itemSelectionChanged.connect(self.expt_selection_changed) self.session = db.session() self.pair = None self.response_list = None self.corrected_response_list = None self._plot_items = [] self.params = pg.parametertree.Parameter( name="crosstalk removal", type="group", children=[ dict(name='data', type='group', children=[ dict(name='pre mode', type='list', values=['ic', 'vc']), dict(name='post mode', type='list', values=['ic', 'vc']), dict(name='limit', type='int', value=100), ]), dict(name='correction', type='group', children=[ dict(name='stimulus', type='bool', value=True, children=[ dict(name='auto', type='action'), dict(name='shift', type='int', value=0), dict(name='scale', type='float', value=30e3, dec=True, step=0.5), dict(name='lowpass', type='float', value=7e3, dec=True, step=0.5, suffix='Hz', siPrefix=True), ]), dict(name='charging', type='bool', value=True, children=[ dict(name='auto', type='action'), dict(name='capacitance', type='float', value=10e-12, suffix='F', dec=True, step=0.5, siPrefix=True), dict(name='resistance', type='float', value=10e6, suffix=u'Ω', dec=True, step=0.5, siPrefix=True), dict(name='scale', type='float', value=30e3, dec=True, step=0.5), dict(name='lowpass', type='float', value=7e3, dec=True, step=0.5, suffix='Hz', siPrefix=True), ]), dict(name='spike', type='bool', value=False, children=[ dict(name='scale', type='float', value=0.001, dec=True, step=0.5), dict(name='lowpass', type='float', value=10e3, dec=True, step=0.5, suffix='Hz', siPrefix=True), ]), dict(name='spike dv/dt', type='bool', value=True, children=[ dict(name='plot only', type='bool', value=False), dict(name='scale', type='float', value=0.03, dec=True, step=0.5), dict(name='lowpass', type='float', value=550., dec=True, step=0.5, suffix='Hz', siPrefix=True), ]), ]), dict(name='display', type='group', children=[ dict(name='limit', type='int', value=20), dict(name='plot spike aligned', type='bool', value=False), dict(name='plot dv/dt', type='bool', value=False), dict(name='plot lowpass', type='float', value=10e3, dec=True, step=0.5, suffix='Hz', siPrefix=True), ]) ]) self.ptree = pg.parametertree.ParameterTree() self.ptree.setParameters(self.params) self.params.child('data').sigTreeStateChanged.connect( self.data_filter_changed) self.params.child('correction').sigTreeStateChanged.connect( self.update_analysis) self.params.child('display').sigTreeStateChanged.connect( self.update_display) self.params.child('correction', 'stimulus', 'auto').sigActivated.connect(self.auto_stim_clicked) self.pw = pg.GraphicsLayoutWidget() self.plt1 = self.pw.addPlot(0, 0) self.plt2 = self.pw.addPlot(1, 0) self.plt3 = self.pw.addPlot(2, 0) self.plt2.setXLink(self.plt1) self.plt3.setXLink(self.plt1)
if __name__ == '__main__': app = pg.mkQApp() parser = argparse.ArgumentParser() parser.add_argument('--check', action='store_true') parser.add_argument('--timestamps', type=str, nargs='*') parser.add_argument('--dbg', default=False, action='store_true') parser.add_argument('expt_id', type=str, nargs='?', default=None) parser.add_argument('pre_cell_id', type=str, nargs='?', default=None) parser.add_argument('post_cell_id', type=str, nargs='?', default=None) args = parser.parse_args(sys.argv[1:]) if args.dbg: pg.dbg() default_session = db.session() notes_session = notes_db.db.session() timestamps = [ r.acq_timestamp for r in db.query(db.Experiment.acq_timestamp).all() ] mw = MainWindow(default_session, notes_session) if args.check is True: pair_in_notes = [] pair_not_in_notes = [] ghost_pair = [] print('checking %d pairs...' % len(synapses)) for pair in synapses: pair_notes = pair_notes_query(notes_session, pair).all() if len(pair_notes) == 0: pair_not_in_notes.append(pair)