def extract_region(atlas_file, label): from nipype.interfaces.base import CommandLine from nipype.pipeline.engine import Node import os from glob import glob node = Node(CommandLine('fslmaths %s -thr %s -uthr %s region_%s.nii.gz' % (atlas_file, label, label, label)), name='extract_roi') cwd = os.getcwd() print("cwd = ", cwd) node.base_dir = cwd node.config = {'execution': {'keep_unnecessary_outputs': 'true'}} node.run() single_region = os.path.realpath( os.path.join(cwd, 'extract_roi', 'region_%s.nii.gz' % label)) print('single region mask file: ', single_region) assert os.path.exists(single_region) return single_region, label, atlas_file
node.config = {'execution': {'keep_unnecessary_outputs': 'true'}} node.run() single_region = os.path.realpath( os.path.join(cwd, 'extract_roi', 'region_%s.nii.gz' % label)) print('single region mask file: ', single_region) assert os.path.exists(single_region) return single_region, label, atlas_file region_extracter = Node(Function( input_names=['atlas_file', 'label'], output_names=['single_region', 'label', 'atlas_file'], function=extract_region), name='region_extracter') region_extracter.config = {'execution': {'keep_unnecessary_outputs': 'true'}} # filter streamlines by seed region of interest def sl_filter(streamlines, target_mask, affine, label): from dipy.tracking.utils import target from nilearn.image import resample_img import numpy as np import os import nibabel as nib trk_file = nib.streamlines.load(streamlines) streams = trk_file.streamlines hdr = trk_file.header # resample mask to resolution of input data & get data