Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add toulligqc wrapper #3171

Merged
merged 20 commits into from
Sep 24, 2024
Merged

Conversation

Salome-Brunon
Copy link
Contributor

@Salome-Brunon Salome-Brunon commented Sep 10, 2024

Added wrapper for ToulligQC which is a quality control tool for nanopore data.

QC

While the contributions guidelines are more extensive, please particularly ensure that:

  • test.py was updated to call any added or updated example rules in a Snakefile
  • input: and output: file paths in the rules can be chosen arbitrarily
  • wherever possible, command line arguments are inferred and set automatically (e.g. based on file extensions in input: or output:)
  • temporary files are either written to a unique hidden folder in the working directory, or (better) stored where the Python function tempfile.gettempdir() points to
  • the meta.yaml contains a link to the documentation of the respective tool or command under url:
  • conda environments use a minimal amount of channels and packages, in recommended ordering

Summary by CodeRabbit

  • New Features

    • Introduced a Conda environment configuration for the toulligqc project, simplifying setup for users.
    • Added metadata for the toulligqc tool, including descriptions and input/output specifications, enhancing user understanding.
    • Implemented multiple workflow rules for processing various sequencing data formats, facilitating integration into bioinformatics pipelines.
    • Developed a wrapper for executing the toulligqc command-line tool, improving flexibility in handling different input file types.
  • Tests

    • Added new test cases for the toulligqc process to ensure functionality is covered.

Copy link
Contributor

coderabbitai bot commented Sep 10, 2024

Warning

Rate limit exceeded

@fgvieira has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 21 minutes and 55 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.

Commits

Files that changed from the base of the PR and between 3aa39af and ac9a383.

Walkthrough

This pull request introduces several new files and configurations for the toulligqc project, a tool for post-sequencing quality control of Oxford Nanopore sequencers. It includes an environment.yaml for Conda environment setup, a meta.yaml for project metadata, a Snakefile for workflow definition, and a wrapper.py for command execution. Additionally, multiple test functions are added to test.py to validate the functionality of the toulligqc process.

Changes

Files Change Summary
bio/toulligqc/environment.yaml Added configuration for Conda environment, specifying channels and dependencies.
bio/toulligqc/meta.yaml Introduced metadata for the toulligqc tool, including name, description, authors, input/output specifications, and parameters.
bio/toulligqc/test/Snakefile Defined three new workflow rules for handling different input types with logging.
bio/toulligqc/wrapper.py Created a wrapper for executing the toulligqc tool, handling input flags and logging.
test.py Added new test functions to validate the toulligqc process for different input types.

Possibly related PRs


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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.
    -- 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 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
Contributor

@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

Outside diff range, codebase verification and nitpick comments (1)
bio/toulligqc/wrapper.py (1)

9-12: Consider using pathlib.Path for handling file paths and extensions.

To make the code more robust and readable, consider using pathlib.Path to handle file paths and extensions. Here's an example:

from pathlib import Path

input_path = Path(snakemake.input[0])
if input_path.suffix in [".fastq", ".fastq.gz", ".fasta"]:
    input_flag = "--fastq "
elif input_path.suffix == ".bam":
    input_flag = "--bam "
else:
    input_flag = "--sequencing-summary-source "

This approach has several benefits:

  • It makes the code more readable by using descriptive variable names (input_path) and methods (.suffix).
  • It eliminates the need for multiple if statements and makes the code more concise.
  • It handles file extensions in a case-sensitive manner, which is more reliable.
Tools
Ruff

9-9: Undefined name snakemake

(F821)


9-9: Undefined name snakemake

(F821)


9-9: Undefined name snakemake

(F821)


9-9: Undefined name snakemake

(F821)


11-11: Undefined name snakemake

(F821)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5928b90 and c8e8f53.

Files selected for processing (5)
  • bio/toulligqc/environment.yaml (1 hunks)
  • bio/toulligqc/meta.yaml (1 hunks)
  • bio/toulligqc/test/Snakefile (1 hunks)
  • bio/toulligqc/wrapper.py (1 hunks)
  • test.py (1 hunks)
Files skipped from review due to trivial changes (1)
  • bio/toulligqc/environment.yaml
Additional context used
Path-based instructions (2)
bio/toulligqc/wrapper.py (2)

Pattern **/*.py: Do not try to improve formatting.
Do not suggest type annotations for functions that are defined inside of functions or methods.
Do not suggest type annotation of the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return statement.


Pattern **/wrapper.py: Do not complain about use of undefined variable called snakemake.

