|
| 1 | +""" |
| 2 | +:Module: nipype_preproc_spm_nyu |
| 3 | +:Synopsis: SPM use-case for preprocessing ABIDE MAxMun rest dataset |
| 4 | +:Author: dohmatob elvis dopgima |
| 5 | +
|
| 6 | +""" |
| 7 | + |
| 8 | +# standard imports |
| 9 | +import os |
| 10 | +import glob |
| 11 | +import sys |
| 12 | + |
| 13 | +# import spm preproc utilities |
| 14 | +import nipype_preproc_spm_utils |
| 15 | + |
| 16 | +DATASET_DESCRIPTION = """\ |
| 17 | +<p>ABIDE MaxMun dataset</p>\ |
| 18 | +""" |
| 19 | + |
| 20 | +if __name__ == '__main__': |
| 21 | + # sanitize cmd-line input |
| 22 | + if len(sys.argv) < 3: |
| 23 | + print "\r\nUsage: python %s <path_to_ABIDE_folder> <output_dir>\r\n" \ |
| 24 | + % sys.argv[0] |
| 25 | + print "Example:\r\npython %s ~/ABIDE ~/ABIDE_runs/MaxMun" % sys.argv[0] |
| 26 | + sys.exit(1) |
| 27 | + |
| 28 | + ABIDE_DIR = os.path.abspath(sys.argv[1]) |
| 29 | + |
| 30 | + OUTPUT_DIR = os.path.abspath(sys.argv[2]) |
| 31 | + if not os.path.isdir(OUTPUT_DIR): |
| 32 | + os.makedirs(OUTPUT_DIR) |
| 33 | + |
| 34 | + # glob for MaxMun subject_ids |
| 35 | + subject_ids = [os.path.basename(x) |
| 36 | + for x in glob.glob( |
| 37 | + os.path.join(ABIDE_DIR, "MaxMun_*/MaxMun_*"))] |
| 38 | + |
| 39 | + # producer for MaxMun subjects |
| 40 | + def subject_factory(): |
| 41 | + for subject_id in subject_ids: |
| 42 | + subject_data = nipype_preproc_spm_utils.SubjectData() |
| 43 | + subject_data.subject_id = subject_id |
| 44 | + subject_data.session_id = 'UNKNOWN_SESSION' |
| 45 | + |
| 46 | + subject_data.func = glob.glob( |
| 47 | + os.path.join( |
| 48 | + ABIDE_DIR, |
| 49 | + "%s/%s/scans/rest/resources/NIfTI/files/rest.nii" % ( |
| 50 | + subject_id, subject_id))) |
| 51 | + |
| 52 | + subject_data.anat = glob.glob( |
| 53 | + os.path.join( |
| 54 | + ABIDE_DIR, |
| 55 | + "%s/%s/scans/anat/resources/NIfTI/files/mprage.nii" % ( |
| 56 | + subject_id, subject_id))) |
| 57 | + |
| 58 | + subject_data.output_dir = os.path.join( |
| 59 | + os.path.join( |
| 60 | + OUTPUT_DIR, subject_data.session_id), |
| 61 | + subject_id) |
| 62 | + |
| 63 | + yield subject_data |
| 64 | + |
| 65 | + # do preprocessing proper |
| 66 | + report_filename = os.path.join(OUTPUT_DIR, |
| 67 | + "_report.html") |
| 68 | + nipype_preproc_spm_utils.do_group_preproc( |
| 69 | + subject_factory(), |
| 70 | + dataset_description=DATASET_DESCRIPTION, |
| 71 | + report_filename=report_filename) |
0 commit comments