Skip to content

BIDS input#132

Open
gdevenyi wants to merge 1 commit into
masterfrom
bids-input
Open

BIDS input#132
gdevenyi wants to merge 1 commit into
masterfrom
bids-input

Conversation

@gdevenyi

@gdevenyi gdevenyi commented Jan 30, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • Added tooling to parse BIDS datasets and produce model-building inputs with options for suffix, derivatives, repeatable column filters, and optional mask extraction.
  • Bug Fixes

    • Fixed handling of unset runtime flags so dry-run/debug default to off and log-level is consistent.
  • Chores

    • Integrated an additional submodule to enhance BIDS dataset support.
    • Updated ignore rules to exclude editor settings and CSV files.

@coderabbitai

coderabbitai Bot commented Jan 30, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@gdevenyi has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 5 minutes and 40 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📝 Walkthrough

Walkthrough

Adds a libBIDS git submodule and pinned commit, defaults two helper flags to "off", introduces a new Argbash CLI script to convert BIDS datasets to CSV (with optional mask output), and updates .gitignore to ignore .vscode and *.csv.

Changes

Cohort / File(s) Summary
Submodule config & pin
/.gitmodules, libBIDS.sh
Adds a new libBIDS submodule entry in .gitmodules and a subproject commit reference line in libBIDS.sh.
Helpers
helpers.sh
Defaults unset flags using ${_arg_dry_run:-off} and ${_arg_debug:-off} when computing LOG_LEVEL (no other behavior changes).
New BIDS CLI
modelbuild_input_from_bids.sh
Adds an Argbash-generated script that converts a BIDS dataset to CSV for modelbuild.sh; supports options --suffix, --derivatives, repeatable --column-filter, --masks, and requires two positional args (BIDS root and output CSV).
Ignore patterns
/.gitignore
Adds .vscode and *.csv to ignore list.

Sequence Diagram(s)

sequenceDiagram
    participant User as User
    participant CLI as modelbuild_input_from_bids.sh
    participant Lib as libBIDS.sh
    participant FS as FileSystem
    participant Out as OutputCSV

    User->>CLI: invoke with options + args
    CLI->>Lib: request BIDS rows (apply suffix/derivatives/column-filters)
    Lib-->>CLI: return filtered rows
    CLI->>FS: resolve file paths
    CLI->>Out: write image paths to CSV
    alt --masks provided
        CLI->>Lib: request mask rows (suffix=mask)
        Lib-->>CLI: return mask rows
        CLI->>FS: resolve mask paths
        CLI->>Out: write mask paths to masks file
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 I hopped through submodules, tiny and neat,
I nudged two flags so defaults are sweet.
I read BIDS rows, sorted masks and scans,
Wrote CSV trails with careful little hands.
Hooray for tidy trees and simpler plans!

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'BIDS input' is vague and does not clearly convey what specific functionality or changes are being introduced to the codebase. Use a more descriptive title that explains the purpose of the changes, such as 'Add BIDS dataset parser script' or 'Create modelbuild input generation from BIDS datasets'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bids-input

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Fix all issues with AI agents
In `@modelbuild_input_from_bids.sh`:
- Around line 164-166: The script uses a hardcoded developer-local path
(/home/gdevenyi/...) when sourcing libBIDS.sh which will fail for other users;
replace that line with the relative/submodule-based sourcing shown in the
commented line (use the BASH_SOURCE dirname approach: "$(cd "$(dirname
"${BASH_SOURCE[0]}")" && pwd)/libBIDS.sh/libBIDS.sh") and add a quick existence
check before sourcing (or a clear process exit error) so
modelbuild_input_from_bids.sh fails fast with a useful message if the submodule
file is missing.
- Around line 181-185: The call to libBIDSsh_csv_filter uses an unquoted array
expansion ${_arg_column_filter[*]} which can split elements with spaces; change
the expansion to a quoted form for the _arg_column_filter array (use
"${_arg_column_filter[@]}") when building filtered_image_table so each array
element is passed as a single argument to libBIDSsh_csv_filter.
- Around line 176-179: The current substitution on _arg_column_filter embeds the
flag and value into single elements, producing malformed arguments for
libBIDSsh_csv_filter; instead build a new array (e.g., _column_filter_args) by
iterating over _arg_column_filter and appending the flag and the value as
separate array entries (append "--row-filter" then the value for each), then
replace uses of the old combined string expansion with the new array expansion
("${_column_filter_args[@]}") when calling libBIDSsh_csv_filter (and at the
other call site referenced in the diff).
🧹 Nitpick comments (1)
modelbuild_input_from_bids.sh (1)

