Browse code

Commit made by the Bioconductor Git-SVN bridge. Consists of 1 commit.

Commit information:

Commit id: fc42468cd9915cc54e61fbbf71ac93f854f42f6a

cleaning up a bit of code for fun

Committed by: nosson
Author Name: nosson
Commit date: 2015-02-11 20:17:21 -0500
Author date: 2015-02-11 20:17:21 -0500


git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/metagenomeSeq@99387 bc3139a8-67e5-0310-9ffc-ced21a209358

Joseph Paulson authored on 12/02/2015 01:17:41
Showing 1 changed files
... ...
@@ -11,11 +11,10 @@
11 11
 #' @param nbreaks Number of bins to break yvector and xvector into.
12 12
 #' @param ybreak The values to break the yvector at.
13 13
 #' @param xbreak The values to break the xvector at.
14
-#' @param ret Boolean to return the observed data that would have been plotted.
15 14
 #' @param scale Scaling of circle bin sizes.
16 15
 #' @param local Boolean to shade by signficant bin numbers (TRUE) or overall proportion (FALSE).
17 16
 #' @param ... Additional plot arguments.
18
-#' @return If ret == TRUE, returns a matrix of features along rows, and the group membership along columns.
17
+#' @return A matrix of features along rows, and the group membership along columns.
19 18
 #' @seealso \code{\link{plotMRheatmap}}
20 19
 #' @examples
21 20
 #' 
... ...
@@ -30,7 +29,7 @@
30 29
 #' plotBubble(y,x)
31 30
 #'
