def results(ants_ct_info, verbose=False): # Create results directory and populate util.mkcd_dir([ants_ct_info['base']['results']], True) files_to_link = [ (ants_ct_info['segment']['p_wm'], ants_ct_info['results']['p_wm']), (ants_ct_info['segment']['segment'], ants_ct_info['results']['segment']), (ants_ct_info['register']['ct'], ants_ct_info['results']['ct']), (ants_ct_info['register']['subject_to_template_affine'], ants_ct_info['results']['subject_to_template_affine']), (ants_ct_info['register']['subject_to_template_warp'], ants_ct_info['results']['subject_to_template_warp']), (ants_ct_info['register']['subject_to_template_jacobian'], ants_ct_info['results']['subject_to_template_jacobian']), (ants_ct_info['register']['template_to_subject_affine'], ants_ct_info['results']['template_to_subject_affine']), (ants_ct_info['register']['template_to_subject_warp'], ants_ct_info['results']['template_to_subject_warp']) ] for ii in files_to_link: util.force_hard_link(ii[0], ii[1]) fsl_command = [ 'fslmaths', ants_ct_info['segment']['p_gm_cortical'], '-add', ants_ct_info['segment']['p_gm_subcortical'], ants_ct_info['results']['p_gm'] ] util.iw_subprocess(fsl_command) methods_write_json_redcap_ants_ct_instrument(ants_ct_info, verbose)
def methods_02_stats(config, verbose=False): input_dir = config['dirs']['input'] util.mkcd_dir([config['methods']['results']['dir']], True) command = [ 'fslmaths', os.path.join(config['dirs']['methods']['01-register'], 'nu_brain.nii.gz'), '-bin', os.path.join(config['dirs']['methods']['results'], 'brain_mask.nii.gz') ] util.iw_subprocess(command, verbose, verbose, False) for ii in ['swi', 'swi_magnitude', 'swi_phase']: command = [ 'fslmaths', os.path.join(config['dirs']['methods']['01-register'], 'swi_Affine_nu__' + ii + '.nii.gz'), '-mas', 'brain_mask.nii.gz', ii + '.nii.gz' ] util.iw_subprocess(command, verbose, verbose, False) util.force_hard_link( os.path.join(config['methods']['input']['dir'], 'nu.nii.gz'), 'nu.nii.gz') util.force_hard_link( os.path.join(config['methods']['input']['dir'], 'nu_brain.nii.gz'), 'nu_brain.nii.gz')
def results(input_dir): """ Gather results and write the MagTran JSON output file""" cenc_dirs = cenc.directories(input_dir) swi_input_dir = cenc_dirs['swi']['dirs']['input'] swi_01_register_dir = cenc_dirs['swi']['dirs']['register'] swi_results_dir = cenc_dirs['swi']['dirs']['results'] util.mkcd_dir([swi_results_dir], True) result_files = [[ os.path.join(cenc_dirs['swi']['dirs']['register'], 'swi_Affine_nu__swi_m0_Warped.nii.gz'), os.path.join(cenc_dirs['swi']['dirs']['results'], 'swi_Affine_nu__swi_m0.nii.gz') ], [ os.path.join(cenc_dirs['swi']['dirs']['register'], 'swi_Affine_nu__swi_m1_Warped.nii.gz'), os.path.join(cenc_dirs['swi']['dirs']['results'], 'swi_Affine_nu__swi_m1.nii.gz') ], [ os.path.join(cenc_dirs['swi']['dirs']['results'], 'magtrans.json'), os.path.join(cenc_dirs['swi']['dirs']['results'], 'magtrans.json') ], [ os.path.join(cenc_dirs['swi']['dirs']['register'], 'swir.nii.gz'), os.path.join(cenc_dirs['swi']['dirs']['results'], 'swir.nii.gz') ], [ os.path.join(cenc_dirs['swi']['dirs']['input'], 'nu.nii.gz'), os.path.join(cenc_dirs['swi']['dirs']['results'], 'nu.nii.gz') ], [ os.path.join(cenc_dirs['swi']['dirs']['register'], 'swir.nii.gz'), os.path.join(cenc_dirs['results']['dirs']['images'], 'swir.nii.gz') ]] for ii in result_files: util.force_hard_link(ii[0], ii[1]) return
def methods_01_register(input_dir, verbose=False): # Register SWI images to nu.nii.gz cenc_dirs = cenc.directories(input_dir) swi_link_inputs(input_dir, cenc_dirs['swi']['dirs']['register']) ants_register('swi_magnitude') util.force_hard_link('swi_Affine_nu__swi_magnitude_Warped.nii.gz', 'swi_Affine_nu__swi_magnitude.nii.gz') ants_apply_transform('swi') ants_apply_transform('swi_phase') return
def results( input_dir): cenc_dirs = cenc.directories( input_dir) util.mkcd_dir( [ cenc_dirs['wmlesions']['dirs']['results'] ], True) # Link Files link_result_files = [ [ os.path.join( cenc_dirs['wmlesions']['dirs']['stats'], 'wmlesions_lpa_t2flair.nii.gz'), os.path.join( cenc_dirs['wmlesions']['dirs']['results'], 'wmlesions_lpa_t2flair.nii.gz') ], [ os.path.join( cenc_dirs['wmlesions']['dirs']['input'], 'nu.nii.gz'), os.path.join( cenc_dirs['wmlesions']['dirs']['results'], 'nu.nii.gz') ], [ os.path.join( cenc_dirs['wmlesions']['dirs']['stats'], 'wmlesions_lpa_pmap.nii.gz'), os.path.join( cenc_dirs['wmlesions']['dirs']['results'], 'wmlesions_lpa_pmap.nii.gz')], [ os.path.join( cenc_dirs['wmlesions']['dirs']['stats'], 'wmlesions.json'), os.path.join( cenc_dirs['wmlesions']['dirs']['results'], 'wmlesions.json')], [os.path.join(cenc_dirs['wmlesions']['dirs']['stats'], 'wmlesions_lpa_labels.nii.gz'), os.path.join(cenc_dirs['wmlesions']['dirs']['results'], 'wmlesions_lpa_labels.nii.gz')], [os.path.join(cenc_dirs['wmlesions']['dirs']['stats'], 'wmlesions_lpa_labels.csv'), os.path.join(cenc_dirs['wmlesions']['dirs']['results'], 'wmlesions_lpa_labels.csv')], [ os.path.join( cenc_dirs['wmlesions']['dirs']['stats'], 'wmlesions_lpa_mask.nii.gz'), os.path.join( cenc_dirs['wmlesions']['dirs']['results'], 'wmlesions_lpa_mask.nii.gz')], [ os.path.join( cenc_dirs['wmlesions']['dirs']['results'], 'wmlesions_lpa_pmap.nii.gz'), os.path.join( cenc_dirs['results']['dirs']['images'], 'wmlesions_lpa_pmap.nii.gz')], [ os.path.join( cenc_dirs['wmlesions']['dirs']['results'], 'wmlesions_lpa_mask.nii.gz'), os.path.join( cenc_dirs['results']['dirs']['labels'], 'wmlesions_lpa_mask.nii.gz')], [ os.path.join( cenc_dirs['wmlesions']['dirs']['results'], 'wmlesions_lpa_labels.nii.gz'), os.path.join( cenc_dirs['results']['dirs']['labels'], 'wmlesions_lpa_labels.nii.gz') ] ] for ii in link_result_files: util.force_hard_link( ii[0], ii[1])
def results(input_dir, verbose): cenc_dirs = cenc.directories(input_dir) cenc_freesurfer_dir = cenc_dirs['freesurfer']['mri'] util.mkcd_dir([ cenc_dirs['results']['dirs']['root'], cenc_dirs['results']['dirs']['images'], cenc_dirs['results']['dirs']['labels'] ], True) files_to_convert = [ os.path.join(cenc_freesurfer_dir, 'nu.mgz'), os.path.join(cenc_freesurfer_dir, 'aseg.mgz'), os.path.join(cenc_freesurfer_dir, 'brainmask.mgz'), os.path.join(cenc_freesurfer_dir, 'aparc.a2009s+aseg.mgz'), os.path.join(cenc_freesurfer_dir, 'wmparc.mgz') ] # Check if files exist if util.check_files(files_to_convert, True) == False: sys.exit() # Create link to directory if not os.path.exists(cenc_dirs['freesurfer']['results']): util.force_symbolic_link(cenc_dirs['freesurfer']['mri'], cenc_dirs['freesurfer']['results']) # TODO use input node to run this instead of a loop. The trick part is to have the files named correctly. for ii in files_to_convert: mc = fs.MRIConvert(in_file=ii, out_file=os.path.join( cenc_dirs['results']['dirs']['labels'], str.replace(os.path.basename(ii), '.mgz', '.nii.gz')), out_type='niigz') mc.run() reorient = fsl.Reorient2Std(in_file=mc.inputs.out_file, out_file=mc.inputs.out_file) reorient.run() # Link nu.nii.gz to results/native/images result_files = [[ os.path.join(cenc_dirs['results']['dirs']['labels'], 'nu.nii.gz'), os.path.join(cenc_dirs['results']['dirs']['images'], 'nu.nii.gz') ]] for ii in result_files: util.force_hard_link(ii[0], ii[1]) # Create final brain mask. cenc.create_mask( os.path.join(cenc_dirs['results']['dirs']['labels'], 'brainmask.nii.gz'), os.path.join(cenc_dirs['results']['dirs']['labels'], 'aparc.a2009s+aseg.nii.gz'), os.path.join(cenc_dirs['results']['dirs']['labels'], 'mask.nii.gz')) # Create macroscopic labels labels.extract(os.path.join(cenc_dirs['results']['dirs']['labels'], 'aseg.nii.gz'), [], [10, 11, 12, 13, 17, 18, 49, 50, 51, 52, 53, 54], os.path.join(cenc_dirs['results']['dirs']['labels'], 'gm.subcortical.nii.gz'), merge=1) labels.extract(os.path.join(cenc_dirs['results']['dirs']['labels'], 'aseg.nii.gz'), [], [3, 42], os.path.join(cenc_dirs['results']['dirs']['labels'], 'gm.cerebral_cortex.nii.gz'), merge=1) labels.extract(os.path.join(cenc_dirs['results']['dirs']['labels'], 'aseg.nii.gz'), [], [8, 47], os.path.join(cenc_dirs['results']['dirs']['labels'], 'gm.cerebellum.nii.gz'), merge=1) labels.extract(os.path.join(cenc_dirs['results']['dirs']['labels'], 'aseg.nii.gz'), [], [2, 41], os.path.join(cenc_dirs['results']['dirs']['labels'], 'wm.cerebral.nii.gz'), merge=1) labels.extract(os.path.join(cenc_dirs['results']['dirs']['labels'], 'aseg.nii.gz'), [], [7, 46], os.path.join(cenc_dirs['results']['dirs']['labels'], 'wm.cerebellum.nii.gz'), merge=1) labels.extract(os.path.join(cenc_dirs['results']['dirs']['labels'], 'aseg.nii.gz'), [], [4, 43], os.path.join(cenc_dirs['results']['dirs']['labels'], 'ventricles.nii.gz'), merge=1) # Brain extraction nu.nii.gz util.iw_subprocess([ 'fslmaths', os.path.join(cenc_dirs['results']['dirs']['images'], 'nu.nii.gz'), '-mas', os.path.join(cenc_dirs['results']['dirs']['labels'], 'mask.nii.gz'), os.path.join(cenc_dirs['results']['dirs']['images'], 'nu_brain.nii.gz') ])