192-202: Same quoting issue and redundant redeclaration.

  1. Line 197 has the same unquoted array expansion issue.
  2. Line 198 redeclares declare -A row which is already declared on line 187—this is redundant.
♻️ Proposed cleanup
-if [[ ! -z "${_arg_masks}" ]]; then
+if [[ -n "${_arg_masks}" ]]; then
   filtered_mask_table=$(libBIDSsh_csv_filter "${bids_table}" \
     -r "suffix:mask" \
     -r "extension:(nii|nii.gz)" \
     -r "derivatives:${_arg_derivatives}" \
-    ${_arg_column_filter[*]})
-  declare -A row
+    "${_column_filter_args[@]}")
   while libBIDS_csv_iterator "$filtered_mask_table" row "subject" "session"; do
     printf "%s\n" "${row[path]}"
   done >"${_arg_masks}"
 fi

Comment thread modelbuild_input_from_bids.sh Outdated
Comment thread modelbuild_input_from_bids.sh Outdated
Comment thread modelbuild_input_from_bids.sh Outdated
Copilot AI review requested due to automatic review settings February 10, 2026 19:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new CLI helper script to generate modelbuild.sh inputs from a BIDS dataset, and wires in libBIDS.sh as a submodule; also hardens helper flag handling when env args are undefined.

Changes:

  • Added modelbuild_input_from_bids.sh to parse BIDS datasets and filter/select images (and optional masks).
  • Added libBIDS.sh as a git submodule for BIDS parsing/filtering utilities.
  • Fixed helpers.sh log-level selection to tolerate unset _arg_dry_run / _arg_debug.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
modelbuild_input_from_bids.sh New Argbash-based CLI script to parse/filter BIDS and write output path lists.
libBIDS.sh Adds libBIDS.sh as a submodule pointer.
helpers.sh Avoids unbound-variable errors when dry-run/debug flags aren’t defined.
.gitmodules Registers the new libBIDS.sh submodule.
.gitignore Ignores editor config and CSV outputs by default.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +180 to +184
filtered_image_table=$(libBIDSsh_csv_filter "${bids_table}" \
-r "suffix:${_arg_suffix}" \
-r "extension:(nii|nii.gz)" \
-r "derivatives:${_arg_derivatives}" \
"${_column_filter_args[@]}")

Copilot AI Feb 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script defines --session and --run CLI options (and documents them in print_help), but they are never applied to the filter. As a result, those flags have no effect. Consider adding conditional -r \"session:${_arg_session}\" and -r \"run:${_arg_run}\" filters when the user supplies them (e.g., non-empty session and run != 'NA'), or folding them into _column_filter_args similarly to --column-filter.

Copilot uses AI. Check for mistakes.
Comment on lines +186 to +189
declare -A row
while libBIDS_csv_iterator "$filtered_image_table" row "subject" "session"; do
printf "%s\n" "${row[path]}"
done >"${_arg_output}"

Copilot AI Feb 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script mixes libBIDSsh_* function names (e.g., libBIDSsh_parse_bids_to_csv, libBIDSsh_csv_filter) with libBIDS_csv_iterator. If the iterator function in the submodule uses the same libBIDSsh_ prefix, this will fail at runtime with command not found. Align the iterator call to the actual exported function name from libBIDS.sh and keep the naming consistent within this script.

