Skip to content

Conversation

dlaehnemann
Copy link
Member

@dlaehnemann dlaehnemann commented Jun 6, 2025

The use case that motivates this, is to generate a datavzrd report table for all the candidate variants that were filtered out due to their PROB_ARTIFACT during FDR control filtering.

The only way that I see to cleanly do this, is to generate two variant sets:

  1. A regular variant set that excludes artifacts as is usually intended.
  2. A second variant set based on the same varlociraptor events, but with retain-artifacts: true set.

We can then take the complement of 1 in 2, to extract those candidate variants that are only found in 2 (with retain-artifacts: true).

This functionality might also be interesting for other debugging scenarios or intensive inspection of variant sets, but is probably not common enough to warrant putting it in the main default config/config.yaml that comes with every snakedeployment as a module.

Summary by CodeRabbit

  • New Features

    • Introduced support for "complement events" in variant and fusion reporting, enabling identification and reporting of filtered artifacts.
    • Added new filtering and FDR control options, including refined event definitions and a more stringent FDR threshold.
    • Enabled report generation by default.
    • Added standardized mutation overview plots activation with maftools.
  • Improvements

    • Unified event handling and naming conventions across workflows for greater consistency by replacing event wildcards with a unified any_event wildcard.
    • Expanded annotation scope to include more information in variant call outputs.
    • Enhanced configuration flexibility for artifact retention and event-specific settings.
  • Bug Fixes

    • Corrected dynamic naming in reporting templates to use updated wildcard keys.
  • Style

    • Minor formatting and whitespace improvements for clarity in workflow definitions.

Copy link

coderabbitai bot commented Jun 6, 2025

Walkthrough

This update restructures and expands the configuration and workflow logic for FDR control and event handling in variant calling. It introduces complement events, refines artifact retention parameters, generalizes event wildcards to any_event, and updates relevant Snakemake rules and templates to support the new event handling and reporting mechanisms.

Changes

File(s) Change Summary
.test/config-sra/config.yaml, config/config.yaml Expanded and restructured FDR control configuration, added complement events, refined artifact retention, updated annotation and reporting flags.
workflow/rules/common.smk Added complement_events support, new helper functions, updated event wildcard handling to any_event, and related logic changes.
workflow/rules/datavzrd.smk, workflow/resources/datavzrd/variant-calls-template.datavzrd.yaml, workflow/resources/datavzrd/fusion-calls-template.datavzrd.yaml Replaced {event} wildcard with {any_event} in rule and template paths, updated parameter resolution for events, and upgraded wrapper versions.
workflow/rules/filtering.smk Added merge_exclude_events and complement_event rules, generalized convert_phred_scores to use {any_event}.
workflow/rules/table.smk Updated vembrane_table rule to use {any_event} wildcard in file paths.
workflow/rules/maf.smk Replaced {event} wildcard with {any_event} in rules, minor whitespace and formatting adjustments; no logic changes.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Snakemake
    participant Config
    participant FilteringRules
    participant DatavzrdRules

    User->>Snakemake: Trigger workflow
    Snakemake->>Config: Load config.yaml (with events & complement_events)
    Snakemake->>FilteringRules: Run merge_exclude_events (if complement event defined)
    FilteringRules->>FilteringRules: Merge BCFs for excluded events
    Snakemake->>FilteringRules: Run complement_event (set subtraction)
    FilteringRules->>FilteringRules: bcftools isec (full event - exclude set)
    Snakemake->>DatavzrdRules: Process variant/fusion calls with {any_event}
    DatavzrdRules->>Config: Resolve event via get_any_event
    DatavzrdRules->>DatavzrdRules: Generate reports and outputs for each event/complement event
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Possibly related PRs

Suggested reviewers

  • johanneskoester

Poem

In the warren of configs, new events now bloom,
With complements and filters, there's plenty of room.
Artifacts are tamed, wildcards set free,
Reports hop to life for all to see.
Snakemake bunnies leap, their logic refined—
In the garden of variants, all events aligned! 🐇

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 edd5604 and 2fc499b.