test.py (1)

Pattern **/*.py: Do not try to improve formatting.
Do not suggest type annotations for functions that are defined inside of functions or methods.
Do not suggest type annotation of the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return statement.

yamllint
bio/toulligqc/meta.yaml

[error] 12-12: no new line character at the end of file

(new-line-at-end-of-file)

Ruff
bio/toulligqc/wrapper.py

9-9: Undefined name snakemake

(F821)


9-9: Undefined name snakemake

(F821)


9-9: Undefined name snakemake

(F821)


9-9: Undefined name snakemake

(F821)


11-11: Undefined name snakemake

(F821)


13-13: Undefined name snakemake

(F821)


14-14: Undefined name snakemake

(F821)

Additional comments not posted (4)
bio/toulligqc/test/Snakefile (1)

1-11: LGTM!

The Snakemake rule for toulligqc is correctly defined with the necessary directives:

  • input: Specifies the input file.
  • output: Specifies the output file.
  • log: Specifies the log file.
  • params: Specifies optional additional parameters.
  • wrapper: Specifies the wrapper to use.

The code changes are approved.

bio/toulligqc/meta.yaml (1)

1-12: LGTM!

The metadata file for toulligqc is correctly defined with the necessary fields:

  • name: Specifies the name of the project.
  • description: Provides a brief description of the project.
  • url: Specifies the URL to the project's documentation.
  • authors: Lists the authors of the project.
  • input: Describes the input data.
  • output: Describes the output data.
  • params: Describes the optional parameters.

The code changes are approved.

Tools
yamllint

[error] 12-12: no new line character at the end of file

(new-line-at-end-of-file)

bio/toulligqc/wrapper.py (1)

1-19: LGTM!

The Python script for the toulligqc wrapper is correctly implemented:

  • It handles different input file types (.fastq, .fastq.gz, .fasta, .bam) and sets the appropriate input flag.
  • It retrieves the optional extra parameters from snakemake.params.
  • It constructs the toulligqc command with the necessary arguments and runs it using snakemake.shell.

The code changes are approved.

Tools
Ruff

9-9: Undefined name snakemake

(F821)


9-9: Undefined name snakemake

(F821)


9-9: Undefined name snakemake

(F821)


9-9: Undefined name snakemake

(F821)


11-11: Undefined name snakemake

(F821)


13-13: Undefined name snakemake

(F821)


14-14: Undefined name snakemake

(F821)

test.py (1)

6917-6927: LGTM!

The new test_toulligqc function looks good. It follows the established pattern for test functions in this file.

bio/toulligqc/meta.yaml Outdated Show resolved Hide resolved
bio/toulligqc/wrapper.py Outdated Show resolved Hide resolved
bio/toulligqc/meta.yaml Outdated Show resolved Hide resolved
bio/toulligqc/wrapper.py Outdated Show resolved Hide resolved
Copy link
Contributor

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d8e973e and 34f24bc.

Files selected for processing (1)
  • bio/toulligqc/wrapper.py (1 hunks)
Additional context used
Path-based instructions (1)
bio/toulligqc/wrapper.py (2)

Pattern **/*.py: Do not try to improve formatting.
Do not suggest type annotations for functions that are defined inside of functions or methods.
Do not suggest type annotation of the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return statement.


Pattern **/wrapper.py: Do not complain about use of undefined variable called snakemake.

Ruff
bio/toulligqc/wrapper.py

9-9: Undefined name snakemake

(F821)


10-10: Undefined name snakemake

(F821)


12-12: Undefined name snakemake

(F821)


21-21: Undefined name snakemake

(F821)


22-22: Undefined name snakemake

(F821)

Additional comments not posted (5)
bio/toulligqc/wrapper.py (5)

1-4: LGTM!

The metadata variables are properly defined and contain appropriate information.


6-7: LGTM!

The imported modules are necessary and properly used in the script.


9-19: Great job addressing the past review comments!

The code segment correctly determines the input flag based on the file type and handles compressed files as suggested in the previous review. The supported file extensions have also been expanded to include .fas and .fq.

Tools
Ruff

9-9: Undefined name snakemake

(F821)


10-10: Undefined name snakemake

(F821)


12-12: Undefined name snakemake

(F821)


21-22: LGTM!

