Diff of /docs/pipeline/pipeline.md [000000] .. [d15511]

Switch to unified view

a b/docs/pipeline/pipeline.md
1
# Pipeline Details
2
3
4
This section describes the HippUnfold workflow, that is, 
5
the steps taken to produce the intermediate and final files.
6
HippUnfold is a Snakemake workflow, and thus the workflow is a 
7
 directed acyclic graph (DAG) that is automatically configured based
8
on a set of rules. 
9
10
## Overall workflow
11
12
Below is a example *simplified* visualization of the workflow DAG
13
for the `--modality T1w` workflow.  Each rounded rectangle in the DAG 
14
represents a *rule*, that is, some code or script that produces 
15
output file(s), and the arrows represent file inputs and outputs to these 
16
rules.  It is *simplified* in that multiple 
17
instances of each rule are not shown, e.g. the `run_inference` rule 
18
runs on both left and right hemispheres (`hemi=L`, `hemi=R`),
19
but only one `run_inference` box is shown here.  
20
21
<img src="../../hippunfold/dags/out_rulegraph/T1w.png" width="800px">
22
23
Although it may still look very complex (click on the image to 
24
enlarge), it is also  organized into groups of rules, 
25
each representing the main phases of the workflow. Each
26
grouped set of rules also exist in separate rule files,
27
 which can be found in
