From 7f70d4e2958bb46ca45faee5548971ff0dd31486 Mon Sep 17 00:00:00 2001 From: Hao-Ting Wang Date: Tue, 2 Apr 2024 14:59:23 -0400 Subject: [PATCH 1/3] skip anatomical metrics when running on anatomical fast track derivatives --- giga_auto_qc/assessments.py | 6 ++++++ giga_auto_qc/workflow.py | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/giga_auto_qc/assessments.py b/giga_auto_qc/assessments.py index d7acd25..d870328 100644 --- a/giga_auto_qc/assessments.py +++ b/giga_auto_qc/assessments.py @@ -334,6 +334,12 @@ def calculate_anat_metrics( """ if verbose > 0: print("Calculate the anatomical dice score.") + # check if the derivative was created with anatomical fast-track + check_anat = fmriprep_bids_layout.get(datatype="anat", return_type="file") + if not check_anat: + print("`anat/` not present in the derivatives. " "Skip anatomical QC.") + return pd.DataFrame() + metrics = {} for sub in tqdm(subjects): anat_filter = { diff --git a/giga_auto_qc/workflow.py b/giga_auto_qc/workflow.py index dd09981..844729e 100644 --- a/giga_auto_qc/workflow.py +++ b/giga_auto_qc/workflow.py @@ -51,6 +51,12 @@ def workflow(args): derivatives=True, reset_database=args.reindex_bids, ) + if fmriprep_bids_layout is None: + raise ValueError( + f"Cannot index directory in {bids_dir}. " + "Please ensure the path is a fMRIPrep output directory." + ) + # check output path output_dir.mkdir(parents=True, exist_ok=True) From adf5437e4fb62f54ba7a7825f12a0ad40e9ea78c Mon Sep 17 00:00:00 2001 From: Hao-Ting Wang Date: Tue, 2 Apr 2024 15:15:14 -0400 Subject: [PATCH 2/3] add test to make sure passing empty anat metrics works --- giga_auto_qc/assessments.py | 6 ++++++ giga_auto_qc/tests/test_assessments.py | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/giga_auto_qc/assessments.py b/giga_auto_qc/assessments.py index d870328..86d2217 100644 --- a/giga_auto_qc/assessments.py +++ b/giga_auto_qc/assessments.py @@ -403,6 +403,12 @@ def quality_accessments( > qulaity_control_standards["functional_dice"] ) functional_metrics["pass_func_qc"] = keep_fd * keep_proportion * keep_func + if anatomical_metrics.empty: + functional_metrics["pass_anat_qc"] = np.nan + functional_metrics["pass_all_qc"] = functional_metrics[ + "pass_func_qc" + ].copy() + return functional_metrics # get the anatomical pass / fail pass_anat_qc = {} diff --git a/giga_auto_qc/tests/test_assessments.py b/giga_auto_qc/tests/test_assessments.py index 1c58e3d..af92381 100644 --- a/giga_auto_qc/tests/test_assessments.py +++ b/giga_auto_qc/tests/test_assessments.py @@ -31,6 +31,17 @@ def test_quality_accessments(): ) assert metrics["pass_all_qc"].astype(int).sum() == 1 + metrics = assessments.quality_accessments( + functional_metrics=functional_metrics, + anatomical_metrics=pd.DataFrame(), + qulaity_control_standards=qc, + ) + assert ( + metrics["pass_all_qc"].astype(int).sum() + == metrics["pass_func_qc"].astype(int).sum() + ) + assert metrics["pass_anat_qc"].isnull().all() == True + def test_dice_coefficient(): """Check the dice coefficient is calculated correctly.""" From f5a438083c205da02145a996105b052a16e24e58 Mon Sep 17 00:00:00 2001 From: Hao-Ting Wang Date: Tue, 2 Apr 2024 16:25:03 -0400 Subject: [PATCH 3/3] update to python 0.10.3 --- giga_auto_qc/assessments.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/giga_auto_qc/assessments.py b/giga_auto_qc/assessments.py index 86d2217..2fbbdac 100644 --- a/giga_auto_qc/assessments.py +++ b/giga_auto_qc/assessments.py @@ -8,7 +8,7 @@ from nibabel import Nifti1Image from nilearn.image import load_img, resample_to_img -from nilearn.masking import intersect_masks, _load_mask_img +from nilearn.masking import intersect_masks, load_mask_img from bids import BIDSLayout @@ -169,7 +169,7 @@ def _check_mask_affine( header_info = {"affine": []} key_to_header = {} for this_mask in mask_imgs: - _, affine = _load_mask_img(this_mask, allow_empty=True) + _, affine = load_mask_img(this_mask, allow_empty=True) affine_hashable = str(affine) header_info["affine"].append(affine_hashable) if affine_hashable not in key_to_header: @@ -281,6 +281,7 @@ def calculate_functional_metrics( "mean_fd_raw": fds_mean_raw, "mean_fd_scrubbed": fds_mean_scrub, "proportion_kept": proportion_kept, + "total_frames": timeseries_length, } func_filter = {