Exemplo n.º 1
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 )
Exemplo n.º 2
0
def prepare( cenc_participant_dir ):

     freesurfer_input_dir = os.path.join( cenc_participant_dir, 'freesurfer', 'input' )

     util.mkcd_dir( [ freesurfer_input_dir ])

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

     util.link_inputs( input_files, freesurfer_input_dir)

     return
Exemplo n.º 3
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
Exemplo n.º 4
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')
Exemplo n.º 5
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)
Exemplo n.º 6
0
    participant_dir = os.path.abspath(os.path.join(inArgs.cenc_dir, id))
    reorient_dir = util.path_relative_to(participant_dir, inArgs.reorient_dir)

    wm_lesions_dir = util.path_relative_to(participant_dir, inArgs.out_dir)
    wm_lesions_input_dir = os.path.join(wm_lesions_dir, 'input')
    wm_lesions_lpa_dir = os.path.join(wm_lesions_dir, '01-lst_lpa')
    wm_lesions_lga_dir = os.path.join(wm_lesions_dir, '02-lst_lga')

    # Create Output Directory if it doesn't exist

    files = [
        os.path.abspath(os.path.join(reorient_dir, 't1w.nii.gz')),
        os.path.abspath(os.path.join(reorient_dir, 't2flair.nii.gz'))
    ]

    util.mkcd_dir(os.path.join(wm_lesions_input_dir))
    util.link_inputs(files, wm_lesions_input_dir)

    #

    util.mkcd_dir(os.path.join(wm_lesions_lpa_dir), False)

    util.mkcd_dir(os.path.join(wm_lesions_lga_dir), True)
    util.copy_inputs(files, wm_lesions_lga_dir)

    for ii in glob.glob('*.gz'):
        os.system('gunzip ' + ii)

    util.link_inputs(glob.glob('*.nii'), wm_lesions_lpa_dir)
Exemplo n.º 7
0
    else:
        tarball_filename = id + '_fmri.tar.gz'

    if os.path.isfile(os.path.join(out_dir, tarball_filename)):
        sys.exit('fMRI tarball already exists for ' + id + '.')

    # Create Output Directory if it doesn't exist

    files = [
        os.path.abspath(os.path.join(dicom_dir, 'dcmConvertAll.cfg')),
        os.path.abspath(os.path.join(dicom_dir, 'dcmConvert_cenc.cfg')),
        os.path.abspath(os.path.join(nifti_dir, 'rest.nii.gz'))
    ]

    util.mkcd_dir(out_dir)
    util.link_inputs(files, out_dir)

    files_to_be_tarred = glob.glob('*')

    # Create TarBall

    tarball = tarfile.open(tarball_filename, 'w:gz')

    for f in files_to_be_tarred:
        tarball.add(f)

    tarball.close()

    # Clean Directory

    for ii in files_to_be_tarred:
Exemplo n.º 8
0
     affine_out_wras_to_wlps  = stage1_output_files[1] 
     affine_out_wlps_to_wctf  = stage1_output_files[3] 

     fiducials_out_iras = stage1_output_files[2]
     fiducials_out_wlps = stage1_output_files[4]
     fiducials_out_wctf = stage1_output_files[5]

     print stage1_output_files

     if inArgs.run and (1 in inArgs.run_stage):
          
          util.print_stage("Entering Stage 1 - Creating matrices", inArgs.verbose)
               
          util.verify_inputs(stage1_input_files, inArgs.verbose)
          util.mkcd_dir( stage1_directory )
          util.link_inputs( stage1_input_files,  stage1_directory)


          #
          # Save ITK affine matrix
          #
          

          if inArgs.verbose:
               print
               print "Image affine RAS image to RAS world  matrix"
               print img_affine_matrix_ras
               print
               
          util.save_itk_affine_matrix( img_affine_matrix_ras, affine_out_iras_to_wras, inArgs.verbose )
               
Exemplo n.º 9
0
     out_fiducials_ctf        = util.path_relative_to( stage1_directory, inArgs.out_ctf )
     out_fiducials_native     = util.path_relative_to( stage1_directory, inArgs.out_native )
     out_fiducials_template   = util.path_relative_to( stage1_directory, inArgs.out_template )
     
     stage1_input_files    = stage0_output_files
     stage1_output_files   = [ affine_iras_to_wlps, affine_iras_to_wlps, affine_wlps_to_wctf, 
                               out_fiducials_ctf, out_fiducials_native, out_fiducials_template  ] 

     if inArgs.run and (1 in inArgs.run_stage):
          
          util.print_stage('Entering Stage 1 - Calculating affine matrices', inArgs.verbose) 

          util.verify_inputs(stage1_input_files, inArgs.verbose)
          util.mkcd_dir( stage1_directory )

          util.link_inputs( stage1_input_files, stage1_directory)


          # iCSA to wLPS
          util.extract_affine(  image_native, affine_iras_to_wlps, True,  False, inArgs.verbose)
          
          ctf.icsa_to_wlps( fiducials_native_icsa, inArgs.out_native,  affine_iras_to_wlps, inArgs.verbose, inArgs.debug )

          # wLPS to wCTF
          # When transforming points use the inverse. I have no idea why. Ask ANTs.

          ctf.calc_matrix( inArgs.out_native, affine_wlps_to_wctf, 1.0, inArgs.verbose)
          ctf.wlps_to_wctf( inArgs.out_native, inArgs.out_ctf, affine_wlps_to_wctf, inArgs.verbose, inArgs.debug)

          # wLPS to wTemplate
          native_to_template_transform = [ template_to_native[1], template_to_native[0] ]