Esempio n. 1
0
def methods_write_json_redcap_swi_instrument(input_dir, verbose):
    """ Write MagTrans Instrument to JSON output file"""

    cenc_dirs = cenc.directories(input_dir)

    swir = os.path.join(cenc_dirs['swi']['dirs']['register'], 'swir.nii.gz')

    labels = [
        os.path.join(cenc_dirs['swi']['dirs']['input'],
                     'gm.cerebral_cortex.nii.gz'),
        os.path.join(cenc_dirs['swi']['dirs']['input'],
                     'gm.subcortical.nii.gz'),
        os.path.join(cenc_dirs['swi']['dirs']['input'], 'wm.cerebral.nii.gz'),
        os.path.join(cenc_dirs['swi']['dirs']['input'],
                     'wmlesions_lpa_mask.nii.gz')
    ]

    pandas.set_option('expand_frame_repr', False)

    df_stats_gm_cortical = iw_labels.measure_image_stats(labels[0], swir)
    df_stats_gm_subcortical = iw_labels.measure_image_stats(labels[1], swir)
    df_stats_wm_cerebral = iw_labels.measure_image_stats(labels[2], swir)
    df_stats_wm_lesions = iw_labels.measure_image_stats(labels[3], swir)

    dict_redcap = OrderedDict(
        (('subject_id', cenc_dirs['cenc']['id']), ('swi_analyst',
                                                   getpass.getuser()),
         ('swi_datetime',
          '{:%Y-%b-%d %H:%M:%S}'.format(datetime.datetime.now())),
         ('swi_gm_cortical_mean',
          '{0:4.3f}'.format(df_stats_gm_cortical['mean'].values[0])),
         ('swi_gm_cortical_std',
          '{0:4.3f}'.format(df_stats_gm_cortical['std'].values[0])),
         ('swi_gm_subcortical_mean',
          '{0:4.3f}'.format(df_stats_gm_subcortical['mean'].values[0])),
         ('swi_gm_subcortical_std',
          '{0:4.3f}'.format(df_stats_gm_subcortical['std'].values[0])),
         ('swi_wm_cortical_mean',
          '{0:4.3f}'.format(df_stats_wm_cerebral['mean'].values[0])),
         ('swi_wm_cortical_std',
          '{0:4.3f}'.format(df_stats_wm_cerebral['std'].values[0])),
         ('swi_wmlesions_mean',
          '{0:4.3f}'.format(df_stats_wm_lesions['mean'].values[0])),
         ('swi_wmlesions_std',
          '{0:4.3f}'.format(df_stats_wm_lesions['std'].values[0]))))

    magtrans_json_filename = os.path.join(cenc_dirs['swi']['dirs']['results'],
                                          'magtrans.json')

    with open(magtrans_json_filename, 'w') as outfile:
        json.dump(dict_redcap,
                  outfile,
                  indent=4,
                  ensure_ascii=True,
                  sort_keys=False)

    if verbose:
        cenc.print_json_redcap_instrument(magtrans_json_filename)

    return
Esempio n. 2
0
def results( input_dir ):
    """ Gather results and write the MagTran JSON output file"""

    cenc_dirs = cenc.directories( input_dir )

    mt_input_dir       = cenc_dirs['mt']['dirs']['input']
    mt_01_register_dir = cenc_dirs['mt']['dirs']['register']
    mt_results_dir     = cenc_dirs['mt']['dirs']['results']

    util.mkcd_dir( [ mt_results_dir ], True)

    result_files = [ [  os.path.join( cenc_dirs['mt']['dirs']['register'], 'mt_Affine_nu__mt_m0_Warped.nii.gz'),
    os.path.join( cenc_dirs['mt']['dirs']['results'],  'mt_Affine_nu__mt_m0.nii.gz')],

    [ os.path.join( cenc_dirs['mt']['dirs']['register'], 'mt_Affine_nu__mt_m1_Warped.nii.gz'),
    os.path.join( cenc_dirs['mt']['dirs']['results'],  'mt_Affine_nu__mt_m1.nii.gz')],

    [ os.path.join( cenc_dirs['mt']['dirs']['02-stats'], 'magtrans.json'),
    os.path.join( cenc_dirs['mt']['dirs']['results'],  'magtrans.json') ],

    [ os.path.join( cenc_dirs['mt']['dirs']['register'], 'mtr.nii.gz'),
    os.path.join( cenc_dirs['mt']['dirs']['results'],  'mtr.nii.gz') ],

    [ os.path.join( cenc_dirs['mt']['dirs']['input'],    'nu.nii.gz'),
    os.path.join( cenc_dirs['mt']['dirs']['results'],  'nu.nii.gz') ],

    [ os.path.join( cenc_dirs['mt']['dirs']['register'], 'mtr.nii.gz'),
    os.path.join( cenc_dirs['results']['dirs']['images'],  'mtr.nii.gz') ]
    ]

    for ii in result_files:
        util.force_hard_link( ii[0], ii[1])

    return
