This is a test version of Biostars. For the public version, visit https://www.biostars.org.
R Kegg Need help ASAP

Hello,

For a research project I'm doing, I am trying to map my own gene IDs to KEGG pathways using the "ggkegg" package for R. This is the code that I'm trying to run:

# Load the required libraries
library(ggkegg)
library(BiocFileCache)
library(dplyr)
library(ggraph)

# Prepare custom gene data
custom_gene_data <- data.frame(
  name = gene_names,  # Replace with custom gene IDs
  ec = c("ec:5.3.1.1", "ec:2.7.1.1", "ec:2.7.1.11", "ec:2.7.1.1", "ec:1.1.1.284 1.1.1.1",
         "ec:1.1.1.284 1.1.1.1", "ec:4.2.1.11", "ec:3.1.3.62 3.1.3.80", "ec:1.1.1.2",
         "ec:3.1.3.11", "ec:5.1.3.15", "ec:2.3.1.12", "ec:1.2.1.31 1.2.1.8 1.2.1.3",
         "ec:5.1.3.3", "ec:2.7.1.11", "ec:2.7.1.40", "ec:4.1.2.13", "ec:5.4.2.11"),  # Replace with EC numbers
  type = "gene"
)

# 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)

# Map the EC number to gene nodes
g <- pathway("osa00010") |> 
  mutate(ec = rntoec[reaction])

# Combine custom gene data with pathway data
combined_data <- bind_rows(g, custom_gene_data)

# Visualize the pathway with custom gene IDs
gg <- combined_data |>
  filter(type %in% c("compound", "gene")) |>
  ggraph(layout = "manual", x = x, y = y) +
  geom_edge_link(aes(color = subtype_name)) +
  geom_node_point(color = "lightblue", aes(filter = type == "compound")) +
  geom_node_rect(fill = "lightpink", aes(filter = type == "gene")) +
  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) +
  theme_void()

# Display the visualization
print(gg)

When I run this script, I get this error code:

Error in `bind_rows()`:
! Argument 1 must be a data frame or a named atomic vector.
Run `rlang::last_trace()` to see where the error occurred.

Argument 1 is a data frame, so I'm confused why I'm getting this error message. If anyone can help with this it would be greatly appreciated! I have a presentation on Friday so I really need help. Thank you!

kegg rstudio

What does class(g) and head(g) return?

It wouldn't let me type it all out, so here's a screenshot: enter image description here

g is an igraph object, not a data.frame

Oh ok, thank you. This is what it looks like after converting it to a data frame:

enter image description here

I'm guessing I have to make my own data frame that looks like this one in order to combine them together?

Need help ASAP

Statements of this sort work against you. You're on a volunteer driven forum, things are not going to progress any faster because you push us.

0 answers

No answers yet.

Log in to answer this question.