Ejemplo n.º 1
0
def gbm_datasource(sub_id, BASE_DIR):

    sessions = [x for x in os.listdir(os.path.join(BASE_DIR, sub_id))
                if 'REF' not in x and 'T10' not in x and 'RT_' not in x]
    datasource = nipype.Node(
        interface=nipype.DataGrabber(
            infields=['sub_id', 'sessions', 'ref_ct', 'ref_t1'],
            outfields=['t1', 'ct1', 't2', 'flair', 'reference', 't1_0']),
            name='datasource')
    datasource.inputs.base_directory = BASE_DIR
    datasource.inputs.template = '*'
    datasource.inputs.sort_filelist = True
    datasource.inputs.raise_on_empty = False
    datasource.inputs.field_template = dict(t1='%s/%s/T1.nii.gz', ct1='%s/%s/CT1.nii.gz',
                                            t2='%s/%s/T2.nii.gz', flair='%s/%s/FLAIR.nii.gz',
                                            reference='%s/%s/CT.nii.gz',
                                            t1_0='%s/%s/T1.nii.gz')
    datasource.inputs.template_args = dict(t1=[['sub_id', 'sessions']],
                                           ct1=[['sub_id', 'sessions']],
                                           t2=[['sub_id', 'sessions']],
                                           flair=[['sub_id', 'sessions']],
                                           reference=[['sub_id', 'ref_ct']],
                                           t1_0=[['sub_id', 'ref_t1']])
    datasource.inputs.sub_id = sub_id
    datasource.inputs.sessions = sessions
    datasource.inputs.ref_ct = 'REF'
    datasource.inputs.ref_t1 = 'T10'
    
    return datasource, sessions
