Exemple #1
0
def main():
    pvals, prob = [], []
    parcellations = putils.get_cammoun_schaefer(data_dir=ROIDIR)
    for spatnull in simnulls.SPATNULLS:
        for alpha in simnulls.ALPHAS:
            if spatnull in simnulls.VERTEXWISE:
                pvals.append(
                    combine_nulls('vertex', 'fsaverage5', spatnull, alpha))
                prob.append(
                    combine_shuffle('vertex', 'fsaverage5', spatnull, alpha))
            for parcellation, annotations in parcellations.items():
                for scale in annotations:
                    pvals.append(
                        combine_nulls(parcellation, scale, spatnull, alpha))
                    prob.append(
                        combine_shuffle(parcellation, scale, spatnull, alpha))

    col = ['parcellation', 'scale', 'spatnull', 'alpha', 'sim', 'corr', 'pval']
    pvals = pd.concat(pvals, ignore_index=True)[col]
    pvals.to_csv(SIMDIR / 'pval_summary.csv.gz', index=False)

    prob = pd.DataFrame(prob)[col[:4] + ['prob']]
    prob.to_csv(SIMDIR / 'prob_summary.csv.gz', index=False)

    prob['alpha'] = prob['alpha'].astype('category')
    auc = prob.groupby(['parcellation', 'scale', 'spatnull']) \
              .apply(lambda x: metrics.auc(x['alpha'].cat.codes, x['prob']))
    auc.name = 'auc'
    auc = auc.reset_index()
    auc.to_csv(SIMDIR / 'auc_summary.csv.gz', index=False)
Exemple #2
0
def run_analysis():
    """ Runs p-value x n_nulls analysis

    Returns
    -------
    pvals : pd.DataFrame
        Data examining p-values based on number of nulls used
    """

    OUTDIR.mkdir(parents=True, exist_ok=True)
    fn = OUTDIR / 'nnulls_summary.csv'
    if fn.exists():
        return pd.read_csv(fn)

    subsets = []
    parcellations = putils.get_cammoun_schaefer(data_dir=ROIDIR)
    for spatnull in simnulls.SPATNULLS:
        for alpha in simnulls.ALPHAS:
            if spatnull in simnulls.VERTEXWISE:
                subsets.append(
                    pval_by_subsets('vertex', 'fsaverage5', spatnull, alpha), )
            for parcellation, annotations in parcellations.items():
                for scale in annotations:
                    subsets.append(
                        pval_by_subsets(parcellation, scale, spatnull,
                                        alpha), )
    subsets = pd.concat(subsets, ignore_index=True, sort=True)
    subsets.to_csv(OUTDIR / 'nnulls_summary.csv.gz', index=False)
    return subsets
def main():
    parcellations = putils.get_cammoun_schaefer(data_dir=ROIDIR)

    # output dataframe
    cols = ['parcellation', 'scale', 'spintype', 'n_sig']
    data = pd.DataFrame(columns=cols)

    # let's run all our parcellations
    for parcellation, annotations in parcellations.items():
        print(f'PARCELLATION: {parcellation}')
        for scale in annotations:
            for spintype in SPINTYPES:
                data = data.append(run_null(parcellation, scale, spintype),
                                   ignore_index=True)

            # now calculate parametric null
            nsdata = load_data(parcellation, scale, spintype)
            corrs = np.corrcoef(nsdata.T)
            # this calculates the correlation value for p < ALPHA cutoff
            ab = (len(nsdata) / 2) - 1
            cutoff = 1 - (special.btdtri(ab, ab, ALPHA / 2) * 2)
            # now add the parametric null to our giant summary dataframe
            data = data.append(pd.DataFrame({
                'parcellation': parcellation,
                'scale': scale,
                'spintype': 'naive-para',
                'n_sig': np.sum(np.triu(corrs > cutoff, k=1))
            }, index=[0]), ignore_index=True)

    data.to_csv(NSDIR / 'ns_summary.csv.gz', index=False)
def main():
    parcellations = putils.get_cammoun_schaefer(data_dir=ROIDIR)

    # get inputs
    args = get_parser()

    # reset some stuff
    for param in ('n_perm', 'n_proc', 'seed', 'n_sim', 'shuffle', 'use_knn'):
        globals()[param.upper()] = args[param]

    print(f'N_PERM: {N_PERM}',
          f'N_PROC: {N_PROC}',
          f'SEED: {SEED}',
          f'SHUFFLE: {SHUFFLE}',
          f'N_SIM: {N_SIM}',
          f'SPATNULLS: {args["spatnull"]}',
          f'ALPHAS: {args["alpha"]}\n', sep='\n')

    if args['show_params']:
        return

    # everyone loves a four-level-deep nested for-loop :man_facepalming:
    for spatnull in args['spatnull']:
        for alpha in args['alpha']:
            if spatnull in simnulls.VERTEXWISE:
                run_null('vertex', 'fsaverage5', spatnull, alpha)
            for parcellation, annotations in parcellations.items():
                for scale in annotations:
                    run_null(parcellation, scale, spatnull, alpha)
