Skip to content

Commit 9604072

Browse files
authored
Merge pull request #21 from BIDS-Apps/fs
run recon_all if freesurfer directory not found and others
2 parents f34b424 + 59f50ed commit 9604072

File tree

10 files changed

+565
-134
lines changed

10 files changed

+565
-134
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.DS_Store
12
.idea
23
# Byte-compiled / optimized / DLL files
34
__pycache__/

Dockerfile

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
FROM bids/base_fsl
22

3-
43
#### FreeSurfer
54
RUN apt-get -y update && \
65
wget -qO- https://surfer.nmr.mgh.harvard.edu/pub/dist/freesurfer/6.0.0/freesurfer-Linux-centos6_x86_64-stable-pub-v6.0.0.tar.gz | tar zxv -C /opt \
@@ -41,17 +40,13 @@ RUN sudo apt-get update && apt-get install -y python3
4140
RUN sudo apt-get update && apt-get install -y python3-pip
4241
RUN pip3 install pandas
4342
RUN pip3 install pybids
43+
RUN pip3 install nibabel
44+
RUN pip3 install joblib
4445

45-
RUN apt-get install -y tree htop
46-
RUN apt-get install -y tcsh
47-
RUN apt-get install -y bc
48-
RUN apt-get install -y tar libgomp1 perl-modules
49-
50-
RUN apt-get install -y curl
51-
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
52-
RUN apt-get install -y nodejs
53-
RUN npm install -g bids-validator@0.19.8
54-
46+
RUN sudo apt-get update && apt-get install -y tree htop
47+
RUN sudo apt-get update && apt-get install -y tcsh
48+
RUN sudo apt-get update && apt-get install -y bc
49+
RUN sudo apt-get update && apt-get install -y tar libgomp1 perl-modules
5550

5651
RUN mkdir /scratch
5752
RUN mkdir /local-scratch
@@ -61,6 +56,14 @@ COPY run.py /code/run.py
6156
COPY tracula.py /code/tracula.py
6257
RUN chmod +x /code/run.py
6358

59+
# freesurfer repo
60+
RUN wget https://github.com/bids-apps/freesurfer/archive/v6.0.0-5.tar.gz && \
61+
tar xfz v6.0.0-5.tar.gz && rm -r v6.0.0-5.tar.gz && \
62+
cd freesurfer-6.0.0-5 && mv run.py /code/run_freesurfer.py
63+
64+
RUN touch /code/version
65+
ENV PATH=/code:$PATH
66+
6467
COPY version /version
6568

6669
ENTRYPOINT ["/code/run.py"]

README.md

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,22 @@ doi: https://doi.org/10.1101/079145*
4747
##
4848

