def transform_vol(invol, xfm, space_defining):
    invol = bg.unzip_file(invol)  # in case zipped
    xfm = bg.unzip_file(xfm)  # in case zipped
    space_defining = bg.unzip_file(space_defining)  # in case zipped
    pp.apply_transform_onefile(xfm, invol)
    pp.reslice(space_defining, invol)
    rinvol = pp.prefix_filename(invol, prefix='r')
    bg.remove_files([invol])
    bg.zip_files([space_defining])
    return rinvol
def transform_vol(invol, xfm, space_defining):
    invol = bg.unzip_file(invol)# in case zipped
    xfm =  bg.unzip_file(xfm)# in case zipped
    space_defining = bg.unzip_file(space_defining)# in case zipped
    pp.apply_transform_onefile(xfm, invol)
    pp.reslice(space_defining, invol)
    rinvol = pp.prefix_filename(invol, prefix='r')
    bg.remove_files([invol])
    bg.zip_files([space_defining])
    return rinvol
            aparc = glob(globstr)
            if not len(aparc) > 0:
                logging.error('NO aparcaseg for %s' % globstr)
                continue
            aparc = aparc[0]
            caparc = bg.copy_file(aparc, roidir)
            caparc = bg.unzip_file(caparc)  # in case zipped
            globstr = '%s/coreg_mri2fdg/*.mat*' % pth
            xfm = pp.find_single_file(globstr)
            if xfm is None:
                logging.error('NO transform for %s' % globstr)
                continue
            cxfm = bg.copy_file(xfm, roidir)
            cxfm = bg.unzip_file(cxfm)  # in case zipped
            pp.apply_transform_onefile(cxfm, caparc)
            pp.reslice(dat, caparc)
            raparc = pp.prefix_filename(caparc, prefix='r')

        data = pp.nibabel.load(dat).get_data()
        meand = pp.mean_from_labels(roid, raparc, data)
        alld[subid] = meand

    ###write to file
    _, roifname = os.path.split(roifile)
    outf = os.path.join(userhome,
                        'roivalues_%s_%s_%s' % (tracer, cleantime, roifname))
    fid = open(outf, 'w+')
    fid.write('SUBID,')
    rois = sorted(meand.keys())
    roiss = ','.join(rois)
    fid.write(roiss)
Exemplo n.º 4
0
            shutil.rmtree(coregdir)
            continue
        cbrainmask = bg.copy_file(brainmask, coregdir)
        cbrainmask = bg.unzip_file(cbrainmask)
        # aparc aseg
        globstr = os.path.join(basedir, 'anatomy', '*aparc_aseg.nii*')
        aparc = pp.find_single_file(globstr)
        if aparc is None:
            logging.error('%s not found. skipping' % globstr)
            shutil.rmtree(coregdir)
            continue
        caparc = bg.copy_file(aparc, coregdir)
        caparc = bg.unzip_file(caparc)
        # cerebellum
        globstr = os.path.join(pth, 'ref_region', 'grey_cerebellum.nii*')
        cere = pp.find_single_file(globstr)
        if cere is None:
            logging.error('%s not found. skipping' % globstr)
            shutil.rmtree(coregdir)
            continue
        ccere = bg.copy_file(cere, coregdir)
        ccere = bg.unzip_file(ccere)
        # have all out files, coreg
        xfm = os.path.join(coregdir, 'mri_to_pet.mat')
        corgout = pp.invert_coreg(cbrainmask, mean_20min, xfm)
        pp.reslice(mean_20min, cbrainmask)
        pp.apply_transform_onefile(xfm, ccere)
        pp.reslice(mean_20min, ccere)
        pp.apply_transform_onefile(xfm, caparc)
        pp.reslice(mean_20min, caparc)
Exemplo n.º 5
0
        cbrainmask = bg.unzip_file(cbrainmask)
        # aparc aseg
        globstr = os.path.join(basedir, 'anatomy', '*aparc_aseg.nii*')
        aparc = pp.find_single_file(globstr)
        if aparc is None:
            logging.error('%s not found. skipping'%globstr)
            shutil.rmtree(coregdir)
            continue
        caparc = bg.copy_file(aparc, coregdir)
        caparc = bg.unzip_file(caparc)
        # cerebellum
        globstr = os.path.join(pth, 'ref_region', 'grey_cerebellum.nii*')
        cere = pp.find_single_file(globstr)
        if cere is None:
            logging.error('%s not found. skipping'%globstr)
            shutil.rmtree(coregdir)
            continue
        ccere = bg.copy_file(cere, coregdir)
        ccere = bg.unzip_file(ccere)
        # have all out files, coreg
        xfm = os.path.join(coregdir, 'mri_to_pet.mat')
        corgout = pp.invert_coreg(cbrainmask, mean_20min,xfm)
        pp.reslice(mean_20min, cbrainmask)
        pp.apply_transform_onefile(xfm, ccere)
        pp.reslice(mean_20min, ccere)
        pp.apply_transform_onefile(xfm, caparc)
        pp.reslice(mean_20min, caparc)
        
        
        
