def main(subject_loc, background_subject_locs, graph, meanDfLoc, verbose, brain):

    ##########################################################
    # Freesurfer setting
    ##########################################################

    ##########################################################
    # Summarize cortical thickness
    ##########################################################
    # if no mean table is given but background list is given
    if meanDfLoc == False and background_subject_locs != None:
        print "Calculating cortical thickness in {0}".format(background_subject_locs)
        # make mean table
        meanDfName = raw_input("Name of the background subject : ")

        if verbose:
            meanDfList = []
            for subjectDir in background_subject_locs:
                meanDfList.append(collectStats_v2(subjectDir))
            meanDf = pd.concat(meanDfList)
        else:
            meanDf = collectStats(background_subject_locs)

    # if no mean table is given, and backround list is empty
    # use subject_loc as the background
    elif meanDfLoc == False and background_subject_locs == None:
        print "No background subjects are given, now running only {0}".format(subject_loc)
        meanDfName = ""

        if verbose:
            meanDf = collectStats_v2([subject_loc])
        else:
            meanDf = collectStats([subject_loc])

    # if meanDfLoc is given
    else:
        print "Now comparing with mean_thickness.csv in /ccnc_bin/meanThickness/"
        meanDfName = "NOR"
        # meanDf = pd.read_csv('/ccnc_bin/meanThickness/new_mean_OCT15.csv')
        if verbose:
            meanDf = pd.read_csv("/ccnc_bin/meanThickness/detailed_mean_2015_12_28.csv", index_col=0)
        else:
            meanDf = pd.read_csv("/ccnc_bin/meanThickness/new_mean_OCT15.csv", index_col=0)

    ##########################################################
    # Get roi dict : 8 cortex each hemisphere
    ##########################################################
    roiDict = get_cortical_rois()

    ##########################################################
    # annotation2label --> merge labels --> freesurfer/tmp
    ##########################################################

    if graph:
        if verbose:
            thicknessDf = collectStats_v2([os.path.dirname(freesurfer_dir)])  # background_subject_locs)
            draw_thickness_detailed(thicknessDf, meanDf, os.path.basename(subject_loc), meanDfName, subject_loc)
        else:
            thicknessDf = collectStats([os.path.dirname(freesurfer_dir)])  # background_subject_locs)
            draw_thickness(thicknessDf, meanDf, os.path.basename(subject_loc), meanDfName, subject_loc)

    if brain:
        if verbose:
            valueSwap.main(freesurfer_dir, os.path.join(freesurfer_dir, "tmp/thick_kev_detailed.csv"))
        else:
            print "Please select verbose mode"
            pass

    print "*" * 80
    print "Outputs are saved in /ccnc/mri_team"
    print "*" * 80
    args = parser.parse_args()

    # Main subject
    main_freesurferDir = get_freesurferDir(os.path.abspath(args.inputDir))
    infoDf = collectStats_v2(main_freesurferDir)

    # Freesurfer environment Settings
    # os.environ["FREESURFER_HOME"] = '/Applications/freesurfer'
    # os.environ["SUBJECTS_DIR"] = '{0}'.format(os.path.dirname(main_freesurferDir))

    # Mean Df
    if args.createMeanFrom:
        freesurferList = subjDirs_to_fsDirs(args.createMeanFrom)
        concatDf = concatFsDf(freesurferList)
        meanDf = concatDf_to_meanDf(concatDf)
        if args.saveMeanDf:
            meanDf.to_csv(args.saveMeanDf)
    elif args.gender == "M":
        meanDf = pd.read_csv("/ccnc_bin/meanThickness/male_df.csv", index_col=0)
    elif args.gender == "F":
        meanDf = pd.read_csv("/ccnc_bin/meanThickness/female_df.csv", index_col=0)
    else:
        meanDf = pd.read_csv("/ccnc_bin/meanThickness/detailed_mean_2015_12_28.csv", index_col=0)

    subjectInitials = raw_input("Subject initial :")
    # Graph
    draw_thickness_detailed(infoDf, meanDf, subjectInitials, "CCNC_mean")

    valueSwap.main(main_freesurfer_dir, os.path.join(main_freesurfer_dir, "tmp/thick_kev_detailed.csv"))
