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

Make sure the number_probes_returned is respected. #79

Merged
merged 2 commits into from
Nov 8, 2024

Conversation

tfenne
Copy link
Member

@tfenne tfenne commented Nov 7, 2024

No description provided.

@tfenne tfenne requested a review from msto November 7, 2024 20:58
@tfenne tfenne requested a review from nh13 as a code owner November 7, 2024 20:58
@@ -219,6 +219,7 @@ def to_input_tags(self) -> dict[Primer3InputTag, Any]:
Primer3InputTag.PRIMER_INTERNAL_MAX_GC: self.probe_gcs.max,
Primer3InputTag.PRIMER_INTERNAL_MAX_POLY_X: self.probe_max_polyX,
Primer3InputTag.PRIMER_INTERNAL_MAX_NS_ACCEPTED: self.probe_max_Ns,
Primer3InputTag.PRIMER_NUM_RETURN: self.number_probes_return
Copy link
Member

Choose a reason for hiding this comment

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

How hard would it be to implement a unit test to catch a potential regression in the future?

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree this would be nice, but there is not an existing test to amend, and I don't have the time to also fix the test shortcomings at this moment.

Copy link

coderabbitai bot commented Nov 7, 2024

Walkthrough

The pull request introduces several changes to the primer3_parameters.py file, specifically affecting the Primer3Parameters and ProbeParameters classes. The Primer3Parameters class is marked as deprecated, with a warning issued to users to transition to the PrimerAndAmpliconParameters class. This change does not alter the existing functionality of Primer3Parameters.

In the ProbeParameters class, a new attribute named number_probes_return is added, which defaults to 5. This attribute specifies the number of probes to return and is incorporated into the to_input_tags() method's mapping dictionary, enabling it to be passed to Primer3. The method now includes the new tag Primer3InputTag.PRIMER_NUM_RETURN, which was previously absent from the mapping.

The __post_init__ method in both classes retains its validation logic, ensuring that parameters conform to expected types and constraints. The overall structure and purpose of the classes remain consistent, focusing on parameter management for primer and probe design. Additionally, the test cases in tests/primer3/test_primer3_input.py have been updated to enhance assertions and coverage for the Primer3Input functionality, ensuring that the new attribute is validated in the tests.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between dcaf38a and 33d21bb.

📒 Files selected for processing (1)
  • tests/primer3/test_primer3_input.py (1 hunks)
🔇 Additional comments (1)
tests/primer3/test_primer3_input.py (1)

104-106: LGTM! Test coverage added for probe number validation.

The new assertions properly verify that:

  1. The PRIMER_NUM_RETURN tag is included in the mapped dictionary
  2. The total number of mapped tags is updated accordingly (28 keys)

This aligns well with the PR objective of ensuring number_probes_returned is respected.

Let's verify the relationship between this test and the implementation:

✅ Verification successful

Test coverage correctly validates probe number parameter implementation

The verification confirms that:

  • ProbeParameters class properly includes number_probes_return attribute
  • The attribute is correctly mapped to PRIMER_NUM_RETURN tag in multiple places:
    • In parameter mapping: prymer/primer3/primer3_parameters.py
    • In tag definition: prymer/primer3/primer3_input_tag.py
    • In test assertions: Both test_primer3_input.py and test_primer3_parameters.py

The test changes align perfectly with the implementation, providing appropriate coverage for the probe number validation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the ProbeParameters class includes number_probes_returned
# and that it's properly mapped to PRIMER_NUM_RETURN

# Test 1: Check ProbeParameters class definition
rg -A 10 "class ProbeParameters"

# Test 2: Check the mapping implementation
rg "PRIMER_NUM_RETURN" --type py

Length of output: 1718


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

@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)
prymer/primer3/primer3_parameters.py (1)

222-222: Add validation for number_probes_return.

While the implementation aligns well with PrimerAndAmpliconParameters, consider adding validation in post_init to ensure number_probes_return is positive.

Add this check to post_init:

     def __post_init__(self) -> None:
         if not isinstance(self.probe_sizes.min, int):
             raise TypeError("Probe sizes must be integers")
         if not isinstance(self.probe_tms.min, float) or not isinstance(self.probe_gcs.min, float):
             raise TypeError("Probe melting temperatures and GC content must be floats")
         if self.probe_max_dinuc_bases % 2 == 1:
             raise ValueError("Max threshold for dinucleotide bases must be an even number of bases")
+        if self.number_probes_return <= 0:
+            raise ValueError("number_probes_return must be positive")
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5d79a52 and 9edd3be.

📒 Files selected for processing (1)
  • prymer/primer3/primer3_parameters.py (1 hunks)
🔇 Additional comments (2)
prymer/primer3/primer3_parameters.py (2)

