def create_nifti_corrs_brain(corrs_atlas, sub, paths, SESSION_RESEARCH3T, atlas_name): ses = basename( glob.glob( join(paths.BIDS_DERIVATIVES_STRUCTURAL_MATRICES, f"sub-{sub}", f"ses-{SESSION_RESEARCH3T}"))[0])[4:] save_loc = join(paths.SEIZURE_SPREAD_ATLASES_PROBABILITIES, f"sub-{sub}") utils.checkPathAndMake(save_loc, save_loc, printBOOL=False) atlas_path = glob.glob( join(paths.BIDS_DERIVATIVES_STRUCTURAL_MATRICES, f"sub-{sub}", f"ses-{ses}", "atlas_registration", f"*{atlas_name}.nii.gz"))[0] img, img_data = utils.load_img_and_data(atlas_path) img_data_cors = copy.deepcopy(img_data) img_data_cors[np.where(img_data_cors == 0)] = -1 #loop thru regions and replace regions with correlation data for r in range(len(corrs_atlas)): utils.printProgressBar(r + 1, len(corrs_atlas)) ind = np.where(img_data == int(corrs_atlas[r, 0])) img_data_cors[ind] = float(corrs_atlas[r, 1]) save_loc_atlas = join(save_loc, f"{atlas_name}.nii.gz") utils.save_nib_img_data(img_data_cors, img, save_loc_atlas) T1_path = glob.glob( join(paths.BIDS_DERIVATIVES_STRUCTURAL_MATRICES, f"sub-{sub}", f"ses-{ses}", "atlas_registration", "*desc-preproc_T1w_std.nii.gz"))[0] if utils.checkIfFileDoesNotExist(f"{join(save_loc, basename(T1_path))}"): utils.executeCommand( cmd=f"cp {T1_path} {join(save_loc, basename(T1_path))}")
def get_tracts_loop_through_patient_list( patient_list, paths, singularity_bind_path=None, path_dsiStudioSingularity=None, SESSION_RESEARCH3T="research3Tv[0-9][0-9]"): if singularity_bind_path == None: singularity_bind_path = paths.BIDS if path_dsiStudioSingularity == None: path_dsiStudioSingularity = paths.DSI_STUDIO_SINGULARITY N = len(patient_list) for i in range(N): sub = patient_list[i] ses = basename( glob.glob( join(paths.BIDS_DERIVATIVES_QSIPREP, "qsiprep", f"sub-{sub}", f"ses-{SESSION_RESEARCH3T}"))[0])[4:] path_dwi = join( paths.BIDS_DERIVATIVES_QSIPREP, "qsiprep", f"sub-{sub}", f"ses-{ses}", "dwi", f"sub-{sub}_ses-{ses}_space-T1w_desc-preproc_dwi.nii.gz") path_tracts = join(paths.BIDS_DERIVATIVES_TRACTOGRAPHY, f"sub-{sub}", f"ses-{ses}") utils.checkPathAndMake(path_tracts, path_tracts, printBOOL=False) utils.checkIfFileExistsGlob(path_dwi, printBOOL=False) trk_name = f"{join(path_tracts, utils.baseSplitextNiiGz(path_dwi)[2])}.trk.gz" if utils.checkIfFileDoesNotExist(trk_name): get_tracts(singularity_bind_path, path_dsiStudioSingularity, path_dwi, path_tracts)
def get_atlas_registration_and_tractography_paths( sub, paths, SESSION_RESEARCH3T="research3Tv[0-9][0-9]"): ses = basename( glob.glob( join(paths.BIDS_DERIVATIVES_QSIPREP, "qsiprep", f"sub-{sub}", f"ses-{SESSION_RESEARCH3T}"))[0])[4:] atlas_registration = os.path.join( paths.BIDS_DERIVATIVES_STRUCTURAL_MATRICES, f"sub-{sub}", f"ses-{ses}", "atlas_registration") structural_matrices = os.path.join( paths.BIDS_DERIVATIVES_STRUCTURAL_MATRICES, f"sub-{sub}", f"ses-{ses}", "matrices") utils.checkPathAndMake(atlas_registration, atlas_registration, printBOOL=False) utils.checkPathAndMake(structural_matrices, structural_matrices, printBOOL=False) mni_base = "from_mni_to_T1" mni_images = os.path.join(atlas_registration, f"{mni_base}") mni_warp = f"{mni_images}_warp.nii.gz" preop_T1 = os.path.join(paths.BIDS_DERIVATIVES_QSIPREP, "qsiprep", f"sub-{sub}", "anat", f"sub-{sub}_desc-preproc_T1w.nii.gz") path_fib = glob.glob( os.path.join(paths.BIDS_DERIVATIVES_TRACTOGRAPHY, f"sub-{sub}", f"ses-{ses}", "*.fib.*"))[0] path_trk = glob.glob( os.path.join(paths.BIDS_DERIVATIVES_TRACTOGRAPHY, f"sub-{sub}", f"ses-{ses}", "*.trk.*"))[0] preop_T1 = os.path.join(atlas_registration, os.path.basename(preop_T1)) preop_T1_std = f"{splitext(splitext(preop_T1)[0])[0]}_std.nii.gz" return atlas_registration, structural_matrices, mni_images, mni_warp, ses, preop_T1, preop_T1_std, path_fib, path_trk
def getBIDSinputAndOutput(BIDS, dataset, sub, ses, acq, derivativesOutput): T1path = join(BIDS, dataset, f"sub-{sub}", f"ses-{ses}", "anat", f"sub-{sub}_ses-{ses}_acq-{acq}_T1w.nii.gz") utils.checkPathError(T1path) out = join(BIDS, "derivatives", f"{derivativesOutput}") utils.checkPathError(out) outputpath = join(BIDS, "derivatives", f"{derivativesOutput}", f"sub-{sub}", f"ses-{ses}") utils.checkPathAndMake(outputpath, outputpath) return T1path, outputpath
def atlasRegistrationBatch(patientsDTI, i): #for i in range(len(patientsDTI)): sub = patientsDTI[i] #input/output paths from QSI prep preop3T = join(pathQSIPREP, "qsiprep", f"sub-{sub}", "anat", f"sub-{sub}_desc-preproc_T1w.nii.gz") preop3Tmask = join(pathQSIPREP, "qsiprep", f"sub-{sub}", "anat", f"sub-{sub}_desc-brain_mask.nii.gz") pathAtlasRegistration = join(pathTractography, f"sub-{sub}", "atlasRegistration") preop3Tbrain = join(pathAtlasRegistration, "brain.nii.gz") preop3TSTD = join(pathAtlasRegistration, utils.baseSplitextNiiGz(preop3T)[2] + "_std.nii.gz") #preop3TmaskExpand = join(pathAtlasRegistration, "brain_maskExpanded.nii.gz") utils.checkPathAndMake(pathTractography, pathAtlasRegistration) #MNI registration if not utils.checkIfFileExists( join(pathAtlasRegistration, "mni_fnirt.nii.gz")): #extract brain getBrainFromMask(preop3T, preop3Tmask, preop3Tbrain) utils.show_slices(preop3Tbrain, save=True, saveFilename=join(pathAtlasRegistration, "brain.png")) #expand Brain mask register_MNI_to_preopT1(preop3T, preop3Tbrain, MNItemplatePath, MNItemplateBrainPath, "mni", pathAtlasRegistration) utils.show_slices(preop3T, save=True, saveFilename=join(pathAtlasRegistration, "preop3T.png")) utils.show_slices(join(pathAtlasRegistration, "mni_flirt.nii.gz"), save=True, saveFilename=join(pathAtlasRegistration, "mni_flirt.png")) utils.show_slices(join(pathAtlasRegistration, "mni_fnirt.nii.gz"), save=True, saveFilename=join(pathAtlasRegistration, "mni_fnirt.png")) #apply warp to atlases applywarp_to_atlas(atlases.getAllAtlasPaths(), preop3TSTD, join(pathAtlasRegistration, "mni_warp.nii.gz"), pathAtlasRegistration, isDir=False)
def make_spherical_regions(patient_list, SESSION, paths, radius = 7, rerun = False, show_slices = False): N = len(patient_list) for i in range(N): sub = patient_list[i] print(sub) localization, localization_channels = atl.get_atlas_localization_file(sub, SESSION, paths) #t1_image = join(paths['BIDS'], "PIER", f"sub-{sub}", f"ses-{ses}", "anat", f"sub-{sub}_ses-{ses}_space-T1w_desc-preproc_dwi.nii.gz" ) t1_image = glob.glob(join(paths.BIDS_DERIVATIVES_ATLAS_LOCALIZATION, f"sub-{sub}", f"ses-{SESSION}", "tmp", "orig_nu_std.nii.gz" ))[0] img = nib.load(t1_image) if show_slices: utils.show_slices(img, data_type = "img") img_data = img.get_fdata() affine = img.affine shape = img_data.shape coordinates = np.array(localization[["x", "y", "z"]]) coordinates_voxels = utils.transform_coordinates_to_voxel(coordinates, affine) path_spheres = join(paths.BIDS_DERIVATIVES_TRACTOGRAPHY, f"sub-{sub}", "electrodeContactSphereROIs") utils.checkPathAndMake(path_spheres, path_spheres, printBOOL = False) for e in range(len(localization_channels)): fname_ROIs_sub_ID = join(path_spheres, f"sub-{sub}_ses-implant01_desc-{localization_channels[e]}.nii.gz") if utils.checkIfFileDoesNotExist(fname_ROIs_sub_ID, printBOOL = False) or rerun: img_data_sphere = copy.deepcopy(img_data) img_data_sphere[ np.where(img_data_sphere != 0) ] = 0 x = coordinates_voxels[e][0] y = coordinates_voxels[e][1] z = coordinates_voxels[e][2] img_data_sphere = utils.make_sphere_from_point(img_data_sphere, x, y, z, radius = radius) #radius = 7mm img_sphere = nib.Nifti1Image(img_data_sphere, img.affine) nib.save(img_sphere, fname_ROIs_sub_ID) #utils.show_slices(img_data_sphere, data_type = "data") utils.printProgressBar(e+1, len(localization_channels))
def batchStructuralConnectivity(patientsDTI, i, batchBegin, batchEnd, pathTractography, pathQSIPREP, atlasList): #for i in range(len(patientsDTI)): sub = patientsDTI[i] print(f"\n\n\n\n{sub}") if utils.getSubType(sub) == "control": ses = "control3T" else: ses = "preop3T" #input/output paths from QSI prep pathTracts = join(pathTractography, f"sub-{sub}", "tracts") pathDWI = join(pathQSIPREP, "qsiprep", f"sub-{sub}", f"ses-{ses}", "dwi", f"sub-{sub}_ses-{ses}_space-T1w_desc-preproc_dwi.nii.gz") pathTRK = f"{join(pathTracts, utils.baseSplitextNiiGz(pathDWI)[2])}.trk.gz" pathFIB = f"{join(pathTracts, utils.baseSplitextNiiGz(pathDWI)[2])}.fib.gz" preop3T = join(pathQSIPREP, "qsiprep", f"sub-{sub}", "anat", f"sub-{sub}_desc-preproc_T1w.nii.gz") pathAtlasRegistration = join(pathTractography, f"sub-{sub}", "atlasRegistration") pathStructuralConnectivity = join(pathTractography, f"sub-{sub}", "structuralConnectivity") utils.checkPathAndMake(pathTractography, pathStructuralConnectivity) for a in range(batchBegin, batchEnd): atlas = join(pathAtlasRegistration, utils.baseSplitextNiiGz(atlasList[a])[0]) if utils.checkIfFileExists(atlas): output = join(pathStructuralConnectivity, f"sub-{sub}") if not utils.checkIfFileExists( output + f".{utils.baseSplitextNiiGz(atlasList[a])[2]}.count.pass.connectogram.txt", returnOpposite=True): t0 = time.time() tractography.getStructuralConnectivity( BIDS, dsiStudioSingularityPatah, pathFIB, pathTRK, preop3T, atlas, output) utils.calculateTimeToComplete(t0, time.time(), len(patientsDTI), i)
atlas_names_all_standard.append(basename(atlas_metadata_json["STANDARD"][key_item]["name"]).split(".")[0]) total = len(sc_paths) for a in range(total): sc_atlas = sc_paths[a] atlas_name = basename(sc_atlas).split(".")[1] utils.printProgressBar(a, len(sc_paths), suffix=atlas_name) save_loc_atlas = join(save_loc, f"{atlas_name}.nii.gz") save_loc_T1 = glob.glob(join(save_loc, f"*T1w_std.nii.gz"))[0] #save_loc_T1 = glob.glob(join(save_loc, f"*post_op.nii.gz"))[0] save_loc_atlas_figure_path = join(save_loc, "atlas_figures") utils.checkPathAndMake(save_loc_atlas_figure_path,save_loc_atlas_figure_path, printBOOL=False) save_loc_atlas_figure = join(save_loc_atlas_figure_path, f"{atlas_name}.nii.gz") img_data = utils.load_img_data(save_loc_atlas) img_data[np.where(img_data < -0.9)] = np.nan T1_data = utils.load_img_data(save_loc_T1) T1_data = T1_data/np.nanmax(T1_data) T1_data[np.where(T1_data <0.1)] = np.nan T1_data[np.where(T1_data < 0.0)] = np.nan #Calculating averages if a ==0: averages_all = np.zeros(shape = (img_data.shape[0], img_data.shape[1], img_data.shape[2], total)) averages_all[:] = np.nan
anats = np.array(glob(join(sessions[w], "anat", "*"))) T1s = anats[np.where(["_T1w.nii" in b for b in anats])[0]] #get T1w images if len(T1s) > 0: #get the ones with specific acquisions that allow for proper freesurfer recon-all processing acquisition = [ key for key in acq if does_match_in_array_of_string(key, T1s) ] if len(acquisition) > 1: IOError(f"More than 1 file exists with acq: \n{acq}") else: T1 = T1s[np.array([acquisition[0] in b for b in T1s])] if len(T1) > 1: IOError( f"More than 1 file exists with acq: \n{acquisition[0]}" ) else: T1path = T1[0] outputpath = join(outputDir, f"sub-{sub}", f"ses-{session}") utils.checkPathAndMake(outputpath, outputpath) elLoc.freesurferReconAll(T1path, outputpath, overwrite=False, threads=12) #send email done sendEmail(subject=f"Recon-all {sub}: {session}", text=f"{basename(T1path)}")
import os from revellLab.packages.utilities import utils import numpy as np import glob path1 = "/media/arevell/data/linux/data/BIDS/derivatives/structural_connectivity/structural_matrices" path2 = "/home/arevell/Desktop/Berckerle_structure" subs = np.sort(os.listdir(path1)) for i in range(len(subs)): sub = subs[i] print( f"\r{sub} {i+1}/{len(subs)}, {np.round((i+1)/len(subs)*100,1)} ", end="\r") path_sub = os.path.join(path2, sub) utils.checkPathAndMake(path_sub, path_sub, printBOOL=False) sc_path = os.path.join(path1, sub, "ses-research3Tv[0-9][0-9]", "matrices", "*connectogram.txt") utils.checkPathErrorGlob(sc_path) sc_paths_all = glob.glob(sc_path) for sc in range(len(sc_paths_all)): sc_p = sc_paths_all[sc] cmd = f"cp {sc_p} {path_sub}" utils.executeCommand(cmd, printBOOL=False)
#sub = "RID0030" sub = subjects[s][4:] print(sub) derivativesOutput = "implantRenders" T00 = join(BIDS, dataset, f"sub-{sub}", f"ses-{implantName}", "anat", f"sub-{sub}_ses-{implantName}_acq-T00_*T1w.nii.gz" ) T00electrodes = join(BIDS, dataset, f"sub-{sub}", f"ses-{implantName}", "ieeg", f"sub-{sub}_ses-{implantName}_space-T00_electrodes.tsv" ) if utils.checkIfFileExistsGlob(T00) and utils.checkIfFileExistsGlob(T00electrodes): #check if freesurfer has been run on preferred session if utils.checkIfFileExistsGlob( join(freesurferReconAllDir, f"sub-{sub}", f"ses-{preferredSurface}", "freesurfer", "surf", "lh.pial" ) ) and utils.checkIfFileExistsGlob( join(freesurferReconAllDir, f"sub-{sub}", f"ses-{preferredSurface}", "freesurfer", "surf", "rh.pial" ) ): sessionPath = np.array(glob( join(freesurferReconAllDir, f"sub-{sub}", f"ses-{preferredSurface}")))[0] session = basename(sessionPath)[4:] outputpath = join(BIDS, "derivatives", f"{derivativesOutput}", f"sub-{sub}", f"ses-{session}") utils.checkPathAndMake(outputpath, join(outputpath, "freesurfer", 'mri' )) utils.checkPathAndMake(outputpath, join(outputpath, "freesurfer", 'surf' )) utils.checkPathAndMake(outputpath, join(outputpath, "html")) utils.executeCommand(f"cp {join(sessionPath, 'freesurfer', 'mri' , 'orig_nu.mgz')} {join(outputpath, 'freesurfer', 'mri' )} ") utils.executeCommand(f"cp {join(sessionPath, 'freesurfer', 'mri' , 'brain.mgz')} {join(outputpath, 'freesurfer', 'mri' )} ") utils.executeCommand(f"cp {join(sessionPath, 'freesurfer', 'surf' , 'lh.pial')} {join(outputpath, 'freesurfer', 'surf')} ") utils.executeCommand(f"cp {join(sessionPath, 'freesurfer', 'surf' , 'rh.pial')} {join(outputpath, 'freesurfer', 'surf')} ") #check if freesurfer has been run on implant session elif utils.checkIfFileExists( join(freesurferReconAllDir, f"sub-{sub}", f"ses-{implantName}", "freesurfer", "surf", "lh.pial" ) ) and utils.checkIfFileExists( join(freesurferReconAllDir, f"sub-{sub}", f"ses-{implantName}", "freesurfer", "surf", "rh.pial" ) ): sessionPath = np.array(glob( join(freesurferReconAllDir, f"sub-{sub}", f"ses-{implantName}")))[0] session = basename(sessionPath)[4:] outputpath = join(BIDS, "derivatives", f"{derivativesOutput}", f"sub-{sub}", f"ses-{session}") utils.checkPathAndMake(outputpath, join(outputpath, "freesurfer", 'mri' )) utils.checkPathAndMake(outputpath, join(outputpath, "freesurfer", 'surf' )) utils.checkPathAndMake(outputpath, join(outputpath, "html"))
] subjects = [basename(item) for item in subDir] #%% functions ControlsList = [ "RID0285", "RID0286", "RID0287", "RID0288", "RID0289", "RID0290", "RID0291", "RID0292", "RID0297", "RID0599", "RID0600", "RID0505", "RID0602", "RID0603", "RID0604", "RID0615", "RID0682", "RID0683" ] T1wDir = join(outputDir, "T1w") T1wImagesDir = join(T1wDir, "images") T1wImagesPATEINTSDir = join(T1wImagesDir, "patients") T1wImagesCONTROLSDir = join(T1wImagesDir, "controls") utils.checkPathAndMake(outputDir, T1wImagesPATEINTSDir) utils.checkPathAndMake(outputDir, T1wImagesCONTROLSDir) T1wDirTemplate = join(T1wDir, "template") utils.checkPathAndMake(outputDir, T1wDirTemplate) T1wDirTemplate2 = join(T1wDir, "templateIteration2") utils.checkPathAndMake(outputDir, T1wDirTemplate2) T1wDirTemplatePatients = join(T1wDir, "patients") utils.checkPathAndMake(outputDir, T1wDirTemplatePatients) T1wDirTemplatePatients01 = join(T1wDirTemplatePatients, "templateIteration01") utils.checkPathAndMake(outputDir, T1wDirTemplatePatients01) T1wDirTemplatePatients02 = join(T1wDirTemplatePatients, "templateIteration02") utils.checkPathAndMake(outputDir, T1wDirTemplatePatients02) acq = "3D"
listOfFiles = list() for (dirpath, dirnames, filenames) in os.walk(BIDSserver): listOfFiles += [join(dirpath, file) for file in filenames] for f in range(len(listOfFiles)): #print(f) SERVERfile = listOfFiles[f] LOCALfile = join( BIDSlocal, relpath(SERVERfile, BIDSserver)) #ignore git if not ".git" in relpath(SERVERfile, BIDSserver): if utils.checkIfFileDoesNotExist(LOCALfile, printBOOL = False): print(f"\n{LOCALfile}") utils.checkPathAndMake( dirname(LOCALfile), dirname(LOCALfile), printBOOL = False ) utils.executeCommand( f"cp -r {SERVERfile} {LOCALfile}", printBOOL = False ) #%% Copy from local to server listOfFiles = list() for (dirpath, dirnames, filenames) in os.walk(BIDSlocal): listOfFiles += [join(dirpath, file) for file in filenames] for f in range(len(listOfFiles)): print(f) LOCALfile = listOfFiles[f] SERVERfile = join( BIDSserver, relpath(LOCALfile, BIDSlocal)) #ignore git
dataset=datasetiEEG, session=session, startUsec=None, stopUsec=None, startKey="EEC", secondsBefore=secondsBefore, secondsAfter=secondsAfter) preprocessed_location = join(BIDS, datasetiEEG_preprocessed, f"v{version:03d}", f"sub-{RID}") if version == 15: version_similar = 14 preprocessed_location = join(BIDS, datasetiEEG_preprocessed, f"v{version_similar:03d}", f"sub-{RID}") utils.checkPathAndMake(preprocessed_location, preprocessed_location, printBOOL=False) preprocessed_file_basename = f"{splitext(fname)[0]}_preprocessed.pickle" preprocessed_file = join(preprocessed_location, preprocessed_file_basename) #check if preproceed file exists, and if it does, load that instead of dowloading ieeg data and performing preprocessing on that if utils.checkIfFileExists(preprocessed_file, printBOOL=False): print(f"\n{RID} {i} PREPROCESSED FILE EXISTS") with open(preprocessed_file, 'rb') as f: [ dataII_scaler, data_scaler, dataII_scalerDS, data_scalerDS, channels ] = pickle.load(f) df, fs, ictalStartIndex, ictalStopIndex = DataJson.get_precitalIctalPostictal( RID,
fillerString = f"\n###########################" * 3 i = 16 sub = patient_list[i] ses = basename( glob.glob( join(paths.BIDS_DERIVATIVES_QSIPREP, "qsiprep", f"sub-{sub}", f"ses-{SESSION_RESEARCH3T}"))[0])[4:] atlas_registration = os.path.join(paths.BIDS_DERIVATIVES_STRUCTURAL_MATRICES, f"sub-{sub}", f"ses-{ses}", "atlas_registration") structural_matrices = os.path.join(paths.BIDS_DERIVATIVES_STRUCTURAL_MATRICES, f"sub-{sub}", f"ses-{ses}", "matrices") utils.checkPathAndMake(atlas_registration, atlas_registration, printBOOL=False) utils.checkPathAndMake(structural_matrices, structural_matrices, printBOOL=False) preop_T1 = os.path.join(paths.BIDS_DERIVATIVES_QSIPREP, "qsiprep", f"sub-{sub}", "anat", f"sub-{sub}_desc-preproc_T1w.nii.gz") preop_T1_mask = os.path.join(paths.BIDS_DERIVATIVES_QSIPREP, "qsiprep", f"sub-{sub}", "anat", f"sub-{sub}_desc-brain_mask.nii.gz") preop_T1_bet = os.path.join(atlas_registration, f"sub-{sub}_desc-preproc_T1w_brain.nii.gz") utils.checkPathError(preop_T1) utils.checkPathError(preop_T1_mask)
cmd = f"qsiprep-docker {BIDSpenn} {pathQSIPREP} participant --output-resolution 1.5 --fs-license-file {freesurferLicense} -w {pathQSIPREP} --participant_label {sub}" print(cmd) #os.system(cmd) cannot run this docker command inside python interactive shell. Must run the printed command in terminal using qsiprep environment in mad in environment directory #02 Tractography for i in range(len(patientsDTI)): sub = patientsDTI[i] print(f"\n\n\n\n{sub}") if utils.getSubType(sub) == "control": ses = "control3T" else: ses = "preop3T" #input/output paths from QSI prep pathDWI = join(pathQSIPREP, "qsiprep", f"sub-{sub}", f"ses-{ses}", "dwi", f"sub-{sub}_ses-{ses}_space-T1w_desc-preproc_dwi.nii.gz") pathTracts = join(pathTractography, f"sub-{sub}", "tracts") trkName = f"{join(pathTracts, utils.baseSplitextNiiGz(pathDWI)[2])}.trk.gz" utils.checkPathAndMake(pathTractography, pathTracts) if not utils.checkIfFileExists(trkName, returnOpposite=False): t0 = time.time() tractography.getTracts(BIDS, dsiStudioSingularityPatah, pathDWI, pathTracts) utils.calculateTimeToComplete(t0, time.time(), len(patientsDTI), i) #%% 06 Structural Connectivity for all atlases #01 Atlas Registration def atlasRegistrationBatch(patientsDTI, i): #for i in range(len(patientsDTI)): sub = patientsDTI[i]
atlasRegistrationTMP = join(outputDirectoryTMP, "atlasRegistration") preopT1_basename = os.path.basename(splitext(splitext(preopT1)[0])[0]) preopT1bet_basename = os.path.basename(splitext(splitext(preopT1bet)[0])[0]) preopT1_output = f"{join(outputDirectoryTMP, preopT1_basename)}" preopT1bet_output = f"{join(outputDirectoryTMP, preopT1bet_basename)}" outputNameTissueSeg = join( outputDirectory, f"{preopT1_basename}_std1x1x1_tissueSegmentation.nii.gz") FIRST = join(outputDirectory, f"{preopT1_basename}_std1x1x1_FIRST.nii.gz") FAST = join(outputDirectory, f"{preopT1_basename}_std1x1x1_FAST.nii.gz") outputMNIname = "mni" MNIwarp = join(outputDirectory, outputMNIname + "_warp.nii.gz") #Make temporary storage utils.checkPathAndMake(outputDirectoryTMP, outputDirectoryTMP, make=True) utils.checkPathAndMake(atlasRegistrationTMP, atlasRegistrationTMP, make=True) """ if rerun: #cleaning clean1 = join(outputDirectory, 'tmp' ) clean2 = join(outputDirectory, outputName) clean3 = join(outputDirectory, "electrodeWM_DistanceToGM.csv") clean4 = join(outputDirectory, "electrodeGM_DistanceToWM.csv") clean5 = join(outputDirectory, "electrodeTissueMetadata.json") clean6 = MNIwarp clean7 = FIRST clean8 = FAST clean9 = outputNameTissueSeg clean = [clean1, clean2, clean3, clean4, clean5, clean6]