AliciaSchep / ggmotif

add DNA sequence motifs to ggplot
Other
11 stars 3 forks source link

Motif logos from PWMatrixClass #1

Open dpcook opened 6 years ago

dpcook commented 6 years ago

Hey Alicia,

Do you have any advice/options for plotting from PWMatrixClass motifs (eg. data(human_pwms_v1) in chromVAR)? ggmotif works well with the PFMatrixClass from getJasparMotifs(), where the matrix values are all positive integers, but for the other motif collections, their matrices include both positive and negative values, so the logos end up a little odd library(chromVAR) library(ggmotif) data(human_pwms_v1) ggmotif_plot(human_pwms_v1[[1]])

image

I'm not familiar enough with the differences between these matrices yet to know if I can transform them or anything, so I just figured I'd check.

Thanks! David

AliciaSchep commented 6 years ago

The PWMatrix ones with negative values are in log scale, so if you transform to be frequencies by taking exp they look nicer:

pwm <- human_pwms_v1[[1]]
mat <- TFBSTools::as.matrix(pwm)
probmat <- exp(mat) * matrix(TFBSTools::bg(pwm), nrow = nrow(mat), 
                             ncol = ncol(mat),  byrow = FALSE)
ggmotif::ggmotif_plot(probmat)

image

It would probably be nice if the ggmotif_plot function would by default do that, maybe with an option to do it the ugly negative way, but I don't know if I"ll get around to implementing that (PR welcome though! basically could adapt top two functions in https://github.com/GreenleafLab/chromVAR/blob/master/R/pwm_dist.R). I've been kinda neglecting this package because I think generally the ggseqlogo package that has come out is a better implementation of sequence logos in ggplot (although doesn't directly take in BioC classes as input, so wouldn't make this issue any easier).