Skip to content

Commit 21f88eb

Browse files
committed
add ezvolcano tests
1 parent fbcfd62 commit 21f88eb

File tree

13 files changed

+547
-40
lines changed

13 files changed

+547
-40
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
.Rhistory
33
.RData
44
inst/doc
5-
Thumbs.db
5+
Thumbs.db
6+
Rplots.pdf

R/ezvolcano.R

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,23 @@
1212
#' @param comparison Name of contrast to plot. If given, it's assumed that \code{lfc.col=paste0(comparison, '.logFC')}
1313
#' and \code{sig.col=paste0(comparison, '.p') or paste0(comparison, '.FDR')}, and these are over-ridden.
1414
#' @param name Name of PNG file to write to. Set to \code{NA} to suppress writing to file.
15-
#' @param add.rnames Additional rownames of features to annotate. These must be in \code{rownames(tab)}.
15+
#' @param ann.rnames Additional rownames of \code{tab} to annotate; must be in \code{rownames(tab)}.
1616
#' @param up.color Color for points that are upregulated (\code{logFC>0}).
1717
#' @param down.color Color for points that are downregulated (\code{logFC<0}).
1818
#' @param x.bound x-axis limits are set to \code{c(-x.bound, x.bound)}. If \code{NULL, x.bound=max(abs(tab[,lfc.col]))}.
1919
#' @param y.bound y-axis limits are set to \code{c(0, y.bound)}. If \code{NULL, y.bound=max(tab[,'nlg10sig'])}.
2020
#' @param type.sig Type of significance y-axis should use, either "p" or "FDR".
2121
#' @param cut.color Color of points that meet both \code{cut.lfc} and \code{cut.sig}. If \code{NULL}, cutoffs are ignored.
2222
#' @param cut.lfc Points need to have \code{|logFC| >= cut.lfc} to have \code{cut.color}.
23-
#' @param cut.sig Points need to have significance \code{<= cut.sig} to have \code{cut.color}. Significance type is of
24-
#' \code{type.sig}.
23+
#' @param cut.sig Points need to have significance \code{tab[,sig.col] <= cut.sig} to have \code{cut.color}.
2524
#' @param sep Separator string between contrast names and suffix such as \code{logFC}.
2625
#' @param na.lab Character vector of labels in \code{lab.col} to treat as missing, in addition to \code{NA}.
2726
#' @details If \code{ntop.sig>0} or \code{ntop.lfc>0}, then \code{lab.col} must be in \code{colnames(tab)}.
2827
#' @return A ggplot object, invisibly.
2928
#' @export
3029