示例#3
0
def main(subject_loc, background_subject_locs, graph, meanDfLoc, verbose,
         brain):

    ##########################################################
    # Freesurfer setting
    ##########################################################

    ##########################################################
    # Summarize cortical thickness
    ##########################################################
    # if no mean table is given but background list is given
    if meanDfLoc == False and background_subject_locs != None:
        print 'Calculating cortical thickness in {0}'.format(
            background_subject_locs)
        # make mean table
        meanDfName = raw_input('Name of the background subject : ')

        if verbose:
            meanDfList = []
            for subjectDir in background_subject_locs:
                meanDfList.append(collectStats_v2(subjectDir))
            meanDf = pd.concat(meanDfList)
        else:
            meanDf = collectStats(background_subject_locs)

    # if no mean table is given, and backround list is empty
    # use subject_loc as the background
    elif meanDfLoc == False and background_subject_locs == None:
        print 'No background subjects are given, now running only {0}'.format(
            subject_loc)
        meanDfName = ''

        if verbose:
            meanDf = collectStats_v2([subject_loc])
        else:
            meanDf = collectStats([subject_loc])

    # if meanDfLoc is given
    else:
        print 'Now comparing with mean_thickness.csv in /ccnc_bin/meanThickness/'
        meanDfName = 'NOR'
        #meanDf = pd.read_csv('/ccnc_bin/meanThickness/new_mean_OCT15.csv')
        if verbose:
            meanDf = pd.read_csv(
                '/ccnc_bin/meanThickness/detailed_mean_2015_12_28.csv',
                index_col=0)
        else:
            meanDf = pd.read_csv('/ccnc_bin/meanThickness/new_mean_OCT15.csv',
                                 index_col=0)

    ##########################################################
    # Get roi dict : 8 cortex each hemisphere
    ##########################################################
    roiDict = get_cortical_rois()

    ##########################################################
    # annotation2label --> merge labels --> freesurfer/tmp
    ##########################################################

    if graph:
        if verbose:
            thicknessDf = collectStats_v2([os.path.dirname(freesurfer_dir)
                                           ])  #background_subject_locs)
            draw_thickness_detailed(thicknessDf, meanDf,
                                    os.path.basename(subject_loc), meanDfName,
                                    subject_loc)
        else:
            thicknessDf = collectStats([os.path.dirname(freesurfer_dir)
                                        ])  #background_subject_locs)
            draw_thickness(thicknessDf, meanDf, os.path.basename(subject_loc),
                           meanDfName, subject_loc)

    if brain:
        if verbose:
            valueSwap.main(
                freesurfer_dir,
                os.path.join(freesurfer_dir, 'tmp/thick_kev_detailed.csv'))
        else:
            print 'Please select verbose mode'
            pass

    print "*" * 80
    print 'Outputs are saved in /ccnc/mri_team'
    print "*" * 80
