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: use primer3-py for primer3 instead of the executable #101

Merged
merged 4 commits into from
Jan 14, 2025
Merged

Conversation

nh13
Copy link
Member

@nh13 nh13 commented Dec 13, 2024

No description provided.

@@ -208,7 +208,7 @@ def __str__(self) -> str:
"""
# If the bases field is None, replace with MISSING_BASES_STRING
bases: str = self.bases if self.bases is not None else MISSING_BASES_STRING
return f"{bases}\t{self.tm}\t{self.penalty}\t{self.span}"
return f"{bases}\t{self.tm:.2f}\t{self.penalty:.2f}\t{self.span}"
Copy link
Member Author

Choose a reason for hiding this comment

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

QoL improvement

Copy link

codecov bot commented Dec 14, 2024

Codecov Report

Attention: Patch coverage is 94.44444% with 2 lines in your changes missing coverage. Please review.

Project coverage is 97.30%. Comparing base (c154af9) to head (5e02f02).
Report is 2 commits behind head on dev.

Files with missing lines Patch % Lines
prymer/primer3/primer3.py 92.59% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #101      +/-   ##
==========================================
+ Coverage   96.81%   97.30%   +0.48%     
==========================================
  Files          26       26              
  Lines        1789     1778      -11     
  Branches      215      208       -7     
==========================================
- Hits         1732     1730       -2     
+ Misses         31       27       -4     
+ Partials       26       21       -5     

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

Copy link
Member

@tfenne tfenne left a comment

Choose a reason for hiding this comment

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

This is very cool - and I'm surprised at actually how small of a PR this is!!

Comment on lines 387 to 391
for tag, value in assembled_primer3_tags.items():
tag_str = f"{tag}"
if tag_str.startswith("SEQUENCE"):
seq_args[tag_str] = value
else:
global_args[tag] = value
Copy link
Member

Choose a reason for hiding this comment

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

This works ... but I think we could probably also add a is_global_arg() to Primer3InputTag that does this more efficiently (e.g. based on ordinal) or split Primer3InputTag into two classes - one for globals and one for sequence tags?

Copy link
Member Author

Choose a reason for hiding this comment

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

Since PrimerInputTag's value is a string, I don't think it's inefficient, so I am going to centralize this as properties in the enum, and get rid of the f-string call (since I don't think that is needed).

Comment on lines 396 to 400
for key, value in design_primers_retval.items():
# Because Primer3 will emit both the input given and the output generated, we
# discard the input that is echo'ed back by looking for tags (keys)
# that do not match any Primer3InputTag
if not any(key == item.value for item in Primer3InputTag):
primer3_results[key] = value
Copy link
Member

Choose a reason for hiding this comment

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

Is this actually needed? I don't think there's any harm in allow the inputs to be present in the dict() used below.

If you feel strongly about this .. perhaps we have a more efficient way than looping through all the values in Primer3InputTag - e.g. create a _ALL_INPUT_TAG_STRINGS set and at the class level and check for membership?

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'll keep removing them, we can open a PR later if you want to see them. I made it not inefficient via set membership.

prymer/primer3/primer3.py Outdated Show resolved Hide resolved
@nh13 nh13 requested a review from tfenne January 13, 2025 21:47
@nh13 nh13 marked this pull request as ready for review January 13, 2025 21:47
Copy link

coderabbitai bot commented Jan 13, 2025

Walkthrough

The pull request introduces several modifications across the Prymer library. In oligo.py, the string representation of the Oligo class now formats tm and penalty attributes to two decimal places. The primer3.py file undergoes a significant refactoring, transitioning the Primer3 class to use context management and directly utilize the primer3 module for primer design. The primer3_input_tag.py adds new properties to distinguish between sequence-specific and global input tags. The pyproject.toml adds a new dependency and updates type-checking configurations. Test files are updated to reflect these changes, with refined error handling and new test cases to validate the new functionality.

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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

🧹 Nitpick comments (3)
prymer/primer3/primer3.py (2)

248-256: Remove unnecessary call to super().__exit__().

Since AbstractContextManager does not have an operational __exit__ method, calling super().__exit__() is redundant and can be omitted.

Apply this diff to remove the call:

 def __exit__(
     self,
     exc_type: Optional[type[BaseException]],
     exc_value: Optional[BaseException],
     traceback: Optional[TracebackType],
 ) -> None:
     """Gracefully terminates any running subprocesses."""
-    super().__exit__(exc_type, exc_value, traceback)
     self.close()

383-393: Simplify tag separation with dictionary comprehensions.

You can streamline the splitting of assembled_primer3_tags into seq_args and global_args using dictionary comprehensions.

Apply this refactor:

-        seq_args = {}
-        global_args = {}
-        for tag, value in assembled_primer3_tags.items():
-            if tag.is_sequence_arg:
-                seq_args[tag] = value
-            else:
-                global_args[tag] = value
+        seq_args = {tag: value for tag, value in assembled_primer3_tags.items() if tag.is_sequence_arg}
+        global_args = {tag: value for tag, value in assembled_primer3_tags.items() if not tag.is_sequence_arg}
prymer/primer3/primer3_input_tag.py (1)

34-43: Enhance docstrings for clarity.

Provide more detailed docstrings for is_sequence_arg and is_global_arg to explain their roles and usage.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2656adf and ce10c4d.

⛔ Files ignored due to path filters (1)
  • poetry.lock is excluded by !**/*.lock
📒 Files selected for processing (7)
  • prymer/api/oligo.py (1 hunks)
  • prymer/primer3/primer3.py (9 hunks)
  • prymer/primer3/primer3_input_tag.py (1 hunks)
  • pyproject.toml (2 hunks)
  • tests/api/test_oligo.py (9 hunks)
  • tests/primer3/test_primer3.py (2 hunks)
  • tests/primer3/test_primer3_input_tag.py (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • prymer/api/oligo.py
  • tests/api/test_oligo.py
🧰 Additional context used
🪛 GitHub Check: codecov/patch
prymer/primer3/primer3.py

[warning] 406-406: prymer/primer3/primer3.py#L406
Added line #L406 was not covered by tests


[warning] 408-408: prymer/primer3/primer3.py#L408
Added line #L408 was not covered by tests

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Tests (3.12)
🔇 Additional comments (6)
prymer/primer3/primer3.py (1)

404-410: 🛠️ Refactor suggestion

Add tests for error handling paths.

Lines 406 and 409 raise exceptions but are not covered by tests. Enhance your test suite to include scenarios that trigger these exceptions.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 406-406: prymer/primer3/primer3.py#L406
Added line #L406 was not covered by tests


[warning] 408-408: prymer/primer3/primer3.py#L408
Added line #L408 was not covered by tests

tests/primer3/test_primer3_input_tag.py (1)

4-9: Tests effectively validate new properties.

The test function accurately verifies the is_sequence_arg and is_global_arg properties for all tags.

tests/primer3/test_primer3.py (2)

162-162: LGTM: Error message is more specific.

New error message better reflects the actual validation failure.


364-364: LGTM: Error message matches new implementation.

Error message correctly reflects file I/O error instead of subprocess termination.

pyproject.toml (2)

43-43: LGTM: Added primer3-py dependency.

Version constraint ^2.0.3 is appropriate.


122-122: LGTM: Updated mypy configuration.

Added primer3 to ignore_missing_imports list.

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

🧹 Nitpick comments (2)
prymer/primer3/primer3.py (2)

442-442: Consider using a more specific type than Any.

While Any works, a more specific type like Union[str, int, float] would provide better type safety.

Also applies to: 547-547, 610-610


404-405: Remove outdated comment about error_lines.

Comment references removed error handling logic.

-        # Check for any errors.  Typically, these are in error_lines, but also the results can
-        # contain the PRIMER_ERROR key.
+        # Check for any errors in the results
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ce10c4d and 31c73fd.

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

213-213: LGTM: Clean context manager implementation.

Proper resource management with context manager protocol.

Also applies to: 245-256, 258-259


384-392: LGTM: Clean refactoring to use primer3 module.

Efficient separation of sequence and global arguments.

@nh13 nh13 changed the base branch from main to dev January 14, 2025 20:06
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

🧹 Nitpick comments (1)
prymer/primer3/primer3.py (1)

404-405: Update comment to match implementation.

Comment mentions error_lines but code only checks PRIMER_ERROR.

-        # Check for any errors.  Typically, these are in error_lines, but also the results can
-        # contain the PRIMER_ERROR key.
+        # Check for any errors in the PRIMER_ERROR key.
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 31c73fd and d9b7dc8.

⛔ Files ignored due to path filters (1)
  • poetry.lock is excluded by !**/*.lock
📒 Files selected for processing (7)
  • prymer/api/oligo.py (1 hunks)
  • prymer/primer3/primer3.py (9 hunks)
  • prymer/primer3/primer3_input_tag.py (1 hunks)
  • pyproject.toml (3 hunks)
  • tests/api/test_oligo.py (9 hunks)
  • tests/primer3/test_primer3.py (2 hunks)
  • tests/primer3/test_primer3_input_tag.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • tests/api/test_oligo.py
  • prymer/api/oligo.py
  • prymer/primer3/primer3_input_tag.py
  • tests/primer3/test_primer3.py
  • tests/primer3/test_primer3_input_tag.py
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Tests (3.12)
🔇 Additional comments (7)
pyproject.toml (3)

3-3: LGTM: Major version bump is appropriate.

Breaking change from executable to library justifies the bump to 3.0.0.


122-122: LGTM: Mypy override added for primer3.

Consistent with existing pattern for external dependencies.


43-43: Verify primer3-py version.

Check if 2.0.3 is the latest stable version.

✅ Verification successful

Version 2.0.3 is current. No security issues.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check PyPI for latest version and potential security advisories
curl -s https://pypi.org/pypi/primer3-py/json | jq '.info.version'

# Check for security advisories
gh api graphql -f query='
{
  securityVulnerabilities(first: 5, ecosystem: PIP, package: "primer3-py") {
    nodes {
      advisory {
        summary
        severity
        publishedAt
      }
      vulnerableVersionRange
      firstPatchedVersion {
        identifier
      }
    }
  }
}'

Length of output: 418

prymer/primer3/primer3.py (4)

213-213: LGTM: Context manager implementation is correct.

Clean transition from ExecutableRunner to AbstractContextManager.

Also applies to: 245-256


384-392: LGTM: Clean primer3 library integration.

Efficient separation of sequence and global args.


442-442: LGTM: Type changes accommodate primer3-py return types.

Consistent use of dict[str, Any] across methods.

Also applies to: 547-547, 610-610


89-93: LGTM: Consistent string formatting.

Clear and readable output format for oligo properties.

@nh13 nh13 merged commit d5e0869 into dev Jan 14, 2025
6 of 7 checks passed
@nh13 nh13 deleted the feat/primer3-py branch January 14, 2025 20:40
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