Copilot uses AI. Check for mistakes.
Comment thread modelbuild_input_from_bids.sh Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@modelbuild_input_from_bids.sh`:
- Around line 180-184: The CLI options _arg_session and _arg_run are parsed but
not passed to libBIDSsh_csv_filter, so add session/run filters when building the
filter calls: update the filtered_image_table libBIDSsh_csv_filter invocation
and the mask filter invocation to include -r "session:${_arg_session}" and -r
"run:${_arg_run}" (only when those variables are non-empty) so that filtering
honors --session and --run; reference the existing calls that populate
filtered_image_table and the mask filter block that uses libBIDSsh_csv_filter to
apply the same conditional additions.
- Around line 174-178: The array expansions under set -u can raise "unbound
variable" on older Bash (<4.4); change usages of "${_arg_column_filter[@]}",
"${_column_filter_args[@]}", and any similar array expansions to the portable
idiom ${_arg_column_filter[@]+"${_arg_column_filter[@]}"} and
${_column_filter_args[@]+"${_column_filter_args[@]}"} so empty arrays don't
trigger an error while keeping the existing logic in the loop that builds
_column_filter_args and where that array is later expanded.
🧹 Nitpick comments (2)
modelbuild_input_from_bids.sh (2)

191-191: Prefer [[ -n ]] over [[ ! -z ]].

Minor style nit: [[ -n "${_arg_masks}" ]] is the more idiomatic equivalent of [[ ! -z "${_arg_masks}" ]].


162-164: Add a shellcheck source directive for libBIDS.sh and consider a guard.

Line 163 has # shellcheck source=helpers.sh but line 164 is missing the corresponding directive. Also, if the submodule isn't initialized, this will fail with a confusing error. A quick existence check would improve the UX.

🛡️ Proposed fix
 # shellcheck source=helpers.sh
 source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/helpers.sh"
+# shellcheck source=libBIDS.sh/libBIDS.sh
+_libBIDS_path="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/libBIDS.sh/libBIDS.sh"
+[[ -f "${_libBIDS_path}" ]] || die "libBIDS.sh not found — did you run 'git submodule update --init'?" 1
-source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/libBIDS.sh/libBIDS.sh"
+source "${_libBIDS_path}"

Comment thread modelbuild_input_from_bids.sh
Comment on lines +180 to +184
filtered_image_table=$(libBIDSsh_csv_filter "${bids_table}" \
-r "suffix:${_arg_suffix}" \
-r "extension:(nii|nii.gz)" \
-r "derivatives:${_arg_derivatives}" \
"${_column_filter_args[@]}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

--session and --run options are parsed but never applied as filters.

_arg_session and _arg_run are accepted via CLI (lines 73-88) but are not passed to libBIDSsh_csv_filter here or in the mask filter block (lines 192-196). Users specifying --session or --run will get no filtering effect, which is silently incorrect.

🐛 Proposed fix — add session/run filters when set
 filtered_image_table=$(libBIDSsh_csv_filter "${bids_table}" \
   -r "suffix:${_arg_suffix}" \
   -r "extension:(nii|nii.gz)" \
   -r "derivatives:${_arg_derivatives}" \
+  ${_arg_session:+-r "session:${_arg_session}"} \
+  ${_arg_run:+-r "run:${_arg_run}"} \
   "${_column_filter_args[@]}")

Apply the same addition to the mask filter block (lines 192-196).

🤖 Prompt for AI Agents
In `@modelbuild_input_from_bids.sh` around lines 180 - 184, The CLI options
_arg_session and _arg_run are parsed but not passed to libBIDSsh_csv_filter, so
add session/run filters when building the filter calls: update the
filtered_image_table libBIDSsh_csv_filter invocation and the mask filter
invocation to include -r "session:${_arg_session}" and -r "run:${_arg_run}"
(only when those variables are non-empty) so that filtering honors --session and
--run; reference the existing calls that populate filtered_image_table and the
mask filter block that uses libBIDSsh_csv_filter to apply the same conditional
additions.

@gdevenyi gdevenyi force-pushed the bids-input branch 3 times, most recently from bbf3091 to 7014876 Compare February 10, 2026 19:56

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@modelbuild_input_from_bids.sh`:
- Line 176: The loop mistakenly calls libBIDS_csv_iterator instead of the
correct libBIDSsh_csv_iterator; update the while invocation that currently
references libBIDS_csv_iterator to call libBIDSsh_csv_iterator (the same helper
used earlier) so the loop over "$filtered_mask_table" with variables row,
subject, session uses the correct function and avoids the "command not found"
runtime error.

-r "derivatives:${_arg_derivatives}" \
"${_column_filter_args[@]}")
declare -A row
while libBIDS_csv_iterator "$filtered_mask_table" row "subject" "session"; do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Bug: libBIDS_csv_iterator should be libBIDSsh_csv_iterator.

Line 165 correctly calls libBIDSsh_csv_iterator, but line 176 drops the sh — calling libBIDS_csv_iterator instead. This will fail at runtime with "command not found" whenever --masks is used.

🐛 Proposed fix
-  while libBIDS_csv_iterator "$filtered_mask_table" row "subject" "session"; do
+  while libBIDSsh_csv_iterator "$filtered_mask_table" row "subject" "session"; do
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
while libBIDS_csv_iterator "$filtered_mask_table" row "subject" "session"; do
while libBIDSsh_csv_iterator "$filtered_mask_table" row "subject" "session"; do
🤖 Prompt for AI Agents
In `@modelbuild_input_from_bids.sh` at line 176, The loop mistakenly calls
libBIDS_csv_iterator instead of the correct libBIDSsh_csv_iterator; update the
while invocation that currently references libBIDS_csv_iterator to call
libBIDSsh_csv_iterator (the same helper used earlier) so the loop over
"$filtered_mask_table" with variables row, subject, session uses the correct
function and avoids the "command not found" runtime error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants