Ejemplo n.º 1
0
def process_subject_anatomy(t1):
    reconall = ReconAll()
    reconall.inputs.subject_id = t1.split('/')[-3]
    reconall.inputs.directive = 'all'
    reconall.inputs.subjects_dir = subjects_dir
    reconall.inputs.T1_files = t1
    reconall.run()
Ejemplo n.º 2
0
def process_subject_anatomy(subject, t1, subjects_dir='/cluster/transcend/MRI/WMA/recons'):
    reconall = ReconAll()
    reconall.inputs.subject_id = subject
    reconall.inputs.directive = 'all'
    reconall.inputs.subjects_dir = subjects_dir
    reconall.inputs.T1_files = t1
    reconall.run()
Ejemplo n.º 3
0
def run_recon_all(subject=None, subjects_dir=subjects_dir, openmp=1):
    reconall = ReconAll()
    if not os.path.isdir(subjects_dir):
        print(
            f"Subjects directory {subjects_dir} does not exist, creating it.")
        os.mkdir(subjects_dir)
    if not os.path.isdir(os.path.join(subjects_dir, subject, "mri")):
        anafolder = os.path.join(args.folder, subject)
        # catch error, if no .nii exists
        try:
            nii_file = glob.glob(anafolder + "/*.nii*")[0]
            reconall.inputs.subject_id = subject
            reconall.inputs.T1_files = nii_file
            reconall.inputs.directive = 'all'
            reconall.inputs.subjects_dir = subjects_dir
            reconall.inputs.openmp = openmp
            reconall.inputs.flags = "-3T"
            print(f"Now running recon-all for subject {subject}")
            print(f".nii-file used was: {nii_file}")
            reconall.run()
        except Exception as e:
            print(e)
    else:
        print(
            f"A freesurfer segmentation of subject {subject} already exists in {subjects_dir} - aborting"
        )
Ejemplo n.º 4
0
 def _nii_to_freesurfer(self):
     reconall = ReconAll()
     if not self.subject.startswith("sub-"):
         self.subject = "sub-" + self.subject
     # check if freesurfer segmentation was already performed
     freesurfered = os.path.join(self.FS_SUBJECTS_DIR, self.subject)
     if not os.path.isdir(freesurfered):
         nii_file = glob.glob(opj(self.mri_folder, "*.nii*"))[0]
         reconall.inputs.subject_id = self.subject
         reconall.inputs.T1_files = nii_file
         reconall.inputs.directive = 'all'
         reconall.inputs.subjects_dir = self.FS_SUBJECTS_DIR
         reconall.inputs.openmp = self.n_jobs
         reconall.inputs.flags = "-3T"
         reconall.run()
     else:
         print(
             f"A freesurfer segmentation of subject {self.subject} already exists in {self.FS_SUBJECTS_DIR}"
         )
Ejemplo n.º 5
0
from nipype.interfaces.freesurfer import ReconAll
import os
import shutil
import sys

##################################################
FREESURFER_HOME = os.environ.get('FREESURFER_HOME')
reconall = ReconAll()

# path to the subject T1 MRI image in .nii format
# this file must be in .nii format
nii_file_path = 'nii_file_path'

# Subject ID: this should be a string which defines the folder name
# that will be created automatically for the subject in /usr/local/freesurfer/subjects/
subject_id = 'subject_id'

print('Data preprocessing started for {subject} in {path}'.format(
    subject=subject_id, path=nii_file_path))

reconall.inputs.subject_id = subject_id
reconall.inputs.directive = 'all'
reconall.inputs.subjects_dir = FREESURFER_HOME + '/subjects'
reconall.inputs.T1_files = nii_file_path
reconall.run()