Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No matlab #64

Merged
merged 36 commits into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
539379a
initial work on converting relevant matlab code. Keeping in a separat…
jordandekraker Mar 29, 2021
a0c1181
added functionality top leave labels unchanged
jordandekraker Apr 20, 2021
677b9e8
integrate into snakemake workflow, various fixes
akhanf May 19, 2021
6561674
Merge branch 'master' into nomatlab
akhanf May 19, 2021
413c71e
fix for inputseg, removed extraneous rules
akhanf May 19, 2021
ef6298f
bugfixes to get laplace running
akhanf May 20, 2021
43933e1
WIP create warps
akhanf May 20, 2021
4728b09
fixed accidental line deletion
akhanf May 20, 2021
3f76e01
Update Dockerfile
akhanf May 21, 2021
ab09a1e
some more progress, still WIP
akhanf May 20, 2021
fff697e
should be functional now, with warp extrapolation missing
akhanf May 20, 2021
710c020
resources all in one place. can soon remove hippunfold/hippocampal_au…
jordandekraker May 21, 2021
ddb24b7
renamed shapeinject files
akhanf May 22, 2021
70decf2
shape inject, laplace, and more refactoring
akhanf May 22, 2021
4b9eae9
fix typo in config
akhanf May 22, 2021
3d6f259
updated container
akhanf May 22, 2021
97ca6a8
updated to use autotop container wherever possible
akhanf May 22, 2021
c833006
removed hippocampal_autotop submodule
akhanf May 22, 2021
d03ab8f
bugfixes to get running, disabled midsurf vis
akhanf May 22, 2021
951ee82
laplace with init, new heuristic for PD sink
akhanf May 24, 2021
a9cac9a
reverted back to old coords
akhanf May 25, 2021
a38599d
revert to not use new PD sink
akhanf May 25, 2021
c08827a
removed earlier files no longer used
akhanf May 25, 2021
565db7d
revert new pd sink in config files
akhanf May 25, 2021
03a4380
fix when reverting to old template coords
akhanf May 25, 2021
f973340
added fix for missing shapeinject labels (require re-install)
akhanf May 25, 2021
b36c182
fix bug in inputfunction for template_shape_reg
akhanf May 27, 2021
1984606
add astropy dependency
akhanf May 27, 2021
804a5a0
reduced memory usage estimate
akhanf May 27, 2021
6a91856
actual for for template_shape_ref input function
akhanf May 27, 2021
9ac5ce3
cleaned up a few stray voxels, will hopefully help avoid SRLM holes
jordandekraker May 27, 2021
92177b9
archive work by default, moved qc to results
akhanf May 27, 2021
468a2d0
updated max iters and added time to laplace
akhanf May 27, 2021
8b3bbd7
added --skip_inject_template_labels option (#71)
akhanf May 27, 2021
6560862
Delete template_shape_inject.sh
akhanf May 28, 2021
5aa9d34
Update MANIFEST.in
akhanf May 28, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "hippunfold/hippocampal_autotop"]
path = hippunfold/hippocampal_autotop
url = http://github.com/jordandekraker/hippocampal_autotop
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM khanlab/autotop_deps:v0.3.1
FROM khanlab/autotop_deps:v0.4.0

MAINTAINER [email protected]

Expand Down
5 changes: 0 additions & 5 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
recursive-include hippunfold/resources *
recursive-include hippunfold/config *
recursive-include hippunfold/workflow *
recursive-include hippunfold/hippocampal_autotop/tools *
recursive-include hippunfold/hippocampal_autotop/mcr_v97 *
recursive-include hippunfold/hippocampal_autotop/misc *
recursive-include hippunfold/hippocampal_autotop/atlases *
recursive-include hippunfold/hippocampal_autotop/CNNmodels *
75 changes: 68 additions & 7 deletions hippunfold/config/snakebids.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ parse_args:
default: False
action: 'store_true'

--skip_inject_template_labels:
help: 'Set this flag to skip post-processing template injection into CNN segmentation (default: %(default)s)'
default: False
action: 'store_true'



--rigid_reg_template:
help: 'Use rigid instead of affine for registration to template. Try this if your images are reduced FOV (default: %(default)s)'
default: False
Expand All @@ -180,8 +187,8 @@ parse_args:
help: 'Sets the output space for results (default: %(default)s)'


--archive_work:
help: 'Archive work folder for each subject after completion, saving space/files (default: %(default)s)'
--keep_work:
help: 'Keep work folder intact instead of archiving it for each subject (default: %(default)s)'
default: False
action: 'store_true'

Expand All @@ -190,7 +197,7 @@ parse_args:

singularity:
prepdwi: 'docker://khanlab/prepdwi:latest'
autotop: 'docker://khanlab/autotop_deps:v0.2'
autotop: 'docker://khanlab/autotop_deps:v0.4.0'
fsl: '/project/6050199/akhanf/singularity/bids-apps/fsl_6.0.3_cuda9.1.sif' #fsl with cuda container not on docker hub yet.. only used for dwi workflow anyhow..
ants: 'docker://kaczmarj/ants:2.3.4'

Expand All @@ -200,9 +207,9 @@ template: CITI168

template_files:
CITI168:
T1w: hippocampal_autotop/atlases/CITI/CIT168_T1w_head_700um.nii.gz
xfm_corobl: hippocampal_autotop/atlases/CITI/CoronalOblique_rigid.txt
crop_ref: hippocampal_autotop/atlases/CITI/img_300umCoronalOblique_hemi-{hemi}.nii.gz
T1w: resources/CITI168/T1w_head_700um.nii.gz
xfm_corobl: resources/CITI168/CoronalOblique_rigid.txt
crop_ref: resources/CITI168/T2w_300umCoronalOblique_hemi-{hemi}.nii.gz


