Skip to content

Commit

Permalink
ko00530 error fix
Browse files Browse the repository at this point in the history
  • Loading branch information
noriakis committed Feb 5, 2024
1 parent a10f611 commit 95527a9
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions R/pathway_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ pathway <- function(pid,
gr_rels <- lapply(names(grs), function(gr_name) {
tmp_rel <- lapply(grs[[gr_name]], function(comp_name) {
## Pad other values by `in_group`
return(c(gr_name, comp_name, "in_group", "in_group", "in_group"))
return(c(gr_name, comp_name, "in_group", NA, NA))
})
do.call(rbind, tmp_rel)
})
Expand All @@ -214,13 +214,12 @@ pathway <- function(pid,
`colnames<-`(c("entry1","entry2","type",
"subtype_name","subtype_value"))
if ("reaction" %in% colnames(kegg_edges)) {
gr_rels$reaction <- "in_group"
gr_rels$reaction_id <- "in_group"
gr_rels$reaction <- NA
gr_rels$reaction_id <- NA
}
kegg_edges <- rbind(kegg_edges, gr_rels)
}
}

if (!is.null(kegg_edges)) {
g <- graph_from_data_frame(kegg_edges, vertices=kegg_nodes)
} else {
Expand Down Expand Up @@ -467,13 +466,19 @@ get_reaction <- function(xml) {
prod <- xmlElementsByTagName(rea,"product")
## Looking for `alt` tag
## Multiple products or substrates are to be expected
lapply(subs, function(ss) {
lapply(prod, function(pp) {
return(c(id, name, type,
xmlAttrs(ss)["id"], xmlAttrs(ss)["name"],
xmlAttrs(pp)["id"], xmlAttrs(pp)["name"]))
})
})
if (length(subs)==0) {
## These do not have edges
return(list(list(c(id, name, type, NA, NA, NA, NA))))
} else {
lapply(subs, function(ss) {
lapply(prod, function(pp) {
return(c(id, name, type,
xmlAttrs(ss)["id"], xmlAttrs(ss)["name"],
xmlAttrs(pp)["id"], xmlAttrs(pp)["name"]))
})
})
}

})
all_reas <- unlist(all_reas, recursive=FALSE)
all_reas <- do.call(rbind, unlist(all_reas, recursive=FALSE)) |>
Expand All @@ -482,14 +487,26 @@ get_reaction <- function(xml) {
"type","substrate_id","substrate_name",
"product_id","product_name"))

sub_all_reas <- all_reas[is.na(all_reas$substrate_id), ]
all_reas <- all_reas[!is.na(all_reas$substrate_id), ]


## Perhaps this parsing would lead to wrong interpretation
## But for preserving Compound -> KO edges, this function
## adds edges of:
## substrate -> ID (KO) (type: type, reaction: reaction)
## ID (KO) -> product (type: type, reaction: reaction)
## Later used in `process_reaction()`.
## Changed this layout to drop duplicates by distinct()

if (dim(all_reas)[1]==0) {
## For the reaction specification with only the name, id, and type,
## these will be omitted from the resulting graph.
## The nodes are already specified in the node data.frame and
## Information of "type" will not be in the node table.
## cbind(sub_all_reas[,"id"], sub_all_reas[,"id"],
## sub_all_reas[,"type"], NA, NA, NA, sub_all_reas[, "id"])
return(NULL)
}
rsp_rels <- lapply(seq_len(nrow(all_reas)), function(i) {
lapply(unlist(strsplit(all_reas[i,"id"], " ")), function(j) {
return(
Expand All @@ -505,7 +522,6 @@ get_reaction <- function(xml) {
})
})


rsp_rels <- do.call(rbind, unlist(rsp_rels, recursive=FALSE)) |>
data.frame() |>
dplyr::distinct() |>
Expand Down

0 comments on commit 95527a9

Please sign in to comment.