Пример #1
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
Пример #2
0
def mri_run(datadir, outdir, rois):
    """Main function to collect MRI volume data
    
    Parameters
    ----------
    datadir : string
        Full path to root directory of freesurfer processed data. Expect file tree
        to be datadir/subcode/stats/aseg.stats
    outdir : string
        Full path to directory where data will be saved
    rois : list of strings
        List of freesurfer rois of interest. These volumes of these rois will be 
        inserted in aseg_change along with their rates of change
        
    Returns
    -------
    aseg_stats : pandas DataFrame
        DataFrame where each row is a scan, and columns are volumes of all
        freesurfer processed regions
    aseg_change : pandas DataFrame
        DataFrame where each row is a scan, and columns are the volumes of interest,
        their rates of change, and icv correction
    """

    #get aseg_stats data from freesurfer processed data
    outfile = '%sFS_aseg_stats.txt' %outdir
    subs, asegout, output = extractFSasegstats(datadir, outfile)
    aseg_stats = pd.read_csv(outfile, header=0, delim_whitespace=True)

    #add columns for SubjID and MRI_TP
    aseg_stats['codea'] = [cf.get_id(sub) for sub in subs]
    aseg_stats['MRI_Tp'] = [cf.get_tp(sub) for sub in subs]
    aseg_stats.drop('Measure:volume', axis=1, inplace=True)

    #get dates of MRI scans that were processed with freesurfer
    mridates = bacs_pet_mri_date_batch(datadir)

    aseg_change = pd.merge(aseg_change, mridates, on=['codea','MRI_Tp'])

    rois_icvcorr = dict([(roi, '%s_icvcorr' %roi) for roi in rois])
    
    aseg_change = icvcorr(aseg_change, rois_icvcorr, 'IntraCranialVol')

    #calculate rate of change in years
    for roi in rois:
        aseg_change = cf.rate_of_change(aseg_change, 'codea', 'MRI_Tp', 
                                    'MRI_Scandate', roi, '%s_sl' %roi)
    
    cf.save_xls_and_pkl(aseg_stats, 'aseg_stats', outdir)
    cf.save_xls_and_pkl(aseg_change, 'aseg_change', outdir)
    
    return aseg_stats, aseg_change