Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
def get_patients_with_dwi(subject_list,
                          paths,
                          dataset="PIER",
                          SESSION_RESEARCH3T="research3Tv[0-9][0-9]"):
    sfc_patient_list = []
    N = len(subject_list)
    for i in range(N):
        sub = subject_list[i]

        dwi_path = join(paths.BIDS, "PIER", f"sub-{sub}",
                        f"ses-{SESSION_RESEARCH3T}", "dwi", "*_dwi.nii.gz")
        dwi_path_json = join(paths.BIDS, "PIER", f"sub-{sub}",
                             f"ses-{SESSION_RESEARCH3T}", "dwi", "*_dwi.json")
        dwi_path_bvec = join(paths.BIDS, "PIER", f"sub-{sub}",
                             f"ses-{SESSION_RESEARCH3T}", "dwi", "*_dwi.bvec")
        dwi_path_bval = join(paths.BIDS, "PIER", f"sub-{sub}",
                             f"ses-{SESSION_RESEARCH3T}", "dwi", "*_dwi.bval")
        dwi_path_fmap_phasediff = join(paths.BIDS, "PIER", f"sub-{sub}",
                                       f"ses-{SESSION_RESEARCH3T}", "fmap",
                                       "*_phasediff.nii.gz")
        dwi_path_fmap_topup = join(paths.BIDS, "PIER", f"sub-{sub}",
                                   f"ses-{SESSION_RESEARCH3T}", "fmap",
                                   "*_epi.nii.gz")
        dwi_path_fmap_T1 = join(paths.BIDS, "PIER", f"sub-{sub}",
                                f"ses-{SESSION_RESEARCH3T}", "anat",
                                f"*acq-3D_T1w.nii.gz")
        exists = all([
            utils.checkIfFileExistsGlob(dwi_path, printBOOL=False),
            utils.checkIfFileExistsGlob(dwi_path_json, printBOOL=False),
            utils.checkIfFileExistsGlob(dwi_path_bvec, printBOOL=False),
            utils.checkIfFileExistsGlob(dwi_path_bval, printBOOL=False),
            utils.checkIfFileExistsGlob(dwi_path_fmap_T1, printBOOL=False)
        ])
        #check if all the necessary imaging files for correction exists
        if exists:
            #check if phasediff or topup exists
            if any([
                    utils.checkIfFileExistsGlob(dwi_path_fmap_phasediff,
                                                printBOOL=False),
                    utils.checkIfFileExistsGlob(dwi_path_fmap_topup,
                                                printBOOL=False)
            ]):
                sfc_patient_list.append(sub)
    sfc_patient_list = list(np.unique(sfc_patient_list))
    return sfc_patient_list
Ejemplo n.º 3
0
for imp in range(len(implantList)):
    implantName = implantList[imp]
    preferredSurface = "research3T*" 
    
    for s in range(0,len(subjects)):
    
        #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" ) ):
Ejemplo n.º 4
0
utils.checkPathAndMake(outputDir, T1wDirTemplatePatients02)

acq = "3D"
ses = "research3T*"

#going thru BIDS directory to get paths of controls and patients

patients = []
controls = []
for s in range(len(subDir)):
    #sub = "RID0588"
    subjectPath = subDir[s]
    sub = basename(subjectPath)[4:]
    print(sub)
    if utils.checkIfFileExistsGlob(
            join(subjectPath, f"ses-{ses}", "anat",
                 f"sub-{sub}_ses-{ses}_acq-{acq}_T1w.nii.gz")):
        if sub not in ControlsList:
            patients.append(
                glob(
                    join(subjectPath, f"ses-{ses}", "anat",
                         f"sub-{sub}_ses-{ses}_acq-{acq}_T1w.nii.gz")))
            file = glob(
                join(subjectPath, f"ses-{ses}", "anat",
                     f"sub-{sub}_ses-{ses}_acq-{acq}_T1w.nii.gz"))[0]
            if utils.checkIfFileDoesNotExistGlob(f"{file}"):
                utils.executeCommand(f"cp {file} {T1wImagesPATEINTSDir}")

        if sub in ControlsList:
            controls.append(
                glob(
Ejemplo n.º 5
0
LINUX_BIDSserver = join("/home/arevell/borel/DATA/Human_Data/BIDS", "PIER")

#
#updating intended for in fmap json files:

directories = os.listdir(LINUX_BIDSserver)

ses_research3T = "research3Tv[0-9][0-9]"

for i in range(len(directories)):
    file = directories[i]
    if "sub-RID" in file:
        sub = file

        if utils.checkIfFileExistsGlob(join(LINUX_BIDSserver, sub,
                                            f"ses-{ses_research3T}"),
                                       printBOOL=False):

            ses_folder = glob.glob(
                join(LINUX_BIDSserver, sub, f"ses-{ses_research3T}"))[0]
            ses = basename(ses_folder)[4:]

            if utils.checkIfFileExistsGlob(join(LINUX_BIDSserver, sub,
                                                f"ses-{ses}", "func",
                                                "*rest_bold.nii.gz"),
                                           printBOOL=False):  #if fMRI exists
                fMRI_path = glob.glob(
                    join(LINUX_BIDSserver, sub, f"ses-{ses}", "func",
                         "*rest_bold.nii.gz"))[0]
                fMRI_path_basename = basename(fMRI_path)
                fMRI_IntendedFor = join(f"ses-{ses}", "func",