Repository navigation
Add integer multiplication methods for Seq, UnknownSeq and MutableSeq - #1669
Conversation
| return self.__class__(str(self) * other, self.alphabet) | ||
|
|
||
| def __imul__(self, other): | ||
| """Multiply Seq in-place |
There was a problem hiding this comment.
Needs trailing full stop, see PEP257 https://www.python.org/dev/peps/pep-0257/
Likewise for the other docstrings.
| """Multiply Seq in-place | ||
|
|
||
| Note although Seq is immutable, the in-place method is | ||
| included to match the behaviour for regular Python strings |
There was a problem hiding this comment.
Can you close that sentence with a full stop please. Likewise for the other docstrings.
|
|
||
| if not isinstance(other, int): | ||
| raise TypeError("can't multiply MutableSeq by non-int type") | ||
| return self.__class__(str(self) * other, self.alphabet) |
There was a problem hiding this comment.
I wonder if we can make this much more efficient by working directly with the self.data array, avoiding conversion to and from a string?
| >>> Seq('ATG', generic_dna) * 2 | ||
| Seq('ATGATG', DNAAlphabet()) | ||
| """ | ||
|
|
There was a problem hiding this comment.
Please remove this blank line, likewise for the other methods.
|
The TravisCI check is failing on some fairly minor style issues: I've made a comment on the Have you tried using the BioSQL wrapper's |
Codecov Report
@@ Coverage Diff @@
## master #1669 +/- ##
=========================================
+ Coverage 85.5% 85.5% +<.01%
=========================================
Files 327 327
Lines 49777 49819 +42
=========================================
+ Hits 42564 42600 +36
- Misses 7213 7219 +6
Continue to review full report at Codecov.
|
|
Thanks Peter, I corrected the style points and I totally agree about using I am not familiar with BioSQL I'm afraid, can you provide more details on what you you would like there? |
|
Your For BioSQL, I am picturing something like this in the tests (untested): class SeqInterfaceTest(unittest.TestCase):
...
def test_seq(self):
"""Make sure Seqs from BioSQL implement the right interface."""
test_seq = self.item.seq
alphabet = test_seq.alphabet
...
tripled = test_seq * 3 # check DBSeq.__mul__
self.assertTrue(isinstance(tripled, Seq))
self.assertEqual(tripled, str(test_seq) * 3)
self.assertEqual(tripled.alphabet, alphabet)
tripled = 3 * test_seq 3 # check DBSeq.__rmul__
self.assertTrue(isinstance(tripled, Seq))
self.assertEqual(tripled, str(test_seq) * 3)
self.assertEqual(tripled.alphabet, alphabet)
# Something similar for __imul__ as well...(You could define a new test method if you like, expanding the existing |
|
Thanks, I can implement those tests, and in terms of the implementation in As I said I don't use BioSQL, so I really don't know if this is appropriate or not? Thanks for your patience |
|
That looks perfect for the BioSQL changes, yes please. |
|
Just needs the BioSQL tests added, and the code side of this should be ready. Would you also like to write a couple of lines about this for the |
|
Thanks Peter, I made a few mistakes (now corrected hopefully) and I've added tests but they are failing on my system at least, it looks like the |
| alphabet = test_seq.alphabet | ||
| tripled = test_seq * 3 | ||
| # Test DBSeq.__mul__ | ||
| self.assertTrue(isinstance(tripled, Seq)) |
There was a problem hiding this comment.
We should probably add a check that this is not a DBSeq, i.e. that is it only a Seq:
self.assertFalse(isinstance(tripled, DBSeq))(And repeat this later on)
|
I think your commit to "correcting typo in method names" would have fixed that exception which is what I would expect to see if the |
|
If you are comfortable doing a git rebase onto the current master, that'd be great. Otherwise I'll deal with the (minor) merge conflict in the NEWS file. |
|
Do you want to be on the list of contributors for Biopython 1.72? |
|
Thanks Peter, you are correct, sorry, I made a mistake with the testing, now all tests pass on my system when I run I am already listed in the contributors because of a previous pull request. Are you able to resolve the conflict easily? |
|
The merge conflict is trivial - two new news entries, keep both. Git can't decide on its own which order to put them in ;) |
|
(I'm going to wait for the penultimate TravisCI and AppVeyor tests to finish) |
994f8c1 to
eae4cc6
Compare
|
Rebased to deal with the merge conflict, and applied to master - thank you! |
|
Great, thanks! |
This pull request addresses issue #1659
The issue explains the rationale, but here is a small example of the utility of the new methods:
The methods should work with all the
Seq,UnknownSeq, andMutableSeqobjects and with any alphabet. I also implemented some unit tests.Let me know if this looks ok?
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.)