Skip to content

Commit

Permalink
FIX reuse pregenerated subject segmentation or masks (#150)
Browse files Browse the repository at this point in the history
* FIX reuse pregenerated subject segmentation or masks

* FIX don't redefine subject_mask_nii

* cover the mask reuse case in smoke test
  • Loading branch information
htwangtw committed May 31, 2024
1 parent 2349127 commit abb2407
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
11 changes: 10 additions & 1 deletion giga_connectome/mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,23 @@ def generate_gm_mask_atlas(
nib.save(
subject_mask_nii, subject_mask_dir / target_subject_mask_file_name
)
else:
subject_mask_nii = load_img(target_subject_mask)

if not target_subject_seg:
if not target_subject_seg or not target_subject_mask:
# resample if the grey matter mask was not generated
# or the atlas was not present
subject_seg_niis = resample_atlas_collection(
target_subject_seg_file_names,
atlas,
subject_mask_dir,
subject_mask_nii,
)
else:
subject_seg_niis = [
load_img(subject_mask_dir / i)
for i in target_subject_seg_file_names
]

return subject_mask_nii, subject_seg_niis

Expand Down
30 changes: 30 additions & 0 deletions giga_connectome/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def test_smoke(tmp_path, caplog):
"simple",
"--reindex-bids",
"--calculate-intranetwork-average-correlation",
"--bids-filter-file",
str(Path(bids_dir).parent / "bids_filter.json"),
str(bids_dir),
str(output_dir),
"participant",
Expand Down Expand Up @@ -94,3 +96,31 @@ def test_smoke(tmp_path, caplog):
assert timeseries_file.exists()
timeseries = pd.read_csv(timeseries_file, sep="\t")
assert len(timeseries.columns) == 100

gm_path = (
atlases_dir
/ "sub-1"
/ "func"
/ "sub-1_space-MNI152NLin2009cAsym_res-2_label-GM_mask.nii.gz"
)
# delete gm_path
gm_path.unlink()
# rerun
main(
[
"--participant_label",
"1",
"-a",
str(atlases_dir),
"--atlas",
"Schaefer2018",
"--denoise-strategy",
"simple",
"--calculate-intranetwork-average-correlation",
"--bids-filter-file",
str(Path(bids_dir).parent / "bids_filter.json"),
str(bids_dir),
str(output_dir),
"participant",
]
)

0 comments on commit abb2407

Please sign in to comment.