Repository navigation
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1746 +/- ##
==========================================
+ Coverage 85.02% 85.05% +0.02%
==========================================
Files 310 311 +1
Lines 49957 50103 +146
==========================================
+ Hits 42476 42615 +139
- Misses 7481 7488 +7
Continue to review full report at Codecov.
|
| from Bio.SeqRecord import SeqRecord # Lazy to avoid circular imports | ||
| temp_data = "" | ||
| if self._data == "": # if the spacer is empty it will initially default to the type of the first sequence | ||
| a = None |
There was a problem hiding this comment.
What if the arguments are all alphabet-less strings? Add if a is None: a = self.alphabet logic at the end?
|
Do you not want to be in the NEWS and CONTRIB listings? If you do, can you think how to make the pull request template clearer that we'd like you to add yourself? In general the changes look good - although I've not had a chance to test them yet. I would like to see more tests, including the error conditions. |
|
Thank you for the comments, I made changes based on your suggestions and added a few more test conditions. At this moment I do not wish to have my name listed, I only checked the box as an acknowledgement that I read the option. Thanks for double checking with me. |
|
Would you be happy for add |
|
If it calls the |
|
I've added join() for MutableSeq objects as well and tested the functionality. Implementation was done based on how the add method functions for Unknown and MutableSeq. |
|
Aside from the alphabet special cases with an empty spacer, the behaviour of |
|
@MarkusPiotrowski or @mdehoon would you be able to look at this for a second opinion? There are some minor changes I might still make like shortening the doctest examples, but I think this would benefit from fresh eyes. |
|
In addition to shortening the doctest what other changes did you have in mind? |
|
Doctest example, >>> spacer = Seq('NNNNN')
>>> seqlist = [Seq("AAA"), Seq("TTT"), Seq("PPP")]
>>> concatenated = spacer.join(seqlist)
>>> concatenated
Seq('AAANNNNNTTTNNNNNPPP')Could be: >>> Seq('NNNNN').join([Seq("AAA"), Seq("TTT"), Seq("PPP")])
Seq('AAANNNNNTTTNNNNNPPP') |
|
Did we discuss the pros and cons of doing the join internally with string concatenation (as now), versus calling the string join method? I suspect the later will scale better, but have not benchmarked this - and what you have now is a useful first implementation which we can always revise later. |
|
I think the discussion of string concatenation vs an internal string join was already spoken about, though I can't find the relevant comments anymore. I did a short test for a join with 300 sequences and I for the moment I see no differences as the most intensive part in both cases seems to be converting everything into a string from a Seq object for the returned Seq() and iterating the list to make sure everything is an allowed object. |
|
OK, that makes sense - I thought we'd talked about it too, but also couldn't find the discussion. |
| a = self.alphabet | ||
| if self._data == "": | ||
| return self.__class__(temp_data, a) | ||
| return self.__class__(temp_data[len(self._data):], a) # remove the last addition of the spacer |
There was a problem hiding this comment.
In the comment, you mean "remove the first addition of the spacer"?
| if a is None: # if spacer is empty alphabet defaults to type of the first sequence | ||
| a = c.alphabet | ||
| else: | ||
| if not Alphabet._check_type_compatible([a, c.alphabet]): |
There was a problem hiding this comment.
I found that all these alphabet checks are intrinsicely slow. Also, I would think that often the alphabets are identical. So you can speed this up considerably if you only do the following checks if the alphabets are not identical:
if a != c.alphabet:
if not Alphabet._ ....
...In a test run with 1000 'AAA' seq objects, this check made the method nearly 9 times faster.
| temp_data += str(self) + str(c) | ||
| else: | ||
| raise ValueError("Input must be an iterable of Seqs or Strings") | ||
|
|
There was a problem hiding this comment.
By replacing + string concatenation with join()
(e.g. remove line 1319, replace 1321 with pass and add below 1323:
temp_data = str(self).join([str(z) for z in other]))
you can gain another 1.6x in speed.
There was a problem hiding this comment.
Good - I did think that would be quicker, but it was masked by the seq/alphabet overhead until your suggestion for the common case of everything having the same alphabet object.
There was a problem hiding this comment.
You're correct, I previously misunderstood and tested this idea poorly. I've updated it to perform this join.
| are not Seq or String objects | ||
| """ | ||
| seq_joined = self.toseq().join(other) # returns Seq object instead of MutableSeq | ||
| return seq_joined |
There was a problem hiding this comment.
It's not clear to me, why you return a Seq object here, instead of a MutableSeq. Somewhere in the discussion you said that you tried to be consistent with the add method (you mean __add__?), but for MutableSeq __add__ returns a new MutableSeq object.
There was a problem hiding this comment.
An earlier iteration did return a MutableSeq, but required a lot of code duplication - returning a Seq avoided that neatly.
There was a problem hiding this comment.
But can't you finally make a new MutableSeq with the joined sequence and alphabet and return this? E.g. using tomutable(). Like in the __add__ method?
On the other hand, I wonder if I would expect the result of a join operation, where the MutableSeq acts "only" as spacer, to be a MutableSeq. So this is probably fine, but should be mentioned in the docstring.
There was a problem hiding this comment.
You could argue either way on the the return type, personally I think a Seq is more likely to be useful as when I have needed a MutableSeq it has only been briefly. The doctest does show a Seq, but you are right, saying so in the text of the docstring would be clearer.
|
The merge conflict is due to another test being added for the MutableSeq object. If you've never dealt with a conflict before, just leave it as is - I can do the merge manually. |
Squashed commit of pull reuqest biopython#1746, closes issue biopython#1731.
|
I don't think I understand, where is the merge conflict? GitHub is showing me that I've passed all 4 checks and that there are no conflicts with the base branch. Maybe it's better if I leave this up to you. |
|
I see "This branch cannot be rebased due to conflicts" and the merge buttons are greyed out. You may not see this message because you won't see the merge buttons either. I pulled your changes into a temporary branch on my fork, and if that passes TravisCI, will merge it: |
|
The conflict itself is from fa9a625 - you both added tests to the class at around line 740 - happily very easy to resolve the conflict as we want both that test and your new tests. |
|
Ok, I see. Thank you! |
|
Do you want to be added to the NEWS.rst or CONTRIB.rst files? Just as "kaskales" is fine if you want to remain pseudonymous. |
|
Applied as e856cd3 - thank you! |
|
Thank you! I would like to make more contributions so I'll remember to add my name for the next time to the NEWS.rst file. |
Original authors David Arenillas and Anthony Mathelier have agreed - see biopython#2473, as have the other contributors as tracked by git version control: - Aziz Khan (@asntech) biopython#3651 - Carlos Pena (@carlosp420) biopython#898 (comment) - Catherine Lesuisse (@kaskales) biopython#1746 - Chris Rands (@chris-rands) biopython#1301 - Christian Brueffer (@cbrueffer) biopython#898 (comment) - Jeremy LaBarge (@biojerm) biopython#1847 (comment) - Markus Piotrowski (@MarkusPiotrowski) biopython#898 (comment) - Michiel de Hoon (@mdehoon) biopython#898 (comment) - @morrme biopython#1172 (comment) - Peter Cock (@peterjc) biopython#898 (comment) - Sergio Valqui (@svalqui) biopython#1749 - Sujan Dulal (@Dsujan) biopython#2430 - Suresh Panneerselvam (@Amrithasuresh) biopython#1575 - Travis Wrightsman (@twrightsman) biopython#898 (comment)
Original authors David Arenillas and Anthony Mathelier have agreed - see biopython#2473, as have the other contributors as tracked by git version control: - Aziz Khan (@asntech) biopython#3651 - Carlos Pena (@carlosp420) biopython#898 (comment) - Catherine Lesuisse (@kaskales) biopython#1746 - Chris Rands (@chris-rands) biopython#1301 - Christian Brueffer (@cbrueffer) biopython#898 (comment) - Jeremy LaBarge (@biojerm) biopython#1847 (comment) - Markus Piotrowski (@MarkusPiotrowski) biopython#898 (comment) - Michiel de Hoon (@mdehoon) biopython#898 (comment) - @morrme biopython#1172 (comment) - Peter Cock (@peterjc) biopython#898 (comment) - Sergio Valqui (@svalqui) biopython#1749 - Sujan Dulal (@Dsujan) biopython#2430 - Suresh Panneerselvam (@Amrithasuresh) biopython#1575 - Travis Wrightsman (@twrightsman) biopython#898 (comment)
Original authors David Arenillas and Anthony Mathelier have agreed - see #2473, as have the other contributors as tracked by git version control: - Aziz Khan (@asntech) #3651 - Carlos Pena (@carlosp420) #898 (comment) - Catherine Lesuisse (@kaskales) #1746 - Chris Rands (@chris-rands) #1301 - Christian Brueffer (@cbrueffer) #898 (comment) - Jeremy LaBarge (@biojerm) #1847 (comment) - Markus Piotrowski (@MarkusPiotrowski) #898 (comment) - Michiel de Hoon (@mdehoon) #898 (comment) - @morrme #1172 (comment) - Peter Cock (@peterjc) #898 (comment) - Sergio Valqui (@svalqui) #1749 - Sujan Dulal (@Dsujan) #2430 - Suresh Panneerselvam (@Amrithasuresh) #1575 - Travis Wrightsman (@twrightsman) #898 (comment)
Added the Seq.Join() method, issue #1731 .
Allows user to concatenate Seq objects with a spacer Seq object.
I hereby agree to dual licence this and any previous contributions under both
the Biopython License Agreement AND the BSD 3-Clause License.
I have read the
CONTRIBUTING.rstfile and understand that AppVeyor andTravisCI will be used to confirm the Biopython unit tests and
flake8stylechecks pass with these changes.
I have added my name to the alphabetical contributors listings in the files
NEWS.rstandCONTRIB.rstas part of this pull request, am listedalready, or do not wish to be listed. (This acknowledgement is optional.)