4949
### Data
50-
Tracula requires one DWI volume and a Freesurfer reconstruction
50+
Tracula requires one DWI volume and a one T1w image
5151
per participant (or session if the data is longitudinal).
52-
The Freesurfer reconstruction should be performed with the
52+
53+
In a first step, the app will run the FreeSurfer reconstruction
54+
(`recon-all`). If the Freesurfer reconstruction is already available
55+
and is provided via the `{freesurfer_dir}` argument, this step is skipped.
56+
In this case `recon-all` should have been performed with the
5357
[Freesurfer BIDS App](https://github.com/bids-apps/freesurfer)
5458
(or at least follow the BIDS naming scheme).
5559

5660
### Analysis levels
5761

5862
- **participant**: Tract reconstruction
5963

60-
Performs the three steps (prep, bedp, path) of Tracula's `trac-all`,
64+
Runs `recon-all` if not already available.
65+
Subsequently, performs the three steps (prep, bedp, path) of Tracula's `trac-all`,
6166
reconstructing major fiber tracts form Freesurfer outputs and
6267
DWI raw data.
6368
All data is written into `{output_dir}`.
@@ -79,21 +84,24 @@ The Freesurfer reconstruction should be performed with the
7984
calculation can be found in the *TMI_info* column of the
8085
output file.
8186

82-
- **group2**: Overall tract statistics
87+
- **group2**: Tract statistics
8388

84-
Collects characteristics of a tract (average FA...)
85-
for multiple subjects.
86-
Output is written to
87-
`{output_dir}/00_group2_tract_stats/{tract_name}_stats.tsv`.
89+
Collects tract stats for multiple subjects.
90+
Mean stats of a tract (average FA...) are written to
91+
`{output_dir}/00_group2_tract_stats/overall_stats/`.
92+
Along-tract stats are written to
93+
`{output_dir}/00_group2_tract_stats/byvoxel_stats/`.
8894

8995

9096
### Usage
9197
This App has the following command line arguments:
9298

9399
usage: run.py [-h] --license_key LICENSE_KEY
94100
[--participant_label PARTICIPANT_LABEL [PARTICIPANT_LABEL ...]]
101+
[--session_label SESSION_LABEL [SESSION_LABEL ...]]
95102
[--freesurfer_dir FREESURFER_DIR]
96-
[--stages {prep,bedp,path,all} [{prep,bedp,path,all} ...]] [-v]
103+
[--stages {prep,bedp,path,all} [{prep,bedp,path,all} ...]]
104+
[--n_cpus N_CPUS] [--run-freesurfer-tests-only] [-v]
97105
bids_dir output_dir {participant,group1,group2}
98106

99107
BIDS App for Tracula processing stream.
@@ -108,10 +116,10 @@ This App has the following command line arguments:
108116
theparticipant level analysis.
109117
{participant,group1,group2}
110118
Level of the analysis that will be performed.
111-
"participant": reconstructs paths (trac-all -prep,
112-
-bedp and -path), "group1": collects motion stats in
113-
one file, "group2": collects single subject overall
114-
path stats in one file.
119+
"participant": runs FreeSurfer and reconstructs paths
120+
(trac-all -prep, -bedp and -path), "group1": collects
121+
motion stats in one file, "group2": collects tract
122+
stats in one file.
115123

116124
optional arguments:
117125
-h, --help show this help message and exit
@@ -128,16 +136,27 @@ This App has the following command line arguments:
128136
parameter is not provided all subjects should be
129137
analyzed. Multiple participants can be specified with
130138
a space separated list. (default: None)
139+
--session_label SESSION_LABEL [SESSION_LABEL ...]
140+
The label of the sessions that should be analyzed. The
141+
label corresponds to ses-<session_label> from the BIDS
142+
spec (so it does not include "ses-"). If this
143+
parameter is not provided all sessions should be
144+
analyzed. Multiple sessions can be specified with a
145+
space separated list. (default: None)
131146
--freesurfer_dir FREESURFER_DIR
132-
The directory with the freesurfer data. If not
133-
specified, output_dir is assumed to be populated with
134-
freesurfer data. (default: None)
147+
The directory with the FreeSurfer data. If not
148+
specified, FreeSurfer data is written into output_dir.
149+
If FreeSurfer data cannot be found for a subject, this
150+
app will run FreeSurfer as well. (default: None)
135151
--stages {prep,bedp,path,all} [{prep,bedp,path,all} ...]
136152
Participant-level trac-all stages to run. Passing"all"
137153
will run "prep", "bedp" and "path". (default: ['all'])
154+
--n_cpus N_CPUS Number of CPUs/cores available to use. (default: 1)
155+
--run-freesurfer-tests-only
156+
Dev option to enable freesurfer tests on circleci
157+
(default: False)
138158
-v, --version show program's version number and exit
139159

140-
141160
##
142161
### Examples
143162
To run it in participant level mode (for one participant):
@@ -175,7 +194,7 @@ To aggregate motion statistics into one file (group1 stage), run:
175194

176195

177196

178-
To collect single subject overall path stats in one file (group2 stage), run:
197+
To aggregate tract statistics into one file (group2 stage), run:
179198

180199
docker run -ti --rm \
181200
-v /data/ds114/sourcedata:/bids_dataset:ro \

circle.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
general:
22
artifacts:
33
- "~/outputs1"
4+
- "~/outputs1_fs_tests"
45
- "~/outputs2"
6+
- "~/outputs2_1ses"
57
- "~/outputs2_session_label"
68

79
machine:
@@ -16,8 +18,9 @@ dependencies:
1618
override:
1719
- if [[ ! -d ~/data/ds114_test1 ]]; then wget -c -O ${HOME}/ds114_test1.tar "https://files.osf.io/v1/resources/9q7dv/providers/osfstorage/57e54a326c613b01d7d3ed90" && mkdir -p ${HOME}/data && tar xf ${HOME}/ds114_test1.tar -C ${HOME}/data; fi
1820
- if [[ ! -d ~/data/ds114_test2 ]]; then wget -c -O ${HOME}/ds114_test2.tar "https://files.osf.io/v1/resources/9q7dv/providers/osfstorage/57e549f9b83f6901d457d162" && mkdir -p ${HOME}/data && tar xf ${HOME}/ds114_test2.tar -C ${HOME}/data; fi
19-
- if [[ ! -d ~/data/ds114_test1_freesurfer ]]; then wget -c -O ${HOME}/ds114_test1_freesurfer.tar "https://files.osf.io/v1/resources/9q7dv/providers/osfstorage/5882adf3b83f6901f564da49" && mkdir -p ${HOME}/data && tar xf ${HOME}/ds114_test1_freesurfer.tar -C ${HOME}/data; fi
20-
- if [[ ! -d ~/data/ds114_test2_freesurfer ]]; then wget -c -O ${HOME}/ds114_test2_freesurfer.tar "https://files.osf.io/v1/resources/9q7dv/providers/osfstorage/5882b0e3b83f6901fb64da18" && mkdir -p ${HOME}/data && tar xf ${HOME}/ds114_test2_freesurfer.tar -C ${HOME}/data; fi
21+
- if [[ ! -d ~/data/ds114_test2_1ses ]]; then cp -r ~/data/ds114_test2 ~/data/ds114_test2_1ses && rm -r ~/data/ds114_test2_1ses/sub-*/ses-retest; fi
22+
- if [[ ! -d ~/data/ds114_test1_freesurfer ]]; then wget -c -O ${HOME}/ds114_test1_freesurfer.tar "https://osf.io/j6zk2/?action=download&version=1" && mkdir -p ${HOME}/data && tar xf ${HOME}/ds114_test1_freesurfer.tar -C ${HOME}/data && cd ${HOME}/data && mv ds114_test1_freesurfer_precomp_v6.0.0 ds114_test1_freesurfer; fi
23+
- if [[ ! -d ~/data/ds114_test2_freesurfer ]]; then wget -c -O ${HOME}/ds114_test2_freesurfer.tar "https://osf.io/yhzzj/?action=download&version=1" && mkdir -p ${HOME}/data && tar xf ${HOME}/ds114_test2_freesurfer.tar -C ${HOME}/data&& cd ${HOME}/data && mv ds114_test2_freesurfer_precomp_v6.0.0 ds114_test2_freesurfer; fi
2124
- if [[ ! -d ~/data/ds114_test1_tracula_precomp ]]; then wget -c -O ${HOME}/ds114_test1_tracula_precomp.tar "https://files.osf.io/v1/resources/9q7dv/providers/osfstorage/5882af28594d9001f447f03a" && mkdir -p ${HOME}/data && tar xf ${HOME}/ds114_test1_tracula_precomp.tar -C ${HOME}/data; fi
2225
- if [[ ! -d ~/data/ds114_test2_tracula_precomp ]]; then wget -c -O ${HOME}/ds114_test2_tracula_precomp.tar "https://files.osf.io/v1/resources/9q7dv/providers/osfstorage/5882b3c3594d9001f047f031" && mkdir -p ${HOME}/data && tar xf ${HOME}/ds114_test2_tracula_precomp.tar -C ${HOME}/data; fi
2326
- if [[ -e ~/docker/image.tar ]]; then docker load -i ~/docker/image.tar; fi
@@ -30,14 +33,17 @@ test:
3033
override:
3134
# print version
3235
- docker run -ti --rm --read-only -v /tmp:/tmp -v /var/tmp:/var/tmp -v ${HOME}/data/ds114_test1:/bids_dataset -v ${HOME}/data/ds114_test1_freesurfer:/freesurfer bids/${CIRCLE_PROJECT_REPONAME,,} --version
36+
# participant level tests for 1ses dataset: cross dataset that has session level with one session
37+
- docker run -ti --rm --read-only -v /tmp:/tmp -v /var/tmp:/var/tmp -v ${HOME}/data/ds114_test2_1ses:/bids_dataset -v ${HOME}/outputs2_1ses:/outputs -v ${HOME}/data/ds114_test1_freesurfer:/freesurfer bids/${CIRCLE_PROJECT_REPONAME,,} /bids_dataset /outputs participant --participant_label 01 --license_key="~/test.key" --freesurfer_dir /freesurfer --stages prep && cat ${HOME}/outputs2_1ses/sub-01/scripts/trac-preproc.done :
38+
timeout: 21600
3339
# participant level tests for single session dataset
3440
- docker run -ti --rm --read-only -v /tmp:/tmp -v /var/tmp:/var/tmp -v ${HOME}/data/ds114_test1:/bids_dataset -v ${HOME}/outputs1:/outputs -v ${HOME}/data/ds114_test1_freesurfer:/freesurfer bids/${CIRCLE_PROJECT_REPONAME,,} /bids_dataset /outputs participant --participant_label 01 --license_key="~/test.key" --freesurfer_dir /freesurfer --stages prep && cat ${HOME}/outputs1/sub-01/scripts/trac-preproc.done :
3541
timeout: 21600
3642
# group level test for single session dataset: group1
3743
- docker run -ti --rm --read-only -v /tmp:/tmp -v /var/tmp:/var/tmp -v ${HOME}/data/ds114_test1:/bids_dataset -v ${HOME}/data/ds114_test1_tracula_precomp:/outputs -v ${HOME}/data/ds114_test1_freesurfer:/freesurfer bids/${CIRCLE_PROJECT_REPONAME,,} /bids_dataset /outputs group1 --license_key="~/test.key" --freesurfer_dir /freesurfer && mkdir -p ${HOME}/outputs1/ && sudo mv ${HOME}/data/ds114_test1_tracula_precomp/00_group* ${HOME}/outputs1/ && cat ${HOME}/outputs1/00_group1_motion_stats/group_motion.tsv :
3844
timeout: 21600
3945
# group level test for single session dataset: group2
40-
- docker run -ti --rm --read-only -v /tmp:/tmp -v /var/tmp:/var/tmp -v ${HOME}/data/ds114_test1:/bids_dataset -v ${HOME}/data/ds114_test1_tracula_precomp:/outputs -v ${HOME}/data/ds114_test1_freesurfer:/freesurfer bids/${CIRCLE_PROJECT_REPONAME,,} /bids_dataset /outputs group2 --license_key="~/test.key" --freesurfer_dir /freesurfer && mkdir -p ${HOME}/outputs1/ && sudo mv ${HOME}/data/ds114_test1_tracula_precomp/00_group* ${HOME}/outputs1/ && cat ${HOME}/outputs1/00_group2_tract_stats/fminor_stats.tsv :
46+
- docker run -ti --rm --read-only -v /tmp:/tmp -v /var/tmp:/var/tmp -v ${HOME}/data/ds114_test1:/bids_dataset -v ${HOME}/data/ds114_test1_tracula_precomp:/outputs -v ${HOME}/data/ds114_test1_freesurfer:/freesurfer bids/${CIRCLE_PROJECT_REPONAME,,} /bids_dataset /outputs group2 --license_key="~/test.key" --freesurfer_dir /freesurfer && mkdir -p ${HOME}/outputs1/ && sudo mv ${HOME}/data/ds114_test1_tracula_precomp/00_group* ${HOME}/outputs1/ && cat ${HOME}/outputs1/00_group2_tract_stats/overall_stats/fminor_stats.tsv && cat ${HOME}/outputs1/00_group2_tract_stats/byvoxel_stats/lh.cab_PP.avg33_mni_bbr.FA.txt:
4147
timeout: 21600
4248
# participant level tests for a longitudinal dataset
4349
- docker run -ti --rm --read-only -v /tmp:/tmp -v /var/tmp:/var/tmp -v ${HOME}/data/ds114_test2:/bids_dataset -v ${HOME}/outputs2:/outputs -v ${HOME}/data/ds114_test2_freesurfer:/freesurfer bids/${CIRCLE_PROJECT_REPONAME,,} /bids_dataset /outputs participant --participant_label 01 --license_key="~/test.key" --freesurfer_dir /freesurfer --stages prep && cat ${HOME}/outputs2/sub-01_ses-test.long.sub-01/scripts/trac-preproc.done :
@@ -49,9 +55,11 @@ test:
4955
- docker run -ti --rm --read-only -v /tmp:/tmp -v /var/tmp:/var/tmp -v ${HOME}/data/ds114_test2:/bids_dataset -v ${HOME}/data/ds114_test2_tracula_precomp:/outputs -v ${HOME}/data/ds114_test2_freesurfer:/freesurfer bids/${CIRCLE_PROJECT_REPONAME,,} /bids_dataset /outputs group1 --license_key="~/test.key" --freesurfer_dir /freesurfer && mkdir -p ${HOME}/outputs2/ && sudo mv ${HOME}/data/ds114_test2_tracula_precomp/00_group* ${HOME}/outputs2/ && cat ${HOME}/outputs2/00_group1_motion_stats/group_motion.tsv :
5056
timeout: 21600
5157
# group level test for a longitudinal dataset: group2
52-
- docker run -ti --rm --read-only -v /tmp:/tmp -v /var/tmp:/var/tmp -v ${HOME}/data/ds114_test2:/bids_dataset -v ${HOME}/data/ds114_test2_tracula_precomp:/outputs -v ${HOME}/data/ds114_test2_freesurfer:/freesurfer bids/${CIRCLE_PROJECT_REPONAME,,} /bids_dataset /outputs group2 --license_key="~/test.key" --freesurfer_dir /freesurfer && mkdir -p ${HOME}/outputs2/ && sudo mv ${HOME}/data/ds114_test2_tracula_precomp/00_group* ${HOME}/outputs2/ && cat ${HOME}/outputs2/00_group2_tract_stats/fminor_stats.tsv:
58+
- docker run -ti --rm --read-only -v /tmp:/tmp -v /var/tmp:/var/tmp -v ${HOME}/data/ds114_test2:/bids_dataset -v ${HOME}/data/ds114_test2_tracula_precomp:/outputs -v ${HOME}/data/ds114_test2_freesurfer:/freesurfer bids/${CIRCLE_PROJECT_REPONAME,,} /bids_dataset /outputs group2 --license_key="~/test.key" --freesurfer_dir /freesurfer && mkdir -p ${HOME}/outputs2/ && sudo mv ${HOME}/data/ds114_test2_tracula_precomp/00_group* ${HOME}/outputs2/ && cat ${HOME}/outputs2/00_group2_tract_stats/overall_stats/fminor_stats.tsv && cat ${HOME}/outputs2/00_group2_tract_stats/byvoxel_stats/lh.cab_PP.avg33_mni_bbr.FA.txt :
59+
timeout: 21600
60+
# starts freesurfer processing only
61+
- mkdir -p ${HOME}/outputs1_fs_tests/tracula && mkdir -p ${HOME}/outputs1_fs_tests/freesurfer && docker run -ti --rm --read-only -v /tmp:/tmp -v /var/tmp:/var/tmp -v ${HOME}/data/ds114_test1:/bids_dataset -v ${HOME}/outputs1_fs_tests:/outputs bids/${CIRCLE_PROJECT_REPONAME,,} /bids_dataset /outputs/tracula participant --participant_label 01 --license_key="~/test.key" --freesurfer_dir /outputs/freesurfer --run-freesurfer-tests-only && cat ${HOME}/outputs1_fs_tests/freesurfer/sub-01/scripts/recon-all.done :
5362
timeout: 21600
54-
5563
deployment:
5664
hub:
5765
owner: BIDS-Apps
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env bash
2+
3+
# cd /data.nfs/ds114/tracula_full_tests
4+
# screen -L bash run_full_tests_....sh ds114_test1 and
5+
# screen -L bash run_full_tests_....sh ds114_test2
6+
7+
ds_name=$1
8+
echo Running ${ds_name}
9+
10+
tracula_version=v6.0.0-3
11+
wd=/data.nfs/ds114/tracula_full_tests/${tracula_version}
12+
13+
data_dir=${wd}/data
14+
out_root_dir=${wd}/out
15+
16+
mkdir -p $data_dir
17+
mkdir -p $out_root_dir
18+
19+
if [[ ! -d ${data_dir}/ds114_test1 ]]; then wget -c -O ${data_dir}/ds114_test1.tar "https://files.osf.io/v1/resources/9q7dv/providers/osfstorage/57e54a326c613b01d7d3ed90" && tar xf ${data_dir}/ds114_test1.tar -C ${data_dir}; fi
20+
if [[ ! -d ${data_dir}/ds114_test2 ]]; then wget -c -O ${data_dir}/ds114_test2.tar "https://files.osf.io/v1/resources/9q7dv/providers/osfstorage/57e549f9b83f6901d457d162" && tar xf ${data_dir}/ds114_test2.tar -C ${data_dir}; fi
21+
if [[ ! -d ${data_dir}/ds114_test1_freesurfer_precomp_v6.0.0 ]]; then wget -c -O ${data_dir}/ds114_test1_freesurfer.tar "https://osf.io/j6zk2/?action=download&version=1" && tar xf ${data_dir}/ds114_test1_freesurfer.tar -C ${data_dir}; fi
22+
if [[ ! -d ${data_dir}/ds114_test2_freesurfer_precomp_v6.0.0 ]]; then wget -c -O ${data_dir}/ds114_test2_freesurfer.tar "https://osf.io/yhzzj/?action=download&version=1" && tar xf ${data_dir}/ds114_test2_freesurfer.tar -C ${data_dir}; fi
23+
if [[ -e ${data_dir}/*.tar ]]; then rm -r ${data_dir}/*.tar; fi
24+
25+
26+
27+
28+
in_dir=${data_dir}/${ds_name}
29+
fs_dir=${data_dir}/${ds_name}_freesurfer_precomp_v6.0.0
30+
out_dir=${out_root_dir}/${ds_name}
31+
mkdir -p $out_dir
32+
chmod -R 777 $out_dir
33+
cd $out_dir
34+
35+
docker run --rm -ti \
36+
-v ${in_dir}:/data/in \
37+
-v ${fs_dir}:/data/fs \
38+
-v ${out_dir}:/data/out \
39+
bids/tracula:${tracula_version} \
40+
/data/in /data/out participant \
41+
--license_key xxx \
42+
--freesurfer_dir /data/fs
43+
44+
45+
docker run --rm -ti \
46+
-v ${in_dir}:/data/in \
47+
-v ${fs_dir}:/data/fs \
48+
-v ${out_dir}:/data/out \
49+
bids/tracula:${tracula_version} \
50+
/data/in /data/out group1 \
51+
--license_key xxx \
52+
--freesurfer_dir /data/fs
53+
54+
55+
56+
docker run --rm -ti \
57+
-v ${in_dir}:/data/in \
58+
-v ${fs_dir}:/data/fs \
59+
-v ${out_dir}:/data/out \
60+
bids/tracula:${tracula_version} \
61+
/data/in /data/out group2 \
62+
--license_key xxx \
63+
--freesurfer_dir /data/fs
64+
65+
tar -zcvf ${wd}/results_tracula_${tracula_version}_${ds_name}.tar.gz ${out_dir}
66+

0 commit comments

Comments
 (0)