-
Notifications
You must be signed in to change notification settings - Fork 57
/
run_cbmas.py
102 lines (87 loc) · 3.96 KB
/
run_cbmas.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# emacs: -*- mode: python-mode; py-indent-offset: 4; tab-width: 4; indent-tabs-mode: nil -*-
# ex: set sts=4 ts=4 sw=4 et:
"""
.. _metas3:
========================================================
Run coordinate-based meta-analyses on 21 pain studies
========================================================
Collection of NIDM-Results packs downloaded from Neurovault collection 1425,
uploaded by Dr. Camille Maumet.
.. note::
This will likely change as we work to shift database querying to a remote
database, rather than handling it locally with NiMARE.
"""
###############################################################################
# Start with the necessary imports
# --------------------------------
import os
import json
from glob import glob
import numpy as np
import pandas as pd
import nibabel as nib
from scipy.stats import t
from nilearn.masking import apply_mask
from nilearn.plotting import plot_stat_map
import nimare
from nimare.tests.utils import get_test_data_path
###############################################################################
# Load Dataset
# --------------------------------------------------
dset_file = os.path.join(get_test_data_path(), 'nidm_pain_dset.json')
dset = nimare.dataset.Dataset(dset_file)
mask_img = dset.masker.mask_img
###############################################################################
# MKDA density analysis
# --------------------------------------------------
mkda = nimare.meta.cbma.MKDADensity(kernel__r=10)
mkda.fit(dset)
corr = nimare.correct.FWECorrector(method='permutation', n_iters=10, n_cores=1)
cres = corr.transform(mkda.results)
plot_stat_map(cres.get_map('logp_level-voxel_corr-FWE_method-permutation'),
cut_coords=[0, 0, -8], draw_cross=False, cmap='RdBu_r')
###############################################################################
# MKDA Chi2 with FDR correction
# --------------------------------------------------
mkda = nimare.meta.cbma.MKDAChi2(kernel__r=10)
dset1 = dset.slice(dset.ids)
dset2 = dset.slice(dset.ids)
mkda.fit(dset1, dset2)
corr = nimare.correct.FDRCorrector(method='fdr_bh', alpha=0.001)
cres = corr.transform(mkda.results)
plot_stat_map(cres.get_map('consistency_z_FDR_corr-FDR_method-fdr_bh'),
threshold=1.65, cut_coords=[0, 0, -8], draw_cross=False,
cmap='RdBu_r')
###############################################################################
# MKDA Chi2 with FWE correction
# --------------------------------------------------
corr = nimare.correct.FWECorrector(method='permutation', n_iters=10, n_cores=1)
cres = corr.transform(mkda.results)
plot_stat_map(cres.get_map('consistency_z'), threshold=1.65,
cut_coords=[0, 0, -8], draw_cross=False, cmap='RdBu_r')
###############################################################################
# KDA
# --------------------------------------------------
kda = nimare.meta.cbma.KDA(kernel__r=10)
kda.fit(dset)
corr = nimare.correct.FWECorrector(method='permutation', n_iters=10, n_cores=1)
cres = corr.transform(kda.results)
plot_stat_map(cres.get_map('logp_level-voxel_corr-FWE_method-permutation'),
cut_coords=[0, 0, -8], draw_cross=False, cmap='RdBu_r')
###############################################################################
# ALE
# --------------------------------------------------
ale = nimare.meta.cbma.ALE()
ale.fit(dset)
corr = nimare.correct.FWECorrector(method='permutation', n_iters=10, n_cores=1)
cres = corr.transform(ale.results)
plot_stat_map(cres.get_map('logp_level-cluster_corr-FWE_method-permutation'),
cut_coords=[0, 0, -8], draw_cross=False, cmap='RdBu_r')
###############################################################################
# SCALE
# --------------------------------------------------
ijk = np.vstack(np.where(mask_img.get_data())).T
scale = nimare.meta.cbma.SCALE(ijk=ijk, n_iters=10, n_cores=1)
scale.fit(dset)
plot_stat_map(scale.results.get_map('z_vthresh'), cut_coords=[0, 0, -8],
draw_cross=False, cmap='RdBu_r')