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

Update to use labelmerge v0.4.3 #50

Merged
merged 8 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
7 changes: 7 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ jobs:
find: version = "(?:([0-9]+\.[0-9]+\.[0-9]+.+)|([0-9]+\.[0-9]+\.[0-9]+))"
replace: version = "${{ env.NEW_RELEASE }}"

- name: Update container version
uses: jacobtomlinson/gha-find-replace@master
with:
include: scattr/config/snakebids.yml
find: 'scattr: "docker://khanlab/scattr:v(?:([0-9]+\.[0-9]+\.[0-9]+.+)|([0-9]+\.[0-9]+\.[0-9]+))"'
replace: 'scattr: "docker://khanlab/scattr:v${{ env.NEW_RELEASE }}"'

- name: Commit updates
env:
LATEST_VERSION: ${{ env.NEW_RELEASE }}
Expand Down
17 changes: 3 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,6 @@ RUN wget https://github.com/ANTsX/ANTs/releases/download/v${ANTS_VER}/ants-${ANT
&& mv /opt/ants-${ANTS_VER} /opt/ants \
&& rm ants.zip

# Stage: FSL
# Copy over fslmaths to "minify"
FROM requirements as fsl
RUN wget https://fsl.fmrib.ox.ac.uk/fsldownloads/fslconda/releases/fslinstaller.py \
&& python fslinstaller.py -d /opt/fsl \
&& rm fslinstaller.py

# Stage: build
FROM requirements AS build
COPY . /opt/scattr/
Expand All @@ -69,7 +62,7 @@ RUN cd /opt/scattr \

# Stage: runtime
# NOTE: use fsl stage for library dependencies
tkkuehn marked this conversation as resolved.
Show resolved Hide resolved
FROM fsl AS runtime
FROM requirements AS runtime
COPY --from=mrtrix /opt/mrtrix3 /opt/mrtrix3
COPY --from=freesurfer /usr/local/freesurfer /usr/local/freesurfer
COPY --from=ants /opt/ants/bin/antsApplyTransforms /opt/ants/bin/antsRegistration /opt/ants/bin/antsRegistrationSyNQuick.sh /opt/ants/bin/
Expand All @@ -81,8 +74,8 @@ RUN WHEEL=`ls /opt/scattr | grep whl` \
&& apt-get --purge -y -qq autoremove
# Setup environments
ENV OS=Linux \
# Path: mrtrix > freesurfer > ants > fsl
PATH=/opt/mrtrix3/bin:/usr/local/freesurfer/bin:/usr/local/freesurfer/fsfast/bin:/usr/local/freesurfer/tktools:/usr/local/freesurfer/mni/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/ants/:/opt/ants/bin:/opt/fsl/bin:$PATH \
# Path: mrtrix > freesurfer > ants
PATH=/opt/mrtrix3/bin:/usr/local/freesurfer/bin:/usr/local/freesurfer/fsfast/bin:/usr/local/freesurfer/tktools:/usr/local/freesurfer/mni/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/ants/:/opt/ants/bin:$PATH \
# freesurfer specific
FREESURFER_HOME=/usr/local/freesurfer \
FREESURFER=/usr/local/freesurfer \
Expand All @@ -102,8 +95,4 @@ ENV OS=Linux \
PERL5LIB=/usr/local/freesurfer/mni/share/perl5 \
# ants specific
ANTSPATH=/opt/ants/bin/ \
# fsl specific
FSLDIR=/opt/fsl \
LD_LIBRARY_PATH=/opt/fsl/lib:$LD_LIBRARY_PATH \
FSLOUTPUTTYPE=NIFTI_GZ
ENTRYPOINT ["scattr"]
6 changes: 3 additions & 3 deletions scattr/config/snakebids.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,14 @@ parse_args:
Space: MNI152NLin6Asym

zona_bb_subcortex:
tsv: 'resources/zona_bb_subcortex/desc-ZonaBBSubcor_dseg.tsv'
tsv: 'resources/zona_bb_subcortex/desc-ZonaBB_dseg.tsv'
MNI152NLin6Asym:
dir: 'resources/zona_bb_subcortex/MNI152NLin6Asym/'
T1w: 'tpl-MNI152NLin6Asym_res-04_desc-brain_T1w.nii.gz'
seg: 'sub-SNSX32NLin2020Asym_space-MNI152NLin6Asym_desc-ZonaBBSubcor_dseg.nii.gz'
seg: 'sub-SNSX32NLin2020Asym_space-MNI152NLin6Asym_desc-ZonaBB_dseg.nii.gz'
MNI152NLin2009bAsym:
dir: 'resources/zona_bb_subcortex/MNI152NLin2009bAsym/'
seg: 'sub-SNSX32NLin2020Asym_space-MNI152NLin2009bAsym_desc-ZonaBBSubcor_dseg.nii.gz'
seg: 'sub-SNSX32NLin2020Asym_space-MNI152NLin2009bAsym_desc-ZonaBB_dseg.nii.gz'