Esempio n. 3
0
def qa_results(in_dir, verbose=False):
    cenc_dirs = cenc.directories(in_dir)

    cenc.print_json_redcap_instrument( os.path.join(cenc_dirs['mt']['dirs']['results'],'magtrans.json'))

    result_files = [os.path.join(cenc_dirs['mt']['dirs']['results'], 'nu.nii.gz') + ':colormap=grayscale',
                    os.path.join(cenc_dirs['mt']['dirs']['results'],
                                 'mt_Affine_nu__mt_m0.nii.gz') + ':colormap=grayscale:visible=0',
                    os.path.join(cenc_dirs['mt']['dirs']['results'],
                                 'mt_Affine_nu__mt_m1.nii.gz') + ':colormap=grayscale:visible=0',
                    os.path.join(cenc_dirs['mt']['dirs']['results'],
                                 'mtr.nii.gz') + ':colormap=jet:colorscale=0,0.6:opacity=0.5'
                    ]

    qa_command = ['freeview', '-v'] + result_files



    if verbose:
        print
        print(' '.join(qa_command))
        print

    DEVNULL = open(os.devnull, 'wb')
    pipe = subprocess.Popen([' '.join(qa_command)], shell=True,
                            stdin=DEVNULL, stdout=DEVNULL, stderr=DEVNULL, close_fds=True)
Esempio n. 4
0
def methods_02_lpa(input_dir, verbose):

    cenc_dirs = cenc.directories(input_dir)

    wm_lesions_dir = cenc_dirs['wmlesions']['dirs']['root']
    wm_lesions_lpa_dir = cenc_dirs['wmlesions']['dirs']['lpa']

    util.mkcd_dir([cenc_dirs['wmlesions']['dirs']['lpa']], True)

    util.copy_inputs([
        os.path.join(cenc_dirs['wmlesions']['dirs']['register'],
                     't2flair_Affine_nu__t2flair_Warped.nii.gz')
    ], cenc_dirs['wmlesions']['dirs']['lpa'])

    glob_files = glob.glob('*.gz')

    for ii in glob_files:
        os.system('gunzip ' + ii)
        os.chmod(str.replace(ii, '.gz', ''),
                 stat.S_IRUSR | stat.S_IRGRP | stat.S_IWUSR | stat.S_IWGRP)

    # Run Matlab

    command = ['cenc_wmlesions_run.sh', cenc_dirs['wmlesions']['dirs']['lpa']]
    util.iw_subprocess(command, verbose, verbose, False)

    os.chdir(cenc_dirs['wmlesions']['dirs']['lpa'])

    for ii in glob.glob('*.nii'):
        os.system('gzip ' + ii)
        os.chmod(str.replace(ii, '.nii', '.nii.gz'),
                 stat.S_IRUSR | stat.S_IRGRP | stat.S_IWUSR | stat.S_IWGRP)
Esempio n. 5
0
def qa_results(in_dir, verbose=False):

    cenc_dirs = cenc.directories(in_dir)

    cenc.print_json_redcap_instrument(
        os.path.join(cenc_dirs['wmlesions']['dirs']['results'],
                     'wmlesions.json'))

    result_files = [
        os.path.join(cenc_dirs['wmlesions']['dirs']['results'], 'nu.nii.gz') +
        ':colormap=grayscale:visible=0',
        os.path.join(cenc_dirs['wmlesions']['dirs']['results'],
                     'wmlesions_lpa_t2flair.nii.gz') + ':colormap=grayscale',
        os.path.join(cenc_dirs['wmlesions']['dirs']['results'],
                     'wmlesions_lpa_pmap.nii.gz') +
        ':colormap=jet:visible=0:opacity=0.5',
        os.path.join(cenc_dirs['wmlesions']['dirs']['results'],
                     'wmlesions_lpa_labels.nii.gz') +
        ':colormap=jet:opacity=0.5'
    ]

    qa_command = ['freeview', '-v'] + result_files

    if verbose:
        print(' ')
        print(' '.join(qa_command))
        print(' ')

    DEVNULL = open(os.devnull, 'wb')
    pipe = subprocess.Popen([' '.join(qa_command)],
                            shell=True,
                            stdin=DEVNULL,
                            stdout=DEVNULL,
                            stderr=DEVNULL,
                            close_fds=True)
