Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Workflow and CBMAWorkflow classes. Support pairwise CBMA workflows #809

Merged
merged 40 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
cb1fa66
Convert cbma_workflow into a class. Support pairwise estimators
JulioAPeraza May 31, 2023
72e1ef4
Add support for reports and diagnostics with pairwise estimator
JulioAPeraza Jun 1, 2023
adfb9f1
fix dicstring
JulioAPeraza Jun 2, 2023
48b5aed
add deprecation warning
JulioAPeraza Jun 2, 2023
5ffa968
fix test for tables == None
JulioAPeraza Jun 2, 2023
7a40379
add version changes to docstring
JulioAPeraza Jun 2, 2023
73fc15e
fix documentation
JulioAPeraza Jun 2, 2023
8839cf6
improve coverage
JulioAPeraza Jun 2, 2023
9b77e9b
Use specificity maps instead
JulioAPeraza Jun 7, 2023
9fb98cc
Merge _preprocess_input
JulioAPeraza Jun 7, 2023
5455231
remove Workflow from __init__
JulioAPeraza Jun 8, 2023
ebd4b13
Add Pairwise estimator report
JulioAPeraza Jun 8, 2023
56ec484
update diagnostics
JulioAPeraza Jun 8, 2023
78bcb0e
reduce the number of iterations. we are running out of time/memory in…
JulioAPeraza Jun 8, 2023
1d25b02
Merge branch 'neurostuff:main' into enh-workflow
JulioAPeraza Jun 8, 2023
2268f17
see if using focuscounter reduces the time for building the documenta…
JulioAPeraza Jun 8, 2023
c7a7bf8
New parameter display_second_group
JulioAPeraza Jun 12, 2023
b08e712
Update 08_plot_cbma_subtraction_conjunction.py
JulioAPeraza Jun 12, 2023
a3573af
Add dataset 2 to summary
JulioAPeraza Jun 12, 2023
6c50469
Update diagnostics.py
JulioAPeraza Jun 12, 2023
3447502
Update versionchanged
JulioAPeraza Jun 12, 2023
5d33e92
Merge branch 'neurostuff:main' into enh-workflow
JulioAPeraza Jun 12, 2023
5630c9f
Reorder matrix only if more than 1 cluster/experiment
JulioAPeraza Jun 12, 2023
4f18d84
display_second_group in the example
JulioAPeraza Jun 13, 2023
98bc738
fix #814
JulioAPeraza Jun 13, 2023
9b950e3
Use iframe only for connectome
JulioAPeraza Jun 13, 2023
363effd
Set the size of the heatmap proportional to rows and columns
JulioAPeraza Jun 13, 2023
fa5d876
Separate positive from negative tail contribution table for pairwise …
JulioAPeraza Jun 13, 2023
385091d
Add subsubtitle
JulioAPeraza Jun 13, 2023
761ee12
Merge branch 'main' into enh-workflow
JulioAPeraza Jun 14, 2023
b923cd9
Test a realistic scenario with different dset1 and desert 2
JulioAPeraza Jun 16, 2023
73347ad
Apply @jdkent code review
JulioAPeraza Jun 16, 2023
e7360ed
consider the length of the study label in the figure size
JulioAPeraza Jun 21, 2023
afdf4a4
fix issues with figure sizes
JulioAPeraza Jun 21, 2023
fbd7ae4
Define "PositiveTail" and "NegativeTail" as variables
JulioAPeraza Jun 21, 2023
a4e8acd
Update diagnostics.py
JulioAPeraza Jun 21, 2023
883fa6e
Make a distinction between studies and experiments in report
JulioAPeraza Jun 21, 2023
cc1a3e0
Restore the diagnostics summary
JulioAPeraza Jun 21, 2023
8ac8e50
Limit the colormap to the total number of clusters
JulioAPeraza Jun 21, 2023
d46e3ca
Update 08_plot_cbma_subtraction_conjunction.py
JulioAPeraza Jun 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ For more information about fetching data from the internet, see :ref:`fetching t

workflows.ale_sleuth_workflow
workflows.macm_workflow
workflows.cbma_workflow
workflows.cbma.CBMAWorkflow
workflows.cbma.PairwiseCBMAWorkflow

:mod:`nimare.reports`: NiMARE report
--------------------------------------------------
Expand Down
54 changes: 36 additions & 18 deletions examples/02_meta-analyses/08_plot_cbma_subtraction_conjunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
6. Compare the two within-sample meta-analyses with a conjunction analysis.
"""
import os
from pathlib import Path

import matplotlib.pyplot as plt
from nilearn.plotting import plot_stat_map
Expand Down Expand Up @@ -104,19 +105,20 @@
target_image="z_desc-size_level-cluster_corr-FWE_method-montecarlo",
voxel_thresh=None,
)
knowledge_corrected_results = counter.transform(knowledge_corrected_results)
knowledge_diagnostic_results = counter.transform(knowledge_corrected_results)

###############################################################################
# Clusters table.
knowledge_clusters_table = knowledge_corrected_results.tables[
knowledge_clusters_table = knowledge_diagnostic_results.tables[
"z_desc-size_level-cluster_corr-FWE_method-montecarlo_tab-clust"
]
knowledge_clusters_table.head(10)

###############################################################################
# Contribution table. Here ``PostiveTail`` refers to clusters with positive statistics.
knowledge_count_table = knowledge_corrected_results.tables[
"z_desc-size_level-cluster_corr-FWE_method-montecarlo_diag-FocusCounter_tab-counts"
knowledge_count_table = knowledge_diagnostic_results.tables[
"z_desc-size_level-cluster_corr-FWE_method-montecarlo_diag-FocusCounter"
"_tab-counts_tail-positive"
]
knowledge_count_table.head(10)

Expand All @@ -127,9 +129,9 @@
target_image="z_desc-size_level-cluster_corr-FWE_method-montecarlo",
voxel_thresh=None,
)
related_corrected_results = jackknife.transform(related_corrected_results)
related_jackknife_table = related_corrected_results.tables[
"z_desc-size_level-cluster_corr-FWE_method-montecarlo_diag-Jackknife_tab-counts"
related_diagnostic_results = jackknife.transform(related_corrected_results)
related_jackknife_table = related_diagnostic_results.tables[
"z_desc-size_level-cluster_corr-FWE_method-montecarlo_diag-Jackknife_tab-counts_tail-positive"
]
related_jackknife_table.head(10)

Expand All @@ -138,20 +140,36 @@
# -----------------------------------------------------------------------------
# Typically, one would use at least 10000 iterations for a subtraction analysis.
# However, we have reduced this to 100 iterations for this example.
# Similarly here we use a voxel-level z-threshold of 0.01, but in practice one would
# use a more stringent threshold (e.g., 1.65).
from nimare.meta.cbma import ALESubtraction
from nimare.reports.base import run_reports
from nimare.workflows import PairwiseCBMAWorkflow

sub = ALESubtraction(n_iters=100, n_cores=1)
res_sub = sub.fit(knowledge_dset, related_dset)
img_sub = res_sub.get_map("z_desc-group1MinusGroup2")

plot_stat_map(
img_sub,
cut_coords=4,
display_mode="z",
title="Subtraction",
cmap="RdBu_r",
vmax=4,
workflow = PairwiseCBMAWorkflow(
estimator=ALESubtraction(n_iters=10, n_cores=1),
corrector="fdr",
diagnostics=FocusCounter(voxel_thresh=0.01, display_second_group=True),
)
res_sub = workflow.fit(knowledge_dset, related_dset)

###############################################################################
# Report
# -----------------------------------------------------------------------------
# Finally, a NiMARE report is generated from the MetaResult.
# root_dir = Path(os.getcwd()).parents[1] / "docs" / "_build"
# Use the previous root to run the documentation locally.
root_dir = Path(os.getcwd()).parents[1] / "_readthedocs"
html_dir = root_dir / "html" / "auto_examples" / "02_meta-analyses" / "08_subtraction"
html_dir.mkdir(parents=True, exist_ok=True)

run_reports(res_sub, html_dir)

####################################
# .. raw:: html
#
# <iframe src="./08_subtraction/report.html" style="border:none;" seamless="seamless" \
# width="100%" height="1000px"></iframe>

###############################################################################
# Conjunction analysis
Expand Down
27 changes: 14 additions & 13 deletions examples/02_meta-analyses/10_plot_cbma_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from nimare.dataset import Dataset
from nimare.reports.base import run_reports
from nimare.utils import get_resource_path
from nimare.workflows import cbma_workflow
from nimare.workflows.cbma import CBMAWorkflow

###############################################################################
# Load Dataset
Expand All @@ -32,25 +32,26 @@
###############################################################################
# Run CBMA Workflow
# -----------------------------------------------------------------------------
# The CBMA workflow function runs the following steps:
# The fit method of a CBMA workflow class runs the following steps:
#
# 1. Runs a meta-analysis using the specified method (default: ALE)
# 2. Applies a corrector to the meta-analysis results (default: FWECorrector, montecarlo)
# 3. Generates cluster tables and runs diagnostics on the corrected results (default: Jackknife)
#
# All in one function call!
# All in one call!
#
# result = cbma_workflow(dset)
# result = CBMAWorkflow().fit(dset)
#
# For this example, we use an FDR correction because the default corrector (FWE correction with
# Monte Carlo simulation) takes a long time to run due to the high number of iterations that
# are required
result = cbma_workflow(dset, corrector="fdr")
workflow = CBMAWorkflow(corrector="fdr")
result = workflow.fit(dset)

###############################################################################
# Plot Results
# -----------------------------------------------------------------------------
# The CBMA workflow function returns a :class:`~nimare.results.MetaResult` object,
# The fit method of the CBMA workflow class returns a :class:`~nimare.results.MetaResult` object,
# where you can access the corrected results of the meta-analysis and diagnostics tables.
#
# Corrected map:
Expand All @@ -73,22 +74,22 @@
###############################################################################
# Contribution table
# ``````````````````````````````````````````````````````````````````````````````
result.tables["z_corr-FDR_method-indep_diag-Jackknife_tab-counts"]
result.tables["z_corr-FDR_method-indep_diag-Jackknife_tab-counts_tail-positive"]

###############################################################################
# Report
# -----------------------------------------------------------------------------
# Finally, a NiMARE report is generated from the MetaResult.
root_dir = Path(os.getcwd()).parents[1]
# Use the following path to run the documentation locally:
# html_dir = root_dir / "docs" / "_build" / "html" / "auto_examples" / "02_meta-analyses"
html_dir = root_dir / "_readthedocs" / "html" / "auto_examples" / "02_meta-analyses"
# root_dir = Path(os.getcwd()).parents[1] / "docs" / "_build"
# Use the previous root to run the documentation locally.
root_dir = Path(os.getcwd()).parents[1] / "_readthedocs"
html_dir = root_dir / "html" / "auto_examples" / "02_meta-analyses" / "10_plot_cbma_workflow"
html_dir.mkdir(parents=True, exist_ok=True)

run_reports(result, html_dir)

####################################
# .. raw:: html
#
# <iframe src="./report.html" style="border:none;" seamless="seamless" width="100%"\
# height="1000px"></iframe>
# <iframe src="./10_plot_cbma_workflow/report.html" style="border:none;" seamless="seamless"\
# width="100%" height="1000px"></iframe>
Loading
Loading