Discrete functional decoding

Perform meta-analytic functional decoding on regions of interest.

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

from nimare.dataset import Dataset
from nimare.decode import discrete
from nimare.utils import get_resource_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 = Dataset(os.path.join(get_resource_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.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0.0 0.0 0.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, np.int32)
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)
01 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()
/home/docs/checkouts/readthedocs.org/user_builds/nimare/envs/latest/lib/python3.9/site-packages/numpy/core/fromnumeric.py:86: FutureWarning:

The behavior of DataFrame.sum with axis=None is deprecated, in a future version this will reduce over both axes and return a scalar. To retain the old behavior, pass axis=0 (or do not pass axis)
pForward zForward likelihoodForward pReverse zReverse probReverse
Term
Neurosynth_TFIDF__critical 1.0 0.0 69.8125 1.0 0.0 0.03412
Neurosynth_TFIDF__voice 1.0 0.0 69.8125 1.0 0.0 0.03412
Neurosynth_TFIDF__critical role 1.0 0.0 69.8125 1.0 0.0 0.03412
Neurosynth_TFIDF__correction 1.0 0.0 69.8125 1.0 0.0 0.03412
Neurosynth_TFIDF__electrophysiological 1.0 0.0 69.8125 1.0 0.0 0.03412


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__role 5.926024e-08 5.421019 0.250000 0.006644 2.714160 1.000000
Neurosynth_TFIDF__presence 3.596754e-08 5.509588 0.500000 0.000037 4.123106 1.000000
Neurosynth_TFIDF__primary 5.035123e-08 5.450066 0.333333 0.001145 3.252350 1.000000
Neurosynth_TFIDF__motor 6.523915e-08 5.403812 0.200000 0.019681 2.332381 1.000000
Neurosynth_TFIDF__strongest 7.756332e-03 2.662497 0.531250 0.004759 2.822897 0.941176


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__presence 0.852701
Neurosynth_TFIDF__primary 0.848964
Neurosynth_TFIDF__motor 0.746275
Neurosynth_TFIDF__inferior frontal 0.621745
Neurosynth_TFIDF__communication 0.621745


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

Gallery generated by Sphinx-Gallery