Dear both,

   I have updated KEGGgraph to version 1.18.0 (subversion revision: 81275)
in the devel branch of bioconductor. The KEGGpathway2reactionGraph function
now returns a reaction graph that can be merged with other KEGG
pathway/reaction graphs.

   The updated function is given below.


KEGGpathway2reactionGraph <- function(pathway) {
  reactions <- getReactions(pathway)
  if(length(reactions)==0) {
    stop("The pathway contains no chemical reactions!\n")
  }
  subs <- sapply(reactions, getSubstrate)
  prods <- sapply(reactions, getProduct)
  types <- sapply(reactions, getType)
  gridlist <- lapply(seq(along=reactions),
                       function(i)
                       expand.grid(subs[[i]], prods[[i]],
stringsAsFactors=FALSE))
  grid <- as.matrix(do.call(rbind, gridlist))
  isRepGrid <- duplicated(grid)
  uniqGrid <- grid[!isRepGrid,,drop=FALSE]
  gridTypes <- rep(types, sapply(gridlist, nrow))
  uniqGridTypes <- gridTypes[!isRepGrid]

  cg <- ftM2graphNEL(uniqGrid)
  allNodes <- nodes(pathway)
  allNodeNames <- sapply(allNodes, function(x) paste(getName(x),
collapse=","))
  cgNodes <- allNodes[match(nodes(cg), allNodeNames)]

  cgEdges <- sapply(1:nrow(uniqGrid),
                    function(x)
                    new("KEGGEdge",
                        entry1ID=uniqGrid[x,1],
                        entry2ID=uniqGrid[x,2],
                        type=uniqGridTypes[x],
                        subtype=list()))

  ## set node and edge data - as KEGGNode and KEGGEdge
  ## attention: KEGGEdges may be more than graph edges, due to non-genes
  names(cgEdges) <- apply(uniqGrid,1L, paste, collapse="~")
  env.node <- new.env()
  env.edge <- new.env()
  assign("nodes", cgNodes, envir=env.node)
  assign("edges", cgEdges, envir=env.edge)

  nodeDataDefaults(cg, "KEGGNode") <- env.node
  edgeDataDefaults(cg, "KEGGEdge") <- env.edge

  return(cg)
}


   Try it out and please let me know if you encounter any problem.

   Best wishes,
David



On Tue, Sep 3, 2013 at 9:47 PM, Paul Shannon <
paul.thurmond.shannon@gmail.com> wrote:

> Hi Stuart,
>
> I have included Jitao David Zhang here as well, the package author and
> maintainer.
>
> I think I can reduce your problem report to these steps:
>
> library(KEGGgraph)
> filename <- "hsa00260.kgml"
> retrieveKGML("00260", organism="hsa", destfile=filename, method =
> "internal")
> pathway <- parseKGML(filename)
>
> g.reaction <- KEGGpathway2reactionGraph(pathway, uniqueReaction = FALSE)
> g.pathway <- KEGGpathway2Graph(pathway, genesOnly=FALSE)
>
> names(nodeDataDefaults(g.reaction))   # NULL
> names(nodeDataDefaults(g.pathway))    # KEGGNode
>
> mergeKEGGgraphs (in KEGGgraph/R/graph.R) requires that there be an edge
> attribute "KEGGEdge" and a node attribute "KEGGNode", and fails with the
> error you saw.
>
>
> So the reaction graph does not have the two attributes required by
> mergeKEGGgraphs.  I am not sure whether this is by design, or whether it is
> an oversight.
> Once David clarifies that, we can devise some possible next steps for you.
>
>  - Paul
>
> P.S   For future posts, please include (as I have tried to do here) a
> smallish, self-contained and reproducible example, along with your
> sessionInfo:
>
> R version 3.0.1 Patched (2013-05-26 r62815)
> Platform: x86_64-apple-darwin10.8.0 (64-bit)
>
> locale:
> [1] C
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
> [1] KEGGgraph_1.17.0 graph_1.39.3     XML_3.95-0.2
>
> loaded via a namespace (and not attached):
> [1] BiocGenerics_0.7.4 parallel_3.0.1     stats4_3.0.1       tools_3.0.1
>
>
> On Sep 2, 2013, at 2:51 PM, Stuart Bradley wrote:
>
> > Hello all,
> >
> > I'm trying to build unified compound pathway maps, and have been
> successful
> > using this method:
> >
> > library(graph)
> > library(KEGGgraph)
> >
> > KEGGList <- list.files(path = "C:/Users/Castor
> > Castle/Documents/kgml/metabolic/ko/subset/", full.names = TRUE)
> >
> > AllGraphs <- lapply(KEGGList, function(x) {
> >  pathway <- parseKGML(x)
> >  pathway <- KEGGpathway2reactionGraph(pathway, uniqueReaction = FALSE)
> > })
> >
> > FinalGraph <- mergeGraphs(AllGraphs, edgemode = "directed")
> >
> > However, I'd like to be able to use mergeKEGGgraphs as it retains more
> > information. The problem is that when I replace  mergeGraphs with
> > mergeKEGGgraphs
> > I get the following error (regardless of whether it's my own files, or
> the
> > example ones provided):
> >
> > Error in .verifyAttrName(attr, names(self@defaults)):
> >  unknown attribute name: ŒKEGGNode‚
> >
> > Has anyone found a work around for this? I was fiddling with
> > setKEGGnodeData/setKEGGEdgeData in conjunction with mergeGraphs, but I
> > can't get it to work.
> >
> > Any help would be greatly appreciated.
> >
> > Cheers,
> > Stuart Bradley
> >
> >       [[alternative HTML version deleted]]
> >
> > _______________________________________________
> > Bioconductor mailing list
> > Bioconductor@r-project.org
> > https://stat.ethz.ch/mailman/listinfo/bioconductor
> > Search the archives:
> http://news.gmane.org/gmane.science.biology.informatics.conductor
>
>


-- 

*Jitao David Zhang | **张继涛** | Computational Biology and Bioinformatics |
Pharmaceutical Divison | F. Hoffmann-La-Roche AG | CH-4070 Basel |
Switzerland*****

*Tel +41 61 688 62 51 *

Confidentiality Note: This message is intended only for ...{{dropped:11}}

