Skip to content

Convert MaxEntropy selftest to doctest - #950

Closed
vincentdavis wants to merge 19 commits into
biopython:masterfrom
vincentdavis:Move_selftests_misc
Closed

vincentdavis wants to merge 19 commits into
biopython:masterfrom
vincentdavis:Move_selftests_misc

Conversation

@vincentdavis

@vincentdavis vincentdavis commented Sep 30, 2016 •

Copy link
Copy Markdown
Contributor

Remove self test from MaxEntropy, duplicates test_maxentropy.py, there are no doc tests.
see issue #820

@peterjc

peterjc commented Sep 30, 2016

Copy link
Copy Markdown
Member

Did you forget to add the new file? Also double check the filename, you have a typo in the commit comment (m vs n).

@vincentdavis vincentdavis changed the title Remove selftest from MaxEntropy, duplicates test_maxemtropy.py Remove selftest from MaxEntropy, duplicates test_maxentropy.py Sep 30, 2016
@codecov-io

codecov-io commented Oct 1, 2016 •

Copy link
Copy Markdown

Current coverage is 80.08% (diff: 34.78%)

Merging #950 into master will decrease coverage by 0.06%

@@             master       #950   diff @@
==========================================
  Files           316        319     +3   
  Lines         48502      48745   +243   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits          38872      39037   +165   
- Misses         9630       9708    +78   
  Partials          0          0          

Powered by Codecov. Last update 857c891...7f2393d

@vincentdavis vincentdavis changed the title Remove selftest from MaxEntropy, duplicates test_maxentropy.py Convert MaxEntropy selftest to doctest Oct 1, 2016
@vincentdavis

Copy link
Copy Markdown
Contributor Author

Converted the self test to a doc test. This seemed like the best way to go, there is now an example in the docs now and the code is tested.
I must have been exceptionally dyslexic yesterday. I confused the NaiveBayes test for the Maxentropy test since is uses the same data.

Comment thread Bio/MaxEntropy.py
>>> ycar = ['Yes','No','Yes','No','Yes','No','Yes','No','No','Yes']

Requires some rules or features
>>> def udf1(ts, cl):

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.

Style wise include a blank line here (not sure if essential for nice RST rendering, but could be)

Comment thread Tests/run_tests.py Outdated
"Bio.KEGG.Compound",
"Bio.KEGG.Enzyme",
"Bio.NMR.xpktools",
"Bio.MaxEntropy"

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.

Missing trailing comma - would instead get concatenated with the next line I think.

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.

This is what triggers the TravisCI failure:

======================================================================
ERROR: Bio.MaxEntropyBio.motifs
----------------------------------------------------------------------
Traceback (most recent call last):
  File "run_tests.py", line 446, in runTest
    module = __import__(name, fromlist=name.split("."))
ImportError: No module named MaxEntropyBio.motifs
----------------------------------------------------------------------

@peterjc

peterjc commented Oct 3, 2016

Copy link
Copy Markdown
Member

