예제 #1
0
def update_paths(ops_path, db_path, tmp_path, file_name, data_key):
    if ops_path == "[]":
        from suite2p.run_s2p import default_ops

        ops = default_ops()
    else:
        ops = np.load(ops_path, allow_pickle=True).item()

    if db_path == "[]":
        db = {}
    else:
        db = np.load(db_path, allow_pickle=True).item()

    # Modify the data path to the sciCORE job temp dir
    data_path = tmp_path
    fd_path = os.path.join(tmp_path, "fd")
    print("data: %s \n fd: %s" % (data_path, fd_path))

    ops["batch_size"] = 4000
    ops["input_format"] = "h5"

    db["data_path"] = []
    db["h5py"] = file_name
    db["h5py_key"] = data_key
    db["fast_disk"] = fd_path
    # db["save_folder"] = "/scicore/home/donafl00/yamauc0000/s2p_multisession"
    print(db)

    return ops, db
예제 #2
0
def run_suite2p(db, out_path, fs, nplanes):
    default = default_ops()
    default2 = {
        'save_path0': out_path,
        'delete_bin': False,
        'look_one_level_down': True,
        'data_path': db['in_dir'],
        'nplanes': nplanes,
        'fs': fs,
        'save_mat': True,
        'reg_tif': False,
        'expts': db['expts'],
        'raw': True,
    }

    if 'ops' in db:
        opts = db['ops']
    else:
        opts = {}

    ops = {**default, **default2, **opts}

    db = {}

    print(ops)

    ops = run_s2p(ops=ops, db=db)
    return ops
예제 #3
0
    def load_ops(self):
        print('loading ops')
        name = QtGui.QFileDialog.getOpenFileName(
            self, 'Open ops file (npy or json)')
        name = name[0]
        if len(name) > 0:
            ext = os.path.splitext(name)[1]
            try:
                if ext == '.npy':
                    ops = np.load(name, allow_pickle=True).item()
                elif ext == '.json':
                    with open(name, 'r') as f:
                        ops = json.load(f)
                ops0 = run_s2p.default_ops()
                ops = {**ops0, **ops}
                for key in ops:
                    if key != 'data_path' and key != 'save_path' and key != 'fast_disk' and key != 'cleanup' and key != 'save_path0' and key != 'h5py':
                        if key in self.keylist:
                            self.editlist[self.keylist.index(key)].set_text(
                                ops)
                        self.ops[key] = ops[key]
                if 'data_path' in ops and len(ops['data_path']) > 0:
                    self.data_path = ops['data_path']
                    for n in range(7):
                        if n < len(self.data_path):
                            self.qdata[n].setText(self.data_path[n])
                        else:
                            self.qdata[n].setText('')
                    self.runButton.setEnabled(True)
                    self.bh5py.setEnabled(False)
                    self.btiff.setEnabled(True)
                    self.listOps.setEnabled(True)
                    if hasattr(self, 'h5_path'):
                        self.h5text.setText('')
                        del self.h5_path
                elif 'h5py' in ops and len(ops['h5py']) > 0:
                    self.h5_path = ops['h5py']
                    self.h5_key = ops['h5py_key']
                    self.h5text.setText(ops['h5py'])
                    self.data_path = []
                    for n in range(7):
                        self.qdata[n].setText('')
                    self.runButton.setEnabled(True)
                    self.btiff.setEnabled(False)
                    self.bh5py.setEnabled(True)
                    self.listOps.setEnabled(True)
                if 'save_path0' in ops and len(ops['save_path0']) > 0:
                    self.save_path = ops['save_path0']
                    self.savelabel.setText(self.save_path)
                if 'fast_disk' in ops and len(ops['fast_disk']) > 0:
                    self.fast_disk = ops['fast_disk']
                    self.binlabel.setText(self.fast_disk)
                if 'clean_script' in ops and len(ops['clean_script']) > 0:
                    self.ops['clean_script'] = ops['clean_script']
                    self.cleanLabel.setText(ops['clean_script'])

            except Exception as e:
                print('could not load ops file')
                print(e)
예제 #4
0
def run_s2p_on(path,
               ops_file=None,
               reprocess=False,
               infer_from_recording_classes=False,
               inferrer=None):
    db = {'data_path': [path]}
    if ops_file == None:
        ops_file = os.path.join(path, "suite2p", "plane0", "ops.npy")
    try:
        ops = np.load(ops_file, allow_pickle=True).item()
        ops["keep_movie_raw"]  #This is so we get a KeyError
        ops["keep_movie_raw"] = True
        ops["connected"]
        ops["connected"] = False
        ops["max_overlap"]
        ops["max_overlap"] = 0.2
        ops["do_registration"]
        ops["do_registration"] = 2  #ALWAYS redo registration
        ops["look_one_level_down"]
        ops["look_one_level_down"] = True
    except FileNotFoundError:
        if all((any(["tif" in file for file in os.listdir(path)]),
                infer_from_recording_classes, inferrer != None)):
            #How many planes?
            no_of_planes = inferrer(exp_id(path))
            if no_of_planes == 1:
                ops = default_ops()
                ops["nchannels"] = 2
                ops["look_one_level_down"] = False
                ops["do_registration"] = 2
                ops["keep_movie_raw"] = True
                ops["align_by_chan"] = 2
                ops["nonrigid"] = False
                ops["connected"] = False
                ops["max_overlap"] = 0.2
                ops["bidi_corrected"] = True
                ops["two_step_reigstration"] = True
                ops["sparse_mode"] = True
                try:
                    run_s2p(ops=ops, db=db)
                except Exception as e:
                    print(
                        f"exception {e} raised at path {path} in response to run s2p call"
                    )
                    print(f"db file:")
                    for key, value in db.items():
                        print(f"{key}: {value}")
                    print(f"ops file:")
                    for key, value in ops.items():
                        print(f"{key}: {value}")
        else:
            print(f"No TIFFS at {path}" if infer_from_recording_classes else
                  f"{path} not yet processed.")
            return
    else:
        if not reprocess:
            print(f"{path} has already been processed by suite2p")
            return
        run_s2p(ops=ops, db=db)