28
 the [rules sub-folder](http://github.com/khanlab/hippunfold/tree/master/hippunfold/workflow/rules)  
29
in the workflow source. For example, the [preproc_t1](http://github.com/khanlab/hippunfold/tree/master/hippunfold/workflow/rules/preproc_t1.smk)  file contains the rules related to pre-processing the T1w images, and these are 
30
grouped together in the above diagram by a blue rectangle labelled `preproc_t1`. 
31
32
33
The main phases of the workflow are described in the sections below, zooming in
34
on the rules used in each blue rectangle, one at a time.
35
36
37
## Pre-processing
38
39
The pre-processing workflow for HippUnfold is generated based on the input data (e.g. whether 
40
there are multiple T2w images or a single T2w image), what modality is used
41
 (e.g. `--modality T1w` or `--modality T2w`), and what optional arguments are
42
 specified (e.g. `--t1-reg-template`). 
43
44
### T1w pre-processing
45
46
T1w images are imported, intensity-corrected using N4, and linearly registered 
47
to the template image (default: CITI168 - an HCP T1w template). An existing transformation to 
48
align the images in a coronal oblique (`space-corobl`) orientation is concatenated, and 
49
this space is used to define the left and right hippocampus bounding boxes in 0.3mm isotropic space. The left 
50
hippocampus subvolume is left-right flipped at this stage too (subsequent steps in the `corobl` space operate
51
on both the `hemi-R` and `hemi-Lflip` images).
52
53
![T1w workflow preproc t1](../../hippunfold/dags/out_dag/T1w.preproc_t1.png)
54
55
56
### T2w pre-processing
57
58
T2w images are processed similarly, except the T2w version of the template is used. If multiple T2w images
59
exist, these are motion-corrected and averaged prior to N4 correction. The diagram below shows the T2w pre-
60
processing workflow for a dataset with three T2w runs.
61
62
![T2w multi preproc_t2](../../hippunfold/dags/out_dag/T2w_multi.preproc_t2.png)
63
64
### T2w with T1w template registration
65
66
For T2w images where template registration is failing (e.g. because the T2w images have a limited FOV),
67
the `--t1-reg-template` option can be used, and will perform template registration with the T1w images, along with 
68
a within-subject registration of the T2w to the T1w, concatenating all the transforms. This is shown in the diagrams below (with a single T2w image in this case):
69
70
![T2w t1-reg-template preproc_t1](../../hippunfold/dags/out_dag/T2w_t1-reg-template.preproc_t1.png)
71
72
![T2w t1-reg-template preproc_t2](../../hippunfold/dags/out_dag/T2w_t1-reg-template.preproc_t2.png)
73
74
Note that these are not the only workflow configurations possible, several other variants exist by using the command-line flags. For example, if you have T1w and T2w images that are already pre-processed and co-registered (e.g. HCP processed data), then you should use the `--skip-preproc` and `--skip-coreg` options to skip N4 and T1w/T2w co-registration.
75
76
## U-net segmentation
77
78
The U-net segmentation is performed on the cropped, `space-corobl` images, producing tissue segmentations (gray matter, SRLM, and anatomical landmarks for unfolding). This step is done in a single rule, which runs inference on the image using the corresponding
79
nnU-net model based on the `modality` chosen. This is done on the `R` and `Lflip` hippocampus images, and the `Lflip` is subsequently unflipped. 
80
81
![U-net workflow](../../hippunfold/dags/out_dag/T1w.nnunet.png)
82
83
84
## Template-based shape injection
85
86
Since the nnU-net segmentation may possibly contain topological errors that can cause issues when the Laplace-based coordinates, we perform an additional registration-based correction step, a shape injection, where we perform non-linear registration of a template hippocampus segmentation and the U-net segmentation, to warp the template shape. Regularization from the registration ensures topology from the template is preserved while it is warped to match the subject hippocampus. In addition to the segmentation, we also propagate Laplace coordinates to serve as an initialization to the next step.
87
88
The following diagram shows the workflow, but simplified to contain one hemisphere (`--hemi R`), and excluding the dentate gyrus.
89
90
![Shape injection](../../hippunfold/dags/out_dag/T1w_hemi-R_hipponly.shape_inject.png)
91
92
93
## Laplace & equivolume coordinates
94
95
The basis of the hippocampal unfolding is the definition of the Laplace coordinates. Here, Laplace's equation is solved on the domain of the gray matter, using the anatomical landmarks to define boundary conditions. This provides the intrinsic set of anatomical coordinates (AP, PD, IO) for unfolding the hippocampus. For the IO (laminar) coordinates we make use of the equivolume solution instead of Laplace.
96
97
The following diagram shows the workflow, but simplified to contain one hemisphere (`--hemi R`), and excluding the dentate gyrus.
98
99
![Laplace coordinates](../../hippunfold/dags/out_dag/T1w_hemi-R_hipponly.autotop.png)
100
101
## Subfields processing
102
103
The volumetric subfield segmentation is derived from the coord images from the last step, along with the atlas that defines how the coordinates map to subfields. 
104
105
The following diagram shows the workflow, but simplified to contain one hemisphere (`--hemi R`), and excluding the dentate gyrus.
106
107
![Subfields](../../hippunfold/dags/out_dag/T1w_hemi-R_hipponly.subfields.png)
108
109
110
## Generating warp files
111
112
To allow users to transform data between the different spaces, we generate warp files that can be applied to transform volumes of surfaces to and from the native and unfolded spaces.
113
114
The following diagram shows the workflow, but simplified to contain one hemisphere (`--hemi R`), and excluding the dentate gyrus.
115
116
![Generating warps](../../hippunfold/dags/out_dag/T1w_hemi-R_hipponly.warps.png)
117
118
## Surface processing
119
120
Using the warps, we transform standard template unfolded meshes to each subject hippocampus, in order to obtain surface meshes in the native space. These are stored in GIFTI format, and we also produce metric files to quantify surface morphometry (thickness, gyrification, curvature).  
121
122
The following diagram shows the workflow, but simplified to contain one hemisphere (`--hemi R`), and excluding the dentate gyrus.
123
124
![Surface processing](../../hippunfold/dags/out_dag/T1w_hemi-R_hipponly.gifti.png)
125
126
127
## Additional steps
128
129
Resampling to output resolution, quality control snapshot generation, and archiving the work folder are steps 
130
that are also carried out by the workflow, but the DAGs are now shown here because of the many inputs/outputs, and 
131
generally have straightforward workflow structures.
132
133
134
135
136