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

fix: skip REF-only records #576

Merged
merged 4 commits into from
Oct 11, 2024
Merged

fix: skip REF-only records #576

merged 4 commits into from
Oct 11, 2024

Conversation

tedil
Copy link
Contributor

@tedil tedil commented Oct 11, 2024

Skip REF-only (no alternative alleles) records

Summary by CodeRabbit

  • New Features

    • Enhanced error handling with checks for REF-only records and empty alternate bases.
    • Introduced coverage annotation functionality for structural variant records.
    • Improved UUID generation for deterministic outputs.
    • Enhanced clustering logic for accurate grouping of SV records.
    • Modularized record conversion for improved maintainability.
  • Bug Fixes

    • Adjusted record processing to skip empty alternate bases and REF-only records.
  • Tests

    • Expanded test suite to cover additional scenarios and SV callers.

Copy link
Contributor

coderabbitai bot commented Oct 11, 2024

Walkthrough

The changes in the src/annotate/strucvars/mod.rs file enhance the processing of structural variant (SV) data in VCF files. Key modifications include improved error handling, refined UUID generation, updated record processing logic, enhanced clustering logic for SV records, the introduction of a coverage annotation function, and modularized record conversion. Additionally, the test suite has been expanded to validate the new functionalities. Method signatures for several functions have been updated to maintain consistency.

Changes

File Path Change Summary
src/annotate/strucvars/mod.rs - Improved error handling with descriptive messages in run_vcf_to_jsonl.
- Refined UUID generation for deterministic outputs.
- Adjusted record processing logic for empty alternate bases.
- Enhanced clustering logic for SV records.
- Introduced annotate_cov_mq function for coverage annotation.
- Modularized conversion to VarFishStrucvarTsvRecord.
- Expanded test suite for additional coverage.
- Updated method signatures for several functions.

Poem

In the code where variants play,
Improvements hop and dance today.
With UUIDs so neat and bright,
And errors logged to shed some light.
Clusters form in genomic grace,
As coverage joins the data race! 🐇✨


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 and nitpick comments (1)
src/annotate/strucvars/mod.rs (1)

2962-2966: Adjust log level and remove unnecessary comma

If skipping REF-only records is expected behavior, consider changing the log level from warning to info to reduce log noise. Additionally, remove the unnecessary comma after record in the logging statement.

Apply this diff to implement the suggestions:

             if record.alternate_bases().is_empty() {
                 // REF-only, skip
-                tracing::warn!("skipping REF-only record {:?}", record,);
+                tracing::info!("skipping REF-only record {:?}", record);
                 continue;
             }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c28ffdd and 67eed24.

📒 Files selected for processing (1)
  • src/annotate/strucvars/mod.rs (2 hunks)
🧰 Additional context used

Copy link

codecov bot commented Oct 11, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 74.01%. Comparing base (c28ffdd) to head (2497598).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/annotate/strucvars/mod.rs 50.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #576      +/-   ##
==========================================
- Coverage   74.01%   74.01%   -0.01%     
==========================================
  Files          26       26              
  Lines        9857     9863       +6     
==========================================
+ Hits         7296     7300       +4     
- Misses       2561     2563       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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 and nitpick comments (1)
src/annotate/strucvars/mod.rs (1)

2962-2968: LGTM with a minor optimization suggestion

The logic for skipping REF-only records is correct and the warning message is informative. However, there's a small optimization opportunity in the comparison.

Consider simplifying the comparison by using == directly on the slice:

-        if record.alternate_bases().is_empty()
-            || record.alternate_bases().as_ref() == &["<*>".to_string()]
+        if record.alternate_bases().is_empty()
+            || record.alternate_bases().as_ref() == &[String::from("<*>")]
         {
             // REF-only, skip
             tracing::warn!("skipping REF-only record {:?}", record);
             continue;
         }

This change avoids creating a new String in the comparison, which is slightly more efficient.

🧰 Tools
🪛 GitHub Check: clippy

[warning] 2963-2963: taken reference of right operand
warning: taken reference of right operand
--> src/annotate/strucvars/mod.rs:2963:16
|
2963 | || record.alternate_bases().as_ref() == &["<*>".to_string()]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--------------------
| |
| help: use the right value directly: ["<*>".to_string()]
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#op_ref
= note: #[warn(clippy::op_ref)] on by default

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 67eed24 and d93246a.

📒 Files selected for processing (1)
  • src/annotate/strucvars/mod.rs (2 hunks)
