Exemplo n.º 1
0
def generate_df(metaroi_vals, outdir):
    """Generates a dataframe with the metaroi values for each subject
    
    Parameters    
    ----------
    metaroi_vals : dict
        Dictionary where keys are the filename and values are the mean
        FDG value
    outdir : string
        Full path where FDG output file should be saved
        
    Returns
    -------
    metaroi_df : pandas DataFrame
        DataFrame where each row is an FDG scan
    """
    metaroi_df = pd.DataFrame.from_dict(metaroi_vals, orient="index")
    metaroi_df.reset_index(level=0, inplace=True)
    metaroi_df.rename(columns={0: "roi_vals", "index": "path"}, inplace=True)
    metaroi_df["roi_vals"] = [float(x) for x in metaroi_df["roi_vals"]]
    metaroi_df["codea"] = [cf.get_id(x) for x in metaroi_df["path"]]
    metaroi_df = metaroi_df.rename(columns={"roi_vals": "FDG_val"})
    metaroi_df = metaroi_df.drop("path", axis=1)

    cf.save_xls_and_pkl(metaroi_df, "fdg_metaroi", outdir)

    return metaroi_df
Exemplo n.º 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