I was trying to extract a KEGG pathway as an igraph object of the gene-gene and gene-compound interactions. I observed that different functions from KEGGgraph seemingly give different results. The number of nodes and edges obtained from parseKGML2DataFrame is less than parseKGML2Graph. Also, after parseKGML, the statistics display different numbers of nodes and edges. The graph obtained from parseKGML2Graph has some additional genes, which I assume are the islands that do not show up in the data frame. But what about the parseKGML statistics? And why does the parseKGML2Graph contain ontology or the path itself as a node?
> path_id <- "dre03320"
>
> retrieveKGML(pathwayid = path_id, organism = "dre", destfile = paste("tmp_dir/", path_id, ".kgml"))
trying URL 'https://rest.kegg.jp/get/dre03320/kgml'
downloaded 25 KB
>
> df <- parseKGML2DataFrame(file = paste("tmp_dir/", path_id, ".kgml"), reactions = TRUE, genesOnly = FALSE)
Warning message:
In KEGGpathway2reactionGraph(pathway) :
The pathway contains no chemical reactions!
> length(unique(c(df$from, df$to)))
[1] 89
> nrow(df)
[1] 501
>
> net_1 <- parseKGML2Graph(file = paste("tmp_dir/", path_id, ".kgml"), genesOnly = FALSE, expandGenes = TRUE)
> net_1
A graphNEL graph with directed edges
Number of Nodes = 111
Number of Edges = 491
>
> path <- parseKGML(file = paste("tmp_dir/", path_id, ".kgml"))
> path
KEGG Pathway
[ Title ]: PPAR signaling pathway
[ Name ]: path:dre03320
[ Organism ]: dre
[ Number ] :03320
[ Image ] :https://www.kegg.jp/kegg/pathway/dre/dre03320.png
[ Link ] :https://www.kegg.jp/kegg-bin/show_pathway?dre03320
------------------------------------------------------------
Statistics:
65 node(s)
53 edge(s)
0 reaction(s)
------------------------------------------------------------
>
> net_2 <- KEGGpathway2Graph(path, genesOnly = FALSE, expandGenes = TRUE)
> net_2
A graphNEL graph with directed edges
Number of Nodes = 111
Number of Edges = 491
Once I have the GraphNEL object from KEGGgraph, i can convert it to igraph object but I get error while doing further processing on these graphs. Any idea why this might be?
> net_1_igraph <- igraph::graph_from_graphnel(net_1)
> net_2_igraph <- igraph::graph_from_graphnel(net_2)
>
> RCy3::createNetworkFromIgraph(net_1_igraph)
Error in FUN(X[[i]], ...) : environments cannot be coerced to other types
> RCy3::createNetworkFromIgraph(net_2_igraph)
Error in FUN(X[[i]], ...) : environments cannot be coerced to other types
> net_1_igraph_df <- igraph::as_data_frame(net_1_igraph, what = "edges")
> net_2_igraph_df <- igraph::as_data_frame(net_2_igraph, what = "edges")
>
> net_1_igraph_df
Error in paste(x, collapse = ", ") :
environments cannot be coerced to other types
> net_2_igraph_df
Error in paste(x, collapse = ", ") :
environments cannot be coerced to other types

The first method seems better. However, there seems to be a small discrepancy in how the KGML is parsed.
Here in
test2_netthere are grouped nodes "dr:D08233 cpd:C01516". But intest1_net, this is spitted as separate nodes. Is this expected?