Skip to content

revert demuxing strategy to initial split2 method#213

Merged
pdimens merged 5 commits intomainfrom
restore_demux
Mar 7, 2025
Merged

revert demuxing strategy to initial split2 method#213
pdimens merged 5 commits intomainfrom
restore_demux

Conversation

@pdimens
Copy link
Copy Markdown
Owner

@pdimens pdimens commented Mar 6, 2025

Summary by CodeRabbit

  • Refactor

    • Streamlined the generation of read sequence files by replacing the previous process-based compression with direct file writing.
  • New Features

    • Updated output handling so that read files are now generated in an uncompressed FASTQ format, with compression applied later during merging.
    • Introduced a configurable threading parameter for quality assessment to enhance processing efficiency.
  • Style

    • Modified comments for a more casual tone in the processing rules.
    • Updated visual representation of reports by changing color attributes and enhancing plot section titles for clarity.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 6, 2025

📝 Walkthrough

Walkthrough

This pull request updates how read output files are handled. In the Python script, the get_read_codes function now writes directly to uncompressed .fq files instead of streaming data through gzip subprocesses. In the Snakefile, output file extensions have been modified from .fq.gz to .fq, and the merge rule now pipes the concatenated data through gzip. Additionally, a threads parameter is added to the assess_quality rule, and a comment in the parse_schema function has been revised.

Changes

File(s) Change Summary
harpy/scripts/demultiplex_gen1.py Updated get_read_codes: removed subprocess-based gzip compression; now writes directly to uncompressed .fq files using standard file write calls.
harpy/snakefiles/demultiplex_gen1.smk Changed output file extensions from .fq.gz to .fq in the demultiplex and merge_partitions rules; added a gzip command in the merge step; introduced a threads parameter in assess_quality; updated a comment.

Sequence Diagram(s)

sequenceDiagram
    participant Script as demultiplex_gen1.py
    participant FS as File System
    participant Snake as Snakefile Workflow
    participant Merge as merge_partitions Rule
    participant Quality as assess_quality Rule

    Script->>FS: Write R1 & R2 read data to uncompressed .fq files
    Snake->>FS: Read .fq files for demultiplexing
    Snake->>Merge: Trigger merge of partitions
    Merge->>FS: Concatenate .fq files then compress output with gzip
    Snake->>Quality: Execute assess_quality with threads=1
Loading

Possibly related PRs

  • divide-and-conquer demultiplexing #202: Modifications to the get_read_codes function, particularly the output file handling changes, align with updates made in this PR.
  • better sim demux support #163: Similar changes to output file formats in the demultiplex and merge rules indicate a common approach to shifting from compressed to uncompressed FASTQ files.
  • Add Metassembly #144: Adjustments in the snakefile for file format handling and process updates are closely related to the changes in this PR.

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6682841 and 9158eb5.

