Пример #1
0
## load the yaml files with parameters
#with open('parameters.yaml', 'rb') as f:
#    params = yaml.load(f)

# ======================================================================
# SET PATHS FOR SPM AND MATLAB:
# ======================================================================
# set paths to matlab and spm depending on the operating system:
if 'win32' in sys.platform:
    path_spm = '/Users/Shared/spm12'
    path_matlab = '/Applications/MATLAB_R2017a.app/bin/matlab -nodesktop -nosplash'
elif 'linux' in sys.platform:
    path_spm = opj('/home', 'mpib', 'wittkuhn', 'tools', 'matlab', 'spm12')
    path_matlab = '/opt/matlab/R2017b/bin/matlab -nodesktop -nosplash'
# set paths for spm:
MatlabCommand.set_default_paths(path_spm)
MatlabCommand.set_default_matlab_cmd(path_matlab)
spm.SPMCommand.set_mlab_paths(paths=path_spm, matlab_cmd=path_matlab)

# ======================================================================
# DEFINE PBS CLUSTER JOB TEMPLATE (NEEDED WHEN RUNNING ON THE CLUSTER):
# ======================================================================
job_template = """
#PBS -l walltime=1:00:00
#PBS -j oe
#PBS -o $HOME/logs/glm
#PBS -m n
#PBS -v FSLOUTPUTTYPE=NIFTI_GZ
source /etc/bash_completion.d/virtualenvwrapper
workon highspeed
module load fsl
Пример #2
0
import nipype.interfaces.utility as util  # utility
import nipype.pipeline.engine as pe  # pypeline engine
import nipype.algorithms.rapidart as ra  # artifact detection
import nipype.algorithms.modelgen as model  # model specification

from nipype.algorithms.misc import Gunzip
from nipype import Node, Workflow, MapNode
from nipype import SelectFiles
from os.path import join as opj

os.chdir('/home/or/Documents/dicom_niix')
import readConditionFiles_r_aPTSD

from nipype.interfaces.matlab import MatlabCommand
#mlab.MatlabCommand.set_default_matlab_cmd("matlab -nodesktop -nosplash")
MatlabCommand.set_default_paths(
    '/home/or/Downloads/spm12/')  # set default SPM12 path in my computer.

# Specify the location of the data.
data_dir = os.path.abspath('/media/Data/FromHPC/output/fmriprep')
from bids.grabbids import BIDSLayout

layout = BIDSLayout(data_dir)
checkGet = layout.get(type="bold", extensions="nii.gz")
checkGet[0].subject
layout.get(type="bold", task="3", session="1", extensions="nii.gz")[0].filename

# Specify the subject directories
subject_list = [
    '1063', '1072', '1206', '1244', '1273', '1291', '1305', '1340', '1345',
    '1346'
]
config.update_config(cfg)

import nipype.interfaces.fsl as fsl
import nipype.interfaces.afni as afni
import nipype.interfaces.ants as ants
import nipype.interfaces.spm as spm

from nipype.interfaces.utility import IdentityInterface, Function, Select, Merge
from os.path import join as opj
from nipype.interfaces.io import SelectFiles, DataSink
from nipype.pipeline.engine import Workflow, Node, MapNode

import numpy as np
import matplotlib.pyplot as plt
from nipype.interfaces.matlab import MatlabCommand
MatlabCommand.set_default_paths('/media/amr/HDD/Sofwares/spm12/')
MatlabCommand.set_default_matlab_cmd("matlab -nodesktop -nosplash")

# import nipype.interfaces.matlab as mlab
# mlab.MatlabCommand.set_default_matlab_cmd("matlab -nodesktop -nosplash")
# mlab.MatlabCommand.set_default_paths('/home/amr/Documents/MATLAB/toolbox/spm8')

#-----------------------------------------------------------------------------------------------------
# In[2]:
experiment_dir = '/media/amr/HDD/Work/Stimulation'

subject_list = [
    '003', '005', '008', '011', '018', '019', '020', '059', '060', '062',
    '063', '066'
]
Пример #4
0
data_dir = opj(experiment_dir, 'data')  # location of data folder
fs_folder = opj(experiment_dir, 'freesurfer')  # location of freesurfer folder

subject_list = ["1002", "1003", "1004"]  # list of subject identifiers
session_list = ['Enc1', 'Enc2', 'Enc3', 'Jud1',
                'Jud2']  # list of session identifiers

output_dir = 'output_firstSteps'  # name of output folder
working_dir = 'workingdir_firstSteps'  # name of working directory

number_of_slices = 38  # number of slices in volume
TR = 2.0  # time repetition of volume
smoothing_size = 8  # size of FWHM in mm

#Have to check this path
MatlabCommand.set_default_paths(
    '/Users/lighthalllab/Documents/MATLAB/toolbox/spm12')
MatlabCommand.set_default_matlab_cmd(
    "/Applications/MATLAB_R2015a.app/bin/matlab -nodesktop -nosplash")

# Gunzip - unzip functional
gunzip = Node(Gunzip(), name="gunzip")

# Slicetiming - correct for slice wise acquisition
interleaved_order = list(range(1, number_of_slices + 1, 2)) + list(
    range(2, number_of_slices + 1, 2))
print(interleaved_order)
sliceTiming = Node(SliceTiming(num_slices=number_of_slices,
                               time_repetition=TR,
                               time_acquisition=TR - TR / number_of_slices,
                               slice_order=interleaved_order,
                               ref_slice=19),
Пример #5
0
        else:
            infile = results_path + subj + '/' + data + '_1/reorient/corr_restingstatefMRI2_warp_reoriented.nii.gz'
            if os.path.isfile(physsig3):
                physsig_a = physsig3
            else:
                physsig_a = None
            if os.path.isfile(physsig4):
                physsig_b = physsig4
            else:
                physsig_b = None

        print "Running DRIFTER..."
        script = "run_drifter_noSPM_kopio('%s','%s','%s')" % (
            infile, physsig_a, physsig_b)
        MatlabCommand.set_default_paths(
            ['/usr/share/spm8/', '/opt2/MATLAB/NIFTI20140122/'])
        mlab = MatlabCommand(
            script=script,
            mfile=True,
            paths=
            '/opt/Laskenta/Control_Room/Biomedicum/DRIFTER-toolbox/DRIFTER/',
            terminal_output="stream")

        try:
            os.stat(results_path + subj + '/' + data +
                    '_1/drifter/drifter_corrected.nii.gz')
        except:
            drifter_result = mlab.run()
            os.mkdir(results_path + subj + '/' + data + '_1/drifter/')
            os.rename(
                results_path + subj + '/drifter_corrected.nii.gz',
Пример #6
0
from nipype.interfaces import spm

import nipype.interfaces.io as nio  # Data i/o
import nipype.interfaces.utility as util  # utility
import nipype.pipeline.engine as pe  # pypeline engine
#import nipype.algorithms.rapidart as ra  # artifact detection
import nipype.algorithms.modelgen as model  # model specification
#from nipype.algorithms.rapidart import ArtifactDetect
# from nipype.algorithms.misc import Gunzip
from nipype import Node, Workflow, MapNode
from nipype.interfaces import fsl

from nipype.interfaces.matlab import MatlabCommand

#%%
MatlabCommand.set_default_paths('/home/rj299/project/MATLAB/toolbox/spm12/'
                                )  # set default SPM12 path in my computer.
fsl.FSLCommand.set_default_output_type('NIFTI_GZ')

data_dir = data_root
output_dir = os.path.join(out_root, 'imaging')
work_dir = os.path.join(base_root, 'work')  # intermediate products

# task_list = [1,2,3,4,5,6,7,8]

#subject_list = [2597, 2658, 2665]
# 2597
#subject_list = [2073, 2550, 2582, 2583, 2584, 2585, 2588, 2592, 2593, 2594, 2596]
#subject_list = [2655, 2658, 2665]
#subject_list = [2597, 2599, 2656, 2657, 2659, 2660, 2661, 2662, 2663, 2664, 2666]

# all subjects
Пример #7
0
        else:
            infile = results_path + subj + '/' + data + '_1/reorient/corr_restingstatefMRI2_warp_reoriented.nii.gz'
            physsig_a = physsig3
            if not os.path.isfile(physsig3):
                print "MISSING PULS DATA!"
            physsig_b = physsig4
            if not os.path.isfile(physsig4):
                print "MISSING RESP DATA!"

        print "Running DRIFTER..."
        script = "run_drifter_noSPM_kopio('%s','%s','%s')" % (
            infile, physsig_a, physsig_b)
        # TODO: muuta seuraavat polut oikeiksi!!
        # tahan Matlabin asennuspolku
        MatlabCommand.set_default_paths([
            '/usr/local/MATLAB/R2015a/spm8/toolbox/DRIFTER-toolbox/DRIFTER',
            '/usr/local/MATLAB/R2015a/spm8/', '/usr/local/MATLAB/NIFTI20130306'
        ])
        # TODO: tahan DRIFTER-toolboxin polku
        mlab = MatlabCommand(
            script=script,
            mfile=True,
            paths='/media/HannaHalmeLevy/scripts/DRIFTER-toolbox/DRIFTER/',
            terminal_output="stream")

        try:
            os.stat(results_path + subj + '/' + data +
                    '_1/drifter/drifter_corrected.nii.gz')
        except:
            drifter_result = mlab.run()
            os.mkdir(results_path + subj + '/' + data + '_1/drifter/')
            os.rename(
from os.path import join as opj
from nipype.interfaces.afni import Despike
from nipype.interfaces.freesurfer import (BBRegister, ApplyVolTransform,
                                          Binarize, MRIConvert, FSCommand)
from nipype.interfaces.spm import (SliceTiming, Realign, Smooth, Level1Design,
                                   EstimateModel, EstimateContrast)
from nipype.interfaces.utility import Function, IdentityInterface
from nipype.interfaces.io import FreeSurferSource, SelectFiles, DataSink
from nipype.algorithms.rapidart import ArtifactDetect
from nipype.algorithms.misc import TSNR, Gunzip
from nipype.algorithms.modelgen import SpecifySPMModel
from nipype.pipeline.engine import Workflow, Node, MapNode

# MATLAB - Specify path to current SPM and the MATLAB's default mode
from nipype.interfaces.matlab import MatlabCommand
MatlabCommand.set_default_paths('/usr/local/MATLAB/R2014a/toolbox/spm12')
MatlabCommand.set_default_matlab_cmd("matlab -nodesktop -nosplash")

# FreeSurfer - Specify the location of the freesurfer folder
fs_dir = '~/nipype_tutorial/freesurfer'
FSCommand.set_default_subjects_dir(fs_dir)


###
# Specify variables
experiment_dir = '~/nipype_tutorial'          # location of experiment folder
subject_list = ['sub001', 'sub002', 'sub003',
                'sub004', 'sub005', 'sub006',
                'sub007', 'sub008', 'sub009',
                'sub010']                     # list of subject identifiers
output_dir = 'output_fMRI_example_1st'        # name of 1st-level output folder
Пример #9
0
def skullstrip_spm12(filename, pathSPM12, path_output):
    """
    The computation of the skullstrip mask is done on the PD-weighted INV2 image. According to 
    S. Kashyap, this shows the best results. Outputs are written in a subfolder of the given output 
    path.
    Inputs:
        *filename: path of input image.
        *pathSPM12: path to SPM12 toolbox.
        *path_output: path where output is saved.
    
    created by Daniel Haenelt
    Date created: 01-11-2018             
    Last modified: 21-01-2019
    """
    import os
    import shutil
    import nibabel as nb
    from nipype.interfaces.spm import NewSegment
    from nipype.interfaces.matlab import MatlabCommand
    
    # set matlab path to SPM12 folder
    MatlabCommand.set_default_paths(pathSPM12)
    
    # parameters
    csf_max = 0.1 # c3 tissue class threshold.
    bone_max = 0.1 # c4 tissue class threshold.
    soft_max = 0.1 # c5 tissue class threshold.
    air_max = 0.1 # c6 tissue class threshold.
    
    # get path and file name
    path_split = os.path.split(filename)
    file = path_split[1]
    
    # make skullstrip folder
    path_skull = os.path.join(path_output, "skull")
    if not os.path.exists(path_skull):
        os.mkdir(path_skull)
        
    shutil.copyfile(filename, os.path.join(path_skull,file))
    os.chdir(path_skull)
    
    skull = NewSegment()
    skull.inputs.channel_files = os.path.join(path_skull,file)
    skull.inputs.channel_info = (0.001, 18, (True, True))
    skull.inputs.affine_regularization = "mni"
    skull.inputs.sampling_distance = 2
    skull.inputs.use_v8struct = True
    skull.inputs.warping_regularization = [0, 0.001, 0.5, 0.05, 0.2]
    skull.inputs.write_deformation_fields = [False, False]
    skull.inputs.mfile = True
    tissue1 = ((os.path.join(pathSPM12, "tpm/TPM.nii"), 1), 1, (True,False), (False, False))
    tissue2 = ((os.path.join(pathSPM12, "tpm/TPM.nii"), 2), 1, (True,False), (False, False))
    tissue3 = ((os.path.join(pathSPM12, "tpm/TPM.nii"), 3), 2, (True,False), (False, False))
    tissue4 = ((os.path.join(pathSPM12, "tpm/TPM.nii"), 4), 3, (True,False), (False, False))
    tissue5 = ((os.path.join(pathSPM12, "tpm/TPM.nii"), 5), 4, (True,False), (False, False))
    tissue6 = ((os.path.join(pathSPM12, "tpm/TPM.nii"), 6), 2, (True,False), (False, False))
    skull.inputs.tissues = [tissue1, tissue2, tissue3, tissue4, tissue5, tissue6]
    skull.run() 
    os.remove(os.path.join(path_skull,os.path.basename(filename)))
    
    # load tissue classes
    gm_img = nb.load(os.path.join(path_skull, "c1"+file))
    wm_img = nb.load(os.path.join(path_skull, "c2"+file))
    csf_img = nb.load(os.path.join(path_skull, "c3"+file))
    bone_img = nb.load(os.path.join(path_skull, "c4"+file))
    soft_img = nb.load(os.path.join(path_skull, "c5"+file))
    air_img = nb.load(os.path.join(path_skull, "c6"+file))
    
    gm_array = gm_img.get_fdata()
    wm_array = wm_img.get_fdata()
    csf_array = csf_img.get_fdata()
    bone_array = bone_img.get_fdata()
    soft_array = soft_img.get_fdata()
    air_array = air_img.get_fdata() 
    
    # generate skullstrip mask
    mask_array = gm_array + wm_array
    mask_array[mask_array > 0] = 1
    
    # get rid of pial noise
    mask_array[csf_array >= csf_max] = 0
    mask_array[bone_array >= bone_max] = 0
    mask_array[soft_array >= soft_max] = 0
    mask_array[air_array >= air_max] = 0
    
    # save skullstrip mask
    output = nb.Nifti1Image(mask_array, gm_img.affine, gm_img.header)
    nb.save(output,os.path.join(path_skull,"skullstrip_mask.nii"))
Пример #10
0
from nipype.interfaces.afni import Despike
from nipype.interfaces.freesurfer import (BBRegister, ApplyVolTransform,
                                          Binarize, MRIConvert, FSCommand)
from nipype.interfaces.spm import (SliceTiming, Realign, Smooth, Level1Design,
                                   EstimateModel, EstimateContrast)
from nipype.interfaces.utility import Function, IdentityInterface
from nipype.interfaces.io import FreeSurferSource, SelectFiles, DataSink
from nipype.algorithms.rapidart import ArtifactDetect
from nipype.algorithms.misc import TSNR, Gunzip
from nipype.algorithms.modelgen import SpecifySPMModel
from nipype.pipeline.engine import Workflow, Node, MapNode

# MATLAB - Specify path to current SPM and the MATLAB's default mode
from nipype.interfaces.matlab import MatlabCommand

MatlabCommand.set_default_paths('/Users/srk482-admin/spm12')
MatlabCommand.set_default_matlab_cmd("matlab -nodesktop -nosplash")

# FreeSurfer - Specify the location of the freesurfer folder
fs_dir = '/Users/srk482-admin/Documents/forcemem_mriDat/nipype_tutorial/freesurfer'
FSCommand.set_default_subjects_dir(fs_dir)

##Define Experiment Parameters
experiment_dir = '/Users/srk482-admin/Documents/forcemem_mriDat/nipype_tutorial'  # location of experiment folder
data_dir = '/Users/srk482-admin/Documents/forcemem_mriDat/'
subject_list = ['2017062801', '2017070601', '2017062701', '2017062101']
block_list = ['block1', 'block2', 'block3', 'block4', 'block5']
# list of subject identifiers
output_dir = 'output_fMRI_example_1st'  # name of 1st-level output folder
working_dir = 'workingdir_fMRI_example_1st'  # name of 1st-level working directory
Пример #11
0
from nipype.interfaces.fsl import Merge
from nipype.pipeline.engine import Workflow, Node
from nipype.interfaces.utility import IdentityInterface
from nipype.interfaces.matlab import MatlabCommand
from nipype.interfaces.io import DataSink
from bair_analysis.wouter.preproc_7TGE import make_workflow
from bair_analysis.workflows.freesurfer2func import make_w_freesurfer2func
from bair_analysis.workflows.filtering import make_w_smooth
from bair_analysis.workflows.coreg_7TGE import make_w_coreg_7T
from bair_analysis.wouter.preproc_7T_coreg import make_w_coreg_3T_ants
from nibabel import load

MatlabCommand.set_default_paths('/home/giovanni/tools/spm12')

TECHNIQUES = ['3TMB', '7TGE', '7TSE']


def make_w_full_preproc(SUBJECT):

    w = Workflow('full_' + SUBJECT)

    n_in = Node(IdentityInterface(fields=[
        'T1w_7TGE',
        'func_7TGE',
        'fmap_7TGE',
        'T1w_7TSE',
        'func_7TSE',
        'fmap_7TSE',
        'T1w_3TMB',
        'func_3TMB',
        'fmap_3TMB',
                print "MISSING RESP DATA!"

        else:
            infile = results_path + '/' + data + '_1/reorient/corr_epi_warp_reoriented.nii.gz'
            physsig_a = physsig3
            if not os.path.isfile(physsig3):
                print "MISSING PULS DATA!"
            physsig_b = physsig4
            if not os.path.isfile(physsig4):
                print "MISSING RESP DATA!"

        print "Running DRIFTER..."
        script = "run_drifter_noSPM_kopio('%s','%s','%s')" % (
            infile, physsig_a, physsig_b)
        MatlabCommand.set_default_paths([
            '/opt/Laskenta/Control_Room/Biomedicum/DRIFTER-toolbox/DRIFTER/',
            '/opt/MATLAB/R2015a/spm8/', '/opt/MATLAB/NIfTI_20140122/'
        ])
        mlab = MatlabCommand(
            script=script,
            mfile=True,
            paths=[
                '/opt/Laskenta/Control_Room/Biomedicum/DRIFTER-toolbox/DRIFTER/',
                '/opt/MATLAB/R2015a/spm8/', '/opt/MATLAB/NIfTI_20140122/'
            ],
            terminal_output="stream")

        try:
            os.stat(results_path + data +
                    '_1/drifter/drifter_corrected.nii.gz')
        except:
            drifter_result = mlab.run()
Пример #13
0
from os.path import join as opj
from nipype.interfaces.afni import Despike
from nipype.interfaces.freesurfer import (BBRegister, ApplyVolTransform,
                                          Binarize, MRIConvert, FSCommand)
from nipype.interfaces.spm import (SliceTiming, Realign, Smooth, Level1Design,
                                   EstimateModel, EstimateContrast)
from nipype.interfaces.utility import Function, IdentityInterface
from nipype.interfaces.io import FreeSurferSource, SelectFiles, DataSink
from nipype.algorithms.rapidart import ArtifactDetect
from nipype.algorithms.misc import TSNR
from nipype.algorithms.modelgen import SpecifySPMModel
from nipype.pipeline.engine import Workflow, Node, MapNode

# MATLAB - Specify path to current SPM and the MATLAB's default mode
from nipype.interfaces.matlab import MatlabCommand
MatlabCommand.set_default_paths('/usr/local/MATLAB/R2014a/toolbox/spm12')
MatlabCommand.set_default_matlab_cmd("matlab -nodesktop -nosplash")

# FreeSurfer - Specify the location of the freesurfer folder
fs_dir = '~/nipype_tutorial/freesurfer'
FSCommand.set_default_subjects_dir(fs_dir)


###
# Specify variables
experiment_dir = '~/nipype_tutorial'          # location of experiment folder
subject_list = ['sub001', 'sub002', 'sub003',
                'sub004', 'sub005', 'sub006',
                'sub007', 'sub008', 'sub009',
                'sub010']                     # list of subject identifiers
output_dir = 'output_fMRI_example_1st'        # name of 1st-level output folder
Пример #14
0
from nipype.interfaces.io import DataSink, SelectFiles, DataGrabber  # Data i/o
from nipype.interfaces.utility import IdentityInterface, Function  # utility
from nipype.pipeline.engine import Node, Workflow, JoinNode  # pypeline engine

from nipype.interfaces.fsl.model import Randomise, GLM, Cluster
from nipype.interfaces.freesurfer.model import Binarize
from nipype.interfaces.fsl.utils import ImageMeants, Merge, Split
from nipype.interfaces.fsl.maths import ApplyMask

#set output file type for FSL to NIFTI
from nipype.interfaces.fsl.preprocess import FSLCommand
FSLCommand.set_default_output_type('NIFTI')

# MATLAB setup - Specify path to current SPM and the MATLAB's default mode
from nipype.interfaces.matlab import MatlabCommand
MatlabCommand.set_default_paths('~/spm12')
MatlabCommand.set_default_matlab_cmd("matlab -nodesktop -nosplash")

# Set study variables
#studyhome = '/Users/catcamacho/Box/FFnHK-Oddball/RESTINGSTATE'
studyhome = '/home/camachocm2/Box_home/CARS_rest'
raw_data = studyhome + '/raw'
preproc_dir = studyhome + '/proc/preproc'
output_dir = studyhome + '/proc/analysis'
workflow_dir = studyhome + '/workflows'
roi_dir = studyhome + '/ROIs'
group_con = studyhome + '/misc/tcon.con'
group_mat = studyhome + '/misc/design.mat'
proc_cores = 2

#subjects_list = ['101']
Пример #15
0
"""
Created on Tue Sep 24 23:49:09 2019

