From 86f6427e4eefcc07b55f273d2414feee8a2f82e6 Mon Sep 17 00:00:00 2001 From: fliem Date: Tue, 15 Aug 2017 11:07:19 +0200 Subject: [PATCH 1/4] freesurfer_dir now defaults to out_dir/freesurfer --- scripts/run_brain_age_bids.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/scripts/run_brain_age_bids.py b/scripts/run_brain_age_bids.py index 5a89e44..abe395a 100644 --- a/scripts/run_brain_age_bids.py +++ b/scripts/run_brain_age_bids.py @@ -19,7 +19,7 @@ 'is extracted automatiacally from that folder. ') parser.add_argument('bids_dir', help='The directory with the input dataset ' 'formatted according to the BIDS standard.') - parser.add_argument('out_dir', help='Results are put here.') + parser.add_argument('out_dir', help='Results are put into {out_dir}/baracus.') parser.add_argument('analysis_level', help='Level of the analysis that will be performed. ' '"participant": predicts single subject brain age, ' '"group": collects single subject predictions.', @@ -31,9 +31,11 @@ 'provided all subjects should be analyzed. Multiple ' 'participants can be specified with a space separated list.', nargs="+") - parser.add_argument('--freesurfer_dir', required=True, help="Folder with FreeSurfer subjects formatted according " - "to BIDS standard. If subject's recon-all folder " - "cannot be found, recon-all will be run.") + parser.add_argument('--freesurfer_dir', help="Folder with FreeSurfer subjects formatted according " + "to BIDS standard. If subject's recon-all folder " + "cannot be found, recon-all will be run. " + "If not specified freesurfer data will be saved to {" + "out_dir}/freesurfer") parser.add_argument('--models', choices=models_list, default=["Liem2016__OCI_norm"], help='', nargs="+") parser.add_argument('--license_key', @@ -46,6 +48,13 @@ version='BARACUS version {}'.format(__version__)) args = parser.parse_args() + if args.freesurfer_dir: + freesurfer_dir = args.freesurfer_dir + else: + freesurfer_dir = os.path.join(args.out_dir, "freesurfer") + + out_dir = os.path.join(args.out_dir, "baracus") + model_dir = resource_filename(Requirement.parse("baracus"), 'models') run("bids-validator " + args.bids_dir) @@ -58,11 +67,11 @@ if args.analysis_level == "participant": - data_files = run_prepare_all(args.bids_dir, args.freesurfer_dir, args.out_dir, subjects_to_analyze, + data_files = run_prepare_all(args.bids_dir, freesurfer_dir, out_dir, subjects_to_analyze, sessions_to_analyze, args.n_cpus, args.license_key) for subject, d in data_files.items(): - d["out_dir"] = args.out_dir + d["out_dir"] = out_dir d["model_dir"] = model_dir d["models"] = args.models d["subject_label"] = subject @@ -72,10 +81,10 @@ print("Creating group table...") df = pd.DataFrame([]) for subject in freesurfer_subjects_to_analyze: - in_file = os.path.join(args.out_dir, subject, subject + "_predicted_age.tsv") + in_file = os.path.join(out_dir, subject, subject + "_predicted_age.tsv") df = df.append(pd.read_csv(in_file, sep="\t")) - group_out_dir = os.path.join(args.out_dir, "00_group") + group_out_dir = os.path.join(out_dir, "00_group") if not os.path.isdir(group_out_dir): os.makedirs(group_out_dir) out_file = os.path.join(group_out_dir, "group_predicted_age.tsv") From d5bf4c5560095ad566aec195f9de95afea87403e Mon Sep 17 00:00:00 2001 From: fliem Date: Tue, 15 Aug 2017 11:24:23 +0200 Subject: [PATCH 2/4] update ci output paths --- circle.yml | 8 ++++---- scripts/run_brain_age_bids.py | 6 +++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/circle.yml b/circle.yml index 33a7657..6597c0f 100644 --- a/circle.yml +++ b/circle.yml @@ -33,13 +33,13 @@ test: # ds114_test1 - docker run --rm -ti -v ${HOME}/data/ds114_test1:/data/in -v ${HOME}/data/ds114_test1_freesurfer:/data/fs -v ${HOME}/outputs/ds114_test1:/data/out bids/${CIRCLE_PROJECT_REPONAME,,} /data/in /data/out participant --freesurfer_dir /data/fs --license_key="~/test.key" - docker run --rm -ti -v ${HOME}/data/ds114_test1:/data/in -v ${HOME}/data/ds114_test1_freesurfer:/data/fs -v ${HOME}/outputs/ds114_test1:/data/out bids/${CIRCLE_PROJECT_REPONAME,,} /data/in /data/out group --freesurfer_dir /data/fs --license_key="~/test.key" - - cat ${HOME}/outputs/ds114_test1/00_group/group_predicted_age.tsv + - cat ${HOME}/outputs/ds114_test1/baracus/00_group/group_predicted_age.tsv # test models - docker run --rm -ti -v ${HOME}/data/ds114_test1:/data/in -v ${HOME}/data/ds114_test1_freesurfer:/data/fs -v ${HOME}/outputs/ds114_test1_models:/data/out bids/${CIRCLE_PROJECT_REPONAME,,} /data/in /data/out participant --freesurfer_dir /data/fs --models Liem2016__OCI_norm Liem2016__full_2samp_training --license_key="~/test.key" - docker run --rm -ti -v ${HOME}/data/ds114_test1:/data/in -v ${HOME}/data/ds114_test1_freesurfer:/data/fs -v ${HOME}/outputs/ds114_test1_models:/data/out bids/${CIRCLE_PROJECT_REPONAME,,} /data/in /data/out group --freesurfer_dir /data/fs --license_key="~/test.key" - - cat ${HOME}/outputs/ds114_test1_models/00_group/group_predicted_age.tsv - + - cat ${HOME}/outputs/ds114_test1_models/baracus/00_group/group_predicted_age.tsv + # test file mode - docker run --rm -ti -v ${HOME}/outputs/ds114_test1/sub-01/data/:/data/in -v ${HOME}/outputs/ds114_test1_file_mode:/data/out --entrypoint=run_brain_age_files.py bids/baracus /data/out --lh_thickness_file /data/in/lh.thickness.mgh --rh_thickness_file /data/in/rh.thickness.mgh --lh_area_file /data/in/lh.area.mgh --rh_area_file /data/in/rh.area.mgh --aseg_file /data/in/aseg --participant_label sub-01 - cat ${HOME}/outputs/ds114_test1_file_mode/sub-01/sub-01_predicted_age.tsv @@ -47,7 +47,7 @@ test: # ds114_test2 - docker run --rm -ti -v ${HOME}/data/ds114_test2:/data/in -v ${HOME}/data/ds114_test2_freesurfer:/data/fs -v ${HOME}/outputs/ds114_test2:/data/out bids/${CIRCLE_PROJECT_REPONAME,,} /data/in /data/out participant --freesurfer_dir /data/fs --license_key="~/test.key" - docker run --rm -ti -v ${HOME}/data/ds114_test2:/data/in -v ${HOME}/data/ds114_test2_freesurfer:/data/fs -v ${HOME}/outputs/ds114_test2:/data/out bids/${CIRCLE_PROJECT_REPONAME,,} /data/in /data/out group --freesurfer_dir /data/fs --license_key="~/test.key" - - cat ${HOME}/outputs/ds114_test2/00_group/group_predicted_age.tsv + - cat ${HOME}/outputs/ds114_test2/baracus/00_group/group_predicted_age.tsv deployment: hub: diff --git a/scripts/run_brain_age_bids.py b/scripts/run_brain_age_bids.py index abe395a..03bd143 100644 --- a/scripts/run_brain_age_bids.py +++ b/scripts/run_brain_age_bids.py @@ -48,12 +48,16 @@ version='BARACUS version {}'.format(__version__)) args = parser.parse_args() + # set up output dirs if args.freesurfer_dir: freesurfer_dir = args.freesurfer_dir else: freesurfer_dir = os.path.join(args.out_dir, "freesurfer") - out_dir = os.path.join(args.out_dir, "baracus") + if not os.path.isdir(freesurfer_dir): + os.makedirs(freesurfer_dir) + if not os.path.isdir(out_dir): + os.makedirs(out_dir) model_dir = resource_filename(Requirement.parse("baracus"), 'models') From 3c765b63cb4e8b3936ee4b7f61f02e1b3394f7a8 Mon Sep 17 00:00:00 2001 From: fliem Date: Tue, 15 Aug 2017 11:31:46 +0200 Subject: [PATCH 3/4] =?UTF-8?q?doc=20update=C2=A0[skip=20ci]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 3bc070f..24668ee 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Your data has to be organized according to the [BIDS standard](http://bids.neuroimaging.io) and each subject needs at least one T1w image. In a first step, BARACUS runs [FreeSurfer's](http://freesurfer.net) -`recon-all` command and saves the output in `--freesurfer_dir`. +`recon-all` command and saves the output in `{out_dir}/freesurfer/` If the data has previously been analyzed with FreeSurfer version 5.3.0, and BARACUS finds them in `--freesurfer_dir` this step ist skippen. @@ -67,36 +67,44 @@ aseg files extracted via asegstats2table. These examples demonstrate how to run the `bids/baracus` docker container. For a brief introduction how to run BIDS Apps see [this site](http://bids-apps.neuroimaging.io/tutorial/). -In the examples `/project/bids_sourcedata`, `/project/freesurfer` and -`/project/baracus` are directories -on your hard drive, which are mapped into the docker container directories -`/data/in`, `/data/freesurfer` and `/data/out`, respectively, via -the `-v` flag. +In the examples `/project/bids_sourcedata` and +`/project/baracus` are directories on your hard drive, which are mapped +into the docker container directories `/data/in` and `/data/out`, +respectively, via the `-v` flag. #### Participants docker run -ti --rm \ -v /project/bids_sourcedata/:/data/in \ - -v /project/freesurfer/:/data/freesurfer \ -v /project/baracus:/data/out \ bids/baracus /data/in /data/out participant \ - --license_key "XX" --freesurfer_dir /data/freesurfer + --license_key "XX" #### Group docker run -ti --rm \ -v /project/bids_sourcedata/:/data/in \ - -v /project/freesurfer/:/data/freesurfer \ -v /project/baracus:/data/out \ bids/baracus /data/in /data/out group \ + --license_key "XX" + +#### Participants with previously processed FreeSurfer data +If FreeSurfer data is already available, for example at +`/project/freesurfer/` running the follwing command will use the +previously processed data: + + docker run -ti --rm \ + -v /project/bids_sourcedata/:/data/in \ + -v /project/freesurfer/:/data/freesurfer \ + -v /project/baracus:/data/out \ + bids/baracus /data/in /data/out participant \ --license_key "XX" --freesurfer_dir /data/freesurfer ### Usage - docker run -ti --rm bids/${CIRCLE_PROJECT_REPONAME,,} -h usage: run_brain_age_bids.py [-h] [--participant_label PARTICIPANT_LABEL [PARTICIPANT_LABEL ...]] - --freesurfer_dir FREESURFER_DIR + [--freesurfer_dir FREESURFER_DIR] [--models {Liem2016__OCI_norm,Liem2016__full_2samp_training} [{Liem2016__OCI_norm,Liem2016__full_2samp_training} ...]] --license_key LICENSE_KEY [--n_cpus N_CPUS] [-v] bids_dir out_dir {participant,group} @@ -108,7 +116,7 @@ the `-v` flag. positional arguments: bids_dir The directory with the input dataset formatted according to the BIDS standard. - out_dir Results are put here. + out_dir Results are put into {out_dir}/baracus. {participant,group} Level of the analysis that will be performed. "participant": predicts single subject brain age, "group": collects single subject predictions. @@ -125,7 +133,8 @@ the `-v` flag. --freesurfer_dir FREESURFER_DIR Folder with FreeSurfer subjects formatted according to BIDS standard. If subject's recon-all folder cannot be - found, recon-all will be run. + found, recon-all will be run. If not specified + freesurfer data will be saved to {out_dir}/freesurfer --models {Liem2016__OCI_norm,Liem2016__full_2samp_training} [{Liem2016__OCI_norm,Liem2016__full_2samp_training} ...] --license_key LICENSE_KEY FreeSurfer license key - letters and numbers after "*" @@ -136,6 +145,7 @@ the `-v` flag. -v, --version show program's version number and exit + ## FILE mode ### Example docker run -ti --rm \ From cfd3b85c49617f5af9d19c691a20ea69cd61b5bc Mon Sep 17 00:00:00 2001 From: fliem Date: Tue, 15 Aug 2017 11:46:28 +0200 Subject: [PATCH 4/4] fix file mode test --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 6597c0f..0c084cf 100644 --- a/circle.yml +++ b/circle.yml @@ -41,7 +41,7 @@ test: - cat ${HOME}/outputs/ds114_test1_models/baracus/00_group/group_predicted_age.tsv # test file mode - - docker run --rm -ti -v ${HOME}/outputs/ds114_test1/sub-01/data/:/data/in -v ${HOME}/outputs/ds114_test1_file_mode:/data/out --entrypoint=run_brain_age_files.py bids/baracus /data/out --lh_thickness_file /data/in/lh.thickness.mgh --rh_thickness_file /data/in/rh.thickness.mgh --lh_area_file /data/in/lh.area.mgh --rh_area_file /data/in/rh.area.mgh --aseg_file /data/in/aseg --participant_label sub-01 + - docker run --rm -ti -v ${HOME}/outputs/ds114_test1/baracus/sub-01/data/:/data/in -v ${HOME}/outputs/ds114_test1_file_mode:/data/out --entrypoint=run_brain_age_files.py bids/baracus /data/out --lh_thickness_file /data/in/lh.thickness.mgh --rh_thickness_file /data/in/rh.thickness.mgh --lh_area_file /data/in/lh.area.mgh --rh_area_file /data/in/rh.area.mgh --aseg_file /data/in/aseg --participant_label sub-01 - cat ${HOME}/outputs/ds114_test1_file_mode/sub-01/sub-01_predicted_age.tsv # ds114_test2