32 31
 plotBubble<-function(yvector,xvector,sigvector=NULL,nbreaks=10, ybreak=quantile(yvector,p=seq(0,1,length.out=nbreaks)),
33
-    xbreak=quantile(xvector,p=seq(0,1,length.out=nbreaks)), ret=FALSE,scale=1,local=FALSE,...){
32
+    xbreak=quantile(xvector,p=seq(0,1,length.out=nbreaks)),scale=1,local=FALSE,...){
34 33
 
35 34
     ybreaks = cut(yvector,breaks=ybreak,include.lowest=TRUE)
36 35
     xbreaks = cut(xvector,breaks=xbreak,include.lowest=TRUE)
... ...
@@ -85,17 +84,13 @@ plotBubble<-function(yvector,xvector,sigvector=NULL,nbreaks=10, ybreak=quantile(
85 84
     axis(1,at = 1:nc,labels=levels(xbreaks),las=2,cex.axis=.5)
86 85
     axis(2,at = 1:nc,labels=levels(ybreaks),las=2,cex.axis=.5)
87 86
 
88
-    if(ret == TRUE){
89
-        res = cbind(as.character(ybreaks),as.character(xbreaks))
90
-        colnames(res) = c("yvector","xvector")
91
-        rownames(res) = names(yvector)
92
-        if(is.null(sigvector)){
93
-            return(res)
94
-        } else {
95
-            sig = rep(0,nrow(res))
96
-            sig[which(rownames(res)%in%sigvector)] = 1
97
-            res = cbind(res,sig)
98
-            return(res)
99
-        }
87
+    res = cbind(as.character(ybreaks),as.character(xbreaks))
88
+    colnames(res) = c("yvector","xvector")
89
+    rownames(res) = names(yvector)
90
+    if(is.null(sigvector)){
91
+        sig = rep(0,nrow(res))
92
+        sig[which(rownames(res)%in%sigvector)] = 1
93
+        res = cbind(res,sig)
100 94
     }
95
+    invisible(res)
101 96
 }
Browse code

Commit made by the Bioconductor Git-SVN bridge. Consists of 1 commit.

Commit information:

Commit id: 327abd1208eaef0aadfa55bc9130ab829c188902
Commit message: added parallel fitDO, fixed desc of fitPA,DO, fixed plotBubble
Committed by: nosson
Author Name: nosson
Commit date: 2014-05-27 19:24:00 -0400
Author date: 2014-05-27 19:24:00 -0400



git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/metagenomeSeq@90755 bc3139a8-67e5-0310-9ffc-ced21a209358

Joseph Paulson authored on 27/05/2014 23:24:27
Showing 1 changed files
... ...
@@ -58,11 +58,11 @@ plotBubble<-function(yvector,xvector,sigvector=NULL,nbreaks=10, ybreak=quantile(
58 58
         if(local==TRUE){
59 59
             contSigTable = sapply(contSig,function(i){i})
60 60
             linMap <- function(x, a, b) approxfun(range(x), c(a, b))(x)
61
-            if(length(ybreak)!=length(xbreak)) {
61
+            if(length(levels(ybreak))!=length(levels(xbreak))) {
62 62
                 warning("Not square matrix - this is not implemented currently")
63 63
             }
64
-            contSigTable = matrix(linMap(contSigTable,a=0,b=1),nrow=length(ybreak))
65
-            for(i in 1:length(ybreak)){
64
+            contSigTable = matrix(linMap(contSigTable,a=0,b=1),nrow=length(levels(ybreaks)))
65
+            for(i in 1:length(levels(ybreaks))){
66 66
                     contSig[[i]] = contSigTable[,i]
67 67
             }
68 68
         }
Browse code

Commit made by the Bioconductor Git-SVN bridge. Consists of 1 commit.

Commit information:

Commit id: c0a17cc278276fdaa39792320a0f77a579220f04
Commit message: Fixing based T/F calls for BiocCheck
Committed by: nosson
Author Name: nosson
Commit date: 2014-05-19 10:19:23 -0400
Author date: 2014-05-19 10:19:23 -0400



git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/metagenomeSeq@90471 bc3139a8-67e5-0310-9ffc-ced21a209358

Joseph Paulson authored on 19/05/2014 14:19:36
Showing 1 changed files
... ...
@@ -32,8 +32,8 @@
32 32
 plotBubble<-function(yvector,xvector,sigvector=NULL,nbreaks=10, ybreak=quantile(yvector,p=seq(0,1,length.out=nbreaks)),
33 33
     xbreak=quantile(xvector,p=seq(0,1,length.out=nbreaks)), ret=FALSE,scale=1,local=FALSE,...){
34 34
 
35
-    ybreaks = cut(yvector,breaks=ybreak,include.lowest=T)
36
-    xbreaks = cut(xvector,breaks=xbreak,include.lowest=T)
35
+    ybreaks = cut(yvector,breaks=ybreak,include.lowest=TRUE)
36
+    xbreaks = cut(xvector,breaks=xbreak,include.lowest=TRUE)
37 37
     contTable = lapply(levels(xbreaks),function(i){
38 38
         k = which(xbreaks==i)
39 39
         sapply(levels(ybreaks),function(j){
Browse code

Commit made by the Bioconductor Git-SVN bridge. Consists of 1 commit.

Commit information:

Commit id: 23e51b8c51d494c02394539a5b07484f7888dcd7
Commit message: Updated plotBubble and fitPA
Committed by: nosson
Author Name: nosson
Commit date: 2014-05-14 14:18:03 -0400
Author date: 2014-05-14 14:18:03 -0400



git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/metagenomeSeq@90333 bc3139a8-67e5-0310-9ffc-ced21a209358

Joseph Paulson authored on 14/05/2014 18:18:11
Showing 1 changed files
... ...
@@ -9,10 +9,13 @@
9 9
 #' @param xvector A vector of values represented along x-axis.
10 10
 #' @param sigvector A vector of the names of significant features (names should match x/yvector).
11 11
 #' @param nbreaks Number of bins to break yvector and xvector into.
12
+#' @param ybreak The values to break the yvector at.
13
+#' @param xbreak The values to break the xvector at.
12 14
 #' @param ret Boolean to return the observed data that would have been plotted.
13
-#' @param scale Scaling of circle bins.
15
+#' @param scale Scaling of circle bin sizes.
16
+#' @param local Boolean to shade by signficant bin numbers (TRUE) or overall proportion (FALSE).
14 17
 #' @param ... Additional plot arguments.
15
-#' @return NA
18
+#' @return If ret == TRUE, returns a matrix of features along rows, and the group membership along columns.
16 19
 #' @seealso \code{\link{plotMRheatmap}}
17 20
 #' @examples
18 21
 #' 
... ...
@@ -21,10 +24,16 @@
21 24
 #' sparsity = rowMeans(MRcounts(mouseData)==0)
22 25
 #' lor = log(fitPA(mouseData,cl=pData(mouseData)[,3])$oddsRatio)
23 26
 #' plotBubble(lor,sparsity,main="lor ~ sparsity")
24
-#' 
25
-plotBubble<-function(yvector,xvector,sigvector=NULL,nbreaks=10,ret=FALSE,scale=1,...){
26
-    ybreaks = cut(yvector,breaks=quantile(yvector,p=seq(0,1,length.out=nbreaks)),include.lowest=T)
27
-    xbreaks = cut(xvector,breaks=quantile(xvector,p=seq(0,1,length.out=nbreaks)),include.lowest=T)
27
+#' # Example 2
28
+#' x = runif(100000)
29
+#' y = runif(100000)
30
+#' plotBubble(y,x)
31
+#'
32
+plotBubble<-function(yvector,xvector,sigvector=NULL,nbreaks=10, ybreak=quantile(yvector,p=seq(0,1,length.out=nbreaks)),
33
+    xbreak=quantile(xvector,p=seq(0,1,length.out=nbreaks)), ret=FALSE,scale=1,local=FALSE,...){
34
+
35
+    ybreaks = cut(yvector,breaks=ybreak,include.lowest=T)
36
+    xbreaks = cut(xvector,breaks=xbreak,include.lowest=T)
28 37
     contTable = lapply(levels(xbreaks),function(i){
29 38
         k = which(xbreaks==i)
30 39
         sapply(levels(ybreaks),function(j){
... ...
@@ -46,6 +55,17 @@ plotBubble<-function(yvector,xvector,sigvector=NULL,nbreaks=10,ret=FALSE,scale=1
46 55
                 x
47 56
             })
48 57
         })
58
+        if(local==TRUE){
59
+            contSigTable = sapply(contSig,function(i){i})
60
+            linMap <- function(x, a, b) approxfun(range(x), c(a, b))(x)
61
+            if(length(ybreak)!=length(xbreak)) {
62
+                warning("Not square matrix - this is not implemented currently")
63
+            }
64
+            contSigTable = matrix(linMap(contSigTable,a=0,b=1),nrow=length(ybreak))
65
+            for(i in 1:length(ybreak)){
66
+                    contSig[[i]] = contSigTable[,i]
67
+            }
68
+        }
49 69
     } else {
50 70
         contSig = lapply(levels(xbreaks),function(i){
51 71
             k = which(xbreaks==i)
... ...
@@ -54,7 +74,7 @@ plotBubble<-function(yvector,xvector,sigvector=NULL,nbreaks=10,ret=FALSE,scale=1
54 74
             })
55 75
         })
56 76
     }
57
-    
77
+
58 78
     medianSizes = median(unlist(contTable))
59 79
     plot(y=yvec,x=rep(1,nc),cex=scale*contTable[[1]]/medianSizes,
60 80
         xlim=c(-0.25,nc+.25),ylim=c(-0.25,nc+.25),bty="n",xaxt="n",yaxt="n",
... ...
@@ -64,7 +84,18 @@ plotBubble<-function(yvector,xvector,sigvector=NULL,nbreaks=10,ret=FALSE,scale=1
64 84
     }
65 85
     axis(1,at = 1:nc,labels=levels(xbreaks),las=2,cex.axis=.5)
66 86
     axis(2,at = 1:nc,labels=levels(ybreaks),las=2,cex.axis=.5)
87
+
67 88
     if(ret == TRUE){
68
-        return(cbind(xbreaks,ybreaks))
89
+        res = cbind(as.character(ybreaks),as.character(xbreaks))
90
+        colnames(res) = c("yvector","xvector")
91
+        rownames(res) = names(yvector)
92
+        if(is.null(sigvector)){
93
+            return(res)
94
+        } else {
95
+            sig = rep(0,nrow(res))
96
+            sig[which(rownames(res)%in%sigvector)] = 1
97
+            res = cbind(res,sig)
98
+            return(res)
99
+        }
69 100
     }
70 101
 }
Browse code

conflicts resolved while setting up Git-SVN bridge

From: Bioconductor Git-SVN Bridge <bioc-sync@bioconductor.org>

git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/metagenomeSeq@90051 bc3139a8-67e5-0310-9ffc-ced21a209358

Joseph Paulson authored on 07/05/2014 19:29:30
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,70 @@
1
+#' Basic plot of binned vectors.
2
+#' 
3
+#' This function plots takes two vectors, calculates the contingency table and 
4
+#' plots circles sized by the contingency table value. Optional significance vectors
5
+#' of the values significant will shade the circles by proportion of significance.
6
+#' 
7
+#' 
8
+#' @param yvector A vector of values represented along y-axis.
9
+#' @param xvector A vector of values represented along x-axis.
10
+#' @param sigvector A vector of the names of significant features (names should match x/yvector).
11
+#' @param nbreaks Number of bins to break yvector and xvector into.
12
+#' @param ret Boolean to return the observed data that would have been plotted.
13
+#' @param scale Scaling of circle bins.
14
+#' @param ... Additional plot arguments.
15
+#' @return NA
16
+#' @seealso \code{\link{plotMRheatmap}}
17
+#' @examples
18
+#' 
19
+#' data(mouseData)
20
+#' mouseData = mouseData[which(rowSums(mouseData)>139),]
21
+#' sparsity = rowMeans(MRcounts(mouseData)==0)
22
+#' lor = log(fitPA(mouseData,cl=pData(mouseData)[,3])$oddsRatio)
23
+#' plotBubble(lor,sparsity,main="lor ~ sparsity")
24
+#' 
25
+plotBubble<-function(yvector,xvector,sigvector=NULL,nbreaks=10,ret=FALSE,scale=1,...){
26
+    ybreaks = cut(yvector,breaks=quantile(yvector,p=seq(0,1,length.out=nbreaks)),include.lowest=T)
27
+    xbreaks = cut(xvector,breaks=quantile(xvector,p=seq(0,1,length.out=nbreaks)),include.lowest=T)
28
+    contTable = lapply(levels(xbreaks),function(i){
29
+        k = which(xbreaks==i)
30
+        sapply(levels(ybreaks),function(j){
31
+            length(which(ybreaks[k]==j))
32
+            })
33
+        })
34
+    names(contTable) = levels(xbreaks)
35
+    yvec = 1:length(levels(ybreaks))
36
+    nc = length(yvec)
37
+
38
+    if(!is.null(sigvector)){
39
+        # I am calculating contTable twice if sigvector==TRUE
40
+        # This can be changed to if else statement to return two rows
41
+        contSig = lapply(levels(xbreaks),function(i){
42
+            k = which(xbreaks==i)
43
+            sapply(levels(ybreaks),function(j){
44
+                x = sum(names(yvector[k])[which(ybreaks[k]==j)]%in%sigvector)/length(which(ybreaks[k]==j))
45
+                if(is.na(x)) x = 0
46
+                x
47
+            })
48
+        })
49
+    } else {
50
+        contSig = lapply(levels(xbreaks),function(i){
51
+            k = which(xbreaks==i)
52
+            sapply(levels(ybreaks),function(j){
53
+                1
54
+            })
55
+        })
56
+    }
57
+    
58
+    medianSizes = median(unlist(contTable))
59
+    plot(y=yvec,x=rep(1,nc),cex=scale*contTable[[1]]/medianSizes,
60
+        xlim=c(-0.25,nc+.25),ylim=c(-0.25,nc+.25),bty="n",xaxt="n",yaxt="n",
61
+        xlab="",ylab="",pch=21,...,bg=rgb(blue=1,red=0,green=0,alpha=contSig[[1]]))
62
+    for(i in 2:length(contTable)){
63
+        points(y=yvec,x=rep(i,nc),cex =scale*contTable[[i]]/medianSizes,pch=21,bg=rgb(blue=1,red=0,green=0,alpha=contSig[[i]]))
64
+    }
65
+    axis(1,at = 1:nc,labels=levels(xbreaks),las=2,cex.axis=.5)
66
+    axis(2,at = 1:nc,labels=levels(ybreaks),las=2,cex.axis=.5)
67
+    if(ret == TRUE){
68
+        return(cbind(xbreaks,ybreaks))
69
+    }
70
+}