Esempio n. 6
0
def status_results(input_dir, verbose):

    cenc_dirs = cenc.directories(input_dir)

    result_files = [
        os.path.join(cenc_dirs['results']['dirs']['labels'],
                     'gm.cerebral_cortex.nii.gz'),
        os.path.join(cenc_dirs['results']['dirs']['labels'],
                     'gm.cerebellum.nii.gz'),
        os.path.join(cenc_dirs['results']['dirs']['labels'],
                     'wm.cerebral.nii.gz'),
        os.path.join(cenc_dirs['results']['dirs']['labels'],
                     'wm.cerebellum.nii.gz'),
        os.path.join(cenc_dirs['results']['dirs']['labels'],
                     'ventricles.nii.gz'),
        os.path.join(cenc_dirs['results']['dirs']['labels'], 'nu.nii.gz'),
        os.path.join(cenc_dirs['results']['dirs']['images'], 'nu.nii.gz'),
        os.path.join(cenc_dirs['results']['dirs']['images'], 'nu_brain.nii.gz')
    ]

    freesurfer_status_results = util.check_files(result_files, False)

    if verbose:
        print(cenc_dirs['cenc']['id'] + ', cenc_freesurfer, results, ' +
              str(freesurfer_status_results))

    return freesurfer_status_results
Esempio n. 7
0
def methods_write_json_redcap_instrument(in_dir, labels_stats_csv,
                                         labels_pmap_stats_csv, verbose):
    """ Writes out REdCap instrument measures to a JSON file"""
    cenc_dirs = cenc.directories(in_dir)

    df_label_stats = pandas.read_csv(labels_stats_csv)
    df_pmap_stats = pandas.read_csv(labels_pmap_stats_csv)

    number_of_lesions, _ = df_label_stats.shape

    if number_of_lesions > 0:
        total_lesion_volume = df_label_stats['volume_mm3'].sum()
        mean_lesion_volume = df_label_stats['volume_mm3'].mean()
        std_lesion_volume = df_label_stats['volume_mm3'].std()
        min_lesion_volume = df_label_stats['volume_mm3'].min()
        max_lesion_volume = df_label_stats['volume_mm3'].max()
        min_lesion_probability = df_pmap_stats['min'].min()
        max_lesion_probability = df_pmap_stats['max'].max()
    else:
        total_lesion_volume = 0
        mean_lesion_volume = 0
        std_lesion_volume = 0
        min_lesion_volume = 0
        max_lesion_volume = 0
        min_lesion_probability = 0
        max_lesion_probability = 0

    dict_redcap = OrderedDict(
        (('subject_id', cenc_dirs['cenc']['id']), ('wm_lesions_analyst',
                                                   getpass.getuser()),
         ('wm_lesions_datetime',
          '{:%Y-%b-%d %H:%M:%S}'.format(datetime.datetime.now())),
         ('wm_lesions_number', '{0:d}'.format(int(number_of_lesions))),
         ('wm_lesions_total_volume_mm3',
          '{0:5.1f}'.format(total_lesion_volume)),
         ('wm_lesions_mean_volume_mm3', '{0:5.1f}'.format(mean_lesion_volume)),
         ('wm_lesions_std_volume_mm3', '{0:5.1f}'.format(std_lesion_volume)),
         ('wm_lesions_min_lesion_volume_mm3',
          '{0:5.1f}'.format(min_lesion_volume)),
         ('wm_lesions_max_lesion_volume_mm3',
          '{0:5.1f}'.format(max_lesion_volume)),
         ('wm_lesions_min_lesion_probability',
          '{0:5.4f}'.format(min_lesion_probability)),
         ('wm_lesions_max_lesion_probability',
          '{0:5.4f}'.format(max_lesion_probability))))

    wmlesions_json_filename = os.path.join(os.path.dirname(labels_stats_csv),
                                           'wmlesions.json')

    with open(wmlesions_json_filename, 'w') as outfile:
        json.dump(dict_redcap,
                  outfile,
                  indent=4,
                  ensure_ascii=True,
                  sort_keys=False)

    if verbose:
        cenc.print_json_redcap_instrument(wmlesions_json_filename)