Do you have the pep8 command line tool installed locally? Try ``pip install pep8` if not.

That would be the easiest way to the blank-line-at-end-file quirk, which may be complicated by your editor doing what it thinks is best:

$ pep8 --max-line-length 92 BioSQL/
$ pep8 --ignore E402 --max-line-length 90 Scripts/
$ pep8 --max-line-length 90 Doc/examples/
$ pep8 --ignore E122,E123,E126,E127,E128,E129,E501,E731 Bio/
Bio/MaxEntropy.py:324:1: W391 blank line at end of file

Comment thread Bio/KEGG/KGML/KGML_parser.py Outdated
class KGMLParser(object):
"""Parses a KGML XML Pathway entry into a Pathway object."""
"""Parses a KGML XML Pathway entry into a Pathway object.
Example: Read and parse large metabolism file

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.

Comment thread Bio/KEGG/KGML/KGML_parser.py Outdated
Example: Read and parse large metabolism file

>>> from Bio.KEGG.KGML.KGML_parser import read
>>> pathway = read(open('KEGG/ko01100.xml', 'rU'))

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.

Does everything work without the universal new line mode option which has been deprecated? See https://bugs.python.org/issue15204

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.

Yes, fixing

Comment thread Bio/KEGG/KGML/KGML_parser.py Outdated
compound: 31
map: 7


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.

Loads of blank lines - can you intersperse this with some text so that the doctest is more informative as documentation?

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.

I will clean this up some. I would prefer to finish converting the self-tests to doc tests then create a new issue to improve the documentation. I don't really know anything about KGML/KEGG and would, therefore, need to learn about that before I have any chance to say anything intelligent about this.

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.

OK - that will still be an improvement :)

Comment thread Bio/MaxEntropy.py

Car data from example Naive Bayes Classifier example by Eric Meisner November 22, 2003
http://www.inf.u-szeged.hu/~ormandi/teaching
>>> from Bio.MaxEntropy import train, classify

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.

I'd include a blank line here - not 100% if it matters or not for most RST rendering tools?

Comment thread Bio/MaxEntropy.py Outdated
... if ts[0] == 'Red':
... return 0
... else:
... return 1

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.

These if/else seem clumsy - does it work with just return ts[0] == 'Red' (giving True and False rather than 0 and 1)?

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.

actually: return ts[0] != 'Red'

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.

Oh yeah - shows how used I am to Python's False and True compared to C and very early Python's 0 and 1 (or rather, any non-zero value) style.

@vincentdavis

Copy link
Copy Markdown
Contributor Author

@peterjc Thanks for the quick review. I meant to post that it was not ready yet but I wanted to see how the Travis CI reports looked.

@peterjc

peterjc commented Oct 6, 2016

Copy link
Copy Markdown
Member

Heh - I had time while tests on something else was running ;)

@vincentdavis

Copy link
Copy Markdown
Contributor Author

@peterjc Still not complete, need to finish moving KGML_parser self-test to doc-test

@peterjc

peterjc commented Oct 7, 2016

Copy link
Copy Markdown
Member

The TravisCI failures are from PyPy because of NumPy, which we avoid in other examples using something like:

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

@peterjc

peterjc commented Oct 7, 2016

Copy link
Copy Markdown
Member

Also don't forget to update Tests/run_tests.py to add new doctests to DOCTEST_MODULES (note there is a second list of doctests which require NumPy).

@peterjc

peterjc commented Oct 7, 2016

Copy link
Copy Markdown
Member

See also newly filed issue #953 for reviewing status of PyPy's NumPy.

Comment thread Tests/run_tests.py Outdated
"Bio.PDB.Selection",
"Bio.SeqIO.PdbIO",
"Bio/SVDSuperimposer/__init__.py"
"Bio/SVDSuperimposer/__init__"

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.

This should be "Bio.SVDSuperimposer", (import namespace with dots, not filename with slashes).

Also include the trailing comma even though this is currently the last entry in the list (so that as here, next time we add something to the list it is a one line insertion).

@vincentdavis

Copy link
Copy Markdown
Contributor Author

@peterjc I have been running them this way. Which, in retrospect, is by I keep not getting the files correctly listed in the run_test.py file ;-).

$ python Bio/SVDSuperimposer/__init__.py
Running doctests...
Done

It also works how you have suggested.
I have removed the init as you suggested.

@vincentdavis

Copy link
Copy Markdown
Contributor Author

For the Bio.UniProt.GOA self-test-doc-test there was not example gaf file. I found one, source in comments, and added it after trimming it to ~600 rows.

@vincentdavis

Copy link
Copy Markdown
Contributor Author

@peterjc I am puzzled by the failed doc-tests for pypy and python2.7 in commit f8a80a2, Is it really the case that python 2.7 prints the results different?

File "/home/travis/build/biopython/biopython/Bio/UniProt/GOA.py", line 363, in Bio.UniProt.GOA.gafiterator
Failed example:
    with open('UniProt/goa_yeast.gaf', 'r') as handle:
        for inrec in gafiterator(handle):
            if record_has(inrec, Taxon_ID) and record_has(inrec, Evidence) and record_has(inrec, Synonym):
                print(inrec['DB_Object_Name'], inrec['Evidence'], inrec['Synonym'], inrec['Taxon_ID'])
Expected:
    Putative uncharacterized protein YAL019W-A ND ['YA19A_YEAST', 'YAL019W-A'] ['taxon:559292']
    Putative uncharacterized protein YAL019W-A ND ['YA19A_YEAST', 'YAL019W-A'] ['taxon:559292']
    Putative uncharacterized protein YAL019W-A ND ['YA19A_YEAST', 'YAL019W-A'] ['taxon:559292']
Got:
    ('Putative uncharacterized protein YAL019W-A', 'ND', ['YA19A_YEAST', 'YAL019W-A'], ['taxon:559292'])
    ('Putative uncharacterized protein YAL019W-A', 'ND', ['YA19A_YEAST', 'YAL019W-A'], ['taxon:559292'])
    ('Putative uncharacterized protein YAL019W-A', 'ND', ['YA19A_YEAST', 'YAL019W-A'], ['taxon:559292'])

@peterjc

peterjc commented Oct 9, 2016 •

Copy link
Copy Markdown
Member

Unless you include the from future import, under Python 2 this means print a tuple:

print("a", "b", "c")

In the documentation we try to use the form print(single_string_or_expression) which will work on both Python 2 (defaults), or Python 3 (and Python 2 with the future import).

Try adding this as the first import (after the module docstring):

from __future__ import print_function

@peterjc

peterjc commented Oct 10, 2016 •

Copy link
Copy Markdown
Member

Did you try from __future__ import print_function? I think the original doctest print function call was simpler (and only one line).

(Edit - was missing the underscores, copy and paste glitch)

peterjc added a commit to peterjc/biopython that referenced this pull request Oct 10, 2016
@peterjc

peterjc commented Oct 10, 2016

Copy link
Copy Markdown
Member

I'm just running the tests on a cleaned up version of this branch (squashing commits for a clearer history). The print_function trick works. Was also missing Bio.KEGG.KGML.KGML_parser in run_tests.py.

I expect to merge your work shortly...

@peterjc

peterjc commented Oct 10, 2016

Copy link
Copy Markdown
Member

Hmm. The KGML doctest fails on PyPy, probably due to assumed dictionary order...

@peterjc

peterjc commented Oct 10, 2016

Copy link
Copy Markdown
Member

Branch re-worked and applied to master, MaxEntropy in eb7e7a7, KEGG/KGML in ef09944, GOA in 0a6838b, SVD in 392fb3e - thank you!

There is room for improvement on the KGML doctests, see 0a4d5e1 and open question about if and how to sort those objects.

@peterjc peterjc closed this Oct 10, 2016
@vincentdavis
vincentdavis deleted the Move_selftests_misc branch October 10, 2016 13:40
MarkusPiotrowski pushed a commit to MarkusPiotrowski/biopython that referenced this pull request Oct 31, 2017
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.

3 participants