Skip to content
Draft
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
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ requires-python = ">=3.10"
dependencies = [
"acres >=0.5",
"attrs >=24.1",
"bidsschematools >=1.1",
"bidsschematools[expressions]>=1.1",
"nibabel>=5.3.0",
"orjson>=3.11.3",
"universal_pathlib >=0.2.1",
Expand Down Expand Up @@ -102,6 +102,10 @@ exclude = ".*"
# Ruff configured in ruff.toml

[dependency-groups]
demo = [
"jupyterlab>=4.5.5",
"jupytext>=1.19.1",
]
dev = [
"ipython>=8.37.0",
"ruff>=0.15.5",
Expand Down
31 changes: 31 additions & 0 deletions src/bids_validator/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,37 @@ def sidecar(self) -> Namespace | None:

return Namespace(sidecar)

def exists(self, arg: str| list[str] | None, rule: str | None = "dataset") -> int:
if arg is None:
return 0

prefix = UPath()
fileTree = self.file.parent if rule == "file" else self.dataset.tree

if rule == "stimuli":
prefix /= "stimuli"
elif rule == "subject":
if "sub" not in self.entities:
return 0
prefix /= f"sub-{self.entities["sub"]}"

if isinstance(arg, str):
arg = [arg]

if rule == "bids-uri":
valid_uris = (uri for uri in arg if uri.startswith("bids:") and uri.count(":") == 2)
uri_parts = (uri.split(":") for uri in valid_uris)
# Find number of files in this dataset that exist
dataset_files = self.exists([part[2] for part in uri_parts if part[1] == ""])

# Still need to account for bids-uris where middle section is not blank
# Find number of files in other dataset that exist
other_files = 0

return dataset_files + other_files
else:
return sum((prefix / file) in fileTree for file in arg)


class Sessions:
"""Collections of sessions in subject."""
Expand Down
Loading