Skip to content

Commit

Permalink
refactor initial subject IDs check and add more intermediate messages…
Browse files Browse the repository at this point in the history
… for BIDS command
  • Loading branch information
alyssadai committed Oct 21, 2023
1 parent b62e37f commit dbc4496
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions bagel/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,6 @@ def bids(
check_overwrite(output, overwrite)

jsonld = load_json(jsonld_path)
layout = BIDSLayout(bids_dir, validate=True)

# Strip and store context to be added back later, since it's not part of
# (and can't be easily added) to the existing data model
context = {"@context": jsonld.pop("@context")}
Expand All @@ -217,21 +215,28 @@ def bids(
pheno_subject.hasLabel: pheno_subject
for pheno_subject in getattr(pheno_dataset, "hasSamples")
}
bids_subject_list = ["sub-" + sub_id for sub_id in layout.get_subjects()]

# TODO: Revert to using Layout.get_subjects() to get BIDS subjects once pybids performance is improved
butil.check_unique_bids_subjects(
pheno_subjects=pheno_subject_dict.keys(),
bids_subjects=bids_subject_list,
bids_subjects=butil.get_bids_subjects_simple(bids_dir),
)

# Display validated input paths to user
space = 32
print(
"Parsing BIDS metadata to be merged with phenotypic annotations:\n"
"Initial checks of inputs passed:\n"
f" {'Phenotypic .jsonld to augment:' : <{space}} {jsonld_path}\n"
f" {'BIDS dataset directory:' : <{space}} {bids_dir}\n"
)

print("Parsing and validating BIDS dataset. This may take a while...")
layout = BIDSLayout(bids_dir, validate=True)
print("BIDS parsing completed.\n")

print(
"Merging subject-level BIDS metadata with the phenotypic annotations...\n"
)
for bids_sub_id in layout.get_subjects():
pheno_subject = pheno_subject_dict.get(f"sub-{bids_sub_id}")
session_list = []
Expand Down

0 comments on commit dbc4496

Please sign in to comment.