noriakis / ggkegg

Analyzing and visualizing KEGG information using the grammar of graphics
https://noriakis.github.io/software/ggkegg
MIT License
201 stars 16 forks source link

RN to EC Mapping Not Working for Some Nodes #14

Closed Ramirj closed 5 months ago

Ramirj commented 6 months ago

Hi @noriakis,

I'm making pathway diagrams for the Lysine Biosynthesis pathway using ggkegg, but for some reason the mapping between reaction numbers and ec numbers doesn't work for some nodes. For example, one reaction number that I'm trying to map is "rn:R04199", but when I run my code the corresponding node doesn't get highlighted. However, when I try other reaction numbers it works fine so I'm confused what the issue is.

I'm using this link to map RN to EC numbers: https://rest.kegg.jp/link/reaction/ec I checked and the link has the rn to ec conversion in it so it should work. Do you know what could be causing the issue?

Here's my code:

Load libraries

library(ggkegg) library(BiocFileCache) library(viridis)

Fetch and cache RN to EC map

url <- "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)

Define the pathway ID

pathway_id <- "dosa00300" # Change depending on the pathway you want to map

Create a graph of the pathway

g <- pathway(pathway_id) |> mutate(ec = rntoec[reaction])

Define a vector of node names to highlight

nodes_to_highlight <- reaction

Add log fold changes (LFCs) to the graph

LFC_vector <- LFCs # Make sure LFCs is a vector with values for each corresponding reaction number

g <- g %>% mutate( LFC = ifelse(reaction %in% nodes_to_highlight, LFC_vector, NA), Color = ifelse(LFC <= -1, "red", ifelse(LFC >= 1, "green", NA)) # red for repressed genes and green for induced genes )

Create a pathway diagram with colors to visualize LFCs

gg <- g |> filter(type %in% c("compound", "gene")) |> ggraph(layout = "manual", x = x, y = y) + geom_node_rect(aes(fill = Color), size = 5) + # Use Color for the fill aesthetic scale_fill_identity() + # Use identity scale for custom colors overlay_raw_map("dosa00300") + # Make diagram look better (change depending on pathway you're mapping) theme_minimal() + # Set background to white theme_void() + # Remove x and y axis ggtitle("Induced (Green) and Repressed (Red) Genes in Lysine Biosythesis Pathway - 0 hr Timepoint")

gg

noriakis commented 5 months ago

Hi @Ramirj, I cannot replicate the issue as I don't have LFC vector. Please provide a reproducible example (consult here for instance). In general, you should double-check whether the value is available in the tbl_graph.