Skip to content

Commit

Permalink
finalized MACM workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
mriedel56 committed Jun 23, 2020
1 parent 64fcb02 commit 4a57e68
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 8 deletions.
11 changes: 6 additions & 5 deletions connectivity/macm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
from nimare.meta.cbma import ALE
from nimare.dataset import Dataset
from nimare.correct import FWECorrector
from nimare.io import convert_neurosynth_to_dataset

import sys
sys.path.append('/Users/miriedel/Desktop/GitHub/niconn/')

def macm_workflow(prefix=None, mask=None, output_dir=None, ns_data_dir=None):

Expand All @@ -15,7 +16,7 @@ def macm_workflow(prefix=None, mask=None, output_dir=None, ns_data_dir=None):
raise Exception('A valid directory is required for downloading Neurosynth data!')

if prefix is None:
prefix = op.basename(mask_fn).split('.')[0]
prefix = op.basename(mask).split('.')[0]

if output_dir is None:
output_dir = op.dirname(op.abspath(mask))
Expand All @@ -24,18 +25,18 @@ def macm_workflow(prefix=None, mask=None, output_dir=None, ns_data_dir=None):

# download neurosynth dataset if necessary
if not op.isfile(dataset_file):
from .datasets import neurosyth.neurosynth_download
from datasets.neurosynth import neurosynth_download
neurosynth_download(ns_data_dir)

dset = Dataset.load(dataset_file)
mask_ids = dset.get_studies_by_mask(mask_fn)
mask_ids = dset.get_studies_by_mask(mask)
maskdset = dset.slice(mask_ids)
nonmask_ids = sorted(list(set(dset.ids) - set(mask_ids)))
nonmaskdset = dset.slice(nonmask_ids)

ale = ALE(kernel__fwhm=15)
ale.fit(maskdset)

corr = FWECorrector(method='permutation', n_iters=10, n_cores=-1, voxel_thresh=0.001)
corr = FWECorrector(method='permutation', n_iters=10000, n_cores=-1, voxel_thresh=0.001)
cres = corr.transform(ale.results)
cres.save_maps(output_dir=output_dir, prefix=prefix)
Binary file added datasets/__pycache__/neurosynth.cpython-37.pyc
Binary file not shown.
4 changes: 3 additions & 1 deletion neurosynth.py → datasets/neurosynth.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import os.path as op
from neurosynth.base.dataset import download
from nimare.io import convert_neurosynth_to_dataset


def neurosynth_download(ns_data_dir=None):

Expand All @@ -11,7 +13,7 @@ def neurosynth_download(ns_data_dir=None):

if not op.isdir(ns_data_dir):
os.mkdir(ns_data_dir)

download(ns_data_dir, unpack=True)
###############################################################################
# Convert Neurosynth database to NiMARE dataset file
Expand Down
Binary file added tests/test_macm/ns_hand_roi.nii.gz
Binary file not shown.
85 changes: 83 additions & 2 deletions tests/test_macm/test_macm_workflow.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,94 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"ERROR:duecredit:Failed to import duecredit due to No module named 'duecredit'\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"200623-06:45:09,54 nipype.utils INFO:\n",
"\t Running nipype version 1.4.2 (latest: 1.5.0)\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:nipype.utils:Running nipype version 1.4.2 (latest: 1.5.0)\n"
]
}
],
"source": [
"import sys\n",
"sys.path.append('/Users/miriedel/Desktop/GitHub/niconn/')\n",
"from connectivity.macm import macm_workflow"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"roi = '/Users/miriedel/Desktop/GitHub/niconn/tests/test_macm/ns_hand_roi.nii.gz'\n",
"ns_data_dir = '/Users/miriedel/Desktop/GitHub/niconn/tests/test_macm/ns_data_dir'"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:nimare.correct.base:Using correction method implemented in Estimator: <class 'nimare.meta.cbma.ale.ALE'>.correct_fwe_permutation.\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "3ab771ceaa714913b2bfdee49eb25d4a",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(FloatProgress(value=0.0, max=10.0), HTML(value='')))"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/miriedel/Desktop/GitHub/NiMARE/nimare/meta/cbma/ale.py:348: RuntimeWarning: divide by zero encountered in log\n",
" logp_vfwe_values = -np.log(p_fwe_values)\n"
]
}
],
"source": [
"macm_workflow(mask=roi, ns_data_dir=ns_data_dir)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down

0 comments on commit 4a57e68

Please sign in to comment.