Beispiel #1
0
def parse_inputs(parser, args):
    if isinstance(args, list):
        args, unknown = parser.parse_known_args()

    if sys.argv[-2] == 'lbl' and sys.argv[-1] == 'stats':
        print("Running in GUI mode")

        title = 'Label Statistics'
        vols = ['Input Volume', 'Registered Labels']
        fields = ['Output file name', 'Sort (def = Mean)', 'Hemi', 'Label depth']

        app = QApplication(sys.argv)
        menu, linedits, labels = gui_opts.OptsMenu(title=title, vols=vols, fields=fields, helpfun=helpmsg())
        menu.show()
        app.exec_()
        app.processEvents()

        volstr = labels[vols[0]].text()
        invol = str(volstr.split(":")[1]).lstrip()

        lblsstr = labels[vols[1]].text()
        lbls = str(lblsstr.split(":")[1]).lstrip()

        outfile = 'clarity_label_statistics.csv' if not linedits[fields[0]].text() else str(linedits[fields[0]].text())
        sort = 'Mean' if not linedits[fields[1]].text() else str(linedits[fields[1]].text())
        hemi = 'Combined' if not linedits[fields[2]].text() else str(linedits[fields[2]].text())
        label_depth = '' if not linedits[fields[3]].text() else str(linedits[fields[3]].text())

    else:
        print("\n running in script mode \n")

        invol = args.invol
        lbls = args.lbls
        outfile = args.outfile
        sort = args.sort
        hemi = args.hemi if args.hemi is not None else "combined"
        label_depth = args.depth if args.depth is not None else None

        # check if pars given

        assert isinstance(invol, str)
        assert os.path.exists(invol), '%s does not exist ... please check path and rerun script' % invol
        assert isinstance(lbls, str)
        assert os.path.exists(lbls), '%s does not exist ... please check path and rerun script' % lbls
        assert isinstance(outfile, str)
        assert isinstance(sort, str)

    return invol, lbls, outfile, sort, hemi, label_depth
def parse_inputs(parser, args):
    if isinstance(args, list):
        args, unknown = parser.parse_known_args()

    if sys.argv[-2] == 'conv' and sys.argv[-1] == 'nii_tiff':

        print("Running in GUI mode")

        title = 'Nii to Tiff conversion'
        dirs = ['Input Nii file']
        fields = [
            'Out nii name (def = clarity)', 'Up-sample ratio (def = 1)',
            'Spline order (def = 3)'
        ]

        app = QApplication(sys.argv)
        menu, linedits, labels = gui_opts.OptsMenu(title=title,
                                                   dirs=dirs,
                                                   fields=fields,
                                                   helpfun=helpmsg())
        menu.show()
        app.exec_()
        app.processEvents()

        indirstr = labels[dirs[0]].text()
        input = str(indirstr.split(":")[1]).lstrip()
        assert os.path.exists(
            input
        ), '%s does not exist ... please check path and rerun script' % input

        # Initialize default params

        outtiff = 'clarity.tif' if not linedits[fields[0]].text() else str(
            linedits[fields[0]].text())

        u = 1 if not linedits[fields[1]].text() else int(
            linedits[fields[1]].text())

        s = 3 if not linedits[fields[2]].text() else int(
            linedits[fields[1]].text())

    else:

        print("\n running in script mode")

        # check if pars given

        assert isinstance(args.input, str)
        input = args.input

        assert os.path.exists(
            input
        ), '%s does not exist ... please check path and rerun script' % input

        if args.outtiff is None:
            outtiff = 'clarity.tif'
        else:
            assert isinstance(args.outtiff, str)
            outtiff = args.outtiff

        if args.up is None:
            u = 1
            print(
                "\n Up-sample ratio not specified ... choosing default value of %d"
                % u)
        else:
            assert isinstance(args.up, int)
            u = args.up

        if args.spline is None:
            s = 3
            print(
                "\n Spline order not specified ... choosing default value of %d"
                % s)
        else:
            assert isinstance(args.spline, int)
            s = args.spline

    return input, outtiff, u, s