📒 Files selected for processing (1)
  • workflow/rules/datavzrd.smk (9 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • workflow/rules/datavzrd.smk
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/add-complement-events

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

Support

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

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 generate unit tests to generate unit tests 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.

@dlaehnemann
Copy link
Member Author

Also, the branching off of an older release version is intended, as we need this functionality in a workflow, where we don't want to re-trigger analyses that later changes in the workflow would trigger. But we can update this branch, once we have reviewed everything and before we merge it. But then the user can point to the last commit that works for them.

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: 2

🧹 Nitpick comments (1)
workflow/rules/common.smk (1)

1512-1512: Consider following PEP 8 spacing conventions.

The removal of spaces around the subtraction operator goes against PEP 8 style guidelines which recommend spaces around binary operators.

-        extra += f" -T {min_primer_len-2}"
+        extra += f" -T {min_primer_len - 2}"
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 200acc8 and 2243864.

📒 Files selected for processing (9)
  • .test/config-sra/config.yaml (3 hunks)
  • config/config.yaml (1 hunks)
  • workflow/resources/datavzrd/fusion-calls-template.datavzrd.yaml (1 hunks)
  • workflow/resources/datavzrd/variant-calls-template.datavzrd.yaml (1 hunks)
  • workflow/rules/common.smk (8 hunks)
  • workflow/rules/datavzrd.smk (8 hunks)
  • workflow/rules/filtering.smk (1 hunks)
  • workflow/rules/maf.smk (1 hunks)
  • workflow/rules/table.smk (1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.37.1)
.test/config-sra/config.yaml

[error] 58-58: trailing spaces

(trailing-spaces)


[error] 61-61: trailing spaces

(trailing-spaces)


[error] 69-69: trailing spaces

(trailing-spaces)


[error] 78-78: trailing spaces

(trailing-spaces)

⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: test no candidate filtering
  • GitHub Check: test sra download
  • GitHub Check: test local input
  • GitHub Check: test target regions, multiple BEDs
  • GitHub Check: test primers
  • GitHub Check: test testcase generation
  • GitHub Check: test target regions
🔇 Additional comments (18)
workflow/resources/datavzrd/variant-calls-template.datavzrd.yaml (1)

3-3: LGTM! Wildcard update aligns with complement events feature.

The change from wildcards.event to wildcards.any_event correctly supports the new event handling that includes both standard and complement events.

workflow/resources/datavzrd/fusion-calls-template.datavzrd.yaml (1)

3-3: LGTM! Consistent wildcard update.

The wildcard change matches the pattern in variant-calls-template.datavzrd.yaml and properly supports the unified event handling.

config/config.yaml (1)

171-174: LGTM! Improved configuration granularity for artifact retention.

Moving retain-artifacts from global to event-specific scope provides the flexibility needed for complement events functionality, where different events may need different artifact retention behaviors.

workflow/rules/maf.smk (2)

36-36: LGTM! Minor formatting improvement.

Removing extra spaces around parameter assignments improves code consistency.


41-41: LGTM! Consistent formatting cleanup.

Matches the formatting improvement applied to the previous lookup call.

workflow/rules/table.smk (3)

3-3: LGTM! Input path updated for unified event handling.

The wildcard change supports both standard and complement events in the table generation workflow.


6-6: LGTM! Output path consistent with wildcard changes.

Properly updated to use the any_event wildcard for unified event handling.


12-12:

✅ Verification successful

Verify that any_event wildcard is properly defined.

The log path update is consistent with other changes. However, ensure that the any_event wildcard is properly defined in the workflow rules to handle both standard and complement events.


🏁 Script executed:

#!/bin/bash
# Description: Verify that any_event wildcard is defined and used consistently across the workflow

# Check for any_event wildcard definition and usage
echo "=== Searching for any_event wildcard definition ==="
rg -A 5 -B 5 "any_event.*=" --type py

echo -e "\n=== Searching for any_event wildcard usage in Snakemake rules ==="
rg "any_event" --type-add 'smk:*.smk' --type smk

echo -e "\n=== Checking for any remaining old event wildcards ==="
rg "\{event\}" --type-add 'smk:*.smk' --type smk

Length of output: 9418


✅ Confirmed any_event wildcard definition and usage

  • The any_event wildcard is defined in workflow/rules/common.smk (via any_event="|".join(...)) and handled in get_any_event for both standard and complement events.
  • workflow/rules/table.smk’s log path (logs/vembrane-table/{group}.{any_event}.{calling_type}.log) matches the established pattern and is used consistently across other rules.

No further action required.

workflow/rules/filtering.smk (2)

98-111: LGTM! Well-structured rule for merging exclude events.

The implementation correctly uses dynamic input generation and appropriate wrapper version for bcftools concat operation.


146-156: Wildcard update correctly implemented.

The systematic replacement of {event} with {any_event} properly extends the rule to handle both regular and complement events.

.test/config-sra/config.yaml (2)

85-93: Well-designed complement events configuration.

The filtered_artifacts event is properly configured to capture variants removed during FDR control, which aligns perfectly with the PR objectives of generating reports for filtered-out candidates.


107-109: Verify the impact of broadening VEP annotations.

Changing from --fields IMPACT to --everything significantly increases the annotation scope, which may impact performance and output size.

Consider whether all annotations are necessary for your use case, as this change could substantially increase processing time and storage requirements.

workflow/rules/datavzrd.smk (2)

10-10: Improved error handling with lookup function.

Good use of the lookup function with a default empty list, making the code more robust when sort configuration is missing.


100-100: Consistent error handling for event descriptions.

The lambda function with lookup and default description ensures the report generation doesn't fail when event descriptions are missing.

workflow/rules/common.smk (4)

144-153: Proper integration of complement events with backward compatibility.

The function correctly extends event collection to include complement events while maintaining compatibility with configurations that don't define them.


460-472: Well-implemented input generation function.

The function follows established patterns and correctly generates input file paths for events to be excluded from complement events.


1002-1014: Correct wildcard constraints for event handling.

The use of symmetric difference (^) for any_event properly ensures mutual exclusivity between regular and complement events.


1559-1564: Clean abstraction for event configuration retrieval.

The get_any_event function provides a simple and effective way to retrieve event configuration regardless of whether it's a regular or complement event.

@johanneskoester
Copy link
Contributor

johanneskoester commented Jun 11, 2025

Can't you get the same by defining an ordinary callset/filter-event that selects everything with an artifact probability of least 5%?

@dlaehnemann
Copy link
Member Author

I think not. Consider a variant with these (decoded) probabilities:

PROB_PRESENT=0.91;
PROB_ARTIFACT=0.041;
PROB_ABSENT=0.049;

With an FDR of 0.05 and setting a call-set that contains only present, this variant would get filtered out in local-smart mode, because 0.91 / (0.91 + 0.049) = 0.9489, which is below 0.95.

If we set retain-artifacts: true, the calculation becomes 0.91 + 0.041 = 0.951, so in this case the variant will be kept in the defined call-set.

I know this is a deliberate corner case, but its existence will mean that we will sometimes miss filtered artifacts if we just do a filtering based on the PROB_ARTIFACT. So I think we won't get around doing the set complement to get a clean set of variants filtered due to PROB_ARTIFACT.

Also, there might be other scenarios, where we might want to do complementing of sets, because we might have a scenario with lots of fine-grained probabilities and we want to figure out which variants will be excluded if we just exclude one of those fine-grained probabilities from the call-set definition.

@johanneskoester
Copy link
Contributor

johanneskoester commented Jun 11, 2025

I see the point. Maybe it would be more convenient and less complex to maintain as a functionality of the varlociraptor control-fdr subcommand though? In the sense of that you can specify additional output files there for storing stuff that was filtered out, stratified by the strongest non-target event?

@dlaehnemann
Copy link
Member Author

Yes, that is a good idea. Basically have the option for varlociraptor to also output everything that it removes during fdr-control, and output one file per non-target varlociraptor (scenario) event, including absent and artifact.

Then I guess we will not merge this pull request here, but I would like to keep the branch around for our current analysis.

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