From ce15ed4fa278a973d3098d2454f0bf0c18596f57 Mon Sep 17 00:00:00 2001 From: almeidasilvaf Date: Fri, 3 Nov 2023 20:59:06 +0100 Subject: [PATCH] Fixed bug in Category-to-Class mapping --- R/03_expression_partitioning.R | 43 +++++++++++++++++++--------------- R/utils.R | 8 +++---- R/visualization.R | 1 - 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/R/03_expression_partitioning.R b/R/03_expression_partitioning.R index 5403df2..7ab9984 100644 --- a/R/03_expression_partitioning.R +++ b/R/03_expression_partitioning.R @@ -34,26 +34,26 @@ expression_partitioning <- function(deg_list) { # Data frame with classification rules for groups and classes cl <- c( - "ADD", "ELD_P1", "DOWN", "ELD_P2", "UP", "UP", - "DOWN", "UP", "ELD_P2", "DOWN", "ELD_P1", "ADD" + "ADD", "ELD_P2", "DOWN", "ELD_P1", "UP", "UP", + "DOWN", "UP", "ELD_P1", "DOWN", "ELD_P2", "ADD" ) partition_rules <- data.frame( - DEG = c( - "down-up-up", - "unchanged-up-up", - "down-down-up", - "up-unchanged-down", - "up-up-up", - "up-up-down", - "down-down-unchanged", - "up-up-unchanged", - "down-unchanged-up", - "down-down-down", - "unchanged-down-down", - "up-down-down" - ), Category = factor(seq_len(12), levels = seq_len(12)), - Class = factor(cl, levels = c("UP", "DOWN", "ADD", "ELD_P1", "ELD_P2")) + Class = factor(cl, levels = c("UP", "DOWN", "ADD", "ELD_P1", "ELD_P2")), + DEG = c( + "down-up-up", # 1 + "unchanged-up-up", # 2 + "down-down-up", # 3 + "up-unchanged-down", # 4 + "up-up-up", # 5 + "up-up-down", # 6 + "down-down-unchanged", # 7 + "up-up-unchanged", # 8 + "down-unchanged-up", # 9 + "down-down-down", # 10 + "unchanged-down-down", # 11 + "up-down-down" # 12 + ) ) # Classify genes in 12 groups @@ -70,11 +70,16 @@ expression_partitioning <- function(deg_list) { data.frame( Gene = rownames(deg_list$F1_vs_P2), lFC_F1_vs_P2 = deg_list$F1_vs_P2$log2FoldChange - ) + ), + all = TRUE ) + log2fc_df[is.na(log2fc_df)] <- 0 # Combine classification data frame with log2foldchange - class_df <- merge(classified_genes[, c("Gene", "Category", "Class")], log2fc_df) + class_df <- merge( + classified_genes[, c("Gene", "Category", "Class")], log2fc_df, + all.x = TRUE + ) class_df <- class_df[!is.na(class_df$Category), ] class_df <- class_df[order(class_df$Category), ] diff --git a/R/utils.R b/R/utils.R index be19436..636760d 100644 --- a/R/utils.R +++ b/R/utils.R @@ -241,11 +241,11 @@ partition_lineplots <- function( # Data frame of point coordinates for each group pline_data <- data.frame( - Category = factor(rep(1:12, each = 3)), + Category = factor(rep(seq_len(12), each = 3)), Class = factor( rep(c( - "ADD", "ELD_P1", "DOWN", "ELD_P2", "UP", "UP", - "DOWN", "UP", "ELD_P2", "DOWN", "ELD_P1", "ADD" + "ADD", "ELD_P2", "DOWN", "ELD_P1", "UP", "UP", + "DOWN", "UP", "ELD_P1", "DOWN", "ELD_P2", "ADD" ), each = 3), levels = c("UP", "DOWN", "ADD", "ELD_P1", "ELD_P2")), x = factor(rep(c("P1", "F1", "P2"), 12), levels = c("P1", "F1", "P2")), @@ -269,7 +269,7 @@ partition_lineplots <- function( pline_data <- split(pline_data, pline_data[[group_by]]) ## Number of genes per level of `group_by` - n <- as.numeric(table(partition_table$Category)) + n <- as.numeric(table(partition_table[[group_by]])) p_line <- lapply(seq_along(pline_data), function(x) { diff --git a/R/visualization.R b/R/visualization.R index 3b78f64..9ad31cf 100644 --- a/R/visualization.R +++ b/R/visualization.R @@ -112,7 +112,6 @@ plot_expression_partitions <- function( ) { pdata <- partition_table - pdata <- pdata[!is.na(pdata$lFC_F1_vs_P1) & !is.na(pdata$lFC_F1_vs_P2), ] # Define color palette pal <- ppal(palette, "partition")[seq_along(levels(pdata[[group_by]]))]