|
a |
|
b/R/PrepLimma.R |
|
|
1 |
#' Prepare limma-voom DEG data for plotting |
|
|
2 |
#' |
|
|
3 |
#' This function reads a limma-voom DEG data frame from an RDS file, filters it using |
|
|
4 |
#' \code{\link{deg_filter}} function, adjusts the logFC to absolute values, adds a pseudo-count to P.Value, |
|
|
5 |
#' and transforms P.Value for plotting. The final data frame is returned and |
|
|
6 |
#' optionally saved to a new RDS file. |
|
|
7 |
#' |
|
|
8 |
#' @param input_path Path to the RDS file containing the limma-voom DEG data frame. |
|
|
9 |
#' @param output_name Name for the processed data frame, also used as the RDS file name. |
|
|
10 |
#' @return A data frame with processed limma-voom DEG data. |
|
|
11 |
#' @export |
|
|
12 |
#' @examples |
|
|
13 |
#' limma_file <- system.file("extdata", |
|
|
14 |
#' "DEG_limma_voom_test.rds", |
|
|
15 |
#' package = "TransProR") |
|
|
16 |
#' limma <- prep_limma(limma_file) |
|
|
17 |
#' |
|
|
18 |
prep_limma <- function(input_path, output_name = NULL) { |
|
|
19 |
# Read the limma-voom DEG data frame from an RDS file |
|
|
20 |
limma <- readRDS(input_path) |
|
|
21 |
|
|
|
22 |
# Filter DEG data using the deg_filter function from the same package |
|
|
23 |
limma_filter <- deg_filter(limma) |
|
|
24 |
limma <- limma[rownames(limma) %in% limma_filter, ] |
|
|
25 |
|
|
|
26 |
# Select columns of interest and adjust logFC values to absolute values |
|
|
27 |
limma <- limma[, c('logFC', "P.Value", "change")] |
|
|
28 |
limma$logFC <- abs(limma$logFC) |
|
|
29 |
|
|
|
30 |
# Add a small pseudo-count to P.Value to avoid log of zero and transform P.Value for plotting |
|
|
31 |
limma$P.Value <- limma$P.Value + .Machine$double.eps |
|
|
32 |
limma$P.Value <- -log10(limma$P.Value) |
|
|
33 |
|
|
|
34 |
# Extract the Gene column from row names |
|
|
35 |
limma$Gene <- rownames(limma) |
|
|
36 |
|
|
|
37 |
# Rename columns |
|
|
38 |
names(limma) <- c('logFC', 'Pvalue', "change", 'Gene') |
|
|
39 |
|
|
|
40 |
# Optionally save the processed data frame as an RDS file |
|
|
41 |
if (!is.null(output_name)) { |
|
|
42 |
saveRDS(limma, paste0(output_name, ".Rdata")) |
|
|
43 |
} |
|
|
44 |
|
|
|
45 |
# Return the processed data frame |
|
|
46 |
return(limma) |
|
|
47 |
} |