Motif finding

Unsupervised KDM finding can be performed over a set of sequences using the following function, which factorizes the k-mer representation of the sequences by projective non-negative matrix factorization (PNMF).

Function: KDMFind

ParameterMeaning
sequencesan array of sequences
minrankinteger: the minimum factorization rank allowed
maxrankinteger [1, number of sequences]: the maximum factorization rank allowed
dictionarythe dictionary defining the k-mer space, as returned by KDMDictionary
toldouble: the factorization iterations stopping criterion (default 1e-6)
Outputan object of class kdmotifs: a matrix [nkmers x rank]. Each column contains the Hellinger transformed probability distribution for a motif. The columns are named M-1, M-2, ...

Running it

Using the sequences we have loaded for the NRF1 transcription factor, we can call KDMFind passing both the positive and negative sequences from our training set:

motifs<-KDMFind(c(NRF1$train$pseq,NRF1$train$nseq),minrank=100,maxrank=500,dictionaryTF,tol=1e-6)

The rank is chosen automatically between minrank and maxrank; discovery is unsupervised, which is why the unbound sequences are included too.

Once the function exits we can print the result:

motifs
kdm motifs matrix
 #N motifs: 165
 Kmer length: 8
 N# gaps: 2
 Double strand: TRUE

Subsetting and renaming

We can subset the results specifying the column indexes (motifs) we want:

motifs_subset<-motifs[,c(1,2,7)]
motifs_subset
kdm motifs matrix
 #N motifs: 3
 Kmer length: 8
 N# gaps: 2
 Double strand: TRUE

Please consider that the column names remain unchanged in the subset:

colnames(motifs_subset)
[1] "M-1" "M-2" "M-7"

You can rename them explicitly:

colnames(motifs_subset)<-c("myname1","myname2","myname3")

Plotting a motif

It is possible to plot the probabilities for a motif as follows:

plot(motifs[,"M-105"]^2,type="h")
Spike plot of the squared Hellinger weights of motif M-105 across the whole 8-mer dictionary: the probability mass is concentrated on a small number of k-mers, with the largest values just above 0.04.
Squaring the Hellinger-embedded weights returns the motif's probability distribution over the dictionary. For M-105, almost all the mass sits on a handful of k-mers.
KDM — source on GitHub · preprint