Trouble Adding Log Fold Changes to KEGG Pathway Visualization
0
0
Entering edit mode
11 months ago
ramirj49 • 0

Hi everyone,

Right now I'm trying to visualize the glycolysis pathway for Oryza Sativa with log fold change values for my genes of interest using the ggkegg package in R. I got the pathway visualization to work and was able to highlight nodes of interest, but I'm not sure how to add log fold changes for these target genes without affected the nodes I'm not interested in. Can anyone help me with this? Thanks!

This is what the data frame I'm using looks like:

enter image description here

This is the code that I used to make the pathway visualization:

# Create a map of glycolysis pathway for Oryza Sativa + map EC number labels
library(ggkegg)
library(BiocFileCache)

# Fetch and cache RN to EC map
url <- paste0("https://rest.kegg.jp/link/reaction/ec")
bfc <- BiocFileCache()
path <- bfcrpath(bfc, url)
convert <- data.frame(data.table::fread(path, header = FALSE, sep = "\t"))
rntoec <- convert$V1 |>
  strsplit(":") |>
  vapply("[", 2, FUN.VALUE = "a") |>
  setNames(convert$V2)
# Map the EC number to gene nodes
g <- pathway("dosa00010") |>
  mutate(ec = rntoec[reaction])
# Define a vector of node names to highlight
nodes_to_highlight <- c("rn:R01786","rn:R01600","rn:R00756","rn:R00762",
                        "rn:R01068","rn:R01015","rn:R01518","rn:R00658",
                        "rn:R00200","rn:R02569","rn:R00754","rn:R00746",
                        "rn:R00710","rn:R01602","rn:R02739","rn:R09532")

# Add the "highlight" column
g <- g |>
  mutate(highlight = ifelse(reaction %in% nodes_to_highlight, "genes present in data",
                                                                 "genes not present"))
# Visualize the pathway with EC number labels and highlighted nodes
gg <- g |>
  filter(type %in% c("compound", "gene")) |>
  ggraph(layout = "manual", x = x, y = y) +
  geom_edge_link(aes(color = subtype_name)) +
  geom_node_rect(aes(fill = highlight), size = 5) +  # Set the fill color based on "highlight" column
  geom_node_shadowtext(aes(label = ec, filter = type == "gene"), color = "black",
                       bg.colour = "white", size = 2) +
  geom_node_text(aes(label = name, filter = type == "compound"),
                 color = "grey50", size = 2, repel = TRUE) +
  scale_fill_manual(values = c("genes not present" = "lightpink",
                               "genes present in data" = "yellow")) +  # Define fill colors for "genes not present" and "genes present"
  theme_void()
gg
KEGG RStudio • 492 views
ADD COMMENT

Login before adding your answer.

Traffic: 2333 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6