Skip to content

Conversation

CMonnin
Copy link
Member

@CMonnin CMonnin commented Jun 3, 2025

Summary by CodeRabbit

  • New Features

    • Introduced a new workflow for processing NIfTI files and associated CSVs, enabling volume collection and combination.
    • Added a workflow to streamline volume collection and combination, improving modularity and maintainability.
  • Documentation

    • Updated the README with clearer requirements, a dedicated section for running on the Niagara cluster, and detailed step-by-step instructions.
  • Refactor

    • Replaced inline logic with dedicated workflows for volume collection and combination to enhance workflow clarity.
  • Chores

    • Enabled Nextflow DSL2 syntax across scripts for improved workflow capabilities.
    • Updated resource specifications and process naming for the Niagara profile to standardize and clarify resource allocation.

Copy link

coderabbitai bot commented Jun 3, 2025

Walkthrough

This update enables Nextflow DSL 2 across all workflow scripts, standardizes resource specifications in the Niagara profile, and introduces a new workflow for collecting and combining volumes tailored for Niagara. The README is expanded with detailed Niagara-specific setup and execution instructions, including handling known issues.

Changes

File(s) Change Summary
README.md Renamed "Prerequisites" to "Requirements", clarified requirements, and added detailed "Running on Niagara" section.
nextflow.config Enabled DSL 2; updated Niagara profile with explicit resource specs; standardized process resource allocations.
collect_and_combine_volumes.nf, validateInputDirectoryStructure.nf, magetbrain.nf Enabled Nextflow DSL 2 at the top of scripts.
magetbrain.nf Added collectAndCombineVolumes workflow; refactored main workflow to use this new workflow.
collect_and_combine_volumes_niagara.nf Added new workflow for Niagara: pairs NIfTI files with CSVs or placeholders, then collects and combines volumes.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Nextflow (Niagara)
    participant FileSystem
    participant collectVolumes
    participant combineVolumes

    User->>Nextflow (Niagara): Start workflow
    Nextflow (Niagara)->>FileSystem: List NIfTI files in output/labels/majorityvote
    loop For each NIfTI file
        Nextflow (Niagara)->>FileSystem: Extract label from filename
        Nextflow (Niagara)->>FileSystem: Check for corresponding CSV in input/atlases
        alt CSV exists
            Nextflow (Niagara)->>collectVolumes: Pair NIfTI + CSV
        else CSV missing
            Nextflow (Niagara)->>collectVolumes: Pair NIfTI + placeholder
        end
    end
    collectVolumes-->>Nextflow (Niagara): Collected volumes
    Nextflow (Niagara)->>combineVolumes: Combine collected volumes
    combineVolumes-->>Nextflow (Niagara): Final combined output
Loading

Possibly related PRs

  • Dev #14: Adds volume collection/combination processes and README documentation, closely related to this PR's new Niagara workflow and documentation updates.
  • Refactor/niagara #17: Introduces a similar Nextflow workflow for pairing NIfTI files with CSVs or placeholders and combining volumes, indicating overlapping features with this PR.

Poem

In clusters where the data flows,
Niagara’s power now clearly shows.
With DSL2, the scripts align,
Resource specs are by design.
Volumes paired, combined anew—
A rabbit’s work, both swift and true!
🐇✨


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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (7)
validateInputDirectoryStructure.nf (1)

1-1: Fix formatting: Remove leading space.

The DSL2 directive should not have a leading space for consistency with other files.

- nextflow.enable.dsl=2 
+nextflow.enable.dsl=2
README.md (5)

30-30: Fix markdown link fragment case sensitivity.

The link fragment should match the actual header case for proper navigation.