예제 #5
0
파일: gui.py 프로젝트: mich11/suite2p-1
 def save_default_ops(self):
     name = self.opsfile
     ops = self.ops.copy()
     self.ops = run_s2p.default_ops()
     self.save_text()
     np.save(name, self.ops)
     self.ops = ops
     print('saved current settings in GUI as default ops')
예제 #6
0
def run_suite2p(hdf5_list, dirname_output, mdata):
    z_planes = mdata['size']['z_planes']
    fs_param = 1. / (mdata['period'] * z_planes)

    # Load suite2p only right before use, as it has a long load time.
    from suite2p import run_s2p
    default_ops = run_s2p.default_ops()
    params = {
        'input_format': 'h5',
        'data_path': [str(f.parent) for f in hdf5_list],
        'save_path0': str(dirname_output),
        'nplanes': z_planes,
        'fs': fs_param,
        'save_mat': True,
        'bidi_corrected': True,
        'spatial_hp': 50,
        'sparse_mode': False,
        'threshold_scaling': 3,
        'diameter': 6,
    }
    logger.info('Running suite2p on files:\n%s\n%s', '\n'.join(str(f) for f in hdf5_list), params)
    with open(dirname_output / 'recording_order.json', 'w') as fout:
        json.dump([str(e) for e in hdf5_list], fout, indent=4)
    run_s2p.run_s2p(ops=default_ops, db=params)
