Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed empty `shell` variable in cluster run scripts.
- A bug in which bandpass filters always assumed 1D regressor files have exactly 5 header rows.
- Removed an erroneous connection to AFNI 3dTProject in nuisance denoising that would unnecessarily send a spike regressor as a censor. This would sometimes cause TRs to unnecessarily be dropped from the timeseries as if scrubbing were being performed.
- Lingering calls to `cpac_outputs.csv` (was changed to `cpac_outputs.tsv` in v1.8.1).

### Removed

Expand Down
60 changes: 7 additions & 53 deletions CPAC/pipeline/cpac_group_runner.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2022-2024 C-PAC Developers
# Copyright (C) 2022-2025 C-PAC Developers

# This file is part of C-PAC.

Expand Down Expand Up @@ -143,31 +143,12 @@ def gather_nifti_globs(pipeline_output_folder, resource_list, pull_func=False):
import glob
import os

import pandas as pd
import pkg_resources as p
from CPAC.utils.outputs import group_derivatives

exts = ".nii"
nifti_globs = []

keys_tsv = p.resource_filename("CPAC", "resources/cpac_outputs.tsv")
try:
keys = pd.read_csv(keys_tsv, delimiter="\t")
except Exception as e:
err = (
"\n[!] Could not access or read the cpac_outputs.tsv "
f"resource file:\n{keys_tsv}\n\nError details {e}\n"
)
raise Exception(err)

derivative_list = list(keys[keys["Sub-Directory"] == "func"]["Resource"])
derivative_list = derivative_list + list(
keys[keys["Sub-Directory"] == "anat"]["Resource"]
)

if pull_func:
derivative_list = derivative_list + list(
keys[keys["Space"] == "functional"]["Resource"]
)
derivative_list = group_derivatives(pull_func)

if len(resource_list) == 0:
err = "\n\n[!] No derivatives selected!\n\n"
Expand Down Expand Up @@ -361,33 +342,14 @@ def create_output_dict_list(
"""Create a dictionary of output filepaths and their associated information."""
import os

import pandas as pd
import pkg_resources as p

if len(resource_list) == 0:
err = "\n\n[!] No derivatives selected!\n\n"
raise Exception(err)

if derivatives is None:
keys_tsv = p.resource_filename("CPAC", "resources/cpac_outputs.tsv")
try:
keys = pd.read_csv(keys_tsv, delimiter="\t")
except Exception as e:
err = (
"\n[!] Could not access or read the cpac_outputs.csv "
f"resource file:\n{keys_tsv}\n\nError details {e}\n"
)
raise Exception(err)
from CPAC.utils.outputs import group_derivatives

derivatives = list(keys[keys["Sub-Directory"] == "func"]["Resource"])
derivatives = derivatives + list(
keys[keys["Sub-Directory"] == "anat"]["Resource"]
)

if pull_func:
derivatives = derivatives + list(
keys[keys["Space"] == "functional"]["Resource"]
)
derivatives = group_derivatives(pull_func)

# remove any extra /'s
pipeline_output_folder = pipeline_output_folder.rstrip("/")
Expand Down Expand Up @@ -752,18 +714,10 @@ def prep_feat_inputs(group_config_file: str) -> dict:
import os

import pandas as pd
import pkg_resources as p

keys_tsv = p.resource_filename("CPAC", "resources/cpac_outputs.tsv")
try:
keys = pd.read_csv(keys_tsv, delimiter="\t")
except Exception as e:
err = (
"\n[!] Could not access or read the cpac_outputs.tsv "
f"resource file:\n{keys_tsv}\n\nError details {e}\n"
)
raise Exception(err)
from CPAC.utils.outputs import Outputs

keys = Outputs.reference
derivatives = list(
keys[keys["Derivative"] == "yes"][keys["Space"] == "template"][
keys["Values"] == "z-score"
Expand Down
16 changes: 1 addition & 15 deletions CPAC/utils/create_fsl_flame_preset.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2018-2024 C-PAC Developers
# Copyright (C) 2018-2025 C-PAC Developers

# This file is part of C-PAC.

Expand Down Expand Up @@ -1092,20 +1092,6 @@ def run(

import os

import pandas as pd
import pkg_resources as p

# make life easy
keys_csv = p.resource_filename("CPAC", "resources/cpac_outputs.csv")
try:
pd.read_csv(keys_csv)
except Exception as e:
err = (
"\n[!] Could not access or read the cpac_outputs.csv "
f"resource file:\n{keys_csv}\n\nError details {e}\n"
)
raise Exception(err)

if derivative_list == "all":
derivative_list = [
"alff",
Expand Down
19 changes: 17 additions & 2 deletions CPAC/utils/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"""Specify the resources that C-PAC writes to the output direcotry."""

from importlib.resources import files
from typing import ClassVar

import pandas as pd

Expand Down Expand Up @@ -47,8 +48,12 @@ class Outputs:
reference[reference["4D Time Series"] == "Yes"]["Resource"]
)

anat = list(reference[reference["Sub-Directory"] == "anat"]["Resource"])
func = list(reference[reference["Sub-Directory"] == "func"]["Resource"])
anat: ClassVar[list[str]] = list(
reference[reference["Sub-Directory"] == "anat"]["Resource"]
)
func: ClassVar[list[str]] = list(
reference[reference["Sub-Directory"] == "func"]["Resource"]
)

# outputs to send into smoothing, if smoothing is enabled, and
# outputs to write out if the user selects to write non-smoothed outputs
Expand All @@ -65,6 +70,8 @@ class Outputs:
all_template_filter = _template_filter | _epitemplate_filter | _symtemplate_filter
all_native_filter = _T1w_native_filter | _bold_native_filter | _long_native_filter

bold_native: ClassVar[list[str]] = list(reference[_bold_native_filter]["Resource"])

native_nonsmooth = list(
reference[all_native_filter & _nonsmoothed_filter]["Resource"]
)
Expand Down Expand Up @@ -121,3 +128,11 @@ def _is_gifti(_file_key):
for gifti in giftis.itertuples()
if " " in gifti.File
}


def group_derivatives(pull_func: bool = False) -> list[str]:
"""Gather keys for anatomical and functional derivatives for group analysis."""
derivatives: list[str] = Outputs.func + Outputs.anat
if pull_func:
derivatives = derivatives + Outputs.bold_native
return derivatives