Esempio n. 1
0
def extractFSasegstats(directory, outfile):
    '''Generate a command-line command to extract freesurfer
    
    Parameters
    ----------
    directory : string
        Full path to root directory of freesurfer processed data. Expect file tree
        to be directory/sub/stats/aseg.stats
    outfile : string
        Full path to directory where summary file should be saved
    
    Returns
    -------
    subs : list
        List of subjects found in the input directory
    commandlinestr : string
        String that was passed to the command line
    output : string
        Command line output
    '''
    subs, _ = cf.lbls_infold(directory)
    subs = [sub for sub in subs if 'long' not in sub]
    subpaths = ['%s%s/stats/aseg.stats' % (directory, sub) for sub in subs]
    sublist = ' '.join(subpaths)
    commandlinestr = 'asegstats2table --inputs %s --skip --tablefile %s' % (sublist, outfile)
    process = subprocess.Popen(commandlinestr.split(), stdout=subprocess.PIPE)
    output = process.communicate()[0]
    return subs, commandlinestr, output
Esempio n. 2
0
def bacs_pet_mri_date_batch(rootpath):
    """Given a path, this function finds subject folders there and finds 
    the date of the freesurfer processed data.

    Parameters 
    ----------
    rootpath : string
        Path where subject directories lie

    Returns
    -------
    datetbl : DataFrame
        Holds codea, MRI_Tp, and MRI_Scandate fields
    """
    subs, _ = cf.lbls_infold(rootpath)
    datetbl = pd.DataFrame(columns=['sub'], data=subs)
    datetbl['MRI_Scandate'] = float('NaN')

    for sub in subs:
        dateout = bacs_pet_mri_date(rootpath, sub)
        datetbl.loc[datetbl['sub']==sub,'MRI_Scandate'] = dateout

    datetbl['codea'] = [cf.get_lbl_id(sub) for sub in datetbl['sub'].tolist()]
    datetbl['MRI_Tp'] = [cf.get_tp(sub) for sub in datetbl['sub'].tolist()]

    datetbl.drop('sub', axis=1, inplace=True)
    datetbl = datetbl[datetbl['MRI_Tp'].notnull()]
    return datetbl