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

Merge in new changes to AntPost branch #330

Merged
merged 19 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/python-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
needs: ["quality"]
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9"]
python-version: ["3.8", "3.9"]

steps:
- name: Install non-python dependencies
Expand Down
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.4.4-fix
FROM khanlab/hippunfold_deps:v0.5.1

MAINTAINER [email protected]

Expand Down
4 changes: 4 additions & 0 deletions docs/contributing/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ from the `hippunfold` folder that contains the
cd hippunfold
snakemake -np

## Wet-run testing your workflow:

Opensource data has been made available for wet-run testing any changes to HippUnfold on OSF [here](https://osf.io/k2nme/). These are real opensource data meant ot span a wide array of HippUnfold use cases with various modalities, resolutions, developmental stages, and species. Please note that some changes to hippUnfold will impact all worflows and should be run and then visually inspected for all these cases. Other changes may impact only one workflow (e.g. adding a new template) and so the recommended run parameters should be adjusted accordingly.

## Instructions for Compute Canada

This section provides an example of how to set up a `pip installed` copy
Expand Down
12 changes: 8 additions & 4 deletions hippunfold/config/snakebids.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ parse_args:
--version:
help: 'Print the version of HippUnfold'
action: version
version: "1.5.0-pre.47"
version: "1.5.2-pre.2"


--modality:
Expand Down Expand Up @@ -384,21 +384,25 @@ template_based_segmentation:
hemi:
- R
- L
CIVM:
dHCP:
hemi:
- R
- L

MBMv2:
hemi:
- R
MBMv3:
hemi:
- R
ABAv3:
CIVM:
hemi:
- R
- L
dHCP:
upenn:
hemi:
- R
ABAv3:
hemi:
- R
- L
Expand Down
2 changes: 1 addition & 1 deletion hippunfold/pipeline_description.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"GeneratedBy": [
{
"Name": "hippunfold",
"Version": "1.5.0-pre.47",
"Version": "1.5.2-pre.2",
"CodeURL": "https://github.com/khanlab/hippunfold",
"Author": "Jordan DeKraker & Ali Khan",
"AuthorEmail": "[email protected]"
Expand Down
2 changes: 2 additions & 0 deletions hippunfold/workflow/rules/common.smk
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from appdirs import AppDirs

# take mean of all scans if >1, otherwise just copy the one scan
def get_avg_or_cp_scans_cmd(wildcards, input, output):
if len(input) > 1:
Expand Down
2 changes: 1 addition & 1 deletion hippunfold/workflow/rules/gifti.smk
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ rule normalize_curvature2:
space="{space}",
hemi="{hemi}",
desc="unnorm",
label="hipp",
label="{autotop}",
**config["subj_wildcards"]
),
output:
Expand Down
70 changes: 42 additions & 28 deletions hippunfold/workflow/rules/nnunet.smk
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
import re
from appdirs import AppDirs


def get_nnunet_input(wildcards):
if config["modality"] == "T2w":
nii = (
bids(
root=work,
datatype="anat",
**config["subj_wildcards"],
suffix="T2w.nii.gz",
space="corobl",
desc="preproc",
hemi="{hemi}",
),
)
T1w_nii = bids(
root=work,
datatype="anat",
**config["subj_wildcards"],
suffix="T1w.nii.gz",
space="corobl",
desc="preproc",
hemi="{hemi}",
)
T2w_nii = bids(
root=work,
datatype="anat",
**config["subj_wildcards"],
suffix="T2w.nii.gz",
space="corobl",
desc="preproc",
hemi="{hemi}",
)
if (config["modality"] == "T1w" or config["modality"] == "T2w") and config[
"force_nnunet_model"
] == "T1T2w":
return (T1w_nii, T2w_nii)

elif config["modality"] == "T2w":
return T2w_nii
elif config["modality"] == "T1w":
nii = (
bids(
root=work,
datatype="anat",
**config["subj_wildcards"],
suffix="T1w.nii.gz",
space="corobl",
desc="preproc",
hemi="{hemi}",
),
)
return T1w_nii
elif config["modality"] == "hippb500":
nii = bids(
return bids(
root=work,
datatype="dwi",
hemi="{hemi}",
Expand All @@ -38,7 +40,6 @@ def get_nnunet_input(wildcards):
)
else:
raise ValueError("modality not supported for nnunet!")
return nii


def get_model_tar():
Expand Down Expand Up @@ -95,14 +96,27 @@ def parse_trainer_from_tar(wildcards, input):
return trainer


def get_cmd_copy_inputs(wildcards, input):
in_img = input.in_img
if isinstance(in_img, str):
# we have one input image
return f"cp {in_img} tempimg/temp_0000.nii.gz"
else:
cmd = []
# we have multiple input images
for i, img in enumerate(input.in_img):
cmd.append(f"cp {img} tempimg/temp_{i:04d}.nii.gz")
return " && ".join(cmd)


rule run_inference:
""" This rule uses either GPU or CPU .
It also runs in an isolated folder (shadow), with symlinks to inputs in that folder, copying over outputs once complete, so temp files are not retained"""
input:
in_img=get_nnunet_input,
model_tar=get_model_tar(),
params:
temp_img="tempimg/temp_0000.nii.gz",
cmd_copy_inputs=get_cmd_copy_inputs,
temp_lbl="templbl/temp.nii.gz",
model_dir="tempmodel",
in_folder="tempimg",
Expand Down Expand Up @@ -149,7 +163,7 @@ rule run_inference:
# run inference
#copy from temp output folder to final output
"mkdir -p {params.model_dir} {params.in_folder} {params.out_folder} && "
"cp {input.in_img} {params.temp_img} && "
"{params.cmd_copy_inputs} && "
"tar -xf {input.model_tar} -C {params.model_dir} && "
"export RESULTS_FOLDER={params.model_dir} && "
"export nnUNet_n_proc_DA={threads} && "
Expand Down
Loading
Loading