🧰 Additional context used
🪛 GitHub Check: clippy
src/annotate/strucvars/mod.rs

[warning] 2963-2963: taken reference of right operand
warning: taken reference of right operand
--> src/annotate/strucvars/mod.rs:2963:16
|
2963 | || record.alternate_bases().as_ref() == &["<*>".to_string()]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--------------------
| |
| help: use the right value directly: ["<*>".to_string()]
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#op_ref
= note: #[warn(clippy::op_ref)] on by default

src/annotate/strucvars/mod.rs 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: 0

🧹 Outside diff range and nitpick comments (1)
src/annotate/strucvars/mod.rs (1)

2962-2968: LGTM with a minor optimization suggestion

The logic for skipping REF-only or empty ALT records is correct, and the warning log is appropriate. This change improves the robustness of the code by handling these edge cases.

However, there's a minor optimization that can be made in the comparison:

-        if record.alternate_bases().is_empty()
-            || record.alternate_bases().as_ref() == &["<*>".to_string()]
+        if record.alternate_bases().is_empty()
+            || record.alternate_bases().as_ref() == ["<*>".to_string()]

This change avoids taking a reference of the right operand, which is unnecessary in this case.

🧰 Tools
🪛 GitHub Check: clippy

[warning] 2963-2963: taken reference of right operand
warning: taken reference of right operand
--> src/annotate/strucvars/mod.rs:2963:16
|
2963 | || record.alternate_bases().as_ref() == &["<*>".to_string()]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--------------------
| |
| help: use the right value directly: ["<*>".to_string()]
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#op_ref
= note: #[warn(clippy::op_ref)] on by default

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d93246a and 663d67c.

📒 Files selected for processing (1)
  • src/annotate/strucvars/mod.rs (2 hunks)
🧰 Additional context used
🪛 GitHub Check: clippy
src/annotate/strucvars/mod.rs

[warning] 2963-2963: taken reference of right operand
warning: taken reference of right operand
--> src/annotate/strucvars/mod.rs:2963:16
|
2963 | || record.alternate_bases().as_ref() == &["<*>".to_string()]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--------------------
| |
| help: use the right value directly: ["<*>".to_string()]
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#op_ref
= note: #[warn(clippy::op_ref)] on by default

🔇 Additional comments (1)
src/annotate/strucvars/mod.rs (1)

1892-1892: Consider using anyhow::bail! instead of panic!

As mentioned in a previous review, it's generally better to use anyhow::bail! in library code instead of panic!. This allows callers to handle the error gracefully. Consider replacing the panic! with anyhow::bail! like this:

-            panic!("Only one alternative allele is supported for SVs, got {} alternative alleles ({:?})", alleles.len(), alleles);
+            anyhow::bail!("Only one alternative allele is supported for SVs, got {} alternative alleles ({:?})", alleles.len(), alleles);

This change will propagate the error up the call stack instead of terminating the program abruptly.

@tedil tedil enabled auto-merge (squash) October 11, 2024 11:57
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 663d67c and 2497598.

📒 Files selected for processing (1)
  • src/annotate/strucvars/mod.rs (2 hunks)
🧰 Additional context used
🔇 Additional comments (1)
src/annotate/strucvars/mod.rs (1)

1892-1892: Previous comment still applies: Replace panic! with anyhow::bail!

The use of panic! can cause the entire program to terminate unexpectedly. As mentioned in a previous review, consider using anyhow::bail! to allow the error to be handled gracefully.

|| record.alternate_bases().as_ref() == ["<*>".to_string()]
{
// REF-only, skip
tracing::warn!("skipping REF-only / empty ALT record {:?}", record);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Avoid logging entire records to prevent potential sensitive data exposure

Logging the full record may inadvertently expose sensitive information. Consider logging only essential details, such as the record's position and reference sequence name, to avoid potential PII leakage.

Apply this diff to address the issue:

-                tracing::warn!("skipping REF-only / empty ALT record {:?}", record);
+                tracing::warn!(
+                    "skipping REF-only / empty ALT record at {}:{}",
+                    record.reference_sequence_name(),
+                    record.position()
+                );
📝 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
tracing::warn!("skipping REF-only / empty ALT record {:?}", record);
tracing::warn!(
"skipping REF-only / empty ALT record at {}:{}",
record.reference_sequence_name(),
record.position()
);

@tedil tedil merged commit 688b968 into main Oct 11, 2024
9 checks passed
@tedil tedil deleted the strucvars-skip-ref-only-records branch October 11, 2024 12:02
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