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

Update to match neurodatascience/nipoppy:main #42

Merged
merged 1 commit into from
Nov 24, 2023
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
31 changes: 29 additions & 2 deletions nipoppy/trackers/run_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import nipoppy.workflow.logger as my_logger
from nipoppy.trackers.tracker import Tracker, get_start_time, get_end_time, SUCCESS, UNAVAILABLE, INCOMPLETE, TRUE
from nipoppy.trackers import bids_tracker, fs_tracker, fmriprep_tracker, mriqc_tracker, tractoflow_tracker
from nipoppy.workflow.make_doughnut import run as run_make_doughnut
from nipoppy.workflow.utils import (
BIDS_SESSION_PREFIX,
COL_DATATYPE_MANIFEST,
Expand All @@ -18,7 +19,9 @@
COL_SESSION_MANIFEST,
DNAME_BACKUPS_BAGEL,
FNAME_BAGEL,
FNAME_DOUGHNUT,
FNAME_MANIFEST,
load_doughnut,
load_manifest,
save_backup,
)
Expand Down Expand Up @@ -48,6 +51,32 @@ def run(global_configs, dash_schema_file, pipelines, session_id="ALL", run_id="1
"""
DATASET_ROOT = global_configs["DATASET_ROOT"]

# load the doughnut (create a new one if needed)
fpath_doughnut = f"{DATASET_ROOT}/scratch/raw_dicom/doughnut.csv"
if not Path(fpath_doughnut).exists():
warnings.warn(f"No doughnut file found, creating one at: {fpath_doughnut}")
run_make_doughnut(global_configs, regenerate=True, empty=False)
df_doughnut = load_doughnut(fpath_doughnut)

# load the manifest
fpath_manifest = f"{DATASET_ROOT}/tabular/{FNAME_MANIFEST}"
df_manifest = load_manifest(fpath_manifest)

# drop existing BIDS ID column if needed
if COL_BIDS_ID_MANIFEST in df_manifest.columns:
warnings.warn(
f"The manifest is not supposed to have a {COL_BIDS_ID_MANIFEST} "
"column, dropping"
)
df_manifest = df_manifest.drop(columns=COL_BIDS_ID_MANIFEST)

# add BIDS ID column to the manifest
df_manifest = df_manifest.merge(
df_doughnut[[COL_SUBJECT_MANIFEST, COL_SESSION_MANIFEST, COL_BIDS_ID_MANIFEST]],
on=[COL_SUBJECT_MANIFEST, COL_SESSION_MANIFEST],
how="left",
)

# for bids tracker
bids_dir = f"{DATASET_ROOT}/bids/"

Expand Down Expand Up @@ -85,8 +114,6 @@ def run(global_configs, dash_schema_file, pipelines, session_id="ALL", run_id="1
logger.warning(f"Skipping pipeline: {pipeline}. Tracker not listed in the config")

# Grab BIDS participants from the manifest
fpath_manifest = f"{DATASET_ROOT}/tabular/{FNAME_MANIFEST}"
df_manifest = load_manifest(fpath_manifest)
df_manifest_imaging = df_manifest.loc[df_manifest[COL_DATATYPE_MANIFEST].apply(lambda x: len(x) != 0)]
n_participants_with_imaging = len(df_manifest_imaging[COL_BIDS_ID_MANIFEST].unique())

Expand Down
11 changes: 6 additions & 5 deletions nipoppy/workflow/make_doughnut.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,8 @@
GLOBAL_CONFIG_DATASET_ROOT = 'DATASET_ROOT'
GLOBAL_CONFIG_SESSIONS = 'SESSIONS'

def run(global_config_file, regenerate=False, empty=False):
def run(global_config: dict, regenerate=False, empty=False):

# parse global config
with open(global_config_file) as file:
global_config = json.load(file)
dpath_dataset = Path(global_config[GLOBAL_CONFIG_DATASET_ROOT])

# generate DICOM/BIDS directory paths
Expand Down Expand Up @@ -261,4 +258,8 @@ def check_dir(dpath):
regenerate = getattr(args, FLAG_REGENERATE.lstrip('-'))
empty = getattr(args, FLAG_EMPTY.lstrip('-'))

run(global_config_file, regenerate=regenerate, empty=empty)
# load global config
with open(global_config_file) as file:
global_config = json.load(file)

run(global_config, regenerate=regenerate, empty=empty)