Skip to content

Consistent error messages for empty file parsing in SeqIO - #1845

Merged
peterjc merged 6 commits into
biopython:masterfrom
DevangThakkar:better-error-messages
Nov 19, 2018
Merged

peterjc merged 6 commits into
biopython:masterfrom
DevangThakkar:better-error-messages

Conversation

@DevangThakkar

Copy link
Copy Markdown
Contributor

This pull request addresses Issue #1838. Current SeqIO code does not optimally handle empty files for certain formats. This pull request raises a standard ValueError("Empty file.") error message on encountering an empty file instead of the current non standard errors. Formats worked on are as
follows: cif-atom, pdb-atom, uniprot-xml. The other formats either do not print anything thing or raise a ValueError("Empty file.") error message.

  • 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.)

@DevangThakkar

Copy link
Copy Markdown
Contributor Author

Does it make sense to raise a similar error for the other formats to maintain consistency?

Comment thread Bio/SeqIO/PdbIO.py Outdated
from Bio.File import UndoHandle
undo_handle = UndoHandle(handle)
firstline = undo_handle.peekline()
if undo_handle.readlines() == []:

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.

Probably you should use if not line: here?

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.

Yeah I ended up using if peekline() == '' and it seems to work perfectly.

Comment thread Bio/SeqIO/PdbIO.py Outdated

buffer.seek(0)
mmcif_dict = MMCIF2Dict(buffer)
if mmcif_dict == {}:

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.

Can you check if the buffer object is empty directly? You could then do this two lines up, before ever calling MMCIF2Dict.

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.

