template building for cam-can dataset

public public 1yr ago 0 bookmarks

Workflow to build cohort templates based on multiple participants_tsv files

This workflow uses greedy instead of ANTS, for the sake of efficiency, in fact, the registrations as compared to ants_build_template seem to be more accurate

Code Snippets

12
13
shell:
    'AverageImages {params.dim} {output} {params.use_n4} {input} &> {log}'
20
shell: 'cp -v {input} {output} &> {log}'
36
shell: '{params.cmd} &> {log}'
80
81
shell:
    'AverageImages {params.dim} {output} {params.use_n4} {input} &> {log}'
94
95
shell:
    'AverageImages {params.dim} {output} {params.use_n4} {input} &> {log}'
106
107
shell:
    'MultiplyImages {params.dim} {input} {params.gradient_step} {output} &> {log}' 
119
120
shell:
    'AverageAffineTransformNoRigid {params.dim} {output} {input} &> {log}'
134
135
shell:
    'antsApplyTransforms {params.dim} -e vector -i {input.invwarp} -o {output} -t [{input.affine},1] -r {input.ref} --verbose 1 &> {log}'
149
150
shell:
    'antsApplyTransforms {params.dim} --float 1 --verbose 1 -i {input.template} -o {output.template} -t [{input.affine},1] '
64
65
66
67
shell: 'greedy -d 3 -rf {input.ref_std} '
      ' -r {input.cohort2std_warp} {input.cohort2std_affine_xfm_ras} '
      '  {input.subj2cohort_warp} {input.subj2cohort_affine_xfm_ras} '
      ' -rc {output.subj2std_warp}'
 99
100
101
102
103
104
shell: 'greedy -d 3 -rf {input.ref_subj} -r '
      ' {input.subj2cohort_affine_xfm_ras},-1 '
      ' {input.subj2cohort_invwarp}'
      ' {input.cohort2std_affine_xfm_ras},-1 '
      ' {input.cohort2std_invwarp} '
      ' -rc {output.subj2std_invwarp}'
10
11
shell:
    'reg_aladin -rigOnly -flo {input.flo} -ref {input.ref} -res {output.warped} -aff {output.xfm_ras}'
24
25
26
27
    shell:
        'greedy -d 3 -threads {threads} -a -dof 6 -m NMI -i {input.ref} {input.flo} -o {output.xfm_ras} -ia-image-centers -n 100x50x10 && '
        'greedy -d 3 -threads {threads} -rf {input.ref} -rm {input.flo} {output.warped} -r {output.xfm_ras}'
""" 
39
40
41
shell:
    'ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS={threads} '
    'N4BiasFieldCorrection -d 3 -i {input.img} -x {input.mask} -o {output}'
52
53
shell:
    'fslmaths {input.img} -mas {input.mask} {output.img}'
63
64
shell:
    'fslmaths {input.img} -mas {input.mask} {output.img}'
7
shell: 'cp {input} {output}'
17
shell: 'fslmaths {input} -bin {output}'
29
script: '../scripts/create_template_description_json.py'
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import nibabel as nib
import numpy as np
import json


img = nib.load(snakemake.input[0])


hdr = img.header
shape = np.array(hdr.get_data_shape()).astype('float').tolist()
zooms = np.array(hdr.get_zooms()).astype('float').tolist()

affine = img.affine
origin = affine @ np.array([0,0,0,1]).T
origin = origin[0:3].astype('float').tolist()

template_dict = dict()

#add extras from config file
template_dict.update(snakemake.config['template_description_extras'])

#add shape, zooms, origin, for the resolution
template_dict.update( { 'res':  {'{res:02d}'.format(res=snakemake.config['resolution_index']) : { 'origin': origin, 'shape': shape, 'zooms': zooms } } } )

#add cohorts to json, with full list of subjects for each cohort..
cohort_dict = dict()
for cohort in snakemake.params.cohorts:
    cohort_dict[cohort] = { 'participants': snakemake.params.subjects[cohort] } 

template_dict.update( { 'cohort': cohort_dict } )


with open(snakemake.output[0],'w') as outfile:
    json.dump(template_dict,outfile,indent=2)
ShowHide 18 more snippets with no or duplicated tags.

Login to post a comment if you would like to share your experience with this workflow.

Do you know this workflow well? If so, you can request seller status , and start supporting this workflow.

Free

Created: 1yr ago
Updated: 1yr ago
Maitainers: public
URL: https://github.com/akhanf/greedy_template_camcan
Name: greedy_template_camcan
Version: 1
Badge:
workflow icon

Insert copied code into your website to add a link to this workflow.

Downloaded: 0
Copyright: Public Domain
License: MIT License
  • Future updates

Related Workflows

cellranger-snakemake-gke
snakemake workflow to run cellranger on a given bucket using gke.
A Snakemake workflow for running cellranger on a given bucket using Google Kubernetes Engine. The usage of this workflow ...