|
| 1 | +# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- |
| 2 | +# vi: set ft=python sts=4 ts=4 sw=4 et: |
| 3 | +"""Example running a parcel-based second-level analysis from a set of |
| 4 | +first-level effect images. |
| 5 | +
|
| 6 | +This script takes as input a directory path that contains first-level |
| 7 | +images in nifti format, as well as a group mask image and a |
| 8 | +parcellation image (such as the AAL atlas, 'ROI_MNI_V4.nii', see |
| 9 | +http://www.gin.cnrs.fr/spip.php?article217). All images are assumed to |
| 10 | +be in a common reference space, e.g. the MNI/Talairach space. |
| 11 | +
|
| 12 | +It outpus three images: |
| 13 | +
|
| 14 | +* tmap.nii.gz, a `t-statistic` image similar to a SPM-like second-level |
| 15 | + t-map, except it is derived under an assumption of localization |
| 16 | + uncertainty in reference space. |
| 17 | +
|
| 18 | +* parcel_mu.nii.gz, an image that maps each voxel to the estimated |
| 19 | + population effect in the parcel it belongs to. |
| 20 | +
|
| 21 | +* parcel_prob.nii.gz, an image that maps each voxel to the probability |
| 22 | + that the population effect in the parcel it belongs to is |
| 23 | + positive-valued. |
| 24 | +
|
| 25 | +See the `nipy.algorithms.group.ParcelAnalysis` class for more general |
| 26 | +usage information. |
| 27 | +""" |
| 28 | +from os.path import join |
| 29 | +from glob import glob |
| 30 | +from nipy import load_image |
| 31 | +from nipy.algorithms.group import ParcelAnalysis |
| 32 | +from nipy.externals.argparse import ArgumentParser |
| 33 | + |
| 34 | +# Parse command line |
| 35 | +description = 'Run a parcel-based second-level analysis from a set of\ |
| 36 | +first-level effect images.' |
| 37 | + |
| 38 | +parser = ArgumentParser(description=description) |
| 39 | +parser.add_argument('con_path', metavar='con_path', |
| 40 | + help='directory where 1st-level images are to be found') |
| 41 | +parser.add_argument('msk_file', metavar='msk_file', |
| 42 | + help='group mask file') |
| 43 | +parser.add_argument('parcel_file', metavar='parcel_file', |
| 44 | + help='parcellation image file') |
| 45 | +args = parser.parse_args() |
| 46 | + |
| 47 | +# Load first-level images |
| 48 | +con_files = glob(join(args.con_path, '*.nii')) |
| 49 | +con_imgs = [load_image(f) for f in con_files] |
| 50 | + |
| 51 | +# Load group mask |
| 52 | +msk_img = load_image(args.msk_file) |
| 53 | + |
| 54 | +# Load parcellation |
| 55 | +parcel_img = load_image(args.parcel_file) |
| 56 | + |
| 57 | +# Run parcel analysis and write output images in the current directory |
| 58 | +g = ParcelAnalysis(con_imgs, parcel_img, |
| 59 | + msk_img=msk_img, fwhm=8, |
| 60 | + res_path='.') |
| 61 | +tmap_img = g.tmap() |
| 62 | +parcel_mu_img, parcel_proba_img = g.parcel_maps() |
0 commit comments