Browse code

big speedup of associateTranscriptionFactors method, exploiting duplicate motifs

paul-shannon authored on 18/10/2018 14:18:37
Showing4 changed files

... ...
@@ -1,8 +1,8 @@
1 1
 Package: MotifDb
2 2
 Type: Package
3 3
 Title: An Annotated Collection of Protein-DNA Binding Sequence Motifs
4
-Version: 1.23.11
5
-Date: 2018-06-17
4
+Version: 1.23.13
5
+Date: 2018-10-18
6 6
 Author: Paul Shannon, Matt Richards
7 7
 Maintainer: Paul Shannon <pshannon@systemsbiology.org>
8 8
 Depends: R (>= 2.15.0), methods, BiocGenerics, S4Vectors, IRanges, Biostrings
... ...
@@ -2,7 +2,8 @@ setGeneric('query', signature='object', function(object, andStrings, orStrings=c
2 2
 setGeneric('motifToGene', signature='object', function(object, motifs, source) standardGeneric('motifToGene'))
3 3
 setGeneric('geneToMotif', signature='object', function(object, geneSymbols, source, ignore.case=FALSE) standardGeneric('geneToMotif'))
4 4
 setGeneric('associateTranscriptionFactors', signature='object',
5
-           function(object, tbl.withMotifs,  source, expand.rows) standardGeneric('associateTranscriptionFactors'))
5
+           function(object, tbl.withMotifs,  source, expand.rows, motifColumnName="motifName")
6
+              standardGeneric('associateTranscriptionFactors'))
6 7
 #------------------------------------------------------------------------------------------------------------------------
7 8
 setClass ('MotifList',
8 9
           contains='SimpleList',
... ...
@@ -529,10 +530,10 @@ setMethod ('geneToMotif', 'MotifList',
529 530
 #-------------------------------------------------------------------------------
530 531
 setMethod('associateTranscriptionFactors', 'MotifList',
531 532
 
532
-     function(object, tbl.withMotifs, source, expand.rows){
533
-        stopifnot("motifName" %in% colnames(tbl.withMotifs))
534
-        tbl.tf <- motifToGene(object, tbl.withMotifs$motifName, source)
535
-        merge(tbl.withMotifs, tbl.tf, by.x="motifName", by.y="motif", all.x=TRUE)
533
+     function(object, tbl.withMotifs, source, expand.rows, motifColumnName="motifName"){
534
+        stopifnot(motifColumnName %in% colnames(tbl.withMotifs))
535
+        tbl.tf <- motifToGene(object, unique(tbl.withMotifs[, motifColumnName]), source)
536
+        merge(tbl.withMotifs, tbl.tf, by.x=motifColumnName, by.y="motif", all.x=TRUE)
536 537
         })
537 538
 
538 539
 #-------------------------------------------------------------------------------
539 540
deleted file mode 100644
... ...
@@ -1,16 +0,0 @@
1
-#------------------------------------------------------------------------------------------------------------------------
2
-plotMotifs <- function(motifs)
3
-{
4
-   stopifnot(length(motifs) > 0)
5
-
6
-  if(length(motifs) == 1){
7
-    pcm <- new("pcm", mat=motifs[[1]], name=names(motifs))
8
-    plot(pcm)
9
-    return()
10
-    }
11
-
12
-  motifStack(lapply(names(motifs), function(mName) new("pfm", motifs[[mName]], name=mName)))
13
-
14
-} # plotMotifs
15
-#------------------------------------------------------------------------------------------------------------------------
16
-
... ...
@@ -26,14 +26,17 @@ for each row in the data.frame.
26 26
 
27 27
 }
28 28
 \usage{
29
-\S4method{associateTranscriptionFactors}{MotifList}(object, tbl.withMotifs, source, expand.rows)
29
+\S4method{associateTranscriptionFactors}{MotifList}(object, tbl.withMotifs, source, expand.rows, motifColumnName="motifName")
30 30
 }
31 31
 \arguments{
32 32
   \item{object}{a \code{MotifList} object.}
33 33
   \item{tbl.withMotifs}{a \code{data.frame}}
34
-  \item{source}{a \code{character} string, either 'MotifDb' or "TFClass' (case insensitive)}
35
-    \item{expand.rows}{a \code{logical} value, recommended especially for the TFClass source,
36
-      in which sometimes many TFs are mapped to the same motif}
34
+  \item{source}{a \code{character} string, either "MotifDb" or "TFClass" (case insensitive)}
35
+  \item{expand.rows}{a \code{logical} value, recommended especially for the TFClass source,
36
+    in which sometimes many TFs are mapped to the same motif}
37
+  \item{motifColumnName}{a \code{character} string identifying the
38
+    column in tbl.withMotifs which contains the motifs to be associated
39
+    with transcription factors}
37 40
 }
38 41
 
39 42
 \value{