bjmt / universalmotif

Motif manipulation functions for R.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't run meme with custom alphabet

manoloff opened this issue · comments

Hello!
I have the issue that I can't run the run_meme function with custom alphabet. The first traceable error is in 'get_custom_meme_alph', where the alphabet file is read. It searches for a match to "END ALPHABET" which can't exist, if the alphabet is to pass other checks. I have made a small reproducible example with Biostrings version 2.64 and universalmotif version 1.13.9 where I create the custom methylated DNA alphabet you have presented in the vignettes and write it to a file then try to use it (https://bioconductor.org/packages/release/bioc/manuals/universalmotif/man/universalmotif.pdf)

library(universalmotif)
library(Biostrings)

meme_alph("ACm", complements = "TGM", alph.name = "MethDNA",
          letter.names = c(A = "Adenine", C = "Cytosine", G = "Guanine",
                           T = "Thymine", m = "Methylcytosine", M = "mC:Guanine"),
          like = "DNA", ambiguity = c(N = "ACGTmM"),
          file = "temp.alph")

sequences <- DNAStringSet(c("ccaagtttcaa", "taaagttgtat", "aaatgccctac", "tccaagtttca", "gtaccttgtga", "ttaaaatcgtc", "gaacactttct", "aatcacttttg", "ttgtcctggcg"))
# Runs great with standard DNA alphabet
first_attempt <- run_meme(sequences, bin = "/path/to/bin", verbose = 0)
# Doesn't run
secont_attempt <- run_meme(sequences, bin = "/path/to/bin", verbose = 0, alph = "temp.alph")

This might be related to #6.

Also, in case this is relevant to a fix, the custom alphabet spec is defined here.

Okay. So there is no intend on running run_meme with a custom alphabet?

I tried writing the sequences to a fasta file and running the whole thing through a system command with the intention of using read_meme to then read the results, however meme-chip (version 5.4.1) doesn't produce an "END ALPHABET" line in the meme output, so I end up having to add it myself in order to read it. So in short - I can neither run meme with a custom alphaber, nor read one after it's ran if I don't myself edit the meme file. Is this desired?

(a snippet from the meme output file)

********************************************************************************
ALPHABET "MethDNA" DNA-LIKE
********************************************************************************
A "Adenine" 660000 ~ T "Thymine" 000066
C "Cytosine" 666600 ~ G "Guanine" 006600
M "mC:Guanine" 006666 ~ m "Methylcytosine" 660066
N = ACGMTm
********************************************************************************

********************************************************************************
TRAINING SET
********************************************************************************
PRIMARY SEQUENCES= output/seqs-centered
CONTROL SEQUENCES= --none--
Sequence name            Weight Length  Sequence name            Weight Length  
-------------            ------ ------  -------------            ------ ------  
1                        1.0000     11  2                        1.0000     11  
3                        1.0000     11  4                        1.0000     11  
5                        1.0000     11  6                        1.0000     11  
7                        1.0000     11  8                        1.0000     11  
9                        1.0000     11  
********************************************************************************

Still using the custom alphabet from the example I mentioned

So there is no intend on running run_meme with a custom alphabet?

The intent is to support custom alphabets. Not fully supporting them was a stopgap in that PR to at least broaden the support to DNA/etc.-like alphabets while waiting on a full custom alphabet support, which Ben later implemented. Clearly there's still some kinks to work out.

The END ALPHABET chunk does exist in some types of MEME suite output file (see: dreme.txt for an example), but the fact that it is not always included is frustrating. I'm working on a quick fix that could solve this.

I appreciate that this is frustrating, thanks for your patience.

Thank you! I will continue with the above mentioned fix until there is an official fix :)

Fix is filed for PR, I also added a better error message to indicate it's failing at parsing the custom alphabet in case this happens with other output types in the future with a hint to file an issue here. How each MEME tool writes the meme.txt file varies with different parameters or just is different between tools, so it's hard to write a perfect parser in one go. Think we'll just have to keep catching these edge cases unless there's a documented spec somewhere.

@bjmt seems worth throwing into release as well since this is a bug? Up to you.

Sorry for taking forever to get around to this. I had no idea the MEME alphabet definition could change like that. Though admittedly I've never used custom alphabets for my own work, so I never really tested read_meme() for such cases too thoroughly.

@snystrom Thanks for the fix, I'm testing it now and will merge into release today/tomorrow. You're right that it's a bit hacky but it doesn't change previous behaviour so I'm happy to merge it in until the next bug report/time I become inclined to fix it properly/etc.

Assuming I get this into the release branch today or tomorrow, it should show up in the Bioconductor release (3.15) sometime in the middle of the week. Thanks for reporting this!