Skip to content

Fast search for motifs based on calculate and chunking - #2386

Merged
peterjc merged 3 commits into
biopython:masterfrom
Phlya:master
Dec 20, 2019
Merged

peterjc merged 3 commits into
biopython:masterfrom
Phlya:master

Conversation

@Phlya

@Phlya Phlya commented Dec 6, 2019 •

Copy link
Copy Markdown
Contributor

This pull request addresses issue #2360

Despite the changes in internal logic, I preserved the generator nature of this method for back-compatibility. Also I ensure that the order of returned elements is preserved, they are sorted by their absolute coordinate.

  • 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.rst file, have run flake8 locally, and
    understand that AppVeyor and TravisCI will be used to confirm the Biopython unit
    tests and style checks pass with these changes.

  • I have added my name to the alphabetical contributors listings in the files
    NEWS.rst and CONTRIB.rst as part of this pull request, am listed
    already, or do not wish to be listed. (This acknowledgement is optional.)

@codecov

codecov Bot commented Dec 6, 2019 •

Copy link
Copy Markdown

Codecov Report

❗ No coverage uploaded for pull request base (master@713b2dc). Click here to learn what that means.
The diff coverage is 85.71%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #2386   +/-   ##
=========================================
  Coverage          ?   84.92%           
=========================================
  Files             ?      323           
  Lines             ?    52887           
  Branches          ?        0           
=========================================
  Hits              ?    44914           
  Misses            ?     7973           
  Partials          ?        0
Impacted Files Coverage Δ
Bio/motifs/matrix.py 80.63% <85.71%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 713b2dc...aa448a8. Read the comment docs.

@mdehoon mdehoon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks! Feel free to commit once the Travis warnings have been resolved.

@Phlya

Phlya commented Dec 9, 2019

Copy link
Copy Markdown
Contributor Author

Ummm anything I can do about travis? I am not sure what it's complaining about.

Another thought, this new approach with splitting is well suited to run in parallel, would that be a good idea?

@MarkusPiotrowski

Copy link
Copy Markdown
Contributor

You can click on Details to see why Travis-CI is complaining. These are all style-issues, mostly missing white space around operators.
I would recommend installing flake8 and the recommended plug-ins (please have a look at CONTRIBUTING.rst) and run flake8 offline before submitting.

@peterjc

peterjc commented Dec 9, 2019

Copy link
Copy Markdown
Member

Quoting travis:

$ flake8
./Bio/motifs/matrix.py:416:9: E741 ambiguous variable name 'l'
./Bio/motifs/matrix.py:422:54: E226 missing whitespace around arithmetic operator
./Bio/motifs/matrix.py:422:64: E226 missing whitespace around arithmetic operator
./Bio/motifs/matrix.py:422:72: E226 missing whitespace around arithmetic operator
./Bio/motifs/matrix.py:424:33: E225 missing whitespace around operator
./Bio/motifs/matrix.py:425:49: E226 missing whitespace around arithmetic operator
./Bio/motifs/matrix.py:429:37: E225 missing whitespace around operator
./Bio/motifs/matrix.py:430:53: E226 missing whitespace around arithmetic operator
./Bio/motifs/matrix.py:436:69: E226 missing whitespace around arithmetic operator

As Markus noted, those should all be easy enough to put right. The pull request template is meant to highlight CONTRIBUTING.rst where the flake8 stuff is documented - but we'd welcome wording suggestions etc to make contributing easier.

(Related to this, we are working on adopting the black formatting tool and style, which will automate much of this - like the whitespace conventions)

@Phlya

Phlya commented Dec 9, 2019

Copy link
Copy Markdown
Contributor Author

OK, cool, thanks! So I just ran black on this file and commited, is that ok?

@Phlya

Phlya commented Dec 9, 2019

Copy link
Copy Markdown
Contributor Author

OK, now I don't get what the conflict is, sorry.

@peterjc

peterjc commented Dec 9, 2019

Copy link
Copy Markdown
Member

We've been doing black incrementally, see #2008. It doesn't look to cause too much trouble as part of this pull request, but it would be easier without it.

The conflict in NEWS looks down to unlucky placement of the new paragraph clashing with a paragraph added on the master branch.