Esempio n. 8
0
def mt_link_inputs( input_dir, link_to_dir, change_to_dir = True ):

     cenc_dirs = cenc.directories( input_dir )

     util.mkcd_dir( [ link_to_dir ], change_to_dir )

     input_files = cenc_dirs['mt']['inputs']
     label_files = cenc_dirs['mt']['labels']

     util.link_inputs( input_files + label_files, link_to_dir )
Esempio n. 9
0
def methods_02_stats(input_dir, verbose=False):

    # Register MT images to nu.nii.gz
    cenc_dirs = cenc.directories(input_dir)

    util.mkcd_dir([cenc_dirs['mt']['dirs']['02-stats']], True)

    methods_write_json_redcap_mt_instrument(input_dir, verbose)

    return
Esempio n. 10
0
def status_run( input_dir, verbose ):

     cenc_dirs = cenc.directories( input_dir )

     result_files = [ os.path.join( cenc_dirs['freesurfer']['mri'], 'wmparc.mgz') ]
     freesurfer_status_run = util.check_files(result_files, False)

     if verbose:
          print( cenc_dirs['cenc']['id'] + ', cenc_freesurfer,     run, ' + str(freesurfer_status_run) )

     return freesurfer_status_run
Esempio n. 11
0
def status_methods_02_stats( input_dir, verbose=False ):

     cenc_dirs = cenc.directories( input_dir )
     
     result_files = [ os.path.join( cenc_dirs['mt']['dirs']['02-stats'], 'magtrans.json') ]
 
     mt_status = util.check_files(result_files, False)

     if verbose:
          print( cenc_dirs['cenc']['id'] + ', cenc_mt, ' + 'methods_02_stats' + ', ' + str(mt_status) )

     return mt_status
Esempio n. 12
0
def status_prepare( input_dir, verbose=False ):

     cenc_dirs = cenc.directories( input_dir )

     input_files = cenc_dirs['mt']['inputs']
     label_files = cenc_dirs['mt']['labels']

     mt_status = util.check_files(input_files + label_files, False)

     if verbose:
          print( cenc_dirs['cenc']['id'] + ', cenc_mt, ' + 'prepare' + ', ' + str(mt_status) )

     return mt_status
Esempio n. 13
0
def prepare(input_dir, verbose=False):

    if verbose:
        print('Entering cenc_swi.py prepare')

    swi_info = cenc.directories(input_dir)

    input_files = swi_info['swi']['inputs']
    label_files = swi_info['swi']['labels']

    swi_link_inputs(input_dir, swi_info['swi']['dirs']['input'])
    swi_link_inputs(input_dir, swi_info['swi']['dirs']['input'])

    return
Esempio n. 14
0
def prepare( input_dir ):

     cenc_dirs = cenc.directories( input_dir )

     util.mkcd_dir( [ cenc_dirs['freesurfer']['input']  ])

     input_files = [ os.path.join( cenc_dirs['cenc']['reorient'], 't1w.nii.gz'),
                     os.path.join( cenc_dirs['cenc']['reorient'], 't2flair.nii.gz'),
                     os.path.join( cenc_dirs['cenc']['reorient'], 't2tse.nii.gz')
                     ]

     util.link_inputs( input_files, cenc_dirs['freesurfer']['input'] )

     return
Esempio n. 15
0
def status_inputs(input_dir, stdout=False, verbose=False):

    cenc_dirs = cenc.directories(input_dir)

    input_files = cenc_dirs['mt']['inputs']
    label_files = cenc_dirs['mt']['labels']

    mt_status = util.check_files(input_files + label_files, verbose)

    if stdout:
        print(cenc_dirs['cenc']['id'] + ', cenc_mt, ' + 'input' + ', ' +
              str(mt_status))

    return mt_status
Esempio n. 16
0
def recon_all(input_dir):

    cenc_dirs = cenc.directories(input_dir)

    freesurfer_command = [
        'recon-all', '-sd', cenc_dirs['cenc']['freesurfer_subjects_dir'],
        '-subjid', cenc_dirs['cenc']['id'], '-all', '-i', 't1w.nii.gz',
        '-qcache', '-measure', 'thickness', '-measure', 'curv', '-measure',
        'sulc', '-measure', 'area', '-measure', 'jacobian_white'
    ]

    util.iw_subprocess(freesurfer_command, True, True, True)

    return