-These are not requirements if running on Niagara [see below](#Running-on-Niagara)
+These are not requirements if running on Niagara [see below](#running-on-niagara)
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

30-30: Link fragments should be valid
Expected: #running-on-niagara; Actual: #Running-on-Niagara

(MD051, link-fragments)


196-196: Add missing comma for clarity.

-> As of writing this openjdk/17.0.9 was the latest version on Niagara.
+> As of writing this, openjdk/17.0.9 was the latest version on Niagara.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~196-~196: Possible missing comma found.
Context: ...17.0.9 ``` > [!NOTE] > As of writing this openjdk/17.0.9 was the latest version o...

(AI_HYDRA_LEO_MISSING_COMMA)


201-201: Fix duplicate word and add missing comma.

-To ensure submission to SLURM the the Niagara profile must be used.
+To ensure submission to SLURM, the Niagara profile must be used.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~201-~201: Possible missing comma found.
Context: ...and on Niagara To ensure submission to SLURM the the Niagara profile must be used. T...

(AI_HYDRA_LEO_MISSING_COMMA)


[duplication] ~201-~201: Possible typo: you repeated a word.
Context: ... Niagara To ensure submission to SLURM the the Niagara profile must be used. This is p...

(ENGLISH_WORD_REPEAT_RULE)


203-203: Remove vim command artifact.

The :w appears to be an accidental vim command insertion.

-Other useful flags to pass are `-bg` to run in background and `-resume` to resume processing if there was an interuption. :w
+Other useful flags to pass are `-bg` to run in background and `-resume` to resume processing if there was an interruption.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~203-~203: Loose punctuation mark.
Context: ...processing if there was an interuption. :w ```bash nextflow run -bg magetbrain.n...

(UNLIKELY_OPENING_PUNCTUATION)


210-211: Fix grammar issues in bug description.

-> A bug when running on Niagara requires and additional script to be run to collect volumes
-> This can be done on the login node without submitting job to SLURM
+> A bug when running on Niagara requires an additional script to be run to collect volumes
+> This can be done on the login node without submitting a job to SLURM
🧰 Tools
🪛 LanguageTool

[uncategorized] ~210-~210: “and” (in addition to, following this) seems less likely than “an” (indefinite article before a vowel sound).
Context: ... A bug when running on Niagara requires and additional script to be run to collect ...

(AI_HYDRA_LEO_CP_AND_AN)


[uncategorized] ~211-~211: Possible missing article found.
Context: ...ne on the login node without submitting job to SLURM ```bash nextflow run collect_...

(AI_HYDRA_LEO_MISSING_A)

magetbrain.nf (1)

254-256: Consider adding error handling for regex matching edge cases.

The regex pattern /_label_([\w]+)\.nii.gz/ assumes a specific filename format. While the code handles non-matches by returning null, consider adding validation to ensure the extracted label is valid.

Consider adding validation for the extracted label:

 .map { a_file ->
     def matcher = a_file.name =~ /_label_([\w]+)\.nii.gz/
     if (matcher.find()) {
         def label = matcher.group(1)
+        if (!label || label.trim().isEmpty()) {
+            log.warn "Empty label extracted from file: ${a_file.name}"
+            return null
+        }
         def csvFile = file("${params.inputDir}/atlases/volume_labels_${label}.csv")
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b69cab0 and 558c6e4.

📒 Files selected for processing (6)
  • README.md (2 hunks)
  • collect_and_combine_volumes.nf (1 hunks)
  • collect_and_combine_volumes_niagara.nf (1 hunks)
  • magetbrain.nf (3 hunks)
  • nextflow.config (2 hunks)
  • validateInputDirectoryStructure.nf (1 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
README.md

30-30: Link fragments should be valid
Expected: #running-on-niagara; Actual: #Running-on-Niagara

(MD051, link-fragments)

🪛 LanguageTool
README.md

[style] ~185-~185: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ...correct modules need to be loaded. This needs to be done every time. > [!IMPORTANT] > D...

(REP_NEED_TO_VB)


[uncategorized] ~196-~196: Possible missing comma found.
Context: ...17.0.9 ``` > [!NOTE] > As of writing this openjdk/17.0.9 was the latest version o...

(AI_HYDRA_LEO_MISSING_COMMA)


[uncategorized] ~201-~201: Possible missing comma found.
Context: ...and on Niagara To ensure submission to SLURM the the Niagara profile must be used. T...

(AI_HYDRA_LEO_MISSING_COMMA)


[duplication] ~201-~201: Possible typo: you repeated a word.
Context: ... Niagara To ensure submission to SLURM the the Niagara profile must be used. This is p...

(ENGLISH_WORD_REPEAT_RULE)


[uncategorized] ~203-~203: Loose punctuation mark.
Context: ...processing if there was an interuption. :w ```bash nextflow run -bg magetbrain.n...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~210-~210: “and” (in addition to, following this) seems less likely than “an” (indefinite article before a vowel sound).
Context: ... A bug when running on Niagara requires and additional script to be run to collect ...

(AI_HYDRA_LEO_CP_AND_AN)


[uncategorized] ~211-~211: Possible missing article found.
Context: ...ne on the login node without submitting job to SLURM ```bash nextflow run collect_...

(AI_HYDRA_LEO_MISSING_A)

🔇 Additional comments (10)
nextflow.config (3)

1-1: LGTM: DSL2 enablement added correctly.

Enabling DSL2 syntax is essential for the new workflow features introduced in this PR.


23-25: Good standardization of resource specifications.

The explicit resource specifications (cpus, time, clusterOptions) provide better control and consistency for the Niagara cluster environment.


32-32: Process name correction appreciated.

The correction from registerNonLinear to registerNonlinear follows standard naming conventions.

collect_and_combine_volumes.nf (1)

1-1: LGTM: DSL2 enablement consistent with other files.

This change aligns with the DSL2 adoption across all workflow scripts in this PR.

collect_and_combine_volumes_niagara.nf (3)

1-2: LGTM: Clean modular approach using include statements.

Good use of include statements to reuse functions from the main volume collection workflow.


13-17: LGTM: Proper handling of missing CSV files.

The logic correctly handles missing CSV files by using a placeholder "NO_FILE" which is consistent with the collectVolumes process implementation.


8-21:

✅ Verification successful

Verify regex pattern consistency with documentation.

The regex pattern /_label_([\w]+)\.nii.gz/ should be consistent with the pattern documented in README.md. Please ensure this matches the expected filename format.


🏁 Script executed:

#!/bin/bash
# Description: Check if the regex pattern used here matches the one documented in README.md
# Expected: Both patterns should be consistent

echo "=== Checking regex patterns ==="
echo "Pattern in collect_and_combine_volumes_niagara.nf:"
rg "_label_\(.*\)\.nii\.gz" --type nf

echo -e "\n=== Pattern mentioned in README.md ==="
rg "_label_.*\.nii\.gz" README.md

Length of output: 3265


Regex pattern is consistent with documentation
The /_label_([\w]+)\.nii.gz/ used in collect_and_combine_volumes_niagara.nf (lines 8–21) exactly matches the example in README.md. No updates are needed.

magetbrain.nf (3)

1-1: LGTM! Enabling DSL 2 syntax.

The addition of nextflow.enable.dsl=2 correctly enables Nextflow DSL 2 syntax, which is required for the workflow definitions in this file.


306-306: LGTM! Clean integration of the new workflow.

The main workflow is cleanly updated to use the new modularized collectAndCombineVolumes workflow, improving code organization and maintainability.


248-277:

✅ Verification successful

Verify downstream handling of placeholder files and consider memory optimization.

The new collectAndCombineVolumes workflow effectively modularizes the volume collection logic. However, there are a few considerations:

  1. Placeholder file handling: Using file("NO_FILE") as a placeholder (line 262) could cause issues if downstream processes (collectVolumes/combineVolumes) don't properly handle non-existent files.

  2. Memory usage: The .collect() operation (line 275) will gather all volumes in memory before passing to combineVolumes. This could be memory-intensive for large datasets.

Please verify that the imported workflows can handle the "NO_FILE" placeholder:


🏁 Script executed:

#!/bin/bash
# Check if collectVolumes and combineVolumes workflows handle placeholder files
echo "Checking for NO_FILE handling in collectVolumes and combineVolumes workflows..."
rg -A 10 -B 5 "NO_FILE|file.*exists" ./collect_and_combine_volumes.nf

Length of output: 815


NO_FILE placeholder correctly handled; memory usage minimal

Downstream scripts already guard against the "NO_FILE" marker—inside collectVolumes the stub and real script both use:

def labelCsvArg = labelCsv.name != 'NO_FILE' ? "${labelCsv}" : ""

so no invalid path is ever passed to collect_volumes_nifti.sh. And combineVolumes only consumes the generated TSVs, not the original CSVs, so it never sees "NO_FILE".

As for the .collect() call, it only gathers a list of file‐reference objects (not their contents), which is negligible in memory for all but truly massive channel sizes. If you anticipate millions of files, you could refactor to a streaming or chunked reduction, but for typical atlas‐sets this poses no concern.

@CMonnin CMonnin closed this Jun 4, 2025
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.

1 participant