### R code from vignette source 'vignettes/motifRG/inst/doc/motifRG.Rnw'

###################################################
### code chunk number 1: motifRG.Rnw:73-82
###################################################
library(motifRG)
data(ctcf.seq)
data(control.seq)
### concatenate the foreground, background sequences
all.seq <- append(ctcf.seq, control.seq)
### specify which sequences are foreground, background. 
category <- c(rep(1, length(ctcf.seq)), rep(0, length(control.seq))) 
### find motifs
ctcf.motifs <- findMotif(all.seq=all.seq, category=category, max.motif=3)     


###################################################
### code chunk number 2: motifRG.Rnw:85-86
###################################################
motifLatexTable(main="CTCF motifs", ctcf.motifs)


###################################################
### code chunk number 3: motifRG.Rnw:90-93
###################################################
###Find a refined PWM model given the motif matches as seed
pwm.match <- refinePWMMotif(ctcf.motifs$motifs[[1]]@match$pattern, ctcf.seq)
library(seqLogo)


###################################################
### code chunk number 4: motifRG.Rnw:98-99
###################################################
seqLogo(pwm.match$model$prob)


###################################################
### code chunk number 5: motifRG.Rnw:105-112
###################################################
## Motifs found by findMotif tend to be relatively short, as longer and
## more specific motif models do not necessarily provide better
## discrimination of foreground background vs background if they are
## already well separated. However, one can refine and extend a PWM model
## given the motif matches by findMotif as seed for more specific model.
pwm.match.extend <- 
    refinePWMMotifExtend(ctcf.motifs$motifs[[1]]@match$pattern, ctcf.seq)


###################################################
### code chunk number 6: motifRG.Rnw:117-118
###################################################
seqLogo(pwm.match.extend$model$prob)


###################################################
### code chunk number 7: motifRG.Rnw:126-127
###################################################
plotMotif(pwm.match.extend$match$pattern)


