-
Notifications
You must be signed in to change notification settings - Fork 128
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
Improve parsing of GenBank / GFF files #1351
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8f17677
[utils] refactor 'load_features', add docstrings
jameshadfield 3b27cdc
[utils] lift error handling to load_features
jameshadfield e57e808
[utils] only allow GFFs with one record
jameshadfield a59272c
[utils] GFF parsing doesn't depend on --genes
jameshadfield afa8bd6
[utils] always extract 'nuc' annotation (GFF)
jameshadfield af62d50
[utils] always extract 'nuc' annotation (GenBank)
jameshadfield 580666a
[utils] Forbid gene/CDS with name 'nuc'
jameshadfield 1d17699
[translate] guarantee nuc annotation produced
jameshadfield cd7055a
[utils] warn if unreadable gene/CDS feature
jameshadfield c91ca33
changelog
jameshadfield File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It's a bummer that this
+ 1
logic needs to exist in so many places (ancestral, translate, and utils) to communicate or compare coordinates between different systems. It's the kind of logic that is easy to forget to include in future code and then lead to subtle bugs. I don't have a great suggestion to fix this except maybe encapsulating or replacing theSeqFeature
functionality so we can interact with objects that format coordinates in our expected "one-origin, inclusive" format. That's outside of the scope of this PR though.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.
Totally. Short of adding another layer on top of
SeqFeature
(which might alleviate this problem but at the cost of another layer to understand) I've leaned heavily on writing tests to catch this. Auspice has this issue as well and tests were the only path to sanity!If this were JavaScript you could monkeypatch
SeqFeature
to add the method (prototype)startOneBased
, but in python you would have to create a separate subclass as far as I understand.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.
Oh - so you can monkeypatch things in Python. For instance, adding
at the top of
utils.py
seemingly allows us to call<feature>.location.start_one_based()
, even when those features are created bySeqIO.read(...)
. I found this a bit surprising because that code is (somewhere) going to have its ownimport FeatureLocation
, so I presume Python's import logic de-duplicates those imports and thus the above code snippet refers to the one-and-onlyFeatureLocation
class.Adding (or rebinding) methods also flows through to already instantiated objects. My understanding of how this works in Python isn't great (JS is much clearer for me). E.g.
<instance>.<method>
is clearly pointing to the (one-and-only) class definition, but<instance>.<some_data>
is clearly pointing to an instance-specific address. My guess would be that instances have a lookup table of attributes (which in this example would include<some_data>
), and if an attribute's not there we go look for it in the class (and then the parent class etc). It's python, so it's probably using namespaces.To complicate matters a bit more,
.location.start
is an instance-attribute (of.location
) and is itself an instance of<class 'Bio.SeqFeature.ExactPosition'>
, so it couldn't be monkeypatched the way I demonstrate above. We might be able to emulate enough of the behaviour by using something like:So long story short, I'm not going to do this in this PR, but we absolutely could do this across Augur to improve the code readability.