Reference: https://github.com/poldracklab/ds003-post-fMRIPrep-analysis/blob/master/workflows.py

@author: rj299
"""
import nipype.interfaces.io as nio  # Data i/o
from nipype.interfaces import spm
from nipype import Node, Workflow, MapNode
import nipype.interfaces.utility as util # utility
from nipype import SelectFiles
import os

from nipype.interfaces.matlab import MatlabCommand
MatlabCommand.set_default_paths('/home/nachshon/Documents/MATLAB/spm12/') # set default SPM12 path in my computer. 

#%% Gourp analysis - based on SPM - should consider the fsl Randomize option (other script)
# OneSampleTTestDesign - creates one sample T-Test Design
onesamplettestdes = Node(spm.OneSampleTTestDesign(),
                         name="onesampttestdes")

# EstimateModel - estimates the model
level2estimate = Node(spm.EstimateModel(estimation_method={'Classical': 1}),
                      name="level2estimate")

# EstimateContrast - estimates group contrast
level2conestimate = Node(spm.EstimateContrast(group_contrast=True),
                         name="level2conestimate")
cont1 = ['Group', 'T', ['mean'], [1]]
level2conestimate.inputs.contrasts = [cont1]
from nipype.interfaces.matlab import MatlabCommand
import matplotlib.pyplot as plt
import numpy as np
from nipype.pipeline.engine import Workflow, Node, MapNode
from nipype.interfaces.io import SelectFiles, DataSink
from os.path import join as opj
from nipype.interfaces.utility import IdentityInterface, Function, Select, Merge
import nipype.interfaces.spm as spm
import nipype.interfaces.ants as ants
import nipype.interfaces.afni as afni
import nipype.interfaces.fsl as fsl
from nipype import config
cfg = dict(execution={'remove_unnecessary_outputs': False})
config.update_config(cfg)

MatlabCommand.set_default_paths('/Users/amr/Downloads/spm12')
MatlabCommand.set_default_matlab_cmd("matlab -nodesktop -nosplash")

# import nipype.interfaces.matlab as mlab
# mlab.MatlabCommand.set_default_matlab_cmd("matlab -nodesktop -nosplash")
# mlab.MatlabCommand.set_default_paths('/home/amr/Documents/MATLAB/toolbox/spm8')

# ============================================================================================================================
# In[2]:
experiment_dir = '/media/amr/Amr_4TB/Work/stimulation'

subject_list = [
    '003', '005', '011', '130', '018', '019', '020', '059', '060', '062',
    '063', '066', '126', '127', '146'
]
Пример #17
0
from nipype.algorithms.misc import Gunzip
from nipype.interfaces.io import SelectFiles, DataSink
from nipype.interfaces.matlab import MatlabCommand
from nipype.interfaces.utility import IdentityInterface, Merge
from nipype.pipeline.engine import Workflow, Node, MapNode

t_start = time()

# Check FSL version
version = 0
if fsl.Info.version() and LooseVersion(
        fsl.Info.version()) > LooseVersion('5.0.6'):
    version = 507

# Set up interface defaults
MatlabCommand.set_default_paths('/usr/local/matlabtools/2016a/spm12')
MatlabCommand.set_default_matlab_cmd("matlab -nodesktop -nosplash")

# Disabled default output type as this will force all other file extensions to NIFTI as well
# fsl.FSLCommand.set_default_output_type('NIFTI')

BASE_DIR = '/data/wbbruin/Desktop/resting-state_nipype/testset'
DATA_DIR = osp.join(BASE_DIR, 'data')
WORKING_DIR = osp.join(BASE_DIR, 'workdir')

# Configure pre processing parameters
template = fsl.Info.standard_image('MNI152_T1_2mm.nii.gz')
template_brain = fsl.Info.standard_image('MNI152_T1_2mm_brain.nii.gz')
template_mask = fsl.Info.standard_image('MNI152_T1_2mm_brain_mask_dil.nii.gz')

# Data dependent parameters
from nipype.interfaces.fsl.epi import ApplyTOPUP, TOPUP
from nipype.interfaces.freesurfer import Resample, Binarize, MRIConvert
from nipype.algorithms.confounds import CompCor
from nipype.interfaces.afni.preprocess import Bandpass
from nipype.interfaces.afni.utils import AFNItoNIFTI
from nipype.interfaces.ants import ApplyTransforms, Registration
from nipype.algorithms.misc import Gunzip
from pandas import DataFrame, Series

#set output file type for FSL to NIFTI
from nipype.interfaces.fsl.preprocess import FSLCommand
FSLCommand.set_default_output_type('NIFTI')

# MATLAB setup - Specify path to current SPM and the MATLAB's default mode
from nipype.interfaces.matlab import MatlabCommand
MatlabCommand.set_default_paths('~/spm12')
MatlabCommand.set_default_matlab_cmd("matlab -nodesktop -nosplash")

# Set study variables
setup='sherlock'
sample='6mo' #6mo or newborn
sequence='spiral'#spiral or mux6

if setup=='sherlock':
    studyhome = '/oak/stanford/groups/iang/BABIES_data/BABIES_rest'
    raw_data = studyhome + '/subjDir/all'
    output_dir = studyhome + '/processed/preproc'
    workflow_dir = studyhome + '/workflows'
elif setup=='Cat':
    studyhome = '/Users/catcamacho/Box/SNAP/BABIES/BABIES_rest'
    raw_data = studyhome + '/rest_raw'
Пример #19
0
import os
import socket
from nipype.interfaces.matlab import MatlabCommand

if socket.gethostname() == 'malin':
    os.environ['MATLABCMD'] = "/opt/matlab/R2015b/bin/matlab -nodesktop -nosplash"
    MatlabCommand.set_default_paths('/opt/matlab/R2015b/toolbox/spm12')
    MatlabCommand.set_default_matlab_cmd("/opt/matlab/R2015b/bin/matlab -nodesktop -nosplash")
    TPM = '/opt/matlab/R2015b/toolbox/spm12/tpm/TPM.nii'
    # os.environ['MATLABCMD'] = "/opt/matlab/R2012a/bin/matlab -nodesktop -nosplash"
    # MatlabCommand.set_default_paths('/opt/matlab/R2012a/toolbox/spm12')
    # MatlabCommand.set_default_matlab_cmd("/opt/matlab/R2012a/bin/matlab -nodesktop -nosplash")
elif socket.gethostname() == 'cala':
    os.environ['MATLABCMD'] = "/opt/matlab/64bit/R2015a/bin/matlab -nodesktop -nosplash"
    MatlabCommand.set_default_paths('/opt/matlab/64bit/R2015a/toolbox/spm12')
    MatlabCommand.set_default_matlab_cmd("/opt/matlab/64bit/R2015a/bin/matlab -nodesktop -nosplash")
    TPM = '/opt/matlab/64bit/R2015a/toolbox/spm12/tpm/TPM.nii'

def display_crash_files(crashfile, rerun=False):
    from nipype.utils.filemanip import loadcrash
    crash_data = loadcrash(crashfile)
    node = crash_data['node']
    tb = crash_data['traceback']
    print("\n")
    print("File: %s"%crashfile)
    print("Node: %s"%node)
    if node.base_dir:
        print("Working directory: %s" % node.output_dir())
    else:
        print("Node crashed before execution")
    print("\n")