Esempio n. 17
0
def prepare( input_dir, verbose=False ):

     if verbose:
          print('Entering cenc_mt.py prepare')

     cenc_dirs = cenc.directories( input_dir )

     input_files = cenc_dirs['mt']['inputs']
     label_files = cenc_dirs['mt']['labels']

     mt_link_inputs( input_dir, cenc_dirs['mt']['dirs']['input'] )
     mt_link_inputs( input_dir, cenc_dirs['mt']['dirs']['input'] )

     return
Esempio n. 18
0
def status_inputs(input_dir, verbose=False):

    cenc_dirs = cenc.directories(input_dir)

    input_files = cenc_dirs['swi']['inputs']
    label_files = cenc_dirs['swi']['labels']

    swi_status = util.check_files(input_files + label_files, False)

    if verbose:
        print(cenc_dirs['cenc']['id'] + ', cenc_swi, ' + 'input' + ', ' +
              str(swi_status))

    return swi_status
Esempio n. 19
0
def status_methods_01_register(input_dir, verbose=False):
    cenc_dirs = cenc.directories(input_dir)

    result_files = [os.path.join(cenc_dirs['mt']['dirs']['register'], 'mt_Affine_nu__mt_m0_Warped.nii.gz'),
                    os.path.join(cenc_dirs['mt']['dirs']['register'], 'mt_Affine_nu__mt_m1_Warped.nii.gz'),
                    os.path.join(cenc_dirs['mt']['dirs']['register'], 'mtr.nii.gz')
                    ]

    mt_status = util.check_files(result_files, False)

    if verbose:
        print(cenc_dirs['cenc']['id'] + ', cenc_mt, ' + 'methods_01_register' + ', ' + str(mt_status))

    return mt_status
Esempio n. 20
0
def status_results(input_dir, verbose=False):
     cenc_dirs = cenc.directories( input_dir)

     result_files =   [ os.path.join( cenc_dirs['wmlesions']['dirs']['results'],  'wmlesions_lpa_t2flair.nii.gz'),
                        os.path.join( cenc_dirs['wmlesions']['dirs']['results'],  'nu.nii.gz'),
                        os.path.join( cenc_dirs['wmlesions']['dirs']['results'],  'wmlesions_lpa_pmap.nii.gz'),
                        os.path.join( cenc_dirs['wmlesions']['dirs']['results'],  'wmlesions_lpa_labels.nii.gz')
                        ]

     wmlesions_status = util.check_files(result_files, False)

     if verbose:
          print( cenc_dirs['cenc']['id'] + ', cenc_wmlesions, results,' + str(wmlesions_status) )

     return wmlesions_status
Esempio n. 21
0
def status_methods_02_stats(input_dir, verbose=False):

    cenc_info = cenc.directories(input_dir)

    result_files = [
        os.path.join(cenc_info['swi']['dirs']['results'], 'magtrans.json')
    ]

    swi_status = util.check_files(result_files, False)

    if verbose:
        print(cenc_info['cenc']['id'] + ', cenc_swi, ' + 'methods_02_stats' +
              ', ' + str(swi_status))

    return swi_status
Esempio n. 22
0
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
Esempio n. 23
0
def methods_01_register( input_dir, verbose=False):

     # Register MT images to nu.nii.gz
     cenc_dirs = cenc.directories( input_dir )
     mt_link_inputs( input_dir, cenc_dirs['mt']['dirs']['register'] )
 
     ants_register('mt_m0')
     ants_register('mt_m1')

     # Calculate MTR image
     command = ['ImageMath', 3, 'mtr.nii.gz', 'MTR', 'mt_Affine_nu__mt_m0_Warped.nii.gz', 
                'mt_Affine_nu__mt_m1_Warped.nii.gz', 'nu_brain.nii.gz']

     util.iw_subprocess( command, verbose, verbose, False)

     return
Esempio n. 24
0
def status_results( input_dir, verbose=False ):

     cenc_dirs = cenc.directories( input_dir )

     result_files = [ os.path.join( cenc_dirs['mt']['dirs']['results'],  'mt_Affine_nu__mt_m0.nii.gz'),
                      os.path.join( cenc_dirs['mt']['dirs']['results'],  'mt_Affine_nu__mt_m1.nii.gz'), 
                      os.path.join( cenc_dirs['mt']['dirs']['results'],  'mtr.nii.gz'),
                      os.path.join( cenc_dirs['mt']['dirs']['results'],  'nu.nii.gz'),
                      os.path.join( cenc_dirs['results']['dirs']['images'],  'mtr.nii.gz')
                      ]

     mt_status = util.check_files(result_files, False)

     if verbose:
          print( cenc_dirs['cenc']['id'] + ', cenc_mt, ' + 'results' + ', ' + str(mt_status) )

     return mt_status