예제 #7
0
파일: gui.py 프로젝트: mich11/suite2p-1
    def __init__(self, parent=None):
        super(RunWindow, self).__init__(parent)
        self.setGeometry(50,50,1200,900)
        self.setWindowTitle('Choose run options')
        self.win = QtGui.QWidget(self)
        self.layout = QtGui.QGridLayout()
        self.layout.setHorizontalSpacing(25)
        self.win.setLayout(self.layout)
        # initial ops values
        self.opsfile = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                                          'ops/ops_user.npy')
        try:
            self.ops = np.load(self.opsfile)
            self.ops = self.ops.item()
            print('loaded default ops')
        except Exception as e:
            print('could not load default ops, using built-in ops settings')
            self.ops = run_s2p.default_ops()
        self.data_path = []
        self.save_path = []
        self.fast_disk = []
        self.opslist = []
        self.batch = False
        tifkeys = ['nplanes','nchannels','functional_chan','diameter','tau','fs','delete_bin']
        outkeys = [['save_mat','combined'],['num_workers','num_workers_roi']]
        regkeys = ['do_registration','align_by_chan','nimg_init', 'batch_size', 'maxregshift','smooth_sigma','keep_movie_raw', 'reg_tif','reg_tif_chan2']
        nrkeys = ['nonrigid','block_size','snr_thresh','maxregshiftNR']
        cellkeys = ['connected','max_overlap','threshold_scaling','smooth_masks','max_iterations','navg_frames_svd','nsvd_for_roi','ratio_neuropil','high_pass']
        neudeconvkeys = [['allow_overlap','inner_neuropil_radius','min_neuropil_pixels'], ['win_baseline','sig_baseline','prctile_baseline','neucoeff']]
        keys = [tifkeys, outkeys, regkeys, nrkeys, cellkeys, neudeconvkeys]
        labels = ['Main settings',['Output settings','Parallel'],'Registration','Nonrigid','ROI detection',['Extraction/Neuropil','Deconvolution']]
        tooltips = ['each tiff has this many planes in sequence',
                    'each tiff has this many channels per plane',
                    'this channel is used to extract functional ROIs (1-based)',
                    'approximate diameter of ROIs in pixels (can input two numbers separated by a comma for elongated ROIs)',
                    'timescale of sensor in deconvolution (in seconds)',
                    'sampling rate (per plane)',
                    'if 1, binary file is deleted after processing is complete',
                    'save output also as mat file "Fall.mat"',
                    'combine results across planes in separate folder "combined" at end of processing',
                    '0 to select num_cores, -1 to disable parallelism, N to enforce value',
                    'ROI detection parallelism: 0 to select number of planes, -1 to disable parallelism, N to enforce value',
                    'if 1, registration is performed',
                    'when multi-channel, you can align by non-functional channel (1-based)',
                    '# of subsampled frames for finding reference image',
                    'number of frames per batch',
                    'max allowed registration shift, as a fraction of frame max(width and height)',
                    '1.15 good for 2P recordings, recommend >5 for 1P recordings',
                    'if 1, unregistered binary is kept in a separate file data_raw.bin',
                    'if 1, registered tiffs are saved',
                    'if 1, registered tiffs of channel 2 (non-functional channel) are saved',
                    'whether to use nonrigid registration (splits FOV into blocks of size block_size)',
                    'block size in number of pixels in Y and X (two numbers separated by a comma)',
                    'if any nonrigid block is below this threshold, it gets smoothed until above this threshold. 1.0 results in no smoothing',
                    'maximum *pixel* shift allowed for nonrigid, relative to rigid',
                    'whether or not to require ROIs to be fully connected (set to 0 for dendrites/boutons)',
                    'ROIs with greater than this overlap as a fraction of total pixels will be discarded',
                    'adjust the automatically determined threshold by this scalar multiplier',
                    'whether to smooth masks in final pass of cell detection',
                    'maximum number of iterations for ROI detection',
                    'max number of binned frames for the SVD',
                    'max number of SVD components to keep for ROI detection',
                    'ratio between neuropil basis size and cell radius',
                    'running mean subtraction with window of size "high_pass" (use low values for 1P)',
                    'allow shared pixels to be used for fluorescence extraction from overlapping ROIs (otherwise excluded from both ROIs)',
                    'number of pixels between ROI and neuropil donut',
                    'minimum number of pixels in the neuropil',
                    'window for maximin',
                    'smoothing constant for gaussian filter',
                    'smoothing constant for gaussian filter',
                    'neuropil coefficient']

        bigfont = QtGui.QFont("Arial", 10, QtGui.QFont.Bold)
        qlabel = QtGui.QLabel('File paths')
        qlabel.setFont(bigfont)
        self.layout.addWidget(qlabel,0,0,1,1)
        #self.loadDb = QtGui.QPushButton('Load db.npy')
        #self.loadDb.clicked.connect(self.load_db)
        #self.layout.addWidget(self.loadDb,0,1,1,1)

        loadOps = QtGui.QPushButton('Load ops file')
        loadOps.clicked.connect(self.load_ops)
        saveDef = QtGui.QPushButton('Save ops as default')
        saveDef.clicked.connect(self.save_default_ops)
        saveOps = QtGui.QPushButton('Save ops to file')
        saveOps.clicked.connect(self.save_ops)
        self.layout.addWidget(loadOps,0,2,1,2)
        self.layout.addWidget(saveDef,1,2,1,2)
        self.layout.addWidget(saveOps,2,2,1,2)
        self.layout.addWidget(QtGui.QLabel(''),3,2,1,2)
        self.layout.addWidget(QtGui.QLabel('Load example ops'),4,2,1,2)
        for k in range(3):
            qw = QtGui.QPushButton('Save ops to file')
        saveOps.clicked.connect(self.save_ops)
        self.opsbtns = QtGui.QButtonGroup(self)
        opsstr = ['cell soma', 'dendrites/axons']
        self.opsname = ['soma', 'dendrite']
        for b in range(len(opsstr)):
            btn = OpsButton(b, opsstr[b], self)
            self.opsbtns.addButton(btn, b)
            self.layout.addWidget(btn, 5+b,2,1,2)
        l=0
        self.keylist = []
        self.editlist = []
        kk=0
        wk=0
        for lkey in keys:
            k = 0
            kl=0
            if type(labels[l]) is list:
                labs = labels[l]
                keyl = lkey
            else:
                labs = [labels[l]]
                keyl = [lkey]
            for label in labs:
                qlabel = QtGui.QLabel(label)
                qlabel.setFont(bigfont)
                self.layout.addWidget(qlabel,k*2,2*(l+2),1,2)
                k+=1
                for key in keyl[kl]:
                    lops = 1
                    if self.ops[key] or (self.ops[key] == 0):
                        qedit = LineEdit(wk,key,self)
                        qlabel = QtGui.QLabel(key)
                        qlabel.setToolTip(tooltips[kk])
                        qedit.set_text(self.ops)
                        qedit.setFixedWidth(90)
                        self.layout.addWidget(qlabel,k*2-1,2*(l+2),1,2)
                        self.layout.addWidget(qedit,k*2,2*(l+2),1,2)
                        self.keylist.append(key)
                        self.editlist.append(qedit)
                        wk+=1
                    k+=1
                    kk+=1
                kl+=1
            l+=1

        # data_path
        key = 'look_one_level_down'
        qlabel = QtGui.QLabel(key)
        qlabel.setToolTip('whether to look in all subfolders when searching for tiffs')
        self.layout.addWidget(qlabel,1,0,1,1)
        qedit = LineEdit(wk,key,self)
        qedit.set_text(self.ops)
        qedit.setFixedWidth(95)
        self.layout.addWidget(qedit,2,0,1,1)
        self.keylist.append(key)
        self.editlist.append(qedit)
        self.btiff = QtGui.QPushButton('Add directory to data_path')
        self.btiff.clicked.connect(self.get_folders)
        self.layout.addWidget(self.btiff,3,0,1,2)
        qlabel = QtGui.QLabel('data_path')
        qlabel.setFont(bigfont)
        self.layout.addWidget(qlabel,4,0,1,1)
        self.qdata = []
        for n in range(7):
            self.qdata.append(QtGui.QLabel(''))
            self.layout.addWidget(self.qdata[n],
                                  n+5,0,1,2)
        # save_path0
        self.bh5py = QtGui.QPushButton('OR add h5 file path')
        self.bh5py.clicked.connect(self.get_h5py)
        self.layout.addWidget(self.bh5py,11,0,1,2)
        self.h5text = QtGui.QLabel('')
        self.layout.addWidget(self.h5text,12,0,1,2)
        self.bsave = QtGui.QPushButton('Add save_path (default is 1st data_path)')
        self.bsave.clicked.connect(self.save_folder)
        self.layout.addWidget(self.bsave,13,0,1,2)
        self.savelabel = QtGui.QLabel('')
        self.layout.addWidget(self.savelabel,14,0,1,2)
        # fast_disk
        self.bbin = QtGui.QPushButton('Add fast_disk (default is save_path)')
        self.bbin.clicked.connect(self.bin_folder)
        self.layout.addWidget(self.bbin,15,0,1,2)
        self.binlabel = QtGui.QLabel('')
        self.layout.addWidget(self.binlabel,16,0,1,2)
        self.runButton = QtGui.QPushButton('RUN SUITE2P')
        self.runButton.clicked.connect(lambda: self.run_S2P(parent))
        self.layout.addWidget(self.runButton,19,0,1,1)
        self.runButton.setEnabled(False)
        self.textEdit = QtGui.QTextEdit()
        self.layout.addWidget(self.textEdit, 20,0,30,2*l)
        self.process = QtCore.QProcess(self)
        self.process.readyReadStandardOutput.connect(self.stdout_write)
        self.process.readyReadStandardError.connect(self.stderr_write)
        # disable the button when running the s2p process
        self.process.started.connect(self.started)
        self.process.finished.connect(lambda: self.finished(parent))
        # stop process
        self.stopButton = QtGui.QPushButton('STOP')
        self.stopButton.setEnabled(False)
        self.layout.addWidget(self.stopButton, 19,1,1,1)
        self.stopButton.clicked.connect(self.stop)
        # cleanup button
        self.cleanButton = QtGui.QPushButton('Add a clean-up *.py')
        self.cleanButton.setToolTip('will run at end of processing')
        self.cleanButton.setEnabled(True)
        self.layout.addWidget(self.cleanButton, 19,2,1,2)
        self.cleanup = False
        self.cleanButton.clicked.connect(self.clean_script)
        self.cleanLabel = QtGui.QLabel('')
        self.layout.addWidget(self.cleanLabel,19,4,1,12)
        self.listOps = QtGui.QPushButton('save settings and\n add more (batch)')
        self.listOps.clicked.connect(self.list_ops)
        self.layout.addWidget(self.listOps,19,14,1,2)
        self.listOps.setEnabled(False)
        self.removeOps = QtGui.QPushButton('remove last added')
        self.removeOps.clicked.connect(self.remove_ops)
        self.layout.addWidget(self.removeOps,19,16,1,2)
        self.removeOps.setEnabled(False)
        self.odata = []
        for n in range(10):
            self.odata.append(QtGui.QLabel(''))
            self.layout.addWidget(self.odata[n],
                                  20+n,14,1,4)
        self.f = 0
