Decode regions of interest and subsets of Datasets

We can use the methods in nimare.decode.discrete to apply functional characterization analysis to regions of interest or subsets of the Dataset.

import os

import nibabel as nib
import numpy as np
from nilearn.plotting import plot_roi

import nimare
from nimare.decode import discrete
from nimare.tests.utils import get_test_data_path

Load dataset with abstracts

We’ll load a small dataset composed only of studies in Neurosynth with Angela Laird as a coauthor, for the sake of speed.

dset = nimare.dataset.Dataset(os.path.join(get_test_data_path(), "neurosynth_laird_studies.json"))
dset.annotations.head(5)
id study_id contrast_id Neurosynth_TFIDF__001 Neurosynth_TFIDF__01 Neurosynth_TFIDF__05 Neurosynth_TFIDF__10 Neurosynth_TFIDF__100 Neurosynth_TFIDF__11 Neurosynth_TFIDF__12 Neurosynth_TFIDF__12 healthy Neurosynth_TFIDF__13 Neurosynth_TFIDF__14 Neurosynth_TFIDF__14 healthy Neurosynth_TFIDF__15 Neurosynth_TFIDF__15 healthy Neurosynth_TFIDF__16 Neurosynth_TFIDF__16 healthy Neurosynth_TFIDF__17 Neurosynth_TFIDF__18 Neurosynth_TFIDF__18 healthy Neurosynth_TFIDF__19 Neurosynth_TFIDF__20 Neurosynth_TFIDF__20 healthy Neurosynth_TFIDF__200 Neurosynth_TFIDF__2014 Neurosynth_TFIDF__21 Neurosynth_TFIDF__22 Neurosynth_TFIDF__23 Neurosynth_TFIDF__24 Neurosynth_TFIDF__25 Neurosynth_TFIDF__26 Neurosynth_TFIDF__27 Neurosynth_TFIDF__28 Neurosynth_TFIDF__29 Neurosynth_TFIDF__30 Neurosynth_TFIDF__31 Neurosynth_TFIDF__32 Neurosynth_TFIDF__33 Neurosynth_TFIDF__34 ... Neurosynth_TFIDF__weight Neurosynth_TFIDF__weighted Neurosynth_TFIDF__whilst Neurosynth_TFIDF__white Neurosynth_TFIDF__white matter Neurosynth_TFIDF__wide Neurosynth_TFIDF__widely Neurosynth_TFIDF__widespread Neurosynth_TFIDF__wiley Neurosynth_TFIDF__wiley periodicals Neurosynth_TFIDF__window Neurosynth_TFIDF__wise Neurosynth_TFIDF__wm Neurosynth_TFIDF__wm task Neurosynth_TFIDF__women Neurosynth_TFIDF__word Neurosynth_TFIDF__word form Neurosynth_TFIDF__word pairs Neurosynth_TFIDF__word recognition Neurosynth_TFIDF__words Neurosynth_TFIDF__work Neurosynth_TFIDF__working Neurosynth_TFIDF__working memory Neurosynth_TFIDF__world Neurosynth_TFIDF__worse Neurosynth_TFIDF__written Neurosynth_TFIDF__year Neurosynth_TFIDF__year old Neurosynth_TFIDF__years Neurosynth_TFIDF__years old Neurosynth_TFIDF__yield Neurosynth_TFIDF__yielded Neurosynth_TFIDF__young Neurosynth_TFIDF__young adults Neurosynth_TFIDF__young healthy Neurosynth_TFIDF__young older Neurosynth_TFIDF__younger Neurosynth_TFIDF__younger adults Neurosynth_TFIDF__youth Neurosynth_TFIDF__zone
0 17029760-1 17029760 1 0.0 0.0 0.0 0.0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
1 18760263-1 18760263 1 0.0 0.0 0.0 0.0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 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0 0.0

5 rows × 3231 columns



Create a region of interest

# First we'll make an ROI
arr = np.zeros(dset.masker.mask_img.shape, int)
arr[65:75, 50:60, 50:60] = 1
mask_img = nib.Nifti1Image(arr, dset.masker.mask_img.affine)
plot_roi(mask_img, draw_cross=False)

# Get studies with voxels in the mask
ids = dset.get_studies_by_mask(mask_img)
plot discrete decoders

Decode an ROI image using the BrainMap method

# Run the decoder
decoder = discrete.BrainMapDecoder(correction=None)
decoder.fit(dset)
decoded_df = decoder.transform(ids=ids)
decoded_df.sort_values(by="probReverse", ascending=False).head()
pForward zForward likelihoodForward pReverse zReverse probReverse
Term
Neurosynth_TFIDF__shift 1.0 0.0 46.541667 1.0 0.0 0.026807
Neurosynth_TFIDF__frontal gyrus 1.0 0.0 46.541667 1.0 0.0 0.026807
Neurosynth_TFIDF__pitch 1.0 0.0 46.541667 1.0 0.0 0.026807
Neurosynth_TFIDF__modulation 1.0 0.0 46.541667 1.0 0.0 0.026807
Neurosynth_TFIDF__electrophysiological 1.0 0.0 46.541667 1.0 0.0 0.026807


Decode an ROI image using the Neurosynth chi-square method

# Run the decoder
decoder = discrete.NeurosynthDecoder(correction=None)
decoder.fit(dset)
decoded_df = decoder.transform(ids=ids)
decoded_df.sort_values(by="probReverse", ascending=False).head()
pForward zForward probForward pReverse zReverse probReverse
Term
Neurosynth_TFIDF__motor 3.776053e-10 6.263015 0.300000 0.003108 2.956832 1.000000
Neurosynth_TFIDF__presence 3.217557e-05 4.157495 0.533333 0.001145 3.252350 0.937500
Neurosynth_TFIDF__primary 4.511984e-05 4.079566 0.369048 0.014119 2.454230 0.903226
Neurosynth_TFIDF__movement 5.060822e-02 1.954787 0.562500 0.025965 2.226732 0.888889
Neurosynth_TFIDF__supplementary motor 5.060822e-02 1.954787 0.562500 0.025965 2.226732 0.888889


Decode an ROI image using the Neurosynth ROI association method

# This method decodes the ROI image directly, rather than comparing subsets of the Dataset like the
# other two.
decoder = discrete.ROIAssociationDecoder(mask_img)
decoder.fit(dset)

# The `transform` method doesn't take any parameters.
decoded_df = decoder.transform()

decoded_df.sort_values(by="r", ascending=False).head()
r
feature
Neurosynth_TFIDF__motor 0.773111
Neurosynth_TFIDF__reliably 0.681833
Neurosynth_TFIDF__reading 0.681833
Neurosynth_TFIDF__oral 0.681833
Neurosynth_TFIDF__mediating 0.681833


Total running time of the script: ( 0 minutes 2.528 seconds)

Gallery generated by Sphinx-Gallery