def main(subject_loc, backgrounds, roi_list, meanDfLoc,verbose, brain):
    ##########################################################
    # Find freesurfer dir
    ##########################################################
    FS_description= ['bem','mri','scripts',
                     'src','stats','surf','tmp']
    freesurfer_dir = ccncpy.subDirSearch(FS_description, 
                                         subject_loc)

    if len(freesurfer_dir) > 1:
        print freesurfer_dir
        sys.exit(re.sub('\s+',' ',
        'There are more than 1 freesurfer directory \
                under {0}'.format(subject_loc)))
    else:
        freesurfer_dir = ''.join(freesurfer_dir)


    ##########################################################
    # Freesurfer setting
    ##########################################################
    os.environ["FREESURFER_HOME"] = '/Applications/freesurfer'
    # where is the freesurfer directory
    os.environ["SUBJECTS_DIR"] = '{0}'.format(os.path.dirname(freesurfer_dir))

    ##########################################################
    # Summarize cortical thickness
    ##########################################################
    # if no mean table is given but background list is given
    if meanDfLoc == False and backgrounds != None:
        print 'Calculating cortical thickness in {0}'.format(backgrounds)
        # make mean table
        meanDfName = raw_input('Name of the background subject : ')

        if verbose:
            meanDf = collectStats_v2(backgrounds)
        else:
            meanDf = collectStats(backgrounds)

    # if no mean table is given, and backround list is empty
    # use subject_loc as the background
    elif meanDfLoc == False and backgrounds == None:
        print 'No background subjects are given, now running only {0}'.format(subject_loc)
        meanDfName = ''

        if verbose:
            meanDf = collectStats_v2([subject_loc])
        else:
            meanDf = collectStats([subject_loc])

    # if meanDfLoc is given
    else:
        print 'Now comparing with mean_thickness.csv in /ccnc_bin/meanThickness/'
        meanDfName = 'NOR'
        #meanDf = pd.read_csv('/ccnc_bin/meanThickness/new_mean_OCT15.csv')
        if verbose:
            meanDf = pd.read_csv('/ccnc_bin/meanThickness/detailed_mean_2015_12_28.csv', index_col=0)
        else:
            meanDf = pd.read_csv('/ccnc_bin/meanThickness/new_mean_OCT15.csv', index_col=0)

    ##########################################################
    # Get roi dict : 8 cortex each hemisphere
    ##########################################################
    roiDict = get_cortical_rois()

    ##########################################################
    # annotation2label --> merge labels --> freesurfer/tmp
    ##########################################################
    
    if args.graph:
        if verbose:
            thicknessDf = collectStats_v2([os.path.dirname(freesurfer_dir)])#backgrounds)
            draw_thickness_detailed(thicknessDf,meanDf,os.path.basename(subject_loc), meanDfName, subject_loc)
        else:
            thicknessDf = collectStats([os.path.dirname(freesurfer_dir)])#backgrounds)
            draw_thickness(thicknessDf,meanDf,os.path.basename(subject_loc), meanDfName, subject_loc)


    if brain:
        if verbose:
            valueSwap.main(freesurfer_dir, 
                    os.path.join(freesurfer_dir,
                        'tmp/thick_kev_detailed.csv'))
        else:
            print 'Please select verbose mode'
            pass

    print "*"*80
    print 'Outputs are saved in /ccnc/mri_team'
    print "*"*80
示例#5
0
    # Freesurfer environment Settings
    # os.environ["FREESURFER_HOME"] = '/Applications/freesurfer'
    # os.environ["SUBJECTS_DIR"] = '{0}'.format(os.path.dirname(main_freesurferDir))

    # Mean Df
    if args.createMeanFrom:
        freesurferList = subjDirs_to_fsDirs(args.createMeanFrom)
        concatDf = concatFsDf(freesurferList)
        meanDf = concatDf_to_meanDf(concatDf)
        if args.saveMeanDf:
            meanDf.to_csv(args.saveMeanDf)
    elif args.gender == 'M':
        meanDf = pd.read_csv('/ccnc_bin/meanThickness/male_df.csv',
                             index_col=0)
    elif args.gender == 'F':
        meanDf = pd.read_csv('/ccnc_bin/meanThickness/female_df.csv',
                             index_col=0)
    else:
        meanDf = pd.read_csv(
            '/ccnc_bin/meanThickness/detailed_mean_2015_12_28.csv',
            index_col=0)

    subjectInitials = raw_input('Subject initial :')
    # Graph
    draw_thickness_detailed(infoDf, meanDf, subjectInitials, 'CCNC_mean')

    valueSwap.main(
        main_freesurfer_dir,
        os.path.join(main_freesurfer_dir, 'tmp/thick_kev_detailed.csv'))