From 54cd91ba18fa83ef227b0b56d4a9bbdde488a9fe Mon Sep 17 00:00:00 2001 From: Carl Helmick Date: Thu, 21 Dec 2023 07:32:18 -0400 Subject: [PATCH 1/3] Updated main.py Moved masker declaration outside of loops for speed and to only run once. Moved glob listing into list before loop, reads cleaner. --- main.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 0965f5d..c7c06da 100644 --- a/main.py +++ b/main.py @@ -50,19 +50,20 @@ def participant_level(args, subjects_to_analyze): # Retrieve the atlas atlas_filename = os.path.join(os.path.dirname(__file__), ATLAS_DIR, ATLAS_FILENAME) + # build masker + masker = input_data.NiftiLabelsMasker( + labels_img=atlas_filename, + standardize=True, + detrend=True, + verbose=3) # find all RS scans and extract time-series on them for subject_label in subjects_to_analyze: - for fmri_file in glob(os.path.join(args.bids_dir, + func_files = glob(os.path.join(args.bids_dir, "derivatives", "sub-%s" % subject_label, - "func", "*_hmc_mni.nii.gz") - ): - masker = input_data.NiftiLabelsMasker( - labels_img=atlas_filename, - standardize=True, - detrend=True, - verbose=3) + "func", "*_hmc_mni.nii.gz")) + for fmri_file in func_files: time_series = masker.fit_transform(fmri_file) out_file = os.path.split(fmri_file)[-1].replace("_hmc_mni.nii.gz", "_time_series.tsv") @@ -93,3 +94,4 @@ def group_level(args, subjects_to_analyze): out_file = "group_connectome.tsv" out_file = os.path.join(args.output_dir, out_file) np.savetxt(out_file, estimator.precision_, delimiter='\t') + From 3371c307642d2209691566a578e3e0eb77242299 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 21 Dec 2023 11:33:13 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/main.py b/main.py index c7c06da..55c4dde 100644 --- a/main.py +++ b/main.py @@ -94,4 +94,3 @@ def group_level(args, subjects_to_analyze): out_file = "group_connectome.tsv" out_file = os.path.join(args.output_dir, out_file) np.savetxt(out_file, estimator.precision_, delimiter='\t') - From 2582870459741404e7675963bb14c72a040e87bb Mon Sep 17 00:00:00 2001 From: Carl Helmick Date: Thu, 21 Dec 2023 07:44:03 -0400 Subject: [PATCH 3/3] Update main.py Simplified nilearn import statements to be more specific. --- main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 55c4dde..44e3320 100644 --- a/main.py +++ b/main.py @@ -7,7 +7,8 @@ import numpy as np from sklearn import covariance -from nilearn import input_data, datasets +from nilearn.input_data import NiftiLabelsMasker +from nilearn.datasets import fetch_atlas_basc_multiscale_2015 ############################################################################### # Functions used to build the container @@ -18,7 +19,7 @@ def copy_atlas(): if not os.path.exists(ATLAS_DIR): os.makedirs(ATLAS_DIR) - atlas_filename = datasets.fetch_atlas_basc_multiscale_2015().scale122 + atlas_filename = fetch_atlas_basc_multiscale_2015().scale122 shutil.copy(atlas_filename, os.path.join(ATLAS_DIR, ATLAS_FILENAME)) @@ -51,7 +52,7 @@ def participant_level(args, subjects_to_analyze): atlas_filename = os.path.join(os.path.dirname(__file__), ATLAS_DIR, ATLAS_FILENAME) # build masker - masker = input_data.NiftiLabelsMasker( + masker = NiftiLabelsMasker( labels_img=atlas_filename, standardize=True, detrend=True,