222-222: LGTM! This change ensures number_probes_return is respected.

The addition of PRIMER_NUM_RETURN to the mapped dictionary correctly propagates the number_probes_return parameter to Primer3, matching the behavior in PrimerAndAmpliconParameters.


222-222: Verify test coverage for number_probes_return.

Let's ensure there's adequate test coverage for this change.

✅ Verification successful

Test coverage exists and implementation is consistent

The verification shows:

  • Test coverage exists in tests/primer3/test_primer3_parameters.py which verifies the number_probes_return value
  • The PRIMER_NUM_RETURN tag is used consistently across the codebase:
    • As an enum in primer3_input_tag.py
    • In parameter mapping in primer3_parameters.py
    • With consistent default value of 5 in both implementation and tests
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for test coverage and potential conflicts

# Test 1: Look for existing tests of number_probes_return
echo "Checking for existing tests..."
rg -l "number_probes_return" --type py --glob "test_*.py"

# Test 2: Check for any direct usage of PRIMER_NUM_RETURN that might conflict
echo "Checking for direct PRIMER_NUM_RETURN usage..."
rg "PRIMER_NUM_RETURN" --type py --exclude "primer3_parameters.py"

Length of output: 708


Script:

#!/bin/bash
# Let's try a different approach to search for tests and usages

# Search for test files containing number_probes_return
echo "=== Searching for test coverage ==="
rg "number_probes_return" -C 3 --type py

# Search for PRIMER_NUM_RETURN usages
echo -e "\n=== Searching for PRIMER_NUM_RETURN usages ==="
rg "PRIMER_NUM_RETURN" -C 3 --type py

Length of output: 5364

Copy link
Collaborator

@msto msto left a comment

Choose a reason for hiding this comment

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

Hey @tfenne

Thanks for catching this and pushing a fix. I noticed there's another attribute on the parameters dataclass (probe_max_dinuc_bases) that isn't propagated to the input tag dict.

Should we review all the parameter dataclasses to ensure that all included parameters are represented in the corresponding input tag dicts?

Also, how did you and Nils determine which subset of primer3 input tags to expose in fgprimer and prymer? I noticed there are several tags relevant to probe design which we don't include. e.g. related to your comments yesterday about ensuring the melting temperature calculation receives the same parameters as IDT uses, prymer does not currently permit the user to specify PRIMER_INTERNAL_SALT_MONOVALENT or PRIMER_INTERNAL_SALT_DIVALENT, or DMSO/DNA/formamide concentration

Screenshot 2024-11-08 at 9 19 17 AM

@@ -219,6 +219,7 @@ def to_input_tags(self) -> dict[Primer3InputTag, Any]:
Primer3InputTag.PRIMER_INTERNAL_MAX_GC: self.probe_gcs.max,
Primer3InputTag.PRIMER_INTERNAL_MAX_POLY_X: self.probe_max_polyX,
Primer3InputTag.PRIMER_INTERNAL_MAX_NS_ACCEPTED: self.probe_max_Ns,
Primer3InputTag.PRIMER_NUM_RETURN: self.number_probes_return
Copy link
Collaborator

Choose a reason for hiding this comment

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

note probe_max_dinuc_bases is also not represented in the input tag mapping

Copy link
Member Author

Choose a reason for hiding this comment

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

This one is actually on purpose - primer3 doesn't do dinuc checking. It's definitely slightly confusing that we then supply the parameter is something that makes it look like it's going to primer3, but the check is done separately after primer3.

@msto
Copy link
Collaborator

msto commented Nov 8, 2024

FYI primer_max_dinuc_bases is also not included in the input tags for PrimerAndAmpliconParameters. I don't see any other examples of attributes that are included on one of the Parameters dataclasses but not in the class's input tags dict.

I'd like to better understand the motivation for limiting these dataclasses to a subset of the available tags/params. It looks like prymer does include all of the primer3 input tags in the Primer3InputTag enum - why not make them available for the user to specify?

@tfenne tfenne force-pushed the tf_probes_returned branch from 9edd3be to dcaf38a Compare November 8, 2024 16:39
Copy link

codecov bot commented Nov 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.74%. Comparing base (9f51325) to head (33d21bb).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #79   +/-   ##
=======================================
  Coverage   96.74%   96.74%           
=======================================
  Files          26       26           
  Lines        1751     1751           
  Branches      333      333           
=======================================
  Hits         1694     1694           
  Misses         31       31           
  Partials       26       26           

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

@tfenne tfenne merged commit e9ddc8d into main Nov 8, 2024
7 checks passed
@tfenne tfenne deleted the tf_probes_returned branch November 8, 2024 16:57
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.

3 participants