The code segment correctly retrieves extra parameters and formats the logging output using the snakemake object. The static analysis hint about snakemake being an undefined name can be ignored because it is a valid object in the context of a Snakemake wrapper script.

Tools
Ruff

21-21: Undefined name snakemake

(F821)


22-22: Undefined name snakemake

(F821)


26-29: LGTM!

The empty lines at the end of the file are acceptable and do not affect the functionality of the script.

bio/toulligqc/wrapper.py Outdated Show resolved Hide resolved
bio/toulligqc/meta.yaml Outdated Show resolved Hide resolved
bio/toulligqc/wrapper.py Outdated Show resolved Hide resolved
bio/toulligqc/wrapper.py Outdated Show resolved Hide resolved
bio/toulligqc/wrapper.py Outdated Show resolved Hide resolved
bio/toulligqc/wrapper.py Outdated Show resolved Hide resolved
bio/toulligqc/wrapper.py Outdated Show resolved Hide resolved
@Salome-Brunon
Copy link
Contributor Author

@fgvieira Thank you for all the edits!

@fgvieira
Copy link
Collaborator

Sure. 😄
Can you just add some small tests for fastq and bam files?

@Salome-Brunon
Copy link
Contributor Author

Sure. 😄 Can you just add some small tests for fastq and bam files?

Yes of course, I'll work on that next week!

@fgvieira fgvieira self-assigned this Sep 20, 2024
Copy link
Contributor

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

Outside diff range and nitpick comments (2)
bio/toulligqc/test/Snakefile (2)

8-9: Consider adding documentation for extra parameters.

The "extra" parameter in the params section provides flexibility, but there's no guidance on what kinds of additional parameters are allowed or useful.

Consider adding a comment or docstring explaining the possible extra parameters:

 rule toulligqc:
     params:
-        extra="",  # optional additional parameters as string
+        extra="",  # optional additional parameters as string
+        # Possible extra parameters include:
+        # --min_pass_qual: Minimum quality score for a read to be considered as pass
+        # --fast5_dir: Directory containing FAST5 files
+        # For more options, see: https://toulligqc.readthedocs.io/en/latest/usage.html

This will help users understand how to utilize the extra parameter effectively.


1-11: Overall assessment: Good structure with room for improvement.

The Snakefile for the toulligqc wrapper is well-structured and follows Snakemake conventions. However, there are several areas where it could be improved:

  1. Input and output paths could be parameterized for better flexibility in testing.
  2. The log file path could be more specific to avoid potential conflicts.
  3. Documentation for the extra parameters could be expanded.
  4. The wrapper version should be pinned to a specific version or commit hash for reproducibility.

Implementing these suggestions will enhance the flexibility, usability, and reproducibility of this Snakefile.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 34f24bc and 2fd468f.

Files selected for processing (4)
  • bio/toulligqc/meta.yaml (1 hunks)
  • bio/toulligqc/test/Snakefile (1 hunks)
  • bio/toulligqc/wrapper.py (1 hunks)
  • test.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • bio/toulligqc/meta.yaml
Additional context used
Path-based instructions (2)
bio/toulligqc/wrapper.py (2)

Pattern **/*.py: Do not try to improve formatting.
Do not suggest type annotations for functions that are defined inside of functions or methods.
Do not suggest type annotation of the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return statement.


Pattern **/wrapper.py: Do not complain about use of undefined variable called snakemake.

test.py (1)