def parse_inputs(parser, args):
    if isinstance(args, list):
        args, unknown = parser.parse_known_args()

    if sys.argv[-2] == 'conv' and sys.argv[-1] == 'tiff_nii':

        print("Running in GUI mode")

        title = 'Tiff to Nii conversion'
        dirs = ['Input tiff folder']
        fields = ['Output dir (def = working dir)', 'Out nii name (def = clarity)', 'Downsample ratio (def = 5)',
                  'chan # (def = 1)', 'chan prefix','Out chan name (def = eyfp)', 'Resolution (x,y) (def = 5 "um")',
                  'Thickness (z) (def = 5 "um")','center (def = 0,0,0)', 'Downsample in z (def = 1)',
                  'Prev Downsampling (def = 1 -> not downsampled)']
        # field_names = ['outnii', 'd', 'chann', 'chanp', 'chan', 'vx', 'vz', 'cent', 'downz', 'pd']

        app = QApplication(sys.argv)
        menu, linedits, labels = gui_opts.OptsMenu(title=title, dirs=dirs, fields=fields, helpfun=helpmsg())
        menu.show()
        app.exec_()
        app.processEvents()

        indirstr = labels[dirs[0]].text()
        indir = str(indirstr.split(":")[1]).lstrip()
        assert os.path.exists(indir), '%s does not exist ... please check path and rerun script' % indir

        # Initialize default params

        work_dir = os.path.abspath(os.getcwd()) if not linedits[fields[0]].text() else str(linedits[fields[0]].text())

        outnii = 'clarity' if not linedits[fields[1]].text() else str(linedits[fields[1]].text())
        # assert isinstance(outnii, str), '-outnii not a string'

        d = 5 if not linedits[fields[2]].text() else int(linedits[fields[2]].text())
        # assert isinstance(d, int), '-d not a integer'

        chann = 0 if not linedits[fields[3]].text() else int(linedits[fields[3]].text())
        # assert isinstance(chann, int), '-chann not a integer'

        chanp = None if not linedits[fields[4]].text() else str(linedits[fields[4]].text())

        chan = 'eyfp' if not linedits[fields[5]].text() else str(linedits[fields[5]].text())

        vx = 5 if not linedits[fields[6]].text() else float(linedits[fields[6]].text())

        vz = 5 if not linedits[fields[7]].text() else float(linedits[fields[7]].text())

        cent = [0, 0, 0] if not linedits[fields[8]].text() else linedits[fields[8]].text()

        downz = 1 if not linedits[fields[9]].text() else int(linedits[fields[9]].text())

        pd = 1 if not linedits[fields[10]].text() else int(linedits[fields[10]].text())

    else:

        print("\n running in script mode")

        # check if pars given
        assert isinstance(args.folder, str)
        indir = args.folder

        assert os.path.exists(indir), '%s does not exist ... please check path and rerun script' % indir

        work_dir = args.work_dir

        if args.outnii is None:
            outnii = 'clarity'
        else:
            assert isinstance(args.outnii, str)
            outnii = args.outnii

        if args.down is None:
            d = 5
            print("\n down-sample ratio not specified ... choosing default value of %d" % d)
        else:
            assert isinstance(args.down, int)
            d = args.down

        if args.channum is None:
            chann = 0
            print("\n channel # not specified ... choosing default value of %d" % chann)
        else:
            assert isinstance(args.channum, int)
            chann = args.channum

            if args.chanprefix is None:
                sys.exit('-cp (channel prefix) not specified ')

        chanp = args.chanprefix if args.chanprefix is not None else None

        if args.channame is None:
            chan = 'eyfp'
            print("\n channel name not specified ... choosing default value of %s" % chan)
        else:
            assert isinstance(args.channame, str)
            chan = args.channame

        if args.resx is None:
            vx = 5
        else:
            vx = args.resx

        if args.resz is None:
            vz = 5
        else:
            vz = args.resz

        if args.center is None:
            cent = [0, 0, 0]
        else:
            cent = args.center

        if args.downzdim is None:
            downz = 1
        else:
            downz = args.downzdim

        if args.prevdown is None:
            pd = 1
        else:
            pd = args.prevdown

    # make res in um
    vx /= float(1000)  # in um
    vz /= float(1000)

    return indir, work_dir, outnii, d, chann, chanp, chan, vx, vz, cent, downz, pd