Skip to content

Review empty file behaviour for SeqIO parsers #1838

Closed

Description

@peterjc

In some sequence formats (e.g. FASTA, FASTQ, GenBank, EMBL, Swiss) an empty file is a legitimate corner case meaning no sequences. In order formats (e.g. SFF, XML) an empty file is invalid as a minimal header is expected.

This issue is to review all the SeqIO file formats and their behaviour when asked to parse an empty file - and document on this issue what they currently do.

They should either return no sequences, or raise a clear exception indicating an invalid empty file. We may want to standardise the wording of the exception and ensure this is always the same exception class, e.g. ValueError.

See discussion on #1835 which touches on this, and white listing some of the parsers in the tests. Those test would ideally validate the exception follows any agreed convention.

Activity

  1. added
    good first issue
    on Oct 30, 2018
  2. DevangThakkar commented on Nov 9, 2018

    @DevangThakkar
    Contributor

    I've tried to document the results that are printed out when SeqIO encounters an empty file in each of the formats mentioned in the documentation. I've uploaded the test script and the results here.

    Most formats do not print anything (25/31). cif-atom and cif-seqres give Unknown format 'cif-atom' and Unknown format 'cif-seqres' errors. pdb-atom raises an exception the message for which is simply 0. sff and sff-trim raise more meaningful Empty file errors. Finally, uniport-xml raises a no element found: line 1, column 0 error.

    This is my first attempt at contributing to Biopython, so if you could help me get started with what comes next, that'll be really great.

  3. peterjc commented on Nov 9, 2018

    @peterjc
    MemberAuthor

    It sounds like a pull request for cif-atom and cif-seqres, and/or a pull request for uniprot-xml, would be a good idea. Rather than the current message I think these should return ValueError("Empty file") like SFF?

    For pdb-atom, I'm not sure if return no records is sensible, or again, the Empty File message is better.

  4. peterjc commented on Aug 30, 2019

    @peterjc
    MemberAuthor

    Current results, using this empty.py script:

    from Bio import SeqIO
    
    for format in SeqIO._FormatToIterator:
        try:
            records = list(SeqIO.parse("empty.ext", format))
        except Exception as err:
            print("%s: %s" % (format, err))
        else:
            print("%s: %i records" % (format, len(records)))

    Gives:

    $ touch empty.ext
    $ python empty.py
    fasta: 0 records
    fasta-2line: 0 records
    gb: 0 records
    genbank: 0 records
    genbank-cds: 0 records
    embl: 0 records
    embl-cds: 0 records
    imgt: 0 records
    ig: 0 records
    swiss: 0 records
    pdb-atom: Empty file.
    pdb-seqres: 0 records
    cif-seqres: 0 records
    cif-atom: Empty file.
    phd: 0 records
    ace: 0 records
    tab: 0 records
    pir: 0 records
    fastq: 0 records
    fastq-sanger: 0 records
    fastq-solexa: 0 records
    fastq-illumina: 0 records
    qual: 0 records
    sff: Empty file.
    sff-trim: Empty file.
    uniprot-xml: Empty file.
    seqxml: 0 records
    abi: 0 records
    abi-trim: 0 records
    

    There is unfortunately an inconsistency in pdb-atom vs pdb-seqres, and cif-seqres and cif-atom - they should all give ValueError("Empty file.") - do you want to add that @DevangThakkar?

    Also, as ABI format is binary, I think abi and abi-trim ought to give the empty file exception too? What do you think @bow?

  5. DevangThakkar commented on Sep 3, 2019

    @DevangThakkar
    Contributor

    Sure, I'll get to it in a bit today. Do we do that for abi as well?

  6. peterjc commented on Sep 3, 2019

    @peterjc
    MemberAuthor

    Probably for ABI too, subject to approval by @bow

  7. Caiofcas commented on Apr 6, 2021

    @Caiofcas
    Contributor

    Is there Still something to do in this Issue? Would love to help, but it seems that it should be closed.

  8. peterjc commented on Apr 6, 2021

    @peterjc
    MemberAuthor

    Running that test script again now,

    abi: Empty file.
    abi-trim: Empty file.
    ace: 0 records
    fasta: 0 records
    fasta-2line: 0 records
    ig: 0 records
    embl: 0 records
    embl-cds: 0 records
    gb: 0 records
    gck: Empty file.
    genbank: 0 records
    genbank-cds: 0 records
    imgt: 0 records
    nib: Empty file.
    cif-seqres: Empty file.
    cif-atom: Empty file.
    pdb-atom: Empty file.
    pdb-seqres: Empty file.
    phd: 0 records
    pir: 0 records
    fastq: 0 records
    fastq-sanger: 0 records
    fastq-solexa: 0 records
    fastq-illumina: 0 records
    qual: 0 records
    seqxml: Empty file.
    sff: Empty file.
    snapgene: Empty file.
    sff-trim: Empty file.
    swiss: 0 records
    tab: 0 records
    twobit: Empty file.
    uniprot-xml: Empty file.
    xdna: Empty file.
    

    I think that all looks fine, so yes - we can close this. Thank you @Caiofcas for taking a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issuehelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions