-
Notifications
You must be signed in to change notification settings - Fork 75
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
Fasta more dict-like behaviour #156
Conversation
Should I worry about the CI/appveyor build failures? |
@Maarten-vd-Sande Thanks for the contribution. You shouldn't worry about the Appveyor errors - that integration hasn't been maintained, and I'll likely stop testing on Windows in the future (unless someone wants to figure out the Windows-specific quirks that are preventing the tests from running). One question I have is about the use case for this change. I have no doubt that making the It seems like a more logical return value would be a list of What I'm proposing then for >>> from pyfaidx import Fasta
>>> x = Fasta('/Users/matt/Downloads/gencode_vM12.fa')
>>> tuple(zip(x.keys(), x))[:10]
(('dfam_5S', FastaRecord("dfam_5S")), ('dfam_7SK', FastaRecord("dfam_7SK")), ('dfam_7SLRNA', FastaRecord("dfam_7SLRNA")), ('dfam_ACRO1', FastaRecord("dfam_ACRO1")), ('dfam_ALR', FastaRecord("dfam_ALR")), ('dfam_ALRa', FastaRecord("dfam_ALRa")), ('dfam_ALRb', FastaRecord("dfam_ALRb")), ('dfam_AluJb', FastaRecord("dfam_AluJb")), ('dfam_AluJo', FastaRecord("dfam_AluJo")), ('dfam_AluJr', FastaRecord("dfam_AluJr"))) |
Thanks for your reply. You are absolutely right! I will change it. Would you object if I change this to methods in the Something like:
|
@Maarten-vd-Sande Sounds good. I was thinking along the same lines, and fully support this change. |
@mdshw5 I haven't really looked into the code thoroughly, but wouldn't it make more sense to just refer to
to this:
This should effectively do the same right? In my opinion the second option is much more clear. |
This makes sense, but I will refactor the section where Lines 1000 to 1006 in f1668d2
|
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.
Looks like we can merge these changes.
pyfaidx/__init__.py
Outdated
if not self.mutable: | ||
self.records = dict( | ||
[(rname, FastaRecord(rname, self)) for rname in self.keys()]) | ||
self.records = {rname: FastaRecord(rname, self) |
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.
Great! You can ignore my previous comment.
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 seems like dictionary key insertion order is the issue, and I will update here to do something similar to what the Fasta.keys
method currently relies on:
Line 399 in f1668d2
self.index = OrderedDict() |
@@ -1062,6 +1060,15 @@ def get_spliced_seq(self, name, intervals, rc=False): | |||
# len(Sequence.seq) != end - start | |||
return Sequence(name=name, seq=seq, start=None, end=None) | |||
|
|||
def keys(self): |
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.
I agree that this brings clarity to the methods.
Okay, nice! 🎉 Thanks for your time |
@mdshw5 dont merge yet! The tests are failing for older python versions. |
Perhaps related to dictionary ordering? |
:) Yes, I was just looking into this. |
I don't have time for it today, but I don't mind taking a look at it somewhere this or next week. |
I've tagged v0.5.7 for release. |
It is a very minor thing, but now
pyfaidx.Fasta
behaves slightly more dictionary-like with.items
and.values
.