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
import pandas as pd
from nilearn.plotting import plot_roi, plot_stat_map

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.load(
    os.path.join(get_test_data_path(), "neurosynth_laird_studies.pkl.gz")
)
dset.annotations.head(5)
id study_id contrast_id Neurosynth_TFIDF__001 Neurosynth_TFIDF__01 Neurosynth_TFIDF__05 Neurosynth_TFIDF__10 Neurosynth_TFIDF__10 healthy 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__2007 Neurosynth_TFIDF__2014 Neurosynth_TFIDF__2014 2014 Neurosynth_TFIDF__2014 wiley 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__weak Neurosynth_TFIDF__weaker Neurosynth_TFIDF__week Neurosynth_TFIDF__weeks 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__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__yield Neurosynth_TFIDF__yielded Neurosynth_TFIDF__young Neurosynth_TFIDF__young adults Neurosynth_TFIDF__young healthy Neurosynth_TFIDF__younger Neurosynth_TFIDF__younger adults Neurosynth_TFIDF__zone
2225 17029760-1 17029760 1 0.0 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
3565 18760263-1 18760263 1 0.0 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.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.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0

5 rows × 3172 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 Neurosynth 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 2.779546e-08 5.554784 0.375000 0.003054 2.962263 1.000000
Neurosynth_TFIDF__presence 2.553341e-04 3.656850 0.545455 0.005002 2.806918 0.916667
Neurosynth_TFIDF__behavioral 3.583888e-04 3.568969 0.383333 0.041038 2.043146 0.869565
Neurosynth_TFIDF__primary 3.583888e-04 3.568969 0.383333 0.041038 2.043146 0.869565
Neurosynth_TFIDF__finally 9.176489e-02 1.686161 0.583333 0.057395 1.900292 0.857143


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__critical 1.0 0.0 40.958333 1.0 0.0 0.025862
Neurosynth_TFIDF__communication 1.0 0.0 40.958333 1.0 0.0 0.025862
Neurosynth_TFIDF__correction 1.0 0.0 40.958333 1.0 0.0 0.025862
Neurosynth_TFIDF__pitch 1.0 0.0 40.958333 1.0 0.0 0.025862
Neurosynth_TFIDF__tasks 1.0 0.0 40.958333 1.0 0.0 0.025862


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

Gallery generated by Sphinx-Gallery