Let me try rebasing this...

Comment thread Bio/motifs/matrix.py Outdated
A generator function, returning found hits in the given sequence
with the pwm score higher than the threshold.
"""
import numpy as np

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdehoon my understanding is Bio.motifs defaults to using C code called via a numpy array, but can fall back on a pure Python no numpy alternative. If so, then the lazy import is OK.

If you regard numpy as a hard requirement of Bio.motifs then we should just have the import numpy once at top level.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since numpy is now a requirement of Biopython, we can remove the pure Python implementation, and have the import numpy once at top level.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in the latest commit.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to clarify the numpy situation, logged as #2390.

@peterjc
peterjc force-pushed the master branch 2 times, most recently from 0a9188c to 44329cc Compare December 9, 2019 12:17
@peterjc

peterjc commented Dec 9, 2019

Copy link
Copy Markdown
Member

Rebased as squashed into a single commit which does not include running black (and introducing additional changes not relevant to the work here). The conflict was in both the news entries, and the list of contributors to the upcoming release.

I have a query about the numpy import...

Comment thread NEWS.rst Resolved
@Phlya

Phlya commented Dec 16, 2019

Copy link
Copy Markdown
Contributor Author

Somehow only one of the test environments failed due to numpy, is that normal?

Comment thread Bio/motifs/matrix.py Outdated

import math
import platform
import numpy as np

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Continuing my query about the numpy import, style aside (#2391) can you use this please:

try:
    import numpy as np
except ImportError:
    from Bio import MissingPythonDependencyError
    raise MissingPythonDependencyError(
        "Install NumPy if you want to use Bio.motifs.matrix.")

This should fix the failures on Travis on the target which deliberately does not have numpy installed. See #2390 for the background to this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Regarding style, I wasn't sure whether there was any specific style choice in Biopython and just went with the universally used convention...

@peterjc

peterjc commented Dec 18, 2019

Copy link
Copy Markdown
Member

This is more fiddly that I expected. The reason for this pain is the old search code would either be C code with NumPy, or a pure Python version without NumPy.

As the pull request code stands, this import means effectively all of Bio.motifs requires numpy, due to:

https://github.com/biopython/biopython/blob/biopython-175/Bio/motifs/__init__.py#L254

Unless we switch to just making numpy a hard requirement (#2390), we could try making the import lazy (within the .search() method)?

@peterjc peterjc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've got to decide what to do about this numpy import and the test suite....

@Phlya

Phlya commented Dec 18, 2019

Copy link
Copy Markdown
Contributor Author

My personal opinion is that having numpy as a requirement in this day and age is completely normal, realistically no one doing any computational analysis in python can do anything useful without numpy anyway.

I am happy to move the import into the search method though.

@peterjc

peterjc commented Dec 18, 2019

Copy link
Copy Markdown
Member

If you can add your comment to #2390 that would be great, and if you want to try the lazy import for now, fingers crossed it takes care of most of the test issues.

@Phlya

Phlya commented Dec 18, 2019

Copy link
Copy Markdown
Contributor Author

Moved the try-except import to search, hopefully this satisfies Travis.

@peterjc

peterjc commented Dec 18, 2019 •

Copy link
Copy Markdown
Member

Sadly the new _calculate needs numpy too. Hopefully Michiel will comment on 2390.

@Phlya

Phlya commented Dec 18, 2019

Copy link
Copy Markdown
Contributor Author

Right...

@Phlya

Phlya commented Dec 18, 2019

Copy link
Copy Markdown
Contributor Author

Shall I revert the last commit then?

@peterjc

peterjc commented Dec 19, 2019

Copy link
Copy Markdown
Member

Yes, as per discussion on #2390 please revert the lazy import commit.

@Phlya

Phlya commented Dec 19, 2019

Copy link
Copy Markdown
Contributor Author

Not sure what's wrong with Travis now...

@MarkusPiotrowski

Copy link
Copy Markdown
Contributor

It's pretty clear from the report. You must remove the blank line 385 (which also contains a white space) from matrix.py.

@peterjc

peterjc commented Dec 19, 2019

Copy link
Copy Markdown
Member

Yes, quoting the relevant output:

$ flake8
./Bio/motifs/matrix.py:380:1: D202 No blank lines allowed after function docstring
./Bio/motifs/matrix.py:385:1: W293 blank line contains whitespace

We encourage contributors to run flake8 on their own machines as described in https://github.com/biopython/biopython/blob/master/CONTRIBUTING.rst

@peterjc

peterjc commented Dec 19, 2019

Copy link
Copy Markdown
Member

Note that until #2418 is merged, it will still fail due to missing numpy

@Phlya

Phlya commented Dec 19, 2019

Copy link
Copy Markdown
Contributor Author

Right, thanks - sorry, I was being lazy and just edited on GitHub, and so didn't check code style.

@peterjc

peterjc commented Dec 19, 2019

Copy link
Copy Markdown
Member

I've done that myself too. Once we've applied black to the entire code base (see #2008, likely to be complete in early 2020), we can start to explore automation to update pull requests (e.g. a bot which runs black if required). That would take care of this kind of white space edit anyway 👍

@peterjc

peterjc commented Dec 20, 2019

Copy link
Copy Markdown
Member

Rebased to (a) clean up history a tiny bit, and (b) trigger a fresh TravisCI run with numpy installed on all targets.

@peterjc
peterjc merged commit 841974a into biopython:master Dec 20, 2019
@peterjc

peterjc commented Dec 20, 2019

Copy link
Copy Markdown
Member

Thank you for your patience - this will be in today's release, Biopython 1.76

@Phlya

Phlya commented Dec 20, 2019

Copy link
Copy Markdown
Contributor Author

No problem, and thank you for your helping getting this in!

peterjc added a commit to peterjc/biopython that referenced this pull request Dec 30, 2019
Originally checked in as Bio/Motif/Matrix.py the
original author Michiel de Hoon and contributors
since as tracked by version control have agreed:

 - Adhemar Zerlotini (@azneto)
   biopython#1412 (comment)
 - Andrey Raspopov (@Andrey-Raspopov)
   biopython#2444
 - Brian Osborne (@bosborne)
   biopython#898 (comment)
 - Carlos Pena (@carlosp420)
   biopython#898 (comment)
 - Christian Brueffer (@cbrueffer)
   biopython#898 (comment)
 - Francesco Gastaldello (@Gasta88)
   biopython#1063
 - Ilya Flyamer (@Phlya)
   biopython#2386
 - Matt Ruffalo (@mruffalo)
   biopython#898 (comment)
 - Michiel de Hoon (@mdehoon)
   biopython#898 (comment)
 - @morrme
   biopython#1172 (comment)
 - Nader Morshed (@naderm)
   biopython#898 (comment)
 - Peter Cock (@peterjc)
   biopython#898 (comment)
 - Sefa Kilic (@sefakilic)
   biopython#898 (comment)
 - Sergio Valqui (@svalqui)
   biopython#1749
 - Zaid Ur-Rehman (@zaidurrehman)
   biopython#867
peterjc added a commit that referenced this pull request Jan 1, 2020
Originally checked in as Bio/Motif/Matrix.py the
original author Michiel de Hoon and contributors
since as tracked by version control have agreed:

 - Adhemar Zerlotini (@azneto)
   #1412 (comment)
 - Andrey Raspopov (@Andrey-Raspopov)
   #2444
 - Brian Osborne (@bosborne)
   #898 (comment)
 - Carlos Pena (@carlosp420)
   #898 (comment)
 - Christian Brueffer (@cbrueffer)
   #898 (comment)
 - Francesco Gastaldello (@Gasta88)
   #1063
 - Ilya Flyamer (@Phlya)
   #2386
 - Matt Ruffalo (@mruffalo)
   #898 (comment)
 - Michiel de Hoon (@mdehoon)
   #898 (comment)
 - @morrme
   #1172 (comment)
 - Nader Morshed (@naderm)
   #898 (comment)
 - Peter Cock (@peterjc)
   #898 (comment)
 - Sefa Kilic (@sefakilic)
   #898 (comment)
 - Sergio Valqui (@svalqui)
   #1749
 - Zaid Ur-Rehman (@zaidurrehman)
   #867
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants