|
a |
|
b/R/PrepEdgeR.R |
|
|
1 |
#' Prepare edgeR DEG data for plotting |
|
|
2 |
#' |
|
|
3 |
#' This function reads an edgeR 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 PValue, |
|
|
5 |
#' and transforms PValue 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 edgeR 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 edgeR DEG data. |
|
|
11 |
#' @export |
|
|
12 |
#' @examples |
|
|
13 |
#' edgeR_file <- system.file("extdata", |
|
|
14 |
#' "DEG_edgeR_test.rds", |
|
|
15 |
#' package = "TransProR") |
|
|
16 |
#' edgeR <- prep_edgeR(edgeR_file) |
|
|
17 |
#' |
|
|
18 |
prep_edgeR <- function(input_path, output_name = NULL) { |
|
|
19 |
# Read the edgeR DEG data frame from an RDS file |
|
|
20 |
DEG_edgeR <- readRDS(input_path) |
|
|
21 |
|
|
|
22 |
# Filter DEG data using the deg_filter function from the same package |
|
|
23 |
edgeR <- deg_filter(DEG_edgeR) |
|
|
24 |
DEG_edgeR <- DEG_edgeR[rownames(DEG_edgeR) %in% edgeR, ] |
|
|
25 |
|
|
|
26 |
# Select columns of interest and adjust logFC values to absolute values |
|
|
27 |
DEG_edgeR <- DEG_edgeR[, c('logFC', "PValue", "change")] |
|
|
28 |
DEG_edgeR$logFC <- abs(DEG_edgeR$logFC) |
|
|
29 |
|
|
|
30 |
# Add a small pseudo-count to PValue to avoid log of zero and transform PValue for plotting |
|
|
31 |
DEG_edgeR$PValue <- DEG_edgeR$PValue + .Machine$double.eps |
|
|
32 |
DEG_edgeR$PValue <- -log10(DEG_edgeR$PValue) |
|
|
33 |
|
|
|
34 |
# Extract the Gene column from row names |
|
|
35 |
DEG_edgeR$Gene <- rownames(DEG_edgeR) |
|
|
36 |
|
|
|
37 |
# Rename columns |
|
|
38 |
names(DEG_edgeR) <- 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(DEG_edgeR, paste0(output_name, ".Rdata")) |
|
|
43 |
} |
|
|
44 |
|
|
|
45 |
# Return the processed data frame |
|
|
46 |
return(DEG_edgeR) |
|
|
47 |
} |