Comment thread Bio/SeqIO/UniprotIO.py Outdated
skip_parsing_errors = True --> if parsing errors are found, skip to next entry
"""
# check if file is empty
from Bio.File import UndoHandle

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.

Can you do this without using the UndoHandle?

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.

@DevangThakkar DevangThakkar reopened this Nov 12, 2018
@peterjc

peterjc commented Nov 12, 2018

Copy link
Copy Markdown
Member

It looks like AppVeyor got confused, I've restarted that.

@etal - do the PDB SeqIO changes look fine to you too? If so, I think this is ready for a squash-merge.

@peterjc

peterjc commented Nov 12, 2018

Copy link
Copy Markdown
Member

@DevangThakkar you are also welcome to add your name to the NEWS.rst list for the next release.

@codecov

codecov Bot commented Nov 12, 2018 •

Copy link
Copy Markdown

Codecov Report

Merging #1845 into master will increase coverage by 3.02%.
The diff coverage is 50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1845      +/-   ##
==========================================
+ Coverage   82.43%   85.45%   +3.02%     
==========================================
  Files         300      301       +1     
  Lines       49264    49314      +50     
==========================================
+ Hits        40609    42142    +1533     
+ Misses       8655     7172    -1483
Impacted Files Coverage Δ
Bio/SeqIO/UniprotIO.py 91.96% <50%> (+0.04%) ⬆️
Bio/SeqIO/PdbIO.py 94.4% <50%> (-1.28%) ⬇️
Bio/PDB/mmtf/DefaultParser.py 100% <0%> (ø)
Bio/Phylo/BaseTree.py 89.21% <0%> (+0.19%) ⬆️
Bio/Data/CodonTable.py 97.89% <0%> (+0.35%) ⬆️
Bio/GenBank/Record.py 92.32% <0%> (+0.4%) ⬆️
Bio/SearchIO/HmmerIO/hmmer2_text.py 97.52% <0%> (+0.41%) ⬆️
Bio/SCOP/__init__.py 61.42% <0%> (+0.62%) ⬆️
Bio/Application/__init__.py 87.74% <0%> (+1.18%) ⬆️
... and 37 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 c204271...b8e12fc. Read the comment docs.

@peterjc

peterjc commented Nov 13, 2018

Copy link
Copy Markdown
Member

AppVeyor looks fine - it just got stuck after the tests trying to update the coverage results.

If there are no objections, I think this can be merged at the end of the week. Thank you!

@DevangThakkar

Copy link
Copy Markdown
Contributor Author

Thank you for your help! I'm looking forward to contributing more to biopython.

@peterjc

peterjc commented Nov 19, 2018

Copy link
Copy Markdown
Member

I'm going to have to rebase this to deal with a trivial merge conflict in the NEWS.rst file (another name was added this morning), and then apply this pull request...

@peterjc
peterjc force-pushed the better-error-messages branch from 7450aac to b8e12fc Compare November 19, 2018 11:33
@peterjc
peterjc merged commit 8ebd3a6 into biopython:master Nov 19, 2018
@peterjc

peterjc commented Nov 19, 2018

Copy link
Copy Markdown
Member

Merged, thank you Devang 👍

@DevangThakkar
DevangThakkar deleted the better-error-messages branch November 20, 2018 19:28
peterjc added a commit to peterjc/biopython that referenced this pull request Aug 30, 2019
Original author Andrea Pierleoni and contributors since as tracked
by version control have all agreed:

 - Adhemar Zerlotini (@azneto)
   biopython#1412 (comment)
 - Andrea Pierleoni (@apierleoni)
   biopython#898 (comment)
 - Carlos Pena (@carlosp420)
   biopython#898 (comment)
 - Chris Rands (@chris-rands)
   biopython#1301
 - chrismit (@Chris7)
   biopython#898 (comment)
 - Christian Brueffer (@cbrueffer)
   biopython#898 (comment)
 - Devang Thakkar (@DevangThakkar)
   biopython#1845
 - Francesco Gastaldello (@Gasta88)
   biopython#1063
 - @morrme
   biopython#1172 (comment)
 - Oscar G. Garcia (@OscarMaestre)
   biopython#898 (comment)
 - Peter Cock (@peterjc)
   biopython#898 (comment)
 - Uri Laserson (@laserson)
   biopython#898 (comment)
 - Vincent Davis (@vincentdavis)
   biopython#898 (comment)
peterjc added a commit to peterjc/biopython that referenced this pull request Sep 3, 2019
Original author Eric Talevich and the contributors since as tracked
with version control have all agreed:

 - Christian Brueffer (@cbrueffer)
   biopython#898 (comment)
 - Devang Thakkar (@DevangThakkar)
   biopython#1845
 - Eric Talevich (@etal)
   biopython#898 (comment)
 - Francesco Gastaldello (@Gasta88)
   biopython#1063
 - Kiran Mukhyala (@mukhyala)
   biopython#2215
 - Matsuyuki Shirota (@matsu3shiro)
   biopython#2244 (comment)
 - Peter Cock (@peterjc)
   biopython#898 (comment)
 - Stefans Mezulis (@StefansM)
   biopython#1445
 - Wayne Decatur (@fomightez)
   biopython#898 (comment)
 - Wibowo Arindrarto (@bow)
   biopython#898 (comment)
peterjc added a commit that referenced this pull request Nov 4, 2019
Original author Andrea Pierleoni and contributors since as tracked
by version control have all agreed:

 - Adhemar Zerlotini (@azneto)
   #1412 (comment)
 - Andrea Pierleoni (@apierleoni)
   #898 (comment)
 - Carlos Pena (@carlosp420)
   #898 (comment)
 - Chris Rands (@chris-rands)
   #1301
 - chrismit (@Chris7)
   #898 (comment)
 - Christian Brueffer (@cbrueffer)
   #898 (comment)
 - Devang Thakkar (@DevangThakkar)
   #1845
 - Francesco Gastaldello (@Gasta88)
   #1063
 - @morrme
   #1172 (comment)
 - Oscar G. Garcia (@OscarMaestre)
   #898 (comment)
 - Peter Cock (@peterjc)
   #898 (comment)
 - Uri Laserson (@laserson)
   #898 (comment)
 - Vincent Davis (@vincentdavis)
   #898 (comment)
peterjc added a commit that referenced this pull request Nov 4, 2019
Original author Eric Talevich and the contributors since as tracked
with version control have all agreed:

 - Christian Brueffer (@cbrueffer)
   #898 (comment)
 - Devang Thakkar (@DevangThakkar)
   #1845
 - Eric Talevich (@etal)
   #898 (comment)
 - Francesco Gastaldello (@Gasta88)
   #1063
 - Kiran Mukhyala (@mukhyala)
   #2215
 - Matsuyuki Shirota (@matsu3shiro)
   #2244 (comment)
 - Peter Cock (@peterjc)
   #898 (comment)
 - Stefans Mezulis (@StefansM)
   #1445
 - Wayne Decatur (@fomightez)
   #898 (comment)
 - Wibowo Arindrarto (@bow)
   #898 (comment)
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.

2 participants