# NOTE: This may not be needed with labelmerge
freesurfer:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ index name
12 Right GPe
13 Left GPi
14 Right GPi
15 Left Hippocampus
16 Right Hippocampus
17 Left NAc
18 Right NAc
19 Left Amygdala
20 Right Amygdala
21 Left ZI
22 Right ZI
15 Left Thalamus
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think 15 and 16 here should be separated by tabs and aren't

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, consequence of vscode. Will fix this.

16 Right Thalamus
17 Left Hippocampus
18 Right Hippocampus
19 Left NAc
20 Right NAc
21 Left Amygdala
22 Right Amygdala
23 Left ZI
24 Right ZI
55 changes: 4 additions & 51 deletions scattr/workflow/rules/zona_bb_subcortex.smk
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ rule cp_zona_tsv:
/ Path(config["zona_bb_subcortex"]["tsv"])
),
output:
zona_tsv=f"{zona_dir}/desc-ZonaBBSubcor_dseg.tsv",
zona_tsv=f"{zona_dir}/desc-ZonaBB_dseg.tsv",
threads: 1
resources:
mem_mb=4000,
Expand Down Expand Up @@ -121,57 +121,10 @@ rule warp2native:
"-o {output.nii} &> {log}"


rule rm_bb_thal:
"""Removes thalamus from existing parcellation

1. Grab labels following thalamus ROI
2. Remove existing thalamus from segmentation
3. Add labels following thalamus ROI back to segmentation
"""
input:
seg=rules.warp2native.output.nii,
output:
seg=bids_anat(
space="T1w",
desc="ZonaBBSubcor",
suffix="dseg.nii.gz",
),
non_thal=temp(
bids_anat(
space="T1w",
desc="NonThal",
suffix="dseg.nii.gz",
)
),
rm_seg=temp(
bids_anat(
space="T1w",
desc="ThalPost",
suffix="dseg.nii.gz",
)
),
threads: 4
resources:
mem_mb=16000,
time=10,
log:
f"{config['output_dir']}/logs/zona_bb_subcortex/sub-{{subject}}/rm_bb_thal.log",
group:
"subcortical_1"
container:
config["singularity"]["neuroglia-core"]
shell:
"fslmaths {input.seg} -sub 2 {output.non_thal} &> {log} && "
"fslmaths {output.non_thal} -thr 15 {output.non_thal} >> {log} 2>&1 && "
"fslmaths {input.seg} -thr 15 {output.rm_seg} >> {log} 2>&1 && "
"fslmaths {input.seg} -sub {output.rm_seg} {output.seg} >> {log} 2>&1 && "
"fslmaths {output.seg} -add {output.non_thal} {output.seg} >> {log} 2>&1"


rule labelmerge:
input:
zona_seg=expand(
rules.rm_bb_thal.output.seg,
rules.warp2native.output.nii,
subject=config["input_lists"]["T1w"]["subject"],
allow_missing=True,
),
Expand All @@ -185,7 +138,7 @@ rule labelmerge:
params:
zona_dir=zona_dir,
fs_dir=rules.thalamic_segmentation.input.freesurfer_dir,
zona_desc="ZonaBBSubcor",
zona_desc="ZonaBB",
fs_desc="FreesurferThal",
labelmerge_dir=directory(labelmerge_dir),
output:
Expand Down Expand Up @@ -218,7 +171,7 @@ rule labelmerge:
container:
config["singularity"]["labelmerge"]
shell:
"labelmerge {params.zona_dir} {params.labelmerge_dir} participant --base_desc {params.zona_desc} --overlay_bids_dir {params.fs_dir} --overlay_desc {params.fs_desc} --cores {threads} --force-output"
"labelmerge {params.zona_dir} {params.labelmerge_dir} participant --base_desc {params.zona_desc} --overlay_bids_dir {params.fs_dir} --overlay_desc {params.fs_desc} --base_drop 15 16 --cores {threads} --force-output"


rule get_num_nodes:
Expand Down