1- rule tckgen :
2- """
3- Tournier, J.-D.; Calamante, F. & Connelly, A. Improved probabilistic
4- streamlines tractography by 2nd order integration over fibre orientation
5- distributions. Proceedings of the International Society for Magnetic
6- Resonance in Medicine, 2010, 1670
7- """
1+ rule tckgen_chunk :
82 input :
93 fod = rules .mtnormalise .output .wm_fod ,
104 mask = rules .nii2mif .output .mask ,
115 convex_hull = rules .create_convex_hull .output .convex_hull ,
126 subcortical_seg = rules .get_num_nodes .input .seg ,
7+ output :
8+ tck = temp (bids_tractography_out (
9+ desc = "iFOD2" ,
10+ suffix = "tractography_{chunk}.tck" ,
11+ )),
1312 params :
1413 step = config ["step" ],
15- sl = config ["sl_count" ],
16- output :
17- tck = bids_tractography_out (
14+ chunk_size = int (config ["sl_count" ]) // config ["num_chunks" ],
15+ seed_offset = lambda wildcards : int (wildcards .chunk ) * 10000 ,
16+ tmp_dir = lambda wildcards : bids_tractography_out (
17+ root = os .environ .get ("SLURM_TMPDIR" ) if config .get ("slurm_tmpdir" ) else "/tmp" ,
1818 desc = "iFOD2" ,
19- suffix = "tractography.tck" ,
19+ suffix = f"tractography_{ wildcards .chunk } .tck" ,
20+ subject = wildcards .subject
2021 ),
21- threads : 32
22+ threads : 12
2223 resources :
23- tmp_dir = lambda wildcards : bids_tractography_out (
24- root = os .environ .get ("SLURM_TMPDIR" )
25- if config .get ("slurm_tmpdir" )
26- else "/tmp" ,
27- ** wildcards ,
24+ mem_mb = 32000 ,
25+ time = 60 * 3 ,
26+ log :
27+ bids_log (suffix = "tckgen_chunk_{chunk}.log" ),
28+ container :
29+ config ["singularity" ]["scattr" ]
30+ shell :
31+ """
32+ mkdir -p {params.tmp_dir}
33+
34+ MRTRIX_RNG_SEED={params.seed_offset} \\
35+ tckgen -nthreads {threads} -algorithm iFOD2 -step {params.step} \\
36+ -select {params.chunk_size} \\
37+ -seed_image {input.mask} \\
38+ -include {input.subcortical_seg} -exclude {input.convex_hull} \\
39+ -mask {input.mask} \\
40+ {input.fod} {output.tck} &> {log}
41+ """
42+
43+ rule tck_concat :
44+ input :
45+ tcks = lambda wildcards : expand (
46+ bids_tractography_out (
47+ desc = "iFOD2" ,
48+ suffix = "tractography_{chunk}.tck" ,
49+ subject = wildcards .subject ,
50+ ),
51+ chunk = range (config ["num_chunks" ])
2852 ),
29- tmp_tck = lambda wildcards : bids_tractography_out (
30- root = os .environ .get ("SLURM_TMPDIR" )
31- if config .get ("slurm_tmpdir" )
32- else "/tmp" ,
53+ output :
54+ tck = bids_tractography_out (
3355 desc = "iFOD2" ,
3456 suffix = "tractography.tck" ,
35- ** wildcards ,
57+ subject = "{subject}" ,
3658 ),
37- mem_mb = 128000 ,
38- time = 60 * 24 ,
3959 log :
40- bids_log (suffix = "tckgen .log" ),
60+ bids_log (suffix = "tck_concat .log" ),
4161 container :
4262 config ["singularity" ]["scattr" ]
4363 shell :
4464 """
45- mkdir -p {resources.tmp_dir}
46-
47- tckgen -nthreads {threads} -algorithm iFOD2 -step {params.step} \\
48- -select {params.sl} -exclude {input.convex_hull} \\
49- -include {input.subcortical_seg} -mask {input.mask} \\
50- -seed_image {input.mask} {input.fod} {resources.tmp_tck} &> {log}
51-
52- rsync -v {resources.tmp_tck} {output.tck} >> {log} 2>&1
65+ tckedit {input.tcks} {output.tck} -force &> {log}
5366 """
5467
5568
@@ -60,7 +73,7 @@ rule tcksift2:
6073 connectome. NeuroImage, 2015, 104, 253-265
6174 """
6275 input :
63- tck = rules .tckgen .output .tck ,
76+ tck = rules .tck_concat .output .tck ,
6477 fod = rules .mtnormalise .output .wm_fod ,
6578 output :
6679 weights = bids_tractography_out (
@@ -82,10 +95,9 @@ rule tcksift2:
8295 {input.tck} {input.fod} {output.weights} &> {log}
8396 """
8497
85-
8698checkpoint create_roi_mask :
8799 input :
88- subcortical_seg = rules .tckgen .input .subcortical_seg ,
100+ subcortical_seg = rules .tckgen_chunk .input .subcortical_seg ,
89101 num_labels = rules .get_num_nodes .output .num_labels ,
90102 params :
91103 base_dir = mrtrix_dir ,
@@ -144,7 +156,7 @@ checkpoint create_exclude_mask:
144156 input :
145157 unpack (aggregate_rois ),
146158 rules .create_roi_mask .output .out_dir ,
147- subcortical_seg = rules .tckgen .input .subcortical_seg ,
159+ subcortical_seg = rules .tckgen_chunk .input .subcortical_seg ,
148160 num_labels = rules .get_num_nodes .output .num_labels ,
149161 params :
150162 base_dir = mrtrix_dir ,
@@ -167,8 +179,6 @@ checkpoint create_exclude_mask:
167179
168180
169181# TODO (v0.2): ADD OPTION TO OUTPUT TDI MAP
170-
171-
172182rule tck2connectome :
173183 """
174184 Smith, R. E.; Tournier, J.-D.; Calamante, F. & Connelly, A. The
@@ -179,21 +189,10 @@ rule tck2connectome:
179189 """
180190 input :
181191 weights = rules .tcksift2 .output .weights ,
182- tck = rules .tckgen .output .tck ,
183- subcortical_seg = rules .tckgen .input .subcortical_seg ,
192+ tck = rules .tck_concat .output .tck ,
193+ subcortical_seg = rules .tckgen_chunk .input .subcortical_seg ,
184194 params :
185195 radius = config ["radial_search" ],
186- output :
187- sl_assignment = bids_tractography_out (
188- desc = "subcortical" ,
189- suffix = "nodeAssignment.txt" ,
190- ),
191- node_weights = bids_tractography_out (
192- desc = "subcortical" ,
193- suffix = "nodeWeights.csv" ,
194- ),
195- threads : 32
196- resources :
197196 tmp_dir = lambda wildcards : bids_tractography_out (
198197 root = os .environ .get ("SLURM_TMPDIR" )
199198 if config .get ("slurm_tmpdir" )
@@ -216,6 +215,17 @@ rule tck2connectome:
216215 suffix = "nodeWeights.csv" ,
217216 ** wildcards ,
218217 ),
218+ output :
219+ sl_assignment = bids_tractography_out (
220+ desc = "subcortical" ,
221+ suffix = "nodeAssignment.txt" ,
222+ ),
223+ node_weights = bids_tractography_out (
224+ desc = "subcortical" ,
225+ suffix = "nodeWeights.csv" ,
226+ ),
227+ threads : 32
228+ resources :
219229 mem_mb = 128000 ,
220230 time = 60 * 3 ,
221231 log :
@@ -226,27 +236,26 @@ rule tck2connectome:
226236 config ["singularity" ]["scattr" ]
227237 shell :
228238 """
229- mkdir -p {resources .tmp_dir}
239+ mkdir -p {params .tmp_dir}
230240
231241 tck2connectome -nthreads {threads} -zero_diagonal -stat_edge sum \\
232242 -assignment_radial_search {params.radius} \\
233243 -tck_weights_in {input.weights} \\
234- -out_assignments {resources .tmp_sl_assignment} \\
244+ -out_assignments {params .tmp_sl_assignment} \\
235245 -symmetric {input.tck} {input.subcortical_seg} \\
236- {resources .tmp_node_weights} &> {log}
246+ {params .tmp_node_weights} &> {log}
237247
238- rsync {resources .tmp_sl_assignment} \\
248+ rsync {params .tmp_sl_assignment} \\
239249 {output.sl_assignment} >> {log} 2>&1
240250
241- rsync {resources .tmp_node_weights} {output.node_weights} >> {log} 2>&1
251+ rsync {params .tmp_node_weights} {output.node_weights} >> {log} 2>&1
242252 """
243253
244-
245254checkpoint connectome2tck :
246255 input :
247256 node_weights = rules .tcksift2 .output .weights ,
248257 sl_assignment = rules .tck2connectome .output .sl_assignment ,
249- tck = rules .tckgen .output .tck ,
258+ tck = rules .tck_concat .output .tck ,
250259 num_labels = rules .get_num_nodes .output .num_labels ,
251260 output :
252261 output_dir = directory (
@@ -258,15 +267,16 @@ checkpoint connectome2tck:
258267 ).parent
259268 )
260269 ),
261- threads : 32
262- resources :
270+ params :
263271 tmp_dir = lambda wildcards : bids_tractography_out (
264272 root = os .environ .get ("SLURM_TMPDIR" )
265273 if config .get ("slurm_tmpdir" )
266274 else "/tmp" ,
267275 datatype = "unfiltered" ,
268276 ** wildcards ,
269277 ),
278+ threads : 32
279+ resources :
270280 edge_weight_prefix = lambda wildcards : bids_tractography_out (
271281 root = os .environ .get ("SLURM_TMPDIR" )
272282 if config .get ("slurm_tmpdir" )
@@ -295,7 +305,7 @@ checkpoint connectome2tck:
295305 config ["singularity" ]["scattr" ]
296306 shell :
297307 """
298- mkdir -p {resources .tmp_dir} {output.output_dir}
308+ mkdir -p {params .tmp_dir} {output.output_dir}
299309
300310 num_labels=$(cat {input.num_labels})
301311
@@ -310,4 +320,4 @@ checkpoint connectome2tck:
310320 {output.output_dir}/ >> {log} 2>&1
311321 rsync {resources.edge_tck_prefix}*.tck \\
312322 {output.output_dir}/ >> {log} 2>&1
313- """
323+ """
0 commit comments