Skip to content

meme file parsing fails with current version of meme #1988

Closed

Description

@mdehoon

Setup

I am reporting a problem with Biopython version, Python version, and operating
system as follows:

>>> import sys; print(sys.version)
2.7.15 (v2.7.15:ca079a3ea3, Apr 29 2018, 17:49:27) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
>>> import platform; print(platform.python_implementation()); print(platform.platform())
CPython
Darwin-18.2.0-x86_64-i386-64bit
>>> import Bio; print(Bio.__version__)
1.74.dev0

Expected behaviour

>>> from Bio import motifs
>>> handle = open('meme.txt')
>>> record = motifs.parse(handle, 'meme')
>>>

Actual behaviour

>>> from Bio import motifs
>>> handle = open('meme.txt')
>>> record = motifs.parse(handle, 'meme')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Bio/motifs/__init__.py", line 78, in parse
    record = meme.read(handle)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Bio/motifs/meme.py", line 40, in read
    __read_datafile(record, handle)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Bio/motifs/meme.py", line 176, in __read_datafile
    raise ValueError("Line does not start with 'DATAFILE':\n%s" % line)
ValueError: Line does not start with 'DATAFILE':
PRIMARY SEQUENCES= Klf1.100.fa

This is with meme version 5.0.5 (the latest version).
Note that meme generates an XML file as well as a human-readable text file. The meme parser in Biopython is currently designed for parsing the text file, which is fragile to any changes to the text file format. I suggest we switch to parsing the XML file instead.

Activity

  1. peterjc commented on Mar 29, 2019

    @peterjc
    Member

    i.e. Goal is to recommend parsing the XML, and formally deprecate the plain text parser? Much like with BLAST (although we've not quite killed the plain text parser). Sounds sensible.

    Cross reference PR #1986, #1958

  2. victorlin commented on Apr 15, 2019

    @victorlin
    Contributor

    I have been using the xml module from Python's standard library to parse the MAST output file. It's been straightforward and I believe all the information from the plain text file can be extracted from the XML as well. It would just be a matter of rewriting the read() functions in mast.py and meme.py while using the classes already defined.

  3. victorlin commented on Apr 15, 2019

    @victorlin
    Contributor

    Actually, it seems that XML output for MAST was introduced in version 4.4.0. Users who want to parse results from older versions of MAST would have to use the plain text parser. I'm not sure if MEME output was once plain text only.

    Instead of replacing the plain text parser, should we maintain it and have an option to detect if the filename ends in .txt or .xml then parse accordingly?

  4. mdehoon commented on Apr 16, 2019

    @mdehoon
    ContributorAuthor

    @victorlin MEME 4.4.0 is nine years old. I don't think we need to support it.

  5. victorlin commented on Apr 16, 2019

    @victorlin
    Contributor

    That will make things easier. Is there a way to generate XML output files using the same data as the plain text output in Tests/motifs? That way we can be sure the same functionality is preserved with the new parser.

  6. mdehoon commented on Apr 27, 2019

    @mdehoon
    ContributorAuthor

    It looks like at least some of those test data were coming from meme itself (you can find the exact command that was used in the output files, and some of the input files can be found by googling). However I wouldn't be too strict about using the exact same test data.

  7. joshuacook487 commented on Oct 13, 2019

    @joshuacook487

    If still needs to be fixed I am able to do it. I previously have made a program to alter the text input so the error doesn't occur, so I am pretty familiar with the issue.

  8. peterjc commented on Oct 14, 2019

    @peterjc
    Member

    It looks like with #1986 and #2082 merged this issue can be closed?

  9. victorlin commented on Oct 14, 2019

    @victorlin
    Contributor

    @peterjc those 2 PRs updated the MAST parser. MEME parsing as of now seems to still be based on the text file which is prone to errors.

    Looks like it would be better to switch to XML only for MEME as well – I can help rewrite the parser accordingly.

  10. peterjc commented on Oct 14, 2019

    @peterjc
    Member

    Ah - an important distinction. Volunteering to work on XML for MEME sounds good!

  11. victorlin commented on Aug 25, 2021

    @victorlin
    Contributor

    @peterjc @mdehoon with the above PR mergred, this issue can be closed.

  12. mdehoon commented on Aug 25, 2021

    @mdehoon
    ContributorAuthor

    @victorlin Thanks

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions