Skip to content

Commit 3107798

Browse files
author
Karin Schork
committed
allow sampling of only a subset of the data for MA-Plots
1 parent 1199445 commit 3107798

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

R/MA_Plot.R

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#' @param do_log_transformation If \code{TRUE}, the data will be log-transformed.
66
#' @param alpha If \code{TRUE}, the data points will be transparent.
77
#' @param point_color A character containing the colors of the data points.
8+
#' @param sampling A numeric containing the sampling rate. Useful to sample part of the data set for data sets on peptide/feature level with many data points.
89
#' @param ... Additional arguments for affy::ma.plot.
910
#'
1011
#' @return Generates the MA plot for two samples.
@@ -25,7 +26,9 @@
2526
MA_Plot_single <- function(sample_1, sample_2,
2627
do_log_transformation = FALSE,
2728
alpha = FALSE,
28-
point_color = "black", ...) {
29+
point_color = "black",
30+
sampling = 1,
31+
...) {
2932

3033

3134
if(do_log_transformation) {
@@ -39,6 +42,14 @@ MA_Plot_single <- function(sample_1, sample_2,
3942
M <- stats::na.omit(sample_1 - sample_2)
4043
A <- stats::na.omit((sample_1 + sample_2)/2)
4144

45+
## sample only parts of the data points for data sets with many data points
46+
if (sample < 1) {
47+
ind_sample <- sample(1:length(M), size = ceiling(length(M) * sampling))
48+
M <- M[ind_sample]
49+
A <- A[ind_sample]
50+
}
51+
52+
4253
if (length(point_color) > 1) {
4354
na.ind <- attr(M, "na.action")
4455
point_color <- point_color[-na.ind]
@@ -62,6 +73,7 @@ MA_Plot_single <- function(sample_1, sample_2,
6273
#' @param alpha If \code{TRUE}, the data points will be transparent.
6374
#' @param plot_height The height of the resulting MA plots.
6475
#' @param plot_width The width of the resulting MA plots.
76+
#' @param sampling A numeric containing the sampling rate. Useful to sample part of the data set for data sets on peptide/feature level with many data points.
6577
#' @param ... Additional arguments for affy::ma.plot.
6678
#'
6779
#' @return A pdf file containing the MA plots for all sample combinations.
@@ -82,7 +94,9 @@ MA_Plots <- function(D,
8294
labels = 1:ncol(D), labels2 = colnames(D),
8395
maxPlots = 5000,
8496
alpha = FALSE,
85-
plot_height = 15, plot_width = 15, ...) {
97+
plot_height = 15, plot_width = 15,
98+
sampling = 1,
99+
...) {
86100

87101

88102
number_states <- max(as.integer(as.factor(colnames(D))))
@@ -117,7 +131,7 @@ MA_Plots <- function(D,
117131
num <- num + 1
118132
utils::setTxtProgressBar(pb, num)
119133

120-
MA_Plot_single(D[,i], D[, j], do_log_transformation = do_log_transformation, main = main, ...)
134+
MA_Plot_single(D[,i], D[, j], do_log_transformation = do_log_transformation, main = main, sampling = sampling, ...)
121135
}
122136
}
123137

0 commit comments

Comments
 (0)