def main():
    parcellations = putils.get_cammoun_schaefer(data_dir=ROIDIR)

    # get inputs
    args = get_parser()

    # reset some stuff
    for param in ('n_perm', 'n_proc', 'seed', 'run_moran', 'shuffle',
                  'use_knn'):
        globals()[param.upper()] = args[param]

    sims = range(args['start'], args['start'] + args['n_sim'])

    print(f'N_PERM: {N_PERM}',
          f'N_PROC: {N_PROC}',
          f'SEED: {SEED}',
          f'RUN_MORAN: {RUN_MORAN}',
          f'SHUFFLE: {SHUFFLE}',
          f'START: {sims.start}',
          f'STOP: {sims.stop}\n',
          sep='\n')

    if args['show_params']:
        return

    for spatnull in args['spatnull']:
        for alpha in args['alpha']:
            # no parallelization here
            for sim in sims:
                # maybe parallelization here
                if spatnull in simnulls.VERTEXWISE:
                    run_null('vertex', 'fsaverage5', spatnull, alpha, sim)
                for parcellation, annotations in parcellations.items():
                    for scale in annotations:
                        run_null(parcellation, scale, spatnull, alpha, sim)
def main():
    parcellations = putils.get_cammoun_schaefer(data_dir=ROIDIR)

    data = []
    for alpha in simnulls.ALPHAS:
        data.append(combine_moran('vertex', 'fsaverage5', alpha))
        for parcellation, annotations in parcellations.items():
            for scale in annotations:
                data.append(combine_moran(parcellation, scale, alpha))

    col = ['parcellation', 'scale', 'alpha', 'spatnull', 'sim', 'moran']
    data = pd.concat(data, ignore_index=True)[col]
    data.to_csv(SIMDIR / 'moran_summary.csv.gz', index=False)
def main():
    parcellations = putils.get_cammoun_schaefer(data_dir=ROIDIR)

    # output dataframe
    cols = [
        'parcellation', 'scale', 'spintype', 'netclass', 'network', 'zscore',
        'pval'
    ]
    data = pd.DataFrame(columns=cols)

    # use both Yeo + VEK network groupings
    for netclass in ['yeo', 'vek']:
        # run all our parcellations + spintypes
        for parcellation, annotations in parcellations.items():
            print(f'PARCELLATION: {parcellation}')
            for scale in annotations.keys():
                for spintype in SPINTYPES:
                    data = data.append(run_null(netclass, parcellation, scale,
                                                spintype),
                                       ignore_index=True)

                # parametric null; use mean + p-value from t-statistic
                raw = load_data(netclass, parcellation, scale)
                raw['myelin'] = stats.zscore(raw['myelin'], ddof=1)
                raw = raw.query('networks != 0')
                pvals = [
                    stats.ttest_1samp(raw.loc[idx, 'myelin'], 0)[-1]
                    for net, idx in raw.groupby('networks').groups.items()
                ]
                # now add the parametric null to our giant summary dataframe
                data = data.append(pd.DataFrame({
                    'parcellation':
                    parcellation,
                    'scale':
                    scale,
                    'spintype':
                    'naive-para',
                    'netclass':
                    netclass,
                    'network':
                    list(NET_CODES[netclass].keys()),
                    'zscore':
                    raw.groupby('networks').mean()['myelin'],
                    'pval':
                    pvals
                }),
                                   ignore_index=True)

    # save the output data !
    data.to_csv(HCPDIR / 'summary.csv', index=False)
Exemple #8
0
def main():
    parcellations = putils.get_cammoun_schaefer(data_dir=ROIDIR)

    # output dataframe
    data = pd.DataFrame(columns=[
        'parcellation', 'scale', 'spintype', 'netclass', 'network', 'zscore',
        'pval'
    ])

    # use both Yeo + VEK network groupings
    for netclass in ['yeo', 'vek']:
        # run all our parcellations + spintypes
        for parcellation, annotations in parcellations.items():
            print(f'PARCELLATION: {parcellation}')
            for scale in annotations.keys():
                for spintype in SPINTYPES:
                    data = data.append(run_null(netclass, parcellation, scale,
                                                spintype),
                                       ignore_index=True)

    # save the output data !
    data.to_csv(HCPDIR / f'summary_thresh{PCTDROPTHRESH * 100:03.0f}.csv.gz',
                index=False)
Exemple #9
0
    rhout = HCPDIR / 'S1200.R.MyelinMap_BC_MSMSAll.32k_fs_LR.func.gii'
    run(CIFTISEP.format(cifti=cifti, lhout=lhout, rhout=rhout), quiet=True)

    # for each hemisphere, resample to FreeSurfer fsaverage5 space and convert
    # the resulting GII file to MGH (for consistency with NeuroSynth data)
    for gii, hemi, surf in zip((lhout, rhout), ('L', 'R'), fsaverage):
        out = HCPDIR / f'fsaverage5.MyelinMap.{hemi}.10k_fsavg_{hemi}.func.gii'
        mgh = HCPDIR / f'{hemi.lower()}h.myelin.mgh'
        run(HCP2FS.format(gii=gii, path=stds, hemi=hemi, out=out), quiet=True)
        run(GIITOMGH.format(gii=out, surf=surf, out=mgh), quiet=True)

        # remove intermediate file
        if out.exists():
            out.unlink()

    # remove intermediate files
    for fn in [lhout, rhout]:
        if fn.exists():
            fn.unlink()

    # get parcellations that we'll use to parcellate data
    parcellations = putils.get_cammoun_schaefer(data_dir=ROIDIR)

    # get vertex-level data first
    get_hcp_data(PARDIR / 'vertex' / 'fsaverage5.csv')

    # now do parcellations
    for name, annotations in parcellations.items():
        for scale, annot in annotations.items():
            get_hcp_data(PARDIR / name / f'{scale}.csv', annot=annot)