-
Notifications
You must be signed in to change notification settings - Fork 3
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: overloaded 'SeqDict.from_sam()' method to support SAM files (#176) #183
base: main
Are you sure you want to change the base?
Conversation
TimD1
commented
Sep 4, 2024
- in addition to pysam SAM headers and SAM header dicts, SeqDicts can now be initialized from SAM file paths and pysam SAM files
- added basic tests for this new functionality
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #183 +/- ##
==========================================
- Coverage 91.06% 90.78% -0.28%
==========================================
Files 18 18
Lines 2283 2301 +18
Branches 337 339 +2
==========================================
+ Hits 2079 2089 +10
- Misses 133 142 +9
+ Partials 71 70 -1 ☔ View full report in Codecov by Sentry. |
2f19451
to
bdf1284
Compare
- in addition to pysam SAM headers and SAM header dicts, SeqDicts can now be initialized from SAM file paths and pysam SAM files - added basic tests for this new functionality
bdf1284
to
45f7eca
Compare
WalkthroughThe pull request introduces changes to the Additionally, the 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🔇 Additional comments (3)
Finishing Touches
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
Plan: Pro
📒 Files selected for processing (3)
fgpyo/fasta/sequence_dictionary.py
(4 hunks)pyproject.toml
(1 hunks)tests/fgpyo/fasta/test_sequence_dictionary.py
(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: testing (3.10)
- GitHub Check: testing (3.9)
🔇 Additional comments (3)
fgpyo/fasta/sequence_dictionary.py (1)
481-499
:from_sam
method implementation effectively handles multiple input types.The use of an
if-elif-else
chain improves readability and accommodates various data inputs as specified.tests/fgpyo/fasta/test_sequence_dictionary.py (1)
335-338
: Test cases validate newfrom_sam
functionality.The added tests ensure that the method correctly processes
Path
andpysam.AlignmentFile
inputs.pyproject.toml (1)
92-96
: Excluding@overload
annotations from coverage improves report accuracy.Adjusting the coverage configuration aligns with best practices for handling type stubs.
except Exception as e: | ||
raise ValueError(f"Could not parse sequence information from data: {data}") from e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Avoid including raw data in exception messages.
Including the entire data
object in the error message may lead to verbose logs or expose sensitive information. Consider providing a more general error message.
Apply this diff to adjust the error message:
-except Exception as e:
- raise ValueError(f"Could not parse sequence information from data: {data}") from e
+except Exception as e:
+ raise ValueError("Could not parse sequence information from provided data.") from e
📝 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.
except Exception as e: | |
raise ValueError(f"Could not parse sequence information from data: {data}") from e | |
except Exception as e: | |
raise ValueError("Could not parse sequence information from provided data.") from e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking really good, nice work! Could you fix up the one TODO and the few other very minor things?
A `SequenceDictionary` mapping refrence names to their metadata. | ||
""" | ||
seq_dict: SequenceDictionary | ||
if isinstance(data, pysam.AlignmentHeader): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is begging for a structural pattern (class pattern) but I think our min python version is 3.9 :/
|
||
return seq_dict | ||
|
||
# TODO: mypy doesn't like these |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FIXME
@@ -88,3 +88,9 @@ warn_unused_configs = true | |||
warn_unused_ignores = true | |||
enable_error_code = "ignore-without-code" | |||
exclude = ["site/", "docs/"] | |||
|
|||
[tool.coverage.report] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
@@ -333,10 +332,15 @@ def test_sequence_dictionary_to_and_from_sam() -> None: | |||
header = pysam.AlignmentHeader.from_dict( | |||
header_dict={"HD": {"VN": "1.5"}, "SQ": mapping, "RG": [{"ID": "foo"}]} | |||
) | |||
|
|||
samfile: Path = builder.SamBuilder(sd=mapping).to_path() | |||
alignment: pysam.AlignmentFile = reader(samfile) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use with a with
statement so it automatically closes.