rigid_reg_template: False
Expand Down Expand Up @@ -244,6 +251,60 @@ hippdwi_opts:
L: '224 351'
bbox_y: '198 453'

unfold_vol_ref:
dims:
- '256'
- '128'
- '16'
voxdims:
- '0.15625'
- '0.15625'
- '0.15625'
origin:
- '0'
- '200'
- '0'
orient: RPI

shape_inject:
labels_reg:
- 1
- 2
- 3
- 4
- 5
- 6
labels_reinsert:
- 7
label_smoothing_stdev: '0.5x0.5x0.5mm'

laplace_labels:
AP:
gm:
- 1
- 8
src:
- 5
sink:
- 6
PD:
gm:
- 1
- 8
src:
- 3
sink:
- 8
IO:
gm:
- 1
- 8
src:
- 2
- 4
- 7
sink:
- 0

#---- dwi options below, not used in the default workflow ----

Expand Down Expand Up @@ -275,4 +336,4 @@ masking:
#'0015': 'bet_from-b0_frac-4'
'0015': 'b0SyN_from-MNI152NLin2009cSym'


archive_work: False
1 change: 0 additions & 1 deletion hippunfold/hippocampal_autotop
Submodule hippocampal_autotop deleted from 79f0d5
5 changes: 5 additions & 0 deletions hippunfold/resources/CITI168/CoronalOblique_rigid.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Insight Transform File V1.0
#Transform 0
Transform: MatrixOffsetTransformBase_double_3_3
Parameters: 1 0 0 0 0.809017 -0.587785 0 0.587785 0.809017 -6.10623e-16 4.36795 -9.04318
FixedParameters: 0 0 0
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions hippunfold/resources/tpl-upenn/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.snakemake
80 changes: 80 additions & 0 deletions hippunfold/resources/tpl-upenn/Snakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
configfile: '../../config/snakebids.yml'

wildcard_constraints:
i = '[0-9]+'



rule all:
input: expand('tpl-upenn_dir-{dir}_level-0_coords.nii.gz', dir=['AP','PD','IO'])

rule create_PD_sink:
""" this rule is still a WIP and shouldn't be used.. """
input:
lbl = 'tpl-upenn_desc-hipptissue_dseg.nii.gz',
output:
lbl = 'tpl-upenn_desc-withPDsink_level-0_dseg.nii.gz',
container: config['singularity']['autotop']
shell:
# dilate DG into the SRLM (lbl 2/4/7) and background (lbl 0) to get a PD sink that is outside the laplace domain
# create a new label for each region dilated into, so the AP/IO src/sink are unaffected
# we can do this easily by just adding 10 to the existing labels (0 -> 10, 2 -> 12, 4->14, 7->17
'c3d {input} -retain-labels 8 -dilate 8 1x1x1vox -binarize -popas DILATED_DG '
' {input} -replace 0 10 -retain-labels 2 4 7 10 -binarize -push DILATED_DG -multiply -as DG_SINK '
' -scale 10 {input} -add -o {output}' # add 10 to original labels, and save it

rule downsample_coords:
input:
lbl = lambda wildcards: 'tpl-upenn_desc-withPDsink_level-{i}_dseg.nii.gz'.format(i=int(wildcards.i)-1)
output:
lbl = 'tpl-upenn_desc-withPDsink_level-{i}_dseg.nii.gz',
shell:
'c3d {input} -interpolation NearestNeighbor -resample 50% {output}'


# run laplace coords without initialization only for lowest resolution
# this is done by setting constraint on output i (i.e. {i,2})
rule laplace_coords:
input:
lbl = 'tpl-upenn_desc-withPDsink_level-{i}_dseg.nii.gz',
params:
gm_labels = lambda wildcards: config['laplace_labels'][wildcards.dir]['gm'],
src_labels = lambda wildcards: config['laplace_labels'][wildcards.dir]['src'],
sink_labels = lambda wildcards: config['laplace_labels'][wildcards.dir]['sink'],
convergence_threshold = 1e-6,
max_iters = 100000
output:
coords = 'tpl-upenn_dir-{dir}_level-{i,2}_coords.nii.gz'
resources:
time = 1200
log: 'log_dir-{dir}_level-{i}_laplace.txt'
script: '../../workflow/scripts/laplace_coords.py'


rule laplace_init_lores:
input:
lbl = 'tpl-upenn_desc-withPDsink_level-{i}_dseg.nii.gz',
init_coords = 'tpl-upenn_dir-{dir}_level-{i}_desc-upsampled_coords.nii.gz'
params:
gm_labels = lambda wildcards: config['laplace_labels'][wildcards.dir]['gm'],
src_labels = lambda wildcards: config['laplace_labels'][wildcards.dir]['src'],
sink_labels = lambda wildcards: config['laplace_labels'][wildcards.dir]['sink'],
convergence_threshold = 1e-8,
max_iters = 100000
output:
coords = 'tpl-upenn_dir-{dir}_level-{i,0|1}_coords.nii.gz'
resources:
time = 1200
log: 'log_dir-{dir}_level-{i}_laplace.txt'
script: '../../workflow/scripts/laplace_coords_withinit.py'


rule upsample_coords:
input:
coords = lambda wildcards: 'tpl-upenn_dir-{dir}_level-{i}_coords.nii.gz'.format(dir=wildcards.dir, i=int(wildcards.i)+1)
output:
coords = 'tpl-upenn_dir-{dir}_level-{i}_desc-upsampled_coords.nii.gz'
shell:
'c3d {input} -interpolation NearestNeighbor -resample 200% {output}'


Binary file added hippunfold/resources/tpl-upenn/dag.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Large diffs are not rendered by default.

Loading