/
cbma.py
165 lines (139 loc) · 6.89 KB
/
cbma.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
"""Workflow for running an coordinates-based meta-analysis from a NiMARE database."""
import logging
from nimare.correct import FWECorrector
from nimare.dataset import Dataset
from nimare.diagnostics import Jackknife
from nimare.meta import ALE, MKDAChi2
from nimare.meta.cbma.base import CBMAEstimator, PairwiseCBMAEstimator
from nimare.utils import _check_type
from nimare.workflows.base import Workflow
LGR = logging.getLogger(__name__)
class CBMAWorkflow(Workflow):
"""Compose a coordinate-based meta-analysis workflow.
.. versionchanged:: 0.1.2
- `cbma_workflow` function was converted to CBMAWorkflow class.
.. versionadded:: 0.0.14
This workflow performs a coordinate-based meta-analysis, multiple comparison corrections,
and diagnostics analyses on corrected meta-analytic z-score maps.
Parameters
----------
estimator : :class:`~nimare.meta.cbma.base.CBMAEstimator`, :obj:`str` {'ale', 'scale', \
'mkdadensity', 'kda'}, optional
Meta-analysis estimator. Default is :class:`~nimare.meta.cbma.ale.ALE`.
corrector : :class:`~nimare.correct.Corrector`, :obj:`str` {'montecarlo', 'fdr', \
'bonferroni'}, optional
Meta-analysis corrector. Default is :class:`~nimare.correct.FWECorrector`.
diagnostics : :obj:`list` of :class:`~nimare.diagnostics.Diagnostics`, \
:class:`~nimare.diagnostics.Diagnostics`, :obj:`str` {'jackknife', 'focuscounter'}, \
optional
List of meta-analysis diagnostic classes. A single diagnostic class can also be passed.
Default is :class:`~nimare.diagnostics.FocusCounter`.
voxel_thresh : :obj:`float` or None, optional
An optional voxel-level threshold that may be applied to the ``target_image`` in the
:class:`~nimare.diagnostics.Diagnostics` class to define clusters. This can be None or 0
if the ``target_image`` is already thresholded (e.g., a cluster-level corrected map).
If diagnostics are passed as initialized objects, this parameter will be ignored.
Default is 1.65, which corresponds to p-value = .05, one-tailed.
cluster_threshold : :obj:`int` or None, optional
Cluster size threshold, in :term:`voxels<voxel>`.
If None, then no cluster size threshold will be applied.
If diagnostics are passed as initialized objects, this parameter will be ignored.
Default is 10.
output_dir : :obj:`str`, optional
Output directory in which to save results. If the directory doesn't
exist, it will be created. Default is None (the results are not saved).
n_cores : :obj:`int`, optional
Number of cores to use for parallelization.
If <=0, defaults to using all available cores.
If estimator, corrector, or diagnostics are passed as initialized objects, this parameter
will be ignored.
Default is 1.
"""
# Options allows for string input
_estm_base = CBMAEstimator
_estm_options = ("ale", "scale", "mkdadensity", "kda")
_corr_options = ("montecarlo", "fdr", "bonferroni")
_diag_options = ("jackknife", "focuscounter")
_mcc_method = "montecarlo"
_estm_default = ALE
_corr_default = FWECorrector
_diag_default = Jackknife
def fit(self, dataset, drop_invalid=True):
"""Fit Workflow to a Dataset.
Parameters
----------
dataset : :obj:`~nimare.dataset.Dataset`
Dataset to analyze.
Returns
-------
:obj:`~nimare.results.MetaResult`
Results of Estimator fitting.
"""
# Check dataset type
dataset = _check_type(dataset, Dataset)
LGR.info("Performing meta-analysis...")
results = self.estimator.fit(dataset, drop_invalid=drop_invalid)
return self._transform(results)
class PairwiseCBMAWorkflow(Workflow):
"""Base class for pairwise coordinate-based meta-analysis workflow methods.
.. versionadded:: 0.1.2
Parameters
----------
estimator : :class:`~nimare.meta.cbma.base.PairwiseCBMAEstimator`, :obj:`str` \
{'alesubtraction', 'mkdachi2'}, or optional
Meta-analysis estimator. Default is :class:`~nimare.meta.cbma.kda.MKDAChi2`.
corrector : :class:`~nimare.correct.Corrector`, :obj:`str` {'montecarlo', 'fdr', \
'bonferroni'} or optional
Meta-analysis corrector. Default is :class:`~nimare.correct.FWECorrector`.
diagnostics : :obj:`list` of :class:`~nimare.diagnostics.Diagnostics`, \
:class:`~nimare.diagnostics.Diagnostics`, :obj:`str` {'jackknife', 'focuscounter'}, \
or optional
List of meta-analysis diagnostic classes. A single diagnostic class can also be passed.
Default is :class:`~nimare.diagnostics.FocusCounter`.
voxel_thresh : :obj:`float` or None, optional
An optional voxel-level threshold that may be applied to the ``target_image`` in the
:class:`~nimare.diagnostics.Diagnostics` class to define clusters. This can be None or 0
if the ``target_image`` is already thresholded (e.g., a cluster-level corrected map).
If diagnostics are passed as initialized objects, this parameter will be ignored.
Default is 1.65, which corresponds to p-value = .05, one-tailed.
cluster_threshold : :obj:`int` or None, optional
Cluster size threshold, in :term:`voxels<voxel>`.
If None, then no cluster size threshold will be applied.
If diagnostics are passed as initialized objects, this parameter will be ignored.
Default is 10.
output_dir : :obj:`str`, optional
Output directory in which to save results. If the directory doesn't
exist, it will be created. Default is None (the results are not saved).
n_cores : :obj:`int`, optional
Number of cores to use for parallelization.
If <=0, defaults to using all available cores.
If estimator, corrector, or diagnostics are passed as initialized objects, this parameter
will be ignored.
Default is 1.
"""
# Options allows for string input
_estm_base = PairwiseCBMAEstimator
_estm_options = ("alesubtraction", "mkdachi2")
_corr_options = ("montecarlo", "fdr", "bonferroni")
_diag_options = ("jackknife", "focuscounter")
_mcc_method = "montecarlo"
_estm_default = MKDAChi2
_corr_default = FWECorrector
_diag_default = Jackknife
def fit(self, dataset1, dataset2, drop_invalid=True):
"""Fit Workflow to two Datasets.
Parameters
----------
dataset1/dataset2 : :obj:`~nimare.dataset.Dataset`
Dataset objects to analyze.
Returns
-------
:obj:`~nimare.results.MetaResult`
Results of Estimator fitting.
"""
# Check dataset type
dataset1 = _check_type(dataset1, Dataset)
dataset2 = _check_type(dataset2, Dataset)
LGR.info("Performing meta-analysis...")
results = self.estimator.fit(dataset1, dataset2, drop_invalid=drop_invalid)
return self._transform(results)