📒 Files selected for processing (1)
  • harpy/reports/align_stats.qmd (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • harpy/reports/align_stats.qmd
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: align strobe
  • GitHub Check: align EMA
  • GitHub Check: demux gen1
  • GitHub Check: align BWA
  • GitHub Check: Rebuild Container

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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
Copy Markdown

@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: 1

🧹 Nitpick comments (1)
harpy/scripts/demultiplex_gen1.py (1)

139-140: Simplify direct file writes to improve readability.

The current implementation writes formatted records to output files. It's correct, but could be more readable.

Consider simplifying:

-        R1_output[sample_name].write(f"{r1_rec}\n")
-        R2_output[sample_name].write(f"{r2_rec}\n")
+        print(r1_rec, file=R1_output[sample_name])
+        print(r2_rec, file=R2_output[sample_name])

This approach is more Pythonic and makes the intention clearer.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 66d1077 and 22c6b44.

📒 Files selected for processing (2)
  • harpy/scripts/demultiplex_gen1.py (2 hunks)
  • harpy/snakefiles/demultiplex_gen1.smk (5 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
harpy/scripts/demultiplex_gen1.py

113-113: Use a context manager for opening files

(SIM115)


114-114: Use a context manager for opening files

(SIM115)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: demux gen1
  • GitHub Check: Rebuild Container
🔇 Additional comments (6)
harpy/snakefiles/demultiplex_gen1.smk (6)

28-28: Improved comment clarity.

The updated comment provides a clearer and more conversational explanation of the error handling approach.


107-107: File extension change aligns with demultiplexing implementation.

The output file extension has been changed from .fq.gz to .fq, which correctly aligns with the changes in demultiplex_gen1.py where direct file writing to uncompressed files now occurs.


123-123: Input file extension update for consistency.

The input file extension has been changed to match the output from the demultiplex rule (.fq instead of .fq.gz).

This change maintains consistency with the modifications in the demultiplex rule.


131-131: Shell command updated to compress output after concatenation.

The shell command now correctly pipes the concatenated .fq files through gzip to produce compressed .fq.gz output files.

This approach allows demultiplexing to work with uncompressed files (potentially faster) while still producing compressed final outputs for storage efficiency.


173-174: Added thread configuration to improve flexibility.

Adding the threads parameter allows for configurable thread usage in the assess_quality rule.

This change improves configurability and ensures the thread value is properly passed to the falco command on line 179.


179-179: Updated falco command to use the thread parameter.

The falco command now correctly uses the thread parameter value.

This change ensures the thread configuration is properly utilized by the underlying tool.

Copy link
Copy Markdown

@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

♻️ Duplicate comments (1)
harpy/scripts/demultiplex_gen1.py (1)

113-114: 🛠️ Refactor suggestion

Use context managers for file handling.

The code opens output files for each sample but doesn't use context managers (with statement), which can lead to resource leaks if an exception occurs between opening and closing these files.

While you've added explicit .close() calls below, using a context manager would be more robust:

-    R1_output[sample] = open(f"{outdir}/{sample}.{part}.R1.fq", 'w')
-    R2_output[sample] = open(f"{outdir}/{sample}.{part}.R2.fq", 'w')

Consider using a context manager approach with ExitStack to manage multiple files:

import contextlib

# At the beginning of the function
with contextlib.ExitStack() as stack:
    R1_output = {}
    R2_output = {}
    for sample in samples:
        R1_output[sample] = stack.enter_context(open(f"{outdir}/{sample}.{part}.R1.fq", 'w'))
        R2_output[sample] = stack.enter_context(open(f"{outdir}/{sample}.{part}.R2.fq", 'w'))
    
    # Rest of your processing...
    # No need for explicit close() calls
🧰 Tools
🪛 Ruff (0.8.2)

113-113: Use a context manager for opening files

(SIM115)


114-114: Use a context manager for opening files

(SIM115)

🧹 Nitpick comments (1)
harpy/scripts/demultiplex_gen1.py (1)

156-158: File closing is good, but context managers would be better.

While explicitly closing files is necessary with the current approach, using context managers (as suggested above) would handle this automatically, even in case of exceptions.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2658830 and 6682841.

📒 Files selected for processing (1)
  • harpy/scripts/demultiplex_gen1.py (3 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
harpy/scripts/demultiplex_gen1.py

113-113: Use a context manager for opening files

(SIM115)


114-114: Use a context manager for opening files

(SIM115)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: demux gen1
  • GitHub Check: Rebuild Container
🔇 Additional comments (1)
harpy/scripts/demultiplex_gen1.py (1)

139-140: LGTM: File writing approach simplified.

The direct file writing is cleaner than using subprocess pipes. This change aligns with the PR objective of reverting to the initial split2 method.

@pdimens pdimens merged commit e281409 into main Mar 7, 2025
20 checks passed
@pdimens pdimens deleted the restore_demux branch March 22, 2025 14:34
@coderabbitai coderabbitai bot mentioned this pull request Apr 25, 2025
@coderabbitai coderabbitai bot mentioned this pull request May 9, 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