Pattern **/*.py: Do not try to improve formatting.
Do not suggest type annotations for functions that are defined inside of functions or methods.
Do not suggest type annotation of the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return statement.

Ruff
bio/toulligqc/wrapper.py

9-9: Undefined name snakemake

(F821)


10-10: Undefined name snakemake

(F821)


12-12: Undefined name snakemake

(F821)


23-23: Undefined name snakemake

(F821)

Additional comments not posted (7)
bio/toulligqc/test/Snakefile (1)

1-1: LGTM: Rule declaration is clear and follows conventions.

The rule name toulligqc is descriptive and follows the snake_case naming convention, which is consistent with Snakemake best practices.

bio/toulligqc/wrapper.py (5)

1-4: LGTM: Metadata section is complete and well-formatted.

The metadata section provides all necessary information including author, copyright, email, and license. This follows good practices for code documentation.


6-7: LGTM: Imports are appropriate for a Snakemake wrapper.

The imports of shell from snakemake.shell and Path from pathlib are correct and necessary for the functionality of this wrapper.


9-14: LGTM: Variable initialization and .gz handling are well-implemented.

The initialization of extra and log variables follows Snakemake wrapper conventions. The handling of .gz file extensions is a good practice for flexibility.

Note: The static analysis tool flags snakemake as an undefined variable, but this is expected in Snakemake wrappers as it's implicitly provided by the Snakemake framework.

Tools
Ruff

9-9: Undefined name snakemake

(F821)


10-10: Undefined name snakemake

(F821)


12-12: Undefined name snakemake

(F821)


16-25: LGTM: Main execution block addresses previous concerns and implements correct logic.

The code effectively determines the appropriate input flag based on file extensions, including .fastq, .fq, and .bam. The output directory is correctly inferred from the first output file, addressing a previous concern. The shell command is well-constructed, including all necessary parameters and the --force flag as suggested in a past review.

This implementation successfully addresses the feedback from previous reviews and provides a flexible and robust execution of the toulligqc tool.

Tools
Ruff

23-23: Undefined name snakemake

(F821)


1-25: Excellent implementation of the toulligqc Snakemake wrapper.

This wrapper successfully implements the toulligqc tool within the Snakemake framework. Key points:

  1. Proper metadata and imports are in place.
  2. Variable initialization follows Snakemake conventions.
  3. The code handles various input file types (FASTQ, FQ, BAM) and compressed (.gz) files.
  4. Output directory is correctly inferred from the output files.
  5. The shell command is well-constructed with all necessary parameters.

The implementation addresses all concerns raised in previous reviews and provides a flexible, robust solution for integrating toulligqc into Snakemake workflows.

Tools
Ruff

9-9: Undefined name snakemake

(F821)


10-10: Undefined name snakemake

(F821)


12-12: Undefined name snakemake

(F821)


23-23: Undefined name snakemake

(F821)

test.py (1)

6943-6955: LGTM! The new test function for ToulligQC is correctly implemented.

The test_toulligqc() function follows the same pattern as other test functions in this file:

  1. It uses the @skip_if_not_modified decorator.
  2. It calls the run() function with appropriate arguments.
  3. The Snakemake command is correctly formatted with the expected output file and necessary flags.

The function tests the ToulligQC wrapper by running Snakemake to generate the report.html file in the toulligqc_sequencing_summary directory.

bio/toulligqc/test/Snakefile Outdated Show resolved Hide resolved
bio/toulligqc/test/Snakefile Show resolved Hide resolved
bio/toulligqc/test/Snakefile Show resolved Hide resolved
Copy link
Contributor

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2fd468f and 4cd04e6.

Files ignored due to path filters (1)
  • bio/toulligqc/test/demodata/test.fastq.gz is excluded by !**/*.gz
Files selected for processing (1)
  • bio/toulligqc/test/Snakefile (1 hunks)
Additional comments not posted (1)
bio/toulligqc/test/Snakefile (1)

6-7: Use a more specific log file path

The current log file path might lead to conflicts or overwriting if multiple runs are performed. Consider using a more specific log file path:

     log:
-        "merged.log",
+        "logs/toulligqc_sequencing_summary.log",

This change will help prevent log file conflicts and make it easier to associate logs with specific runs.

Likely invalid or redundant comment.

bio/toulligqc/test/Snakefile Outdated Show resolved Hide resolved
bio/toulligqc/test/Snakefile Show resolved Hide resolved
bio/toulligqc/test/Snakefile Show resolved Hide resolved
bio/toulligqc/test/Snakefile Show resolved Hide resolved
bio/toulligqc/test/Snakefile Show resolved Hide resolved
bio/toulligqc/test/Snakefile Outdated Show resolved Hide resolved
bio/toulligqc/test/Snakefile Outdated Show resolved Hide resolved
bio/toulligqc/test/Snakefile Show resolved Hide resolved
bio/toulligqc/test/Snakefile Show resolved Hide resolved
@Salome-Brunon
Copy link
Contributor Author

@fgvieira Hello! I have submitted the test bam and fast files, is there anything else needed for this PR to be approved? :)

@fgvieira
Copy link
Collaborator

you need to add the tests to the test.py file. I've suggested the changes, so just accept them all.

@fgvieira
Copy link
Collaborator

Thanks for your contribution. Great work! 😄

@fgvieira fgvieira merged commit 874c84e into snakemake:master Sep 24, 2024
6 checks passed
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