예제 #8
0
    def __init__(self, parent=None):
        super(RunWindow, self).__init__(parent)
        self.setGeometry(0, 0, 1500, 900)
        self.setWindowTitle(
            'Choose run options (hold mouse over parameters to see descriptions)'
        )
        self.win = QtGui.QWidget(self)
        self.layout = QtGui.QGridLayout()
        self.layout.setVerticalSpacing(2)
        self.layout.setHorizontalSpacing(25)
        self.win.setLayout(self.layout)
        # initial ops values
        self.opsfile = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                                    'ops/ops_user.npy')
        try:
            self.ops = np.load(self.opsfile, allow_pickle=True).item()
            ops0 = run_s2p.default_ops()
            self.ops = {**ops0, **self.ops}
            print('loaded default ops')
        except Exception as e:
            print('could not load default ops, using built-in ops settings')
            self.ops = run_s2p.default_ops()
        self.data_path = []
        self.save_path = []
        self.fast_disk = []
        self.opslist = []
        self.batch = False
        self.intkeys = [
            'nplanes', 'nchannels', 'functional_chan', 'align_by_chan',
            'nimg_init', 'batch_size', 'max_iterations', 'nbinned',
            'inner_neuropil_radius', 'min_neuropil_pixels', 'spatial_scale',
            'do_registration'
        ]
        self.boolkeys = [
            'delete_bin', 'do_bidiphase', 'reg_tif', 'reg_tif_chan2',
            'save_mat', 'combined', '1Preg', 'nonrigid', 'bruker', 'connected',
            'roidetect', 'keep_movie_raw', 'allow_overlap', 'sparse_mode'
        ]
        tifkeys = [
            'nplanes', 'nchannels', 'functional_chan', 'tau', 'fs',
            'delete_bin', 'do_bidiphase', 'bidiphase'
        ]
        outkeys = [
            'preclassify', 'save_mat', 'combined', 'reg_tif', 'reg_tif_chan2',
            'aspect', 'bruker'
        ]
        regkeys = [
            'do_registration', 'align_by_chan', 'nimg_init', 'batch_size',
            'smooth_sigma', 'maxregshift', 'th_badframes', 'keep_movie_raw'
        ]
        nrkeys = [['nonrigid', 'block_size', 'snr_thresh', 'maxregshiftNR'],
                  ['1Preg', 'spatial_hp', 'pre_smooth', 'spatial_taper']]
        cellkeys = [
            'roidetect', 'sparse_mode', 'diameter', 'spatial_scale',
            'connected', 'threshold_scaling', 'max_overlap', 'max_iterations',
            'high_pass'
        ]
        neudeconvkeys = [[
            'allow_overlap', 'inner_neuropil_radius', 'min_neuropil_pixels'
        ], ['win_baseline', 'sig_baseline', 'neucoeff']]
        keys = [tifkeys, outkeys, regkeys, nrkeys, cellkeys, neudeconvkeys]
        labels = [
            'Main settings', 'Output settings', 'Registration',
            ['Nonrigid', '1P'], 'ROI detection',
            ['Extraction/Neuropil', 'Deconvolution']
        ]
        tooltips = [
            'each tiff has this many planes in sequence',
            'each tiff has this many channels per plane',
            'this channel is used to extract functional ROIs (1-based)',
            'timescale of sensor in deconvolution (in seconds)',
            'sampling rate (per plane)',
            'if 1, binary file is deleted after processing is complete',
            'whether or not to compute bidirectional phase offset of recording (from line scanning)',
            'set a fixed number (in pixels) for the bidirectional phase offset',
            'apply ROI classifier before signal extraction with probability threshold (set to 0 to turn off)',
            'save output also as mat file "Fall.mat"',
            'combine results across planes in separate folder "combined" at end of processing',
            'if 1, registered tiffs are saved',
            'if 1, registered tiffs of channel 2 (non-functional channel) are saved',
            'um/pixels in X / um/pixels in Y (for correct aspect ratio in GUI)',
            'if you have bruker single-page tiffs with Ch1 and Ch2, say 1',
            "if 1, registration is performed if it wasn't performed already",
            'when multi-channel, you can align by non-functional channel (1-based)',
            '# of subsampled frames for finding reference image',
            'number of frames per batch',
            'gaussian smoothing after phase corr: 1.15 good for 2P recordings, recommend 2-5 for 1P recordings',
            'max allowed registration shift, as a fraction of frame max(width and height)',
            'this parameter determines which frames to exclude when determining cropped frame size - set it smaller to exclude more frames',
            'if 1, unregistered binary is kept in a separate file data_raw.bin',
            'whether to use nonrigid registration (splits FOV into blocks of size block_size)',
            'block size in number of pixels in Y and X (two numbers separated by a comma)',
            'if any nonrigid block is below this threshold, it gets smoothed until above this threshold. 1.0 results in no smoothing',
            'maximum *pixel* shift allowed for nonrigid, relative to rigid',
            'whether to perform high-pass filtering and tapering for registration (necessary for 1P recordings)',
            'window for spatial high-pass filtering before registration',
            'whether to smooth before high-pass filtering before registration',
            "how much to ignore on edges (important for vignetted windows, for FFT padding do not set BELOW 3*smooth_sigma)",
            'whether or not to run cell (ROI) detection',
            'whether to run sparse_mode cell extraction (scale-free) or original algorithm (default is original)',
            'if sparse_mode=0, input average diameter of ROIs in recording (can give a list e.g. 6,9)',
            'if sparse_mode=1, choose size of ROIs: 0 = multi-scale; 1 = 6 pixels, 2 = 12, 3 = 24, 4 = 48',
            'whether or not to require ROIs to be fully connected (set to 0 for dendrites/boutons)',
            'adjust the automatically determined threshold by this scalar multiplier',
            'ROIs with greater than this overlap as a fraction of total pixels will be discarded',
            'maximum number of iterations for ROI detection',
            'running mean subtraction with window of size "high_pass" (use low values for 1P)',
            'allow shared pixels to be used for fluorescence extraction from overlapping ROIs (otherwise excluded from both ROIs)',
            'number of pixels between ROI and neuropil donut',
            'minimum number of pixels in the neuropil', 'window for maximin',
            'smoothing constant for gaussian filter', 'neuropil coefficient'
        ]

        bigfont = QtGui.QFont("Arial", 10, QtGui.QFont.Bold)
        qlabel = QtGui.QLabel('File paths')
        qlabel.setFont(bigfont)
        self.layout.addWidget(qlabel, 0, 0, 1, 1)
        #self.loadDb = QtGui.QPushButton('Load db.npy')
        #self.loadDb.clicked.connect(self.load_db)
        #self.layout.addWidget(self.loadDb,0,1,1,1)

        loadOps = QtGui.QPushButton('Load ops file')
        loadOps.clicked.connect(self.load_ops)
        saveDef = QtGui.QPushButton('Save ops as default')
        saveDef.clicked.connect(self.save_default_ops)
        saveOps = QtGui.QPushButton('Save ops to file')
        saveOps.clicked.connect(self.save_ops)
        self.layout.addWidget(loadOps, 0, 2, 1, 2)
        self.layout.addWidget(saveDef, 1, 2, 1, 2)
        self.layout.addWidget(saveOps, 2, 2, 1, 2)
        self.layout.addWidget(QtGui.QLabel(''), 3, 2, 1, 2)
        self.layout.addWidget(QtGui.QLabel('Load example ops'), 4, 2, 1, 2)
        for k in range(3):
            qw = QtGui.QPushButton('Save ops to file')
        saveOps.clicked.connect(self.save_ops)
        self.opsbtns = QtGui.QButtonGroup(self)
        opsstr = ['1P imaging', 'dendrites/axons']
        self.opsname = ['1P', 'dendrite']
        for b in range(len(opsstr)):
            btn = OpsButton(b, opsstr[b], self)
            self.opsbtns.addButton(btn, b)
            self.layout.addWidget(btn, 5 + b, 2, 1, 2)
        l = 0
        self.keylist = []
        self.editlist = []
        kk = 0
        wk = 0
        for lkey in keys:
            k = 0
            kl = 0
            if type(labels[l]) is list:
                labs = labels[l]
                keyl = lkey
            else:
                labs = [labels[l]]
                keyl = [lkey]
            for label in labs:
                qlabel = QtGui.QLabel(label)
                qlabel.setFont(bigfont)
                self.layout.addWidget(qlabel, k * 2, 2 * (l + 2), 1, 2)
                k += 1
                for key in keyl[kl]:
                    lops = 1
                    if self.ops[key] or (self.ops[key] == 0):
                        qedit = LineEdit(wk, key, self)
                        qlabel = QtGui.QLabel(key)
                        qlabel.setToolTip(tooltips[kk])
                        qedit.set_text(self.ops)
                        qedit.setToolTip(tooltips[kk])
                        qedit.setFixedWidth(90)
                        self.layout.addWidget(qlabel, k * 2 - 1, 2 * (l + 2),
                                              1, 2)
                        self.layout.addWidget(qedit, k * 2, 2 * (l + 2), 1, 2)
                        self.keylist.append(key)
                        self.editlist.append(qedit)
                        wk += 1
                    k += 1
                    kk += 1
                kl += 1
            l += 1

        # data_path
        key = 'look_one_level_down'
        qlabel = QtGui.QLabel(key)
        qlabel.setToolTip(
            'whether to look in all subfolders when searching for tiffs')
        self.layout.addWidget(qlabel, 1, 0, 1, 1)
        qedit = LineEdit(wk, key, self)
        qedit.set_text(self.ops)
        qedit.setFixedWidth(95)
        self.layout.addWidget(qedit, 2, 0, 1, 1)
        self.keylist.append(key)
        self.editlist.append(qedit)
        self.btiff = QtGui.QPushButton('Add directory to data_path')
        self.btiff.clicked.connect(self.get_folders)
        self.layout.addWidget(self.btiff, 3, 0, 1, 2)
        qlabel = QtGui.QLabel('data_path')
        qlabel.setFont(bigfont)
        self.layout.addWidget(qlabel, 4, 0, 1, 1)
        self.qdata = []
        for n in range(7):
            self.qdata.append(QtGui.QLabel(''))
            self.layout.addWidget(self.qdata[n], n + 5, 0, 1, 2)
        # save_path0
        self.bh5py = QtGui.QPushButton('OR add h5 file path')
        self.bh5py.clicked.connect(self.get_h5py)
        self.layout.addWidget(self.bh5py, 11, 0, 1, 2)
        self.h5text = QtGui.QLabel('')
        self.layout.addWidget(self.h5text, 12, 0, 1, 2)
        self.bsave = QtGui.QPushButton(
            'Add save_path (default is 1st data_path)')
        self.bsave.clicked.connect(self.save_folder)
        self.layout.addWidget(self.bsave, 13, 0, 1, 2)
        self.savelabel = QtGui.QLabel('')
        self.layout.addWidget(self.savelabel, 14, 0, 1, 2)
        # fast_disk
        self.bbin = QtGui.QPushButton('Add fast_disk (default is save_path)')
        self.bbin.clicked.connect(self.bin_folder)
        self.layout.addWidget(self.bbin, 15, 0, 1, 2)
        self.binlabel = QtGui.QLabel('')
        self.layout.addWidget(self.binlabel, 16, 0, 1, 2)
        self.runButton = QtGui.QPushButton('RUN SUITE2P')
        self.runButton.clicked.connect(lambda: self.run_S2P(parent))
        n0 = 21
        self.layout.addWidget(self.runButton, n0, 0, 1, 1)
        self.runButton.setEnabled(False)
        self.textEdit = QtGui.QTextEdit()
        self.layout.addWidget(self.textEdit, n0 + 1, 0, 30, 2 * l)
        self.textEdit.setFixedHeight(300)
        self.process = QtCore.QProcess(self)
        self.process.readyReadStandardOutput.connect(self.stdout_write)
        self.process.readyReadStandardError.connect(self.stderr_write)
        # disable the button when running the s2p process
        self.process.started.connect(self.started)
        self.process.finished.connect(lambda: self.finished(parent))
        # stop process
        self.stopButton = QtGui.QPushButton('STOP')
        self.stopButton.setEnabled(False)
        self.layout.addWidget(self.stopButton, n0, 1, 1, 1)
        self.stopButton.clicked.connect(self.stop)
        # cleanup button
        self.cleanButton = QtGui.QPushButton('Add a clean-up *.py')
        self.cleanButton.setToolTip('will run at end of processing')
        self.cleanButton.setEnabled(True)
        self.layout.addWidget(self.cleanButton, n0, 2, 1, 2)
        self.cleanup = False
        self.cleanButton.clicked.connect(self.clean_script)
        self.cleanLabel = QtGui.QLabel('')
        self.layout.addWidget(self.cleanLabel, n0, 4, 1, 12)
        self.listOps = QtGui.QPushButton(
            'save settings and\n add more (batch)')
        self.listOps.clicked.connect(self.list_ops)
        self.layout.addWidget(self.listOps, n0, 12, 1, 2)
        self.listOps.setEnabled(False)
        self.removeOps = QtGui.QPushButton('remove last added')
        self.removeOps.clicked.connect(self.remove_ops)
        self.layout.addWidget(self.removeOps, n0, 14, 1, 2)
        self.removeOps.setEnabled(False)
        self.odata = []
        for n in range(10):
            self.odata.append(QtGui.QLabel(''))
            self.layout.addWidget(self.odata[n], n0 + 1 + n, 12, 1, 4)
        self.f = 0
        if run_suite2p:

            matplotlib.use('Agg')

            print('Preprocessing {} {}'.format(subj, session))

            # copy to local:
            print('copying to local drive')
            for f in files:
                if not os.path.exists(
                        os.path.join(temp_directory,
                                     f.split('/')[-1])):
                    os.system('cp {} {}'.format(f, temp_directory))

            # get default obs:
            ops = default_ops()

            # run analysis:
            print('run preprocessing')
            db = {
                # main settings:
                'data_path': [temp_directory],
                'save_path0': temp_directory,
                'nchannels': nchannels,
                'fs': 15,
                'keep_movie_raw': True,
                'frames_include': -1,

                # motion correction:
                'do_registration': 1,
                'two_step_registration': True,
예제 #10
0
파일: gui.py 프로젝트: neurodroid/suite2p
 def __init__(self, parent=None):
     super(RunWindow, self).__init__(parent)
     self.setGeometry(50, 50, 1200, 800)
     self.setWindowTitle('Choose run options')
     self.win = QtGui.QWidget(self)
     self.layout = QtGui.QGridLayout()
     self.layout.setHorizontalSpacing(25)
     self.win.setLayout(self.layout)
     # initial ops values
     self.ops = run_s2p.default_ops()
     self.data_path = []
     self.save_path = []
     self.fast_disk = []
     tifkeys = [
         'nplanes', 'nchannels', 'functional_chan', 'diameter', 'tau', 'fs'
     ]
     outkeys = [['save_mat', 'combined'],
                ['num_workers', 'num_workers_roi']]
     regkeys = [
         'do_registration', 'nimg_init', 'batch_size', 'maxregshift',
         'align_by_chan', 'reg_tif'
     ]
     cellkeys = [
         'connected', 'max_overlap', 'threshold_scaling', 'max_iterations',
         'navg_frames_svd', 'nsvd_for_roi', 'tile_factor'
     ]
     neukeys = [
         'ratio_neuropil_to_cell', 'inner_neuropil_radius',
         'outer_neuropil_radius', 'min_neuropil_pixels'
     ]
     deconvkeys = [
         'win_baseline', 'sig_baseline', 'prctile_baseline', 'neucoeff'
     ]
     keys = [[], tifkeys, outkeys, regkeys, cellkeys, neukeys, deconvkeys]
     labels = [
         'Filepaths', 'Main settings', ['Output settings', 'Parallel'],
         'Registration', 'ROI detection', 'Neuropil', 'Deconvolution'
     ]
     tooltips = [
         'each tiff has this many planes in sequence',
         'each tiff has this many channels per plane',
         'this channel is used to extract functional ROIs (1-based)',
         'approximate diameter of ROIs in pixels (can input two numbers separated by a comma for elongated ROIs)',
         'timescale of sensor in deconvolution (in seconds)',
         'sampling rate (per plane)',
         'save output also as mat file "Fall.mat"',
         'combine results across planes in separate folder "combined" at end of processing',
         '0 to select num_cores, -1 to disable parallelism, N to enforce value',
         'ROI detection parallelism: 0 to select number of planes, -1 to disable parallelism, N to enforce value',
         'whether or not to perform registration on tiffs or h5 file',
         '# of subsampled frames for finding reference image',
         'number of frames per batch',
         'max allowed registration shift, as a fraction of frame max(width and height)',
         'when multi-channel, you can align by non-functional channel (1-based)',
         'if 1, registered tiffs are saved',
         'whether or not to require ROIs to be fully connected (set to 0 for dendrites/boutons)',
         'ROIs with greater than this overlap as a fraction of total pixels will be discarded',
         'adjust the automatically determined threshold by this scalar multiplier',
         'maximum number of iterations for ROI detection',
         'max number of binned frames for the SVD',
         'max number of SVD components to keep for ROI detection',
         'tiling of neuropil during cell detection (1.0 corresponds to approx 14x14 grid of basis functions, 0.5 -> 7x7)',
         'minimum ratio between neuropil radius and cell radius',
         'number of pixels between ROI and neuropil donut',
         'maximum neuropil radius',
         'minimum number of pixels in the neuropil', 'window for maximin',
         'smoothing constant for gaussian filter',
         'smoothing constant for gaussian filter', 'neuropil coefficient'
     ]
     l = 0
     self.keylist = []
     self.editlist = []
     kk = 0
     bigfont = QtGui.QFont("Arial", 10, QtGui.QFont.Bold)
     for lkey in keys:
         k = 0
         kl = 0
         if type(labels[l]) is list:
             labs = labels[l]
             keyl = lkey
         else:
             labs = [labels[l]]
             keyl = [lkey]
         for label in labs:
             qlabel = QtGui.QLabel(label)
             qlabel.setFont(bigfont)
             self.layout.addWidget(qlabel, k * 2, 2 * l, 1, 2)
             k += 1
             for key in keyl[kl]:
                 lops = 1
                 if self.ops[key] or (self.ops[key] == 0):
                     qedit = QtGui.QLineEdit()
                     qlabel = QtGui.QLabel(key)
                     qlabel.setToolTip(tooltips[kk])
                     if key == 'diameter':
                         if (type(self.ops[key])
                                 is not int) and (len(self.ops[key]) > 1):
                             dstr = str(int(self.ops[key][0])) + ', ' + str(
                                 int(self.ops[key][1]))
                         else:
                             dstr = str(int(self.ops[key]))
                     else:
                         if type(self.ops[key]) is not bool:
                             dstr = str(self.ops[key])
                         else:
                             dstr = str(int(self.ops[key]))
                     qedit.setText(dstr)
                     qedit.setFixedWidth(105)
                     self.layout.addWidget(qlabel, k * 2 - 1, 2 * l, 1, 2)
                     self.layout.addWidget(qedit, k * 2, 2 * l, 1, 2)
                     self.keylist.append(key)
                     self.editlist.append(qedit)
                 k += 1
                 kk += 1
             kl += 1
         l += 1
     # data_path
     key = 'look_one_level_down'
     qlabel = QtGui.QLabel(key)
     qlabel.setToolTip(
         'whether to look in all subfolders when searching for tiffs')
     self.layout.addWidget(qlabel, 1, 0, 1, 1)
     qedit = QtGui.QLineEdit()
     self.layout.addWidget(qedit, 2, 0, 1, 1)
     qedit.setText(str(int(self.ops[key])))
     qedit.setFixedWidth(95)
     self.keylist.append(key)
     self.editlist.append(qedit)
     btiff = QtGui.QPushButton('Add directory to data_path')
     btiff.clicked.connect(self.get_folders)
     self.layout.addWidget(btiff, 3, 0, 1, 2)
     qlabel = QtGui.QLabel('data_path')
     qlabel.setFont(bigfont)
     self.layout.addWidget(qlabel, 4, 0, 1, 1)
     # save_path0
     bh5py = QtGui.QPushButton('OR add h5 file path')
     bh5py.clicked.connect(self.get_h5py)
     self.layout.addWidget(bh5py, 13, 0, 1, 2)
     self.h5text = QtGui.QLabel('')
     self.layout.addWidget(self.h5text, 14, 0, 1, 2)
     bsave = QtGui.QPushButton('Add save_path (default is 1st data_path)')
     bsave.clicked.connect(self.save_folder)
     self.layout.addWidget(bsave, 15, 0, 1, 2)
     self.savelabel = QtGui.QLabel('')
     self.layout.addWidget(self.savelabel, 16, 0, 1, 2)
     # fast_disk
     bbin = QtGui.QPushButton('Add fast_disk (default is save_path)')
     bbin.clicked.connect(self.bin_folder)
     self.layout.addWidget(bbin, 17, 0, 1, 2)
     self.binlabel = QtGui.QLabel('')
     self.layout.addWidget(self.binlabel, 18, 0, 1, 2)
     self.runButton = QtGui.QPushButton('RUN SUITE2P')
     self.runButton.clicked.connect(lambda: self.run_S2P(parent))
     self.layout.addWidget(self.runButton, 20, 0, 1, 1)
     self.runButton.setEnabled(False)
     self.textEdit = QtGui.QTextEdit()
     self.layout.addWidget(self.textEdit, 21, 0, 30, 2 * l)
     self.process = QtCore.QProcess(self)
     self.process.readyReadStandardOutput.connect(self.stdout_write)
     self.process.readyReadStandardError.connect(self.stderr_write)
     # disable the button when running the s2p process
     self.process.started.connect(self.started)
     self.process.finished.connect(lambda: self.finished(parent))
     # stop process
     self.stopButton = QtGui.QPushButton('STOP')
     self.stopButton.setEnabled(False)
     self.layout.addWidget(self.stopButton, 20, 1, 1, 1)
     self.stopButton.clicked.connect(self.stop)