Ejemplo n.º 2
0
def single_tp_segmentation_datasource(sub_id, BASE_DIR):

    sessions = [
        x for x in os.listdir(os.path.join(BASE_DIR, sub_id))
        if 'REF' not in x and 'T10' not in x and 'RT_' not in x
        and os.path.isdir(os.path.join(BASE_DIR, sub_id, x))
    ]
    ref_session = [
        x for x in os.listdir(os.path.join(BASE_DIR, sub_id))
        if x == 'REF' and os.path.isdir(os.path.join(BASE_DIR, sub_id, x))
    ]
    if ref_session:
        reference = True
    else:
        print('NO REFERENCE CT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
        reference = False

    datasource = nipype.Node(interface=nipype.DataGrabber(
        infields=['sub_id', 'sessions', 'ref_ct'],
        outfields=[
            't1', 'ct1', 't2', 'flair', 'reference', 'reg2t1_warp',
            'reg2t1_mat', 'ct1_preproc', 'flair_preproc', 't1_preproc',
            't2_preproc', 'regT12CT'
        ]),
                             name='datasource')
    datasource.inputs.base_directory = BASE_DIR
    datasource.inputs.template = '*'
    datasource.inputs.sort_filelist = True
    datasource.inputs.raise_on_empty = False
    datasource.inputs.field_template = dict(
        t1='%s/%s/T1.nii.gz',
        ct1='%s/%s/CT1.nii.gz',
        t2='%s/%s/T2.nii.gz',
        flair='%s/%s/FLAIR.nii.gz',
        reference='%s/%s/CT.nii.gz',
        regT12CT='%s/%s/reg2T1_ref.mat',
        ct1_preproc='%s/%s/CT1_preproc.nii.gz',
        t1_preproc='%s/%s/T1_preproc.nii.gz',
        t2_preproc='%s/%s/T2_preproc.nii.gz',
        flair_preproc='%s/%s/FLAIR_preproc.nii.gz')
    datasource.inputs.template_args = dict(
        t1=[['sub_id', 'sessions']],
        ct1=[['sub_id', 'sessions']],
        t2=[['sub_id', 'sessions']],
        flair=[['sub_id', 'sessions']],
        reference=[['sub_id', 'ref_ct']],
        regT12CT=[['sub_id', 'sessions']],
        ct1_preproc=[['sub_id', 'sessions']],
        t1_preproc=[['sub_id', 'sessions']],
        t2_preproc=[['sub_id', 'sessions']],
        flair_preproc=[['sub_id', 'sessions']])
    datasource.inputs.sub_id = sub_id
    datasource.inputs.sessions = sessions
    datasource.inputs.ref_ct = 'REF'

    return datasource, sessions, reference
Ejemplo n.º 3
0
    def create_datasource(self):

        datasource = nipype.Node(interface=nipype.DataGrabber(
            infields=['sub_id'], outfields=self.outfields),
                                 name='datasource')
        datasource.inputs.base_directory = self.input_dir
        datasource.inputs.template = '*'
        datasource.inputs.sort_filelist = True
        datasource.inputs.raise_on_empty = False
        datasource.inputs.field_template = self.field_template
        datasource.inputs.template_args = self.template_args
        datasource.inputs.sub_id = self.sub_id

        return datasource
Ejemplo n.º 4
0
    def create_datasource(self):

        datasource = nipype.Node(interface=nipype.DataGrabber(
            infields=['sub_id', 'sessions', 'ref_ct', 'ref_t1'],
            outfields=self.outfields),
                                 name='datasource')
        datasource.inputs.base_directory = self.base_dir
        datasource.inputs.template = '*'
        datasource.inputs.sort_filelist = True
        datasource.inputs.raise_on_empty = False
        datasource.inputs.field_template = self.field_template
        datasource.inputs.template_args = self.template_args
        datasource.inputs.sub_id = self.sub_id
        datasource.inputs.sessions = self.sessions
        datasource.inputs.ref_ct = 'REF'
        datasource.inputs.ref_t1 = 'T10'
        if self.rt is not None:
            datasource.inputs.rt = self.rt['session']
        if self.ct_sessions:
            datasource.inputs.ct_session = self.ct_sessions

        return datasource
Ejemplo n.º 5
0
for n, sub in enumerate(SUB_LIST):
    for contrast in CONTRASTS:
        sub_name = sub.split('/')[-1]
        sessions = [x for x in sorted(glob.glob(os.path.join(sub, '*')))]
        ct_tp = [i for i, s in enumerate(sessions) if CTS[n] in s]
        sessions = [
            x for x in sessions[ct_tp[0] + 1:]
            if glob.glob(x + '/{}.nii.gz'.format(contrast))
        ]
        if len(sessions) > 1:
            ref_tp = sessions[0].split('/')[-1]
            sessions.remove(sessions[0])
            sessions = [x.split('/')[-1] for x in sessions]
            datasource = nipype.Node(interface=nipype.DataGrabber(
                infields=['contrasts', 'sub_id', 'sessions', 'ref_tp'],
                outfields=['reference', 'to_reg']),
                                     name='datasource')
            datasource.inputs.base_directory = BASE_DIR
            datasource.inputs.template = '*'
            datasource.inputs.sort_filelist = True
            datasource.inputs.field_template = dict(
                reference='%s/%s/%s.nii.gz', to_reg='%s/%s/%s.nii.gz')
            datasource.inputs.template_args = dict(
                to_reg=[['sub_id', 'sessions', 'contrasts']],
                reference=[['sub_id', 'ref_tp', 'contrasts']])
            datasource.inputs.raise_on_empty = False
            datasource.inputs.contrasts = contrast
            datasource.inputs.sub_id = sub.split('/')[-1]
            datasource.inputs.sessions = sessions
            datasource.inputs.ref_tp = ref_tp
Ejemplo n.º 6
0
from nipype.interfaces.dcm2nii import Dcm2niix


contrasts = ['T1KM', 'FLAIR', 'CT', 'ADC', 'T1', 'SWI', 'T2', 'T2KM']
rt_files = ['RTSTRUCT', 'RTDOSE', 'RTPLAN']
base_dir = '/media/fsforazz/portable_hdd/data_sorted/test/'
result_dir = '/mnt/sdb/Cinderella_FU_sorted_all_test2/'
cache_dir = '/mnt/sdb/sorted_data/sorting_cache2/'

inputnode = nipype.Node(
    interface=util.IdentityInterface(fields=['contrasts']),
    name='inputnode')
inputnode.iterables = ('contrasts', contrasts)

datasource = nipype.Node(
    interface=nipype.DataGrabber(infields=['contrasts'], outfields=['directory']),
    name='datasource')  
datasource.inputs.base_directory = base_dir
datasource.inputs.template = '*'
datasource.inputs.sort_filelist = True
datasource.inputs.field_template = dict(directory='*/*/%s/1-*')

inputnode_rt = nipype.Node(
    interface=util.IdentityInterface(fields=['rt_files']),
    name='inputnode_rt')
inputnode_rt.iterables = ('rt_files', rt_files)

datasource_rt = nipype.Node(
    interface=nipype.DataGrabber(infields=['rt_files'], outfields=['directory']),
    name='datasource_rt')
datasource_rt.inputs.base_directory = base_dir
Ejemplo n.º 7
0
                    data.append(os.path.join(sub_name, current_tp))
                else:
                    previous = [x for x in data if sub_name in x][0]
                    previous_tp = previous.split('/')[-1]
                    if current_tp > previous_tp:
                        data.remove(previous)
                        data.append(os.path.join(sub_name, current_tp))
    return data


base_dir = '/mnt/sdb/anal_sorted/'
cache_dir = '/mnt/sdb/feat_cache'
result_dir = '/mnt/sdb/anal_fe'
sub_list = creste_sub_list(base_dir)

datasource = nipype.Node(interface=nipype.DataGrabber(
    infields=['sub_id'], outfields=['ct', 'rtstruct']),
                         name='datasource')
datasource.inputs.base_directory = base_dir
datasource.inputs.template = '*'
datasource.inputs.sort_filelist = True
datasource.inputs.field_template = dict(ct='%s/CT.nii.gz',
                                        rtstruct='%s/RTSTRUCT/*.dcm')
datasource.inputs.template_args = dict(ct=[['sub_id']], rtstruct=[['sub_id']])
datasource.inputs.raise_on_empty = False
datasource.inputs.sub_id = sub_list

voxelizer = nipype.MapNode(interface=Voxelizer(),
                           iterfield=['reference', 'struct_file'],
                           name='voxelizer')
voxelizer.inputs.regular_expression = '.*PTV.*'
voxelizer.inputs.multi_structs = True
Ejemplo n.º 8
0
# contrasts = ['T1KM', 'FLAIR', 'CT', 'ADC', 'T1', 'SWI', 'T2', 'T2KM']
contrasts = ['T1', 'FLAIR', 'CT1', 'T2']
rt_files = ['RTCT', 'RTSTRUCT', 'RTDOSE', 'RTPLAN']
ct_files = ['CT']
base_dir = '/mnt/sdb/debugging_workflow'
result_dir = '/mnt/sdb/debugging_workflow_out'
cache_dir = '/mnt/sdb/debugging_workflow_cache'

if not os.path.isdir(result_dir):
    os.mkdir(result_dir)

inputnode = nipype.Node(interface=util.IdentityInterface(fields=['contrasts']),
                        name='inputnode')
inputnode.iterables = ('contrasts', contrasts)

datasource = nipype.Node(interface=nipype.DataGrabber(infields=['contrasts'],
                                                      outfields=['directory']),
                         name='datasource')
datasource.inputs.base_directory = base_dir
datasource.inputs.template = '*'
datasource.inputs.sort_filelist = True
datasource.inputs.field_template = dict(directory='*/*/%s')

datasource_ct = nipype.Node(interface=nipype.DataGrabber(
    infields=['name'], outfields=['directory']),
                            name='datasource_ct')
datasource_ct.inputs.base_directory = base_dir
datasource_ct.inputs.template = '*'
datasource_ct.inputs.sort_filelist = True
datasource_ct.inputs.field_template = dict(directory='*/*/%s')
datasource_ct.inputs.name = 'CT'
Ejemplo n.º 9
0
    CLEAN_CACHE = ARGS.clean_cache

    sequences = ['t1', 'ct1', 't2', 'flair']
    sub_list = os.listdir(BASE_DIR)

    if not os.path.isdir(WORKFLOW_CACHE):
        os.makedirs(WORKFLOW_CACHE)

    for sub_id in sub_list:
        NIPYPE_CACHE = os.path.join(NIPYPE_CACHE_BASE, sub_id)

        sessions = [x for x in os.listdir(os.path.join(BASE_DIR, sub_id))
                    if 'REF' not in x and 'T10' not in x and 'RT_' not in x]
        datasource = nipype.Node(
            interface=nipype.DataGrabber(
                infields=['sub_id', 'sessions', 'ref_ct', 'ref_t1'],
                outfields=['t1', 'ct1', 't2', 'flair', 'reference', 't1_0']),
                name='datasource')
        datasource.inputs.base_directory = BASE_DIR
        datasource.inputs.template = '*'
        datasource.inputs.sort_filelist = True
        datasource.inputs.raise_on_empty = False
        datasource.inputs.field_template = dict(t1='%s/%s/T1.nii.gz', ct1='%s/%s/CT1.nii.gz',
                                                t2='%s/%s/T2.nii.gz', flair='%s/%s/FLAIR.nii.gz',
                                                reference='%s/%s/CT.nii.gz',
                                                t1_0='%s/%s/T1.nii.gz')
        datasource.inputs.template_args = dict(t1=[['sub_id', 'sessions']],
                                               ct1=[['sub_id', 'sessions']],
                                               t2=[['sub_id', 'sessions']],
                                               flair=[['sub_id', 'sessions']],
                                               reference=[['sub_id', 'ref_ct']],