Esempio n. 25
0
def prepare( input_dir ):

     cenc_dirs = cenc.directories( input_dir)

     wm_lesions_dir       = cenc_dirs['wmlesions']['dirs']['root']
     wm_lesions_input_dir = cenc_dirs['wmlesions']['dirs']['input']
     wm_lesions_lpa_dir   = cenc_dirs['wmlesions']['dirs']['lpa']

     # Create Input Directory if it doesn't exist and link files 

     files = [  os.path.abspath( os.path.join( cenc_dirs['results']['dirs']['images'], 'nu.nii.gz')), 
                os.path.abspath( os.path.join( cenc_dirs['results']['dirs']['labels'], 'mask.nii.gz')), 
                os.path.abspath( os.path.join( cenc_dirs['cenc']['reorient'], 't2flair.nii.gz'))
                ]

     util.mkcd_dir( os.path.join(  wm_lesions_input_dir ) )
     util.link_inputs( files, wm_lesions_input_dir )
Esempio n. 26
0
def prepare(input_dir):

    cenc_dirs = cenc.directories(input_dir)

    util.mkcd_dir([cenc_dirs['freesurfer']['input']])

    input_files = [os.path.join(cenc_dirs['cenc']['reorient'], 't1w.nii.gz')]

    #    Preliminary testing of Freesurfer with the T2FLAIR and T2_TSE has not been very successful.
    #    Removing them from the workflow.
    #
    #     input_files = [ os.path.join( cenc_dirs['cenc']['reorient'], 't2flair.nii.gz'),
    #                     os.path.join( cenc_dirs['cenc']['reorient'], 't2tse.nii.gz')
    #                     ]

    util.link_inputs(input_files, cenc_dirs['freesurfer']['input'])

    return
Esempio n. 27
0
def methods_01_register( input_dir, verbose ):

    cenc_dirs = cenc.directories( input_dir)

    wm_lesions_dir       = cenc_dirs['wmlesions']['dirs']['root']
    wm_lesions_lpa_dir   = cenc_dirs['wmlesions']['dirs']['lpa']

    # Register

    util.mkcd_dir( [ cenc_dirs['wmlesions']['dirs']['register'] ], True)

    files = [  os.path.join( cenc_dirs['wmlesions']['dirs']['input'], 'nu.nii.gz'),
            os.path.join( cenc_dirs['wmlesions']['dirs']['input'], 't2flair.nii.gz'),
            os.path.join( cenc_dirs['results']['dirs']['labels'], 'mask.nii.gz')
            ]

    util.link_inputs( files, cenc_dirs['wmlesions']['dirs']['register'] )

    ants_register('t2flair')
Esempio n. 28
0
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])
Esempio n. 29
0
def status_results(input_dir, verbose=False):

    cenc_info = cenc.directories(input_dir)

    result_files = [
        os.path.join(cenc_info['swi']['dirs']['results'],
                     'swi_Affine_nu__swi_m0.nii.gz'),
        os.path.join(cenc_info['swi']['dirs']['results'],
                     'swi_Affine_nu__swi_m1.nii.gz'),
        os.path.join(cenc_info['swi']['dirs']['results'], 'swir.nii.gz'),
        os.path.join(cenc_info['swi']['dirs']['results'], 'nu.nii.gz'),
        os.path.join(cenc_info['results']['dirs']['images'], 'swir.nii.gz')
    ]

    swi_status = util.check_files(result_files, False)

    if verbose:
        print(cenc_info['cenc']['id'] + ', cenc_swi, ' + 'results' + ', ' +
              str(swi_status))

    return swi_status
Esempio n. 30
0
def status_methods_01_register(config, verbose=False):

    input_dir = config['dirs']['input']

    cenc_dirs = cenc.directories(input_dir)

    result_files = [
        os.path.join(cenc_dirs['swi']['dirs']['register'],
                     'swi_Affine_nu__swi_magnitude.nii.gz'),
        os.path.join(cenc_dirs['swi']['dirs']['register'],
                     'swi_Affine_nu__swi_phase.nii.gz'),
        os.path.join(cenc_dirs['swi']['dirs']['register'],
                     'swi_Affine_nu__swi.nii.gz')
    ]

    swi_status = util.check_files(result_files, False)

    if verbose:
        print(cenc_dirs['cenc']['id'] + ', cenc_swi, ' +
              'methods_01_register' + ', ' + str(swi_status))

    return swi_status