31-
ezvolcano <- function(tab, lfc.col=NULL, sig.col=NULL, lab.col='Gene.Symbol', ntop.sig=0, ntop.lfc=0, comparison=NULL,
32-
name='volcano', add.rnames=NULL, up.color='black', down.color='black', x.bound=NULL, y.bound=NULL,
30+
ezvolcano <- function(tab, lfc.col=NULL, sig.col=NULL, lab.col=NULL, ntop.sig=0, ntop.lfc=0, comparison=NULL,
31+
name='volcano', ann.rnames=NULL, up.color='black', down.color='black', x.bound=NULL, y.bound=NULL,
3332
type.sig=c('p', 'FDR'), cut.color=NULL, cut.lfc=1, cut.sig=0.05, sep='.', na.lab=c('---', '')){
3433
if (!requireNamespace("ggplot2", quietly = TRUE)){
3534
stop("Package 'ggplot2' needed for this function to work. Please install it.", call. = FALSE)
@@ -44,9 +43,9 @@ ezvolcano <- function(tab, lfc.col=NULL, sig.col=NULL, lab.col='Gene.Symbol', nt
4443
ntop.sig <- 0
4544
warning("ntop.sig > 0 but lab.col is null.")
4645
}
47-
if (!is.null(add.rnames)){
48-
add.rnames <- NULL
49-
warning("add.rnames is not null, but lab.col is null.")
46+
if (!is.null(ann.rnames)){
47+
ann.rnames <- NULL
48+
warning("ann.rnames is not null, but lab.col is null.")
5049
}
5150
}
5251

@@ -69,8 +68,9 @@ ezvolcano <- function(tab, lfc.col=NULL, sig.col=NULL, lab.col='Gene.Symbol', nt
6968
}
7069

7170
stopifnot((ntop.sig==0 & ntop.lfc==0) | lab.col %in% colnames(tab), ntop.sig==as.integer(ntop.sig),
72-
ntop.lfc==as.integer(ntop.lfc), is.null(add.rnames)|add.rnames %in% rownames(tab),
73-
lfc.col %in% colnames(tab), sig.col %in% colnames(tab), any(tab[,lfc.col]<0), any(tab[,lfc.col]>=0))
71+
ntop.lfc==as.integer(ntop.lfc), is.null(ann.rnames)|ann.rnames %in% rownames(tab),
72+
lfc.col %in% colnames(tab), sig.col %in% colnames(tab), any(tab[,lfc.col]<0), any(tab[,lfc.col]>=0),
73+
length(x.bound)<=1, length(y.bound)<=1)
7474

7575
tab <- data.frame(tab, nlg10sig=-log10(tab[,sig.col]))
7676
#want symmetric x-axis
@@ -99,13 +99,14 @@ ezvolcano <- function(tab, lfc.col=NULL, sig.col=NULL, lab.col='Gene.Symbol', nt
9999
if (ntop.sig > 0) top.sig.ind <- order(tab[,sig.col])[1:ntop.sig] else top.sig.ind <- NULL
100100
ind.annot <- setdiff(union(top.sig.ind, top.lfc.ind), na.lab.ind)
101101
}
102-
#add.rnames to plot with symbol
103-
if (!is.null(add.rnames)){
104-
ind.add.rnames <- which(rownames(tab) %in% add.rnames)
105-
ind.annot <- union(ind.add.rnames, ind.annot)
102+
#ann.rnames to plot with symbol
103+
if (!is.null(ann.rnames)){
104+
ind.ann.rnames <- which(rownames(tab) %in% ann.rnames)
105+
ind.annot <- union(ind.ann.rnames, ind.annot)
106106
}
107107
if (!is.null(ind.annot)){
108-
vol <- vol + ggplot2::geom_text(data=tab[ind.annot,], mapping=ggplot2::aes_string(x=lfc.col, y='nlg10sig', label=lab.col), size=3, vjust=2)
108+
vol <- vol + ggplot2::geom_text(data=tab[ind.annot,], mapping=ggplot2::aes_string(x=lfc.col, y='nlg10sig', label=lab.col),
109+
size=3, vjust=2)
109110
}
110111

111112
if (!is.na(name)) ggplot2::ggsave(filename=paste0(name, ".png"), plot=vol) else graphics::plot(vol)

R/multi_volcano.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#' @param ntop.sig Number of top significant features to annotate.
88
#' @param ntop.lfc Number of top logFC features to annotate.
99
#' @param name Name of PDF file to write to. Set to \code{NA} to suppress writing to file.
10-
#' @param add.rnames Additional rownames of features to annotate. These must be in \code{rownames(tab)}.
10+
#' @param ann.rnames Additional rownames of features to annotate. These must be in \code{rownames(tab)}.
1111
#' @param up.color Color for points that are upregulated (\code{logFC>0}).
1212
#' @param down.color Color for points that are downregulated (\code{logFC<0}).
1313
#' @param same.scale Logical indicating if different volcano plots should have the same x-limits and y-limits.
@@ -22,7 +22,7 @@
2222
#' @return List of ggplot objects from \code{\link{ezvolcano}}, invisibly.
2323
#' @export
2424

25-
multi_volcano <- function(tab, lab.col=NULL, ntop.sig=0, ntop.lfc=0, name='volcanoes', add.rnames=NULL,
25+
multi_volcano <- function(tab, lab.col=NULL, ntop.sig=0, ntop.lfc=0, name='volcanoes', ann.rnames=NULL,
2626
up.color='black', down.color='black', same.scale=FALSE, type.sig=c('p', 'FDR'), cut.color=NULL,
2727
cut.lfc=1, cut.sig=0.05, sep='.', na.lab=c('---', '')){
2828

@@ -49,7 +49,7 @@ multi_volcano <- function(tab, lab.col=NULL, ntop.sig=0, ntop.lfc=0, name='volca
4949
ret.lst <- list()
5050
for (contr in contr.names){
5151
ret.lst[[contr]] <- ezvolcano(tab=tab, lab.col=lab.col, ntop.sig=ntop.sig, ntop.lfc=ntop.lfc, comparison=contr,
52-
name=NA, add.rnames=add.rnames, up.color=up.color, down.color=down.color, x.bound=x.bound,
52+
name=NA, ann.rnames=ann.rnames, up.color=up.color, down.color=down.color, x.bound=x.bound,
5353
y.bound=y.bound, type.sig=type.sig, cut.color=cut.color, cut.lfc=cut.lfc, cut.sig=cut.sig,
5454
sep=sep, na.lab=na.lab)
5555
}

R/prune_mat.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@ prune_mat <- function(object, symbols=NULL, only.symbols=FALSE, unique.rows=FALS
2222
}
2323

2424
if (only.symbols){
25-
if (verbose) message('Removing', length(na.sym.ind), 'rows without gene symbols.')
25+
if (verbose) message('Removing ', length(na.sym.ind), ' rows without gene symbols.')
2626
object <- object[-na.sym.ind,]
2727
}
2828
if (unique.rows){
29-
if (verbose) message('Removing', sum(duplicated(rownames(object))), 'rows with duplicated names.')
29+
if (verbose) message('Removing ', sum(duplicated(rownames(object))), ' rows with duplicated names.')
3030
object <- object[!duplicated(rownames(object)),]
3131
}
3232
}#end if !is.null(sym)
3333

3434
if (!is.null(ntop)){
35-
if (verbose) cat('Selecting top', ntop, 'rows\n')
35+
if (verbose) message('Selecting top ', ntop, ' rows.')
3636
if (ntop <= nrow(object)){
3737
object <- object[1:ntop,]
3838
} else {
39-
if (verbose) message("After processing, object has only", nrow(object), "rows, so cannot subset to", ntop, "rows.")
39+
if (verbose) message("After processing, object has only ", nrow(object), " rows, so cannot subset to ", ntop, " rows.")
4040
}
4141
}
4242
return(object)

man/ezheat.Rd

Lines changed: 9 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/ezvolcano.Rd

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/multi_volcano.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)