Exemplo n.º 6
0
 caparc = bg.copy_file(aparc, coreg_dir)
 xfm_file = pp.make_transform_name(cpet, cmri)
 logging.info("coreg %s" % (subid))
 corg_out = pp.invert_coreg(cmri, cpet, xfm_file)
 if not corg_out.runtime.returncode == 0:
     logging.warning(corg_out.runtime.stderr)
     continue
 apply_out = pp.apply_transform_onefile(xfm_file, cpons)
 if not apply_out.runtime.returncode == 0:
     logging.warning(apply_out.runtime.stderr)
     continue
 apply_out = pp.apply_transform_onefile(xfm_file, caparc)
 if not apply_out.runtime.returncode == 0:
     logging.warning(apply_out.runtime.stderr)
     continue
 rout_mri = pp.reslice(cpet, cmri)
 if not rout_mri.runtime.returncode == 0:
     logging.warning(rout_mri.runtime.stderr)
 else:
     rmri = pp.prefix_filename(cmri, prefix="r")
     _, rmri_nme = os.path.split(rmri)
     new_rmri = rmri_nme.replace("rbr", "rfdg_br")
     newmri = bg.copy_file(rmri, "%s/anatomy/%s" % (sub, new_rmri))
     if newmri:
         bg.remove_files([cmri, rmri])
 rout_pons = pp.reslice(cpet, cpons)
 if not rout_pons.runtime.returncode == 0:
     logging.warning(rout_pons.runtime.stderr)
 else:
     rpons = pp.prefix_filename(cpons, prefix="r")
     newpons = bg.copy_file(rpons, "%s/ref_region" % (tracerdir))
            aparc = glob(globstr)
            if not len(aparc)>0:
                logging.error('NO aparcaseg for %s'%globstr)
                continue
            aparc = aparc[0]
            caparc = bg.copy_file(aparc, roidir)
            caparc = bg.unzip_file(caparc)# in case zipped
            globstr = '%s/coreg_mri2fdg/*.mat*'%pth
            xfm = pp.find_single_file(globstr)
            if xfm is None:
                logging.error('NO transform for %s'%globstr)
                continue
            cxfm = bg.copy_file(xfm, roidir)
            cxfm = bg.unzip_file(cxfm)# in case zipped
            pp.apply_transform_onefile(cxfm, caparc)
            pp.reslice(dat, caparc)
            raparc = pp.prefix_filename(caparc, prefix='r')
            
                
        data = pp.nibabel.load(dat).get_data()
        meand = pp.mean_from_labels(roid, raparc, data)
        alld[subid] = meand

    ###write to file
    _, roifname = os.path.split(roifile)
    outf = os.path.join(userhome, 'roivalues_%s_%s_%s'%(tracer,
                                                        cleantime,
                                                        roifname))
    fid =open(outf, 'w+')
    fid.write('SUBID,')
    rois = sorted(meand.keys())
 caparc = bg.copy_file(aparc, coreg_dir)
 xfm_file = pp.make_transform_name(cpet, cmri)
 logging.info('coreg %s' % (subid))
 corg_out = pp.invert_coreg(cmri, cpet, xfm_file)
 if not corg_out.runtime.returncode == 0:
     logging.warning(corg_out.runtime.stderr)
     continue
 apply_out = pp.apply_transform_onefile(xfm_file, cpons)
 if not apply_out.runtime.returncode == 0:
     logging.warning(apply_out.runtime.stderr)
     continue
 apply_out = pp.apply_transform_onefile(xfm_file, caparc)
 if not apply_out.runtime.returncode == 0:
     logging.warning(apply_out.runtime.stderr)
     continue
 rout_mri = pp.reslice(cpet, cmri)
 if not rout_mri.runtime.returncode == 0:
     logging.warning(rout_mri.runtime.stderr)
 else:
     rmri = pp.prefix_filename(cmri, prefix='r')
     _, rmri_nme = os.path.split(rmri)
     new_rmri = rmri_nme.replace('rbr', 'rfdg_br')
     newmri = bg.copy_file(rmri, '%s/anatomy/%s' % (sub, new_rmri))
     if newmri:
         bg.remove_files([cmri, rmri])
 rout_pons = pp.reslice(cpet, cpons)
 if not rout_pons.runtime.returncode == 0:
     logging.warning(rout_pons.runtime.stderr)
 else:
     rpons = pp.prefix_filename(cpons, prefix='r')
     newpons = bg.copy_file(rpons, '%s/ref_region' % (tracerdir))