A tool for graphic representation of multiple motifs
author: Jianhong Ou, Julie Zhu
date: July 30, 2014
single motif: package seqlogo, or webLogo
Multiple motifs: motifStack

library(motifStack)
pcm <- readPCM(file.path(find.package("motifStack"),
"extdata"), pattern="bin_SOLEXA.pcm")
plot(pcm[[1]], font="mono,Courier")
protein<-read.table(file.path(
find.package("motifStack"),
"extdata", "cap.txt"))
protein<-t(protein[,1:20])
motif<-pcm2pfm(protein)
motif<-new("pfm", mat=motif, name="CAP",
color=colorset(alphabet="AA",
colorScheme="chemistry"))
plot(motif)
pcms<-readPCM(file.path(
find.package("motifStack"),
"extdata"),
"pcm$")
pfms<-lapply(pcms, pcm2pfm)
motifStack(pfms, layout="tree", trueDist=TRUE)
motifStack(pfms, layout="tree", trueDist=TRUE, ic.scale=FALSE)
library("MotifDb")
matrix.fly <- query(MotifDb,
"Dmelanogaster")
motifs2 <- as.list(matrix.fly)
## use data from FlyFactorSurvey
motifs2 <- motifs2[grepl("Dmelanogaster\\-FlyFactorSurvey\\-",
names(motifs2))]
## format the names
names(motifs2) <- gsub("Dmelanogaster_FlyFactorSurvey_", "",
gsub("_FBgn\\d+$", "",
gsub("[^a-zA-Z0-9]","_",
gsub("(_\\d+)+$", "",
names(motifs2)))))
names(motifs2) <- gsub("_\\d+$", "",
names(motifs2))
motifs2 <- motifs2[unique(names(motifs2))]
pfms <- sample(motifs2, 50)
## creat a list of object of pfm
motifs2 <- lapply(names(pfms),
function(.ele, pfms){new("pfm",mat=pfms[[.ele]], name=.ele)}
,pfms)
## trim the motifs
motifs2 <- lapply(motifs2, trimMotif, t=0.4)
## use MotIV to calculate the distances of motifs
jaspar.scores <- MotIV::readDBScores(
file.path(find.package("MotIV"),
"extdata",
"jaspar2010_PCC_SWU.scores"))
d <- MotIV::motifDistances(pfms)
hc <- MotIV::motifHclust(d)
## convert the hclust to phylog object
phylog <- hclust2phylog(hc)
## reorder the pfms by the order of hclust
leaves <- names(phylog$leaves)
pfms <- pfms[leaves]
## create a list of pfm objects
pfms <- lapply(names(pfms), function(.ele, pfms){
new("pfm",mat=pfms[[.ele]], name=.ele)}
,pfms)
## extract the motif signatures
motifSig <- motifSignature(pfms, phylog, groupDistance=0.01, min.freq=1)
## assign groups for motifs
methods <- gsub("^.*?_(SANGER|FlyReg|SOLEXA|Cell|NAR)$", "\\1", leaves)
names(methods) <- leaves
## assign group colors
methods.col <- 1:length(methods)
names(methods.col)<-unique(methods)
## get the signatures from object of motifSignature
sig <- signatures(motifSig)
## set the inner-circle color for each signature
gpCol <- sigColor(motifSig)
plotMotifStackWithRadialPhylog(phylog=phylog, pfms=sig,
circle=0.6, cleaves = 0.5,
clabel.leaves = 0.7,
col.bg=methods.col, col.bg.alpha=0.3,
col.leaves=rep(1:6, 10)[1:length(gpCol)],
col.inner.label.circle=gpCol,
inner.label.circle.width=0.03,
angle=350, circle.motif=1.2,
motifScale="logarithmic")
motifCloud(motifSig, scale=c(6, .5),
layout="rectangles",
draw.legend=T)
motifCloud(motifSig, layout = "cloud", ic.scale = FALSE)