Skip to content

fixed doctest for Bio.SubsMat - #2042

Merged
peterjc merged 4 commits into
biopython:masterfrom
svalqui:issue_1902_Bio_SubsMat
May 5, 2019
Merged

peterjc merged 4 commits into
biopython:masterfrom
svalqui:issue_1902_Bio_SubsMat

Conversation

@svalqui

@svalqui svalqui commented May 1, 2019

Copy link
Copy Markdown
Contributor

This pull request addresses issue #1902

  • 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 and understand that AppVeyor and
    TravisCI will be used to confirm the Biopython unit tests and flake8 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.)

@peterjc

peterjc commented May 1, 2019

Copy link
Copy Markdown
Member

Since you are working on this, could you fix up the reStructuredText markup too please? e.g. http://rst.ninjs.org can be used online. Things like bullet point lists for the four bases etc.

Comment thread Bio/SubsMat/FreqTable.py Outdated
>>> ftab = FreqTable.read_count(f_count)
>>> nucleobases = list(ftab.keys())
>>> nucleobases.sort()
>>> for nb in nucleobases:

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.

How about replacing those three lines with:

>>> for nb in sorted(ftab):

If we're lucky this will also fix the Python 2 problem which I have not looked closely at.

Comment thread Bio/SubsMat/FreqTable.py Resolved
@peterjc

peterjc commented May 1, 2019

Copy link
Copy Markdown
Member

The test is breaking on Python 2, unclear why - that is worth exploring. I noted an alternative style for that bit of code anyway which might fix the test.

@MarkusPiotrowski

MarkusPiotrowski commented May 1, 2019 •

Copy link
Copy Markdown
Contributor

io.StringIO in Python 2 needs an unicode string.

f_count = io.StringIO(u"A 50\nC 37\nG 23\nT 58")

should work under Python 2 and Python 3.

@codecov

codecov Bot commented May 1, 2019

Copy link
Copy Markdown

Codecov Report

Merging #2042 into master will decrease coverage by 0.29%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #2042     +/-   ##
=========================================
- Coverage   84.92%   84.62%   -0.3%     
=========================================
  Files         315      315             
  Lines       50543    50541      -2     
=========================================
- Hits        42923    42772    -151     
- Misses       7620     7769    +149
Impacted Files Coverage Δ
Bio/SubsMat/FreqTable.py 97.36% <100%> (ø) ⬆️
Bio/_py3k/__init__.py 41.66% <0%> (-34.53%) ⬇️
Bio/SeqIO/NibIO.py 77.17% <0%> (-14.14%) ⬇️
Bio/Phylo/_utils.py 57.37% <0%> (-7.79%) ⬇️
BioSQL/BioSeqDatabase.py 72.52% <0%> (-5.2%) ⬇️
Bio/SearchIO/_model/query.py 87.25% <0%> (-5.18%) ⬇️
Bio/AlignIO/Interfaces.py 87.5% <0%> (-5%) ⬇️
Bio/SeqUtils/CheckSum.py 84.12% <0%> (-4.77%) ⬇️
Bio/Nexus/StandardData.py 68.65% <0%> (-2.99%) ⬇️
Bio/Phylo/_io.py 91.66% <0%> (-2.78%) ⬇️
... and 19 more

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 3d235ad...619860a. Read the comment docs.

@codecov

codecov Bot commented May 1, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #2042 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2042   +/-   ##
=======================================
  Coverage   84.92%   84.92%           
=======================================
  Files         315      315           
  Lines       50545    50545           
=======================================
  Hits        42924    42924           
  Misses       7621     7621
Impacted Files Coverage Δ
Bio/SubsMat/FreqTable.py 97.36% <100%> (ø) ⬆️

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 df42303...31b5c72. Read the comment docs.

@svalqui

svalqui commented May 2, 2019

Copy link
Copy Markdown
Contributor Author

Thank you for the Tips, I have updated the code, it runs on Python3; in terms of the reStructureText no sure if that's all what is needed, let me know.

@peterjc

peterjc commented May 2, 2019

Copy link
Copy Markdown
Member

Regarding the RST markup, copy-and-paste the main docstring, i.e. this:

A class to handle frequency tables or letter count files.

Example files for a DNA alphabet:

A count file (whitespace separated):

- A  50
- C  37
- G  23
- T  58

The same info as a frequency file:

- A 0.2976
- C 0.2202
- G 0.1369
- T 0.3452

Functions:
  read_count(f): read a count file from stream f. Then convert to
  frequencies
  read_freq(f): read a frequency data file from stream f. Of course, we then
  don't have the counts, but it is usually the letter frquencies which are
  interesting.

Methods:
  (all internal)

Attributes:
  alphabet: The IUPAC alphabet set (or any other) whose letters you are
  using. Common sets are: IUPAC.protein (20-letter protein),
  IUPAC.unambiguous_dna (4-letter DNA). See Bio/alphabet for more.
  data: frequency dictionary.
  count: count dictionary. Empty if no counts are provided.

Example of use:
    >>> import io
    >>> from Bio.SubsMat import FreqTable
    >>> f_count = io.StringIO(u"A  50\nC  37\nG  23\nT  58")
    >>> ftab = FreqTable.read_count(f_count)
    >>> for nb in sorted(ftab):
    ...     print("%s %0.4f" %(nb, ftab[nb]))
    ...
    A 0.2976
    C 0.2202
    G 0.1369
    T 0.3452

into http://rst.ninjs.org/ or your favourite RST editor (the four space indentation does not seem to matter). Notice that the functions and attribute lists are not displaying clearly. Again, bullet points would seem simplest - see e.g. Bio/SeqRecord.py

(We've talked about moving towards the NumPy docstring style, but that is a bigger effort)

You can see how it look as of our last release here, not great: http://biopython.org/DIST/docs/api/Bio.SubsMat.FreqTable-module.html

@MarkusPiotrowski

Copy link
Copy Markdown
Contributor

@svalqui As you are also working on many docstring issues in #1963 and related, can you add the docstrings here as well? Should be not too hard this time, since the module docstring explains most of it.

@MarkusPiotrowski

Copy link
Copy Markdown
Contributor

Regarding RST markup: This is an example for a reStructured docstring (you can use it as it is, just copy&paste):

A class to handle frequency tables or letter count files.
Example files for a DNA alphabet:

A count file (whitespace separated)::

 A 50
 C 37
 G 23
 T 58

The same info as a frequency file::

 A 0.2976
 C 0.2202
 G 0.1369
 T 0.3452

Functions:
  :read_count(f): read a count file from stream f. Then convert to
                  frequencies
  :read_freq(f): read a frequency data file from stream f. Of course, we then
                 don't have the counts, but it is usually the letter frquencies
                 which are interesting.
Methods:
  (all internal)

Attributes:
  :alphabet: The IUPAC alphabet set (or any other) whose letters you are using.
             Common sets are: ``IUPAC.protein`` (20-letter protein), ``IUPAC.unambiguous_dna``
             (4-letter DNA). See ``Bio.Alphabet`` for more.
  :data: Frequency dictionary.
  :count: Count dictionary. Empty if no counts are provided.

Example of use:

    >>> import io
    >>> from Bio.SubsMat import FreqTable
    >>> f_count = io.StringIO(u"A  50\nC  37\nG  23\nT  58")
    >>> ftab = FreqTable.read_count(f_count)
    >>> for nb in sorted(ftab):
    ...     print("%s %0.4f" %(nb, ftab[nb]))
    ...
    A 0.2976
    C 0.2202
    G 0.1369
    T 0.3452

@svalqui

svalqui commented May 3, 2019

Copy link
Copy Markdown
Contributor Author

Thank you for that, that makes it more clear, amended.

Comment thread Bio/SubsMat/FreqTable.py Outdated


def read_freq(f):
"""Read a frequency data file f and load values to the Frequency Table"""

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 full stop,

$ flake8 Bio/
Bio/SubsMat/FreqTable.py:102:1: D400 First line should end with a period

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.

flake has been a bit odd, not picking the missing DocStrings at first, so I haven't used on this file; anyway full stop added.

@peterjc
peterjc force-pushed the issue_1902_Bio_SubsMat branch from 6ecff5d to 31b5c72 Compare May 5, 2019 09:31
@peterjc

peterjc commented May 5, 2019

Copy link
Copy Markdown
Member

Rebased to fix the merge conflict in Tests/run_tests.py, by eye this looks ready to merge now 👍

@peterjc
peterjc merged commit feb97e2 into biopython:master May 5, 2019
@peterjc

peterjc commented May 5, 2019

Copy link
Copy Markdown
Member

Thank you both, nice job 👍

svalqui added a commit to svalqui/biopython that referenced this pull request May 14, 2019
@svalqui
svalqui deleted the issue_1902_Bio_SubsMat branch May 20, 2019 13:11
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