def subject_factory():
    """
    Producer for HAXBY subject data.

    """

    for subject_id in set(
        [os.path.basename(os.path.dirname(x)) for x in haxby_data.func]):

        # instantiate subject_data object
        subject_data = SubjectData()
        subject_data.subject_id = subject_id
        subject_data.session_id = "haxby2001"

        # set func
        subject_data.func = [x for x in haxby_data.func if subject_id in x]

        assert len(subject_data.func) == 1
        subject_data.func = subject_data.func[0]

        # set anat
        subject_data.anat = [x for x in haxby_data.func if subject_id in x]
        assert len(subject_data.anat) == 1
        subject_data.anat = subject_data.anat[0]

        # set subject output directory
        subject_data.output_dir = os.path.join(OUTPUT_DIR,
                                               subject_data.subject_id)

        yield subject_data
Ejemplo n.º 2
0
def _nyu_rest_factory(session=1):
    from pypreprocess.nipype_preproc_spm_utils import SubjectData

    nyu_data = fetch_nyu_rest(sessions=[session], n_subjects=7)

    session_func = [x for x in nyu_data.func if "session%i" % session in x]
    session_anat = [
        x for x in nyu_data.anat_skull if "session%i" % session in x]

    for subject_id in set([os.path.basename(os.path.dirname
                                            (os.path.dirname(x)))
                           for x in session_func]):
        # instantiate subject_data object
        subject_data = SubjectData()
        subject_data.subject_id = subject_id
        subject_data.session_id = session

        # set func
        subject_data.func = [x for x in session_func if subject_id in x]
        assert len(subject_data.func) == 1
        subject_data.func = subject_data.func[0]

        # set anat
        subject_data.anat = [x for x in session_anat if subject_id in x]
        assert len(subject_data.anat) == 1
        subject_data.anat = subject_data.anat[0]

        # set subject output directory
        subject_data.output_dir = "/tmp/%s" % subject_id

        subject_data.sanitize(deleteorient=True, niigz2nii=False)

        yield (subject_data.subject_id, subject_data.func[0],
               subject_data.anat)
def subject_factory():
    """
    Producer for HAXBY subject data.

    """

    for subject_id in set([os.path.basename(
                os.path.dirname(x))
                           for x in haxby_data.func]):

        # instantiate subject_data object
        subject_data = SubjectData()
        subject_data.subject_id = subject_id
        subject_data.session_id = "haxby2001"

        # set func
        subject_data.func = [x for x in haxby_data.func if subject_id in x]

        assert len(subject_data.func) == 1
        subject_data.func = subject_data.func[0]

        # set anat
        subject_data.anat = [x for x in haxby_data.func if subject_id in x]
        assert len(subject_data.anat) == 1
        subject_data.anat = subject_data.anat[0]

        # set subject output directory
        subject_data.output_dir = os.path.join(OUTPUT_DIR,
                                               subject_data.subject_id)

        yield subject_data
Ejemplo n.º 4
0
def _nyu_rest_factory(session=1):
    from pypreprocess.nipype_preproc_spm_utils import SubjectData

    nyu_data = fetch_nyu_rest(sessions=[session], n_subjects=7)

    session_func = [x for x in nyu_data.func if "session%i" % session in x]
    session_anat = [
        x for x in nyu_data.anat_skull if "session%i" % session in x]

    for subject_id in set([os.path.basename(os.path.dirname
                                            (os.path.dirname(x)))
                           for x in session_func]):
        # instantiate subject_data object
        subject_data = SubjectData()
        subject_data.subject_id = subject_id
        subject_data.session_id = session

        # set func
        subject_data.func = [x for x in session_func if subject_id in x]
        assert len(subject_data.func) == 1
        subject_data.func = subject_data.func[0]

        # set anat
        subject_data.anat = [x for x in session_anat if subject_id in x]
        assert len(subject_data.anat) == 1
        subject_data.anat = subject_data.anat[0]

        # set subject output directory
        subject_data.output_dir = "/tmp/%s" % subject_id

        subject_data.sanitize(deleteorient=True, niigz2nii=False)

        yield (subject_data.subject_id, subject_data.func[0],
               subject_data.anat)
    def subject_factory():
        for subject_id in subject_ids:
            if subject_id in exclusions:
                continue

            # construct subject data structure
            subject_data = SubjectData()
            subject_data.session_id = session_ids
            subject_data.subject_id = subject_id
            subject_data.func = []

            # glob for bold data
            has_bad_sessions = False
            for session_id in subject_data.session_id:
                bold_dir = os.path.join(
                    data_dir,
                    "%s/BOLD/%s" % (subject_id, session_id))

                # # extract .nii.gz to .nii
                # unzip_nii_gz(bold_dir)

                # glob bold data for this session
                func = glob.glob(os.path.join(bold_dir, "bold.nii.gz"))

                # check that this session is OK (has bold data, etc.)
                if not func:
                    has_bad_sessions = True
                    break

                subject_data.func.append(func[0])

            # exclude subject if necessary
            if has_bad_sessions:
                continue

            # glob for anatomical data
            # anat_dir = os.path.join(
            #     data_dir,
            #     "%s/anatomy" % subject_id)

            # # extract .nii.gz to .ni
            # unzip_nii_gz(anat_dir)

            # glob anatomical data proper
            subject_data.anat = glob.glob(
                os.path.join(
                    data_dir,
                    "%s/anatomy/highres001_brain.nii.gz" % subject_id))[0]

            # set subject output dir (all calculations for
            # this subject go here)
            subject_data.output_dir = os.path.join(
                    output_dir,
                    subject_id)

            yield subject_data
N_SUBJECTS = 2
haxby_data = fetch_haxby(n_subjects=N_SUBJECTS)

# set output dir
OUTPUT_DIR = os.path.join(os.path.dirname(haxby_data.mask), "haxby_runs")
if not os.path.exists(OUTPUT_DIR):
    os.makedirs(OUTPUT_DIR)

# get subject data
subjects = []
for subject_id in set(
    [os.path.basename(os.path.dirname(x)) for x in haxby_data.func]):
    # instantiate subject_data object
    subject_data = SubjectData()
    subject_data.subject_id = subject_id
    subject_data.session_id = "haxby2001"

    # set func
    subject_data.func = [x for x in haxby_data.func if subject_id in x]

    assert len(subject_data.func) == 1
    subject_data.func = subject_data.func[0]

    # set anat
    subject_data.anat = [x for x in haxby_data.anat if subject_id in x]
    assert len(subject_data.anat) == 1
    subject_data.anat = subject_data.anat[0]

    # set subject output directory
    subject_data.output_dir = os.path.join(OUTPUT_DIR, subject_data.subject_id)
haxby_data = fetch_haxby(n_subjects=N_SUBJECTS)

# set output dir
OUTPUT_DIR = os.path.join(os.path.dirname(haxby_data.mask),
                          "haxby_runs")
if not os.path.exists(OUTPUT_DIR):
    os.makedirs(OUTPUT_DIR)

# get subject data
subjects = []
for subject_id in set([os.path.basename(os.path.dirname(x))
                       for x in haxby_data.func]):
    # instantiate subject_data object
    subject_data = SubjectData()
    subject_data.subject_id = subject_id
    subject_data.session_id = "haxby2001"

    # set func
    subject_data.func = [x for x in haxby_data.func if subject_id in x]

    assert len(subject_data.func) == 1
    subject_data.func = subject_data.func[0]

    # set anat
    subject_data.anat = [x for x in haxby_data.anat if subject_id in x]
    assert len(subject_data.anat) == 1
    subject_data.anat = subject_data.anat[0]

    # set subject output directory
    subject_data.output_dir = os.path.join(OUTPUT_DIR,
                                           subject_data.subject_id)