You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Minimal MEME format support in Bio.motifs.MEME parser #232
The MEME parser fails to even load X.meme files downloaded FROM MEME.
The complaint is:
ValueError("Unexpected end of stream: 'TRAINING SET' not found.")
Looking at the code, it will fail again even if that worked bc it expects **** to follow.
it seems the parser only understands the FULL MEME output format, not the minimal format that seems to be what MEME actually stores its motifs in. This seems a MAJOR oversight. At the very least it limits the usefulness of the module greatly.
Is there any plan to support the minimal MEME format? IS it supported? Am I just being a dunce? I am good at being a dunce.
Yeah I will work on it. I am in the homestretch of my dissertation though so it will be a couple weeks. But if the world has survived this long, it will probably be ok!
$ python
Python 2.7.5 (default, Aug 25 2013, 00:04:04)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from Bio import motifs
>>> with open("hallikas2006.meme") as h:
... for m in motifs.parse(h, "meme"): print m
...
Traceback (most recent call last):
File "", line 2, in
File "/Library/Python/2.7/site-packages/Bio/motifs/__init__.py", line 72, in parse
record = meme.read(handle)
File "/Library/Python/2.7/site-packages/Bio/motifs/meme.py", line 29, in read
__read_datafile(record, handle)
File "/Library/Python/2.7/site-packages/Bio/motifs/meme.py", line 146, in __read_datafile
raise ValueError("Unexpected end of stream: 'TRAINING SET' not found.")
ValueError: Unexpected end of stream: 'TRAINING SET' not found.
The MEME files produced by XXmotif (see Bio/motifs/applications/_xxmotif.py) would be good to keep in mind as well, they can't be read by the current code either. Not sure whether the format corresponds to the minimal format referenced above.
Thanks for pointing out that commit and issue, @saketkc.
I don't think that fixes this though, since that didn't have to do with getting the minimal MEME format to parse. In particular, line 188 of Bio/motifs/meme.py still raises an error when the training set is not found, as mentioned by @xguse, in the initial report for this issue.
I began working on it but there was so much that needed to be integrated with existing BioPython structure (which is a bit quite overly convoluted IMHO) that I had to move on to other job related things. What works for me was MUCH simpler and would have been a massive style/convention shift for the code as it stood.
That's too bad, but quite understandable. Thanks for your comments; they confirm my initial impression upon looking at the relevant code. I will likely avoid trying to implement this as well.
Same problem here. Anyone can suggest an alternative solution? I need to translate minimal meme to another format. Biopython also fails to read other meme output (count matrix or freq matrix or jaspar).
Maybe meme minimal format can be treated as a different format.
Below is a relatively functioning parser for minimal format.
It's inspired on meme parser. I also made a writer function.
fromBio.AlphabetimportIUPACfromBioimportSeqfromBioimportmotifsimportmathdefread(handle):
"""Parses the text output of the MEME program into a meme.Record object. Example: >>> from Bio.motifs import meme >>> with open("meme.output.txt") as f: ... record = meme.read(f) >>> for motif in record: ... for instance in motif.instances: ... print(instance.motif_name, instance.sequence_name, instance.strand, instance.pvalue) """motif_number=0record=Record()
__read_version(record, handle)
__read_alphabet(record, handle)
__read_background(record, handle)
whileTrue:
forlineinhandle:
ifline.startswith('MOTIF'):
breakelse :
returnrecordname=line.split()[1]
motif_number+=1length, num_occurrences, evalue=__read_motif_statistics(line,handle)
counts=__read_lpm(line,handle)
#{'A': 0.25, 'C': 0.25, 'T': 0.25, 'G': 0.25}motif=motifs.Motif(alphabet=record.alphabet,counts=counts)
motif.background=record.backgroundmotif.length=lengthmotif.num_occurrences=num_occurrencesmotif.evalue=evaluemotif.name=namerecord.append(motif)
assertlen(record) ==motif_numberreturnrecordclassRecord(list):
"""A class for holding the results of a MEME run. """def__init__(self):
"""__init__ (self)"""self.version=""self.datafile=""self.command=""self.alphabet=Noneself.background= {}
self.sequences= []
def__getitem__(self, key):
ifisinstance(key, str):
formotifinself:
ifmotif.name==key:
returnmotifelse:
returnlist.__getitem__(self, key)
# Everything below is privatedef__read_background(record, handle):
forlineinhandle:
ifline.startswith('Background letter frequencies'):
breakelse:
raiseValueError("Improper input file. File should contain a line starting background frequencies.")
try:
line=next(handle)
exceptStopIteration:
raiseValueError("Unexpected end of stream: Expected to find line starting background frequencies.")
line=line.strip()
ls=line.split()
A,C,G,T=float(ls[1]),float(ls[3]),float(ls[5]),float(ls[7])
record.background= {'A':A,'C':C,'G':G,'T':T }
def__read_version(record, handle):
forlineinhandle:
ifline.startswith('MEME version'):
breakelse:
raiseValueError("Improper input file. File should contain a line starting MEME version.")
line=line.strip()
ls=line.split()
record.version=ls[2]
def__read_alphabet(record, handle):
forlineinhandle:
ifline.startswith('ALPHABET'):
breakelse:
raiseValueError("Unexpected end of stream: Expected to find line starting with 'ALPHABET'")
ifnotline.startswith('ALPHABET'):
raiseValueError("Line does not start with 'ALPHABET':\n%s"%line)
line=line.strip()
line=line.replace('ALPHABET= ', '')
ifline=='ACGT':
al=IUPAC.unambiguous_dnaelse:
al=IUPAC.proteinrecord.alphabet=aldef__read_lpm(line,handle):
counts= [[],[],[],[]]
forlineinhandle:
freqs=line.split()
iflen(freqs) !=4:
breakcounts[0].append(int(float(freqs[0])*1000000))
counts[1].append(int(float(freqs[1])*1000000))
counts[2].append(int(float(freqs[2])*1000000))
counts[3].append(int(float(freqs[3])*1000000))
c= {}
c['A'] =counts[0]
c['C'] =counts[1]
c['G'] =counts[2]
c['T'] =counts[3]
returncdef__read_motif_statistics(line,handle):
# minimal :# letter-probability matrix: alength= 4 w= 19 nsites= 17 E= 4.1e-009 forlineinhandle:
ifline.startswith('letter-probability matrix:'):
breaknum_occurrences=int(line.split("nsites=")[1].split()[0])
length=int(line.split("w=")[1].split()[0])
evalue=float(line.split("E=")[1].split()[0])
returnlength, num_occurrences, evaluedef__read_motif_name(handle):
forlineinhandle:
if'sorted by position p-value'inline:
breakelse:
raiseValueError('Unexpected end of stream: Failed to find motif name')
line=line.strip()
words=line.split()
name=" ".join(words[0:2])
returnname
@aralap Is the difference between the full MEME output and the minimal MEME output a matter of how information is stored in the file? Or does the full MEME output store more information than the minimal MEME output? This can help us decide how to organize the code. For example, could we use the same Record class for both full and minimal MEME output?
The full MEME output contains instances, and these are required by the parser.
The minimal MEME output only contains statistics with a pwm/log-odds matrix .
Although the full MEME does contain pwm/log-odds matrix they are different in format.
(For example, they are transversed in version 4.12.0)
If full MEME = minimal MEME + instances, then I would suggest to use the same module and parser, and update the parser such that it can handle both formats.
@j-andrews7 I planned to do it but haven't found the time recently. Also i wasn't sure the approach i would take was the desired one. I already have a minimal format parser working and wouldn't bother to make a pull request with that.
Activity
peterjc commentedon Sep 5, 2013
@mdehoon & @barwil - one for you
P.S. Are you getting pull request notifications?
mdehoon commentedon Sep 6, 2013
Hi @xguse, can you provide a patch to allow the MEME parser to parse the minimal MEME format?
xguse commentedon Sep 6, 2013
Yeah I will work on it. I am in the homestretch of my dissertation though so it will be a couple weeks. But if the world has survived this long, it will probably be ok!
peterjc commentedon Dec 27, 2013
@xguse are you talking about the MEME motif database downloads from http://ebi.edu.au/ftp/software/MEME/Databases/motifs/ where the latest release is http://ebi.edu.au/ftp/software/MEME/Databases/motifs/motif_databases.10.3.tgz used below:
$ python Python 2.7.5 (default, Aug 25 2013, 00:04:04) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from Bio import motifs >>> with open("hallikas2006.meme") as h: ... for m in motifs.parse(h, "meme"): print m ... Traceback (most recent call last): File "", line 2, in File "/Library/Python/2.7/site-packages/Bio/motifs/__init__.py", line 72, in parse record = meme.read(handle) File "/Library/Python/2.7/site-packages/Bio/motifs/meme.py", line 29, in read __read_datafile(record, handle) File "/Library/Python/2.7/site-packages/Bio/motifs/meme.py", line 146, in __read_datafile raise ValueError("Unexpected end of stream: 'TRAINING SET' not found.") ValueError: Unexpected end of stream: 'TRAINING SET' not found.daquang commentedon Jun 27, 2014
Did this issue ever get resolved? I would like for the parser to read minimal MEME
mdehoon commentedon Jul 4, 2014
Hi @daquang , @xguse , can either of you provide a patch to allow the MEME parser to parse the minimal MEME format?
cbrueffer commentedon Sep 4, 2014
The MEME files produced by XXmotif (see Bio/motifs/applications/_xxmotif.py) would be good to keep in mind as well, they can't be read by the current code either. Not sure whether the format corresponds to the minimal format referenced above.
cviner commentedon Jun 17, 2015
Hi @xguse @mdehoon @barwil,
This issue appears to still be outstanding. Is anyone working on or planning to work on this?
saketkc commentedon Jun 17, 2015
I think this was fixed in c6e8d02
It should be in the next BioPython release(?)
cviner commentedon Jun 17, 2015
Thanks for pointing out that commit and issue, @saketkc.
I don't think that fixes this though, since that didn't have to do with getting the minimal MEME format to parse. In particular, line 188 of
Bio/motifs/meme.pystill raises an error when the training set is not found, as mentioned by @xguse, in the initial report for this issue.saketkc commentedon Jun 17, 2015
Sorry, I misunderstood the point of this issue.
cviner commentedon Jun 17, 2015
@saketkc,
No problem; I appreciate your looking into it!
xguse commentedon Jun 18, 2015
I began working on it but there was so much that needed to be integrated with existing BioPython structure (which is
a bitquite overly convoluted IMHO) that I had to move on to other job related things. What works for me was MUCH simpler and would have been a massive style/convention shift for the code as it stood.cviner commentedon Jun 18, 2015
@xguse,
That's too bad, but quite understandable. Thanks for your comments; they confirm my initial impression upon looking at the relevant code. I will likely avoid trying to implement this as well.
egenomics commentedon Aug 26, 2016
Same problem here. Anyone can suggest an alternative solution? I need to translate minimal meme to another format. Biopython also fails to read other meme output (count matrix or freq matrix or jaspar).
2 remaining items
Thank Jared for MEME exception improvement.
aralap commentedon Sep 1, 2017
Maybe meme minimal format can be treated as a different format.
Below is a relatively functioning parser for minimal format.
It's inspired on meme parser. I also made a writer function.
[-]Bio.motifs.MEME parser outdated?[/-][+]Minimal MEME format support in Bio.motifs.MEME parser[/+]peterjc commentedon Sep 1, 2017
What do you think @mdehoon, @barwil - should we ask @aralap to turn that into a pull request?
mdehoon commentedon Sep 11, 2017
@aralap Is the difference between the full MEME output and the minimal MEME output a matter of how information is stored in the file? Or does the full MEME output store more information than the minimal MEME output? This can help us decide how to organize the code. For example, could we use the same Record class for both full and minimal MEME output?
aralap commentedon Sep 11, 2017
The full MEME output contains instances, and these are required by the parser.
The minimal MEME output only contains statistics with a pwm/log-odds matrix .
Although the full MEME does contain pwm/log-odds matrix they are different in format.
(For example, they are transversed in version 4.12.0)
mdehoon commentedon Sep 14, 2017
If full MEME = minimal MEME + instances, then I would suggest to use the same module and parser, and update the parser such that it can handle both formats.
j-andrews7 commentedon Oct 23, 2017
@aralap did you plan to submit a pull request for this? If not, I will revise the existing parser to also handle the minimal MEME format.
Thank Jared for MEME exception improvement.
aralap commentedon Dec 11, 2017
@j-andrews7 I planned to do it but haven't found the time recently. Also i wasn't sure the approach i would take was the desired one. I already have a minimal format parser working and wouldn't bother to make a pull request with that.
xguse commentedon Dec 11, 2017
aralap commentedon Jul 11, 2018
Initial commit of code #1734 to make this work, will add test for it soon.
chebizarro commentedon Jul 22, 2020
Pull request #1734 has been merged successfully, can this issue be closed now or is additional work required for minimal MEME support?
peterjc commentedon Jul 22, 2020
Probably - do you agree @mdehoon ?