def main(): niigz = "${petInputNii}" nii = gzipd(niigz) dst = nii.replace("_input_", "_").replace("_copy", "") shutil.move(nii, dst) tags = { "pet": dst, } #if "${config.set_origin_to_centerOfMass_pet}" == "true": if False: run_matlab(os.path.join(TPL_PATH, "set_origin_to_centerOfMass_pet.m"), tags, "set_origin_to_centerOfMass.m") run_shell("gzip {}".format(dst))
def main(): for d in ["baker", "stats"]: os.mkdir(d) tags = { "bakerDir": "${bakerDir}", "atlas": gzipd("${atlas}"), "pet": gzipd("${pet4070}"), "gmSpm": gzipd("${gmSpm}"), "wmSpm": gzipd("${wmSpm}"), "csfSpm": gzipd("${csfSpm}"), "boneSpm": gzipd("${boneSpm}"), "softSpm": gzipd("${softSpm}"), "atlasCereb": gzipd("${atlasCereb}"), "scannerResolution": "${scannerResolution}", } run_matlab(os.path.join(TPL_PATH, "suvr_baker.m"), tags, "suvr_baker.m") #atlas src = "FINAL0_edited_aparc+aseg.nii" dst = os.path.join("baker", add_suffix(tags["atlas"], "edited-baker")) dst = dst.replace("_copy", "") shutil.copy(src, dst) run_shell("gzip {}".format(dst)) #suvr src = "FINAL0_suvr_normalized_infcereg.nii" dst = os.path.join("baker", add_suffix(tags["pet"], "ref-infcereg_suvr")) suvr = dst.replace("_copy", "") shutil.copy(src, suvr) run_shell("gzip {}".format(suvr)) suvr = suvr + ".gz" #stat stats = os.path.join("stats", os.path.basename(suvr).replace(".nii.gz", ".tsv")) atlas = "${atlas}" imgstats = ImgStatsFromAtlas(suvr, atlas, stats) imgstats.compute() #roigroups src = "FINAL0_roigroups.mat" dst = os.path.join("baker", add_suffix(tags["pet"], "pvc-rousset")) dst = dst.replace("_copy", "").replace(".nii", ".mat") shutil.copy(src, dst)
def seg_suit(img, spmDir): for d in ["suit", "mask", "transform"]: os.mkdir(d) nii = gzipd(img) generic = "img.nii" shutil.move(nii, generic) tags = { "anat": generic, "spmDir": spmDir, } run_matlab(os.path.join(TPL_PATH, "seg_suit.m"), tags, "segmentation.m") src = "iCerebellum-SUIT.nii" dst = "suit/{}_suit.nii".format(PARTICIPANT) shutil.move(src, dst) run_shell("gzip {}".format(dst)) '''
def main(): anat = "${anatInputNii}" nu = "${nuInputNii}" atlas = "${atlasInputNii}" dsts = [] for niigz in [anat, nu, atlas]: nii = gzipd(niigz) dst = nii.replace("_input_", "_").replace("_copy", "") shutil.move(nii, dst) dsts.append(dst) tags = { "anat": dsts[0], "nu": dsts[1], "atlas": dsts[2], } if "${config.set_origin_to_centerOfMass_anat}" != "false": run_matlab(os.path.join(TPL_PATH, "set_origin_to_centerOfMass_anat.m"), tags, "set_origin_to_centerOfMass.m") for dst in dsts: run_shell("gzip {}".format(dst))
def seg_spm12(img, spmDir): for d in ["mask", "transform"]: os.mkdir(d) tags = { "anat": gzipd(img), "spmDir": spmDir, } run_matlab(os.path.join(TPL_PATH, "seg_spm12.m"), tags, "segmentation.m") for src in glob("c*nii"): dst_tpl = "mask/{}_roi-c{}${suffix.mask}".replace(".gz", "") dst = dst_tpl.format(PARTICIPANT, src[1]) shutil.copy(src, dst) run_shell("gzip {}".format(dst)) anat2tpl = "transform/{}${suffix.anat2tpl}".format(PARTICIPANT) shutil.copy(glob("y_*.nii")[0], anat2tpl) run_shell("gzip {}".format(anat2tpl)) tpl2anat = "transform/{}${suffix.tpl2anat}".format(PARTICIPANT) shutil.copy(glob("iy_*.nii")[0], tpl2anat) run_shell("gzip {}".format(tpl2anat))
def main(): transitional = "${transitional}" mode = "${config.pet2anat.mode}" os.mkdir("pet") os.mkdir("centiloid") os.mkdir("tmp") pet4070 = "${pet4070}" pet5070 = "${pet5070}" #centiloid pet2anat = "${pet2anat}" anat = "${anat}" brain = "${brain}" gmwm = "${gmwm}" petParams = nfmap2dict("${pet2anatPetParams}") centiloidParams = nfmap2dict("${pet2anatCentiloidParams}") tmpParams = { "mask": "null", "fwhm": 6, } petToEstimate = "${petToEstimate}" if "${config.set_origin_to_centerOfMass_pet}" == "true": dsts = [] for niigz in [petToEstimate, pet4070, pet5070]: nii = gzipd(niigz) #dst = nii.replace("_input_", "_").replace("_copy", "") #shutil.move(nii, dst) #dsts.append(dst) dsts.append(nii) tags = { "petToEstimate": dsts[0], "pet4070": dsts[1], "pet5070": dsts[2], } run_matlab(os.path.join(TPL_PATH, "set_origin_to_centerOfMass_pet.m"), tags, "set_origin_to_centerOfMass.m") for dst in dsts: run_shell("gzip {}".format(dst)) petToEstimate = dsts[0].replace("_copy", "_acpc") + ".gz" os.rename(dsts[0] + ".gz", petToEstimate) pet4070 = dsts[1].replace("_copy", "_acpc") + ".gz" os.rename(dsts[1] + ".gz", pet4070) pet5070 = dsts[2].replace("_copy", "_acpc") + ".gz" os.rename(dsts[2] + ".gz", pet5070) for pet, _dir, params in zip( [pet4070, pet5070, pet4070], ["pet", "centiloid", "tmp"], [petParams, centiloidParams, tmpParams], ): output = os.path.join(_dir, add_suffix(pet, "space-anat")).replace("_acpc", "") # Apply transform if transitional != "false": transitPet = glob( "{}/tmp/*tmp-estimate.nii.gz".format(transitional))[0] transit2anat = glob( "{}/transform/*${suffix.pet2anat}".format(transitional))[0] petInTransit = applyWarpImageMultiTransform( pet, transitPet, pet2anat, "petInTransit.nii.gz") petTemp = applyWarpImageMultiTransform(petInTransit, anat, transit2anat) else: if mode == "ants": petTemp = applyWarpImageMultiTransform(pet, anat, pet2anat) elif mode == "spm": petTemp = estimatePet2Anat(petToEstimate, anat, mode="estwrite", other=pet, tag=_dir) # Masking step mask = params["mask"] cmd = "fslmaths {0} -mul {1} {0}" if mask == "brain": run_shell(cmd.format(petTemp, brain)) elif mask == "gmwm": run_shell(cmd.format(petTemp, gmwm)) elif mask == "null": pass else: warn([ "Process: apply_pet2anat", " {} option to mask {} data is not supported".format( mask, pet), " See default configuration for more information", " {} data won't be masked".format(pet), ]) # Smoothing step fwhm = params["fwhm"] try: sigma = int(fwhm) / 2.3548 if sigma > 0: cmd = "fslmaths {0} -kernel gauss {1} -fmean {2}" run_shell(cmd.format(petTemp, sigma, output)) else: cmd = "fslmaths {0} -fmean {1}" run_shell(cmd.format(petTemp, output)) except: warn([ "Process: apply_pet2anat", " {} is not an integer".format(fwhm), " {} data won't be smoothed".format(pet), ]) cmd = "fslmaths {0} -fmean {1}" run_shell(cmd.format(petTemp, output))