diff --git a/.gitignore b/.gitignore index 4aaef6e..5d6aadf 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ .git/ .RData -.Rhistory \ No newline at end of file +.Rhistory +.Rproj.user diff --git a/DESCRIPTION b/DESCRIPTION index 45f8a98..3a40772 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: NetPathMiner -Version: 1.41.0 +Version: 1.41.1 Date: 2014 onwards Title: NetPathMiner for Biological Network Construction, Path Mining and Visualization @@ -33,6 +33,6 @@ SystemRequirements: libxml2, libSBML (>= 5.5) Biarch: TRUE biocViews: GraphAndNetwork, Pathways, Network, Clustering, Classification -RoxygenNote: 6.1.1 +RoxygenNote: 7.2.3 Encoding: UTF-8 PackageStatus: Deprecated diff --git a/NAMESPACE b/NAMESPACE index 39f29d3..6c21247 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -39,7 +39,6 @@ export(registerMemoryErr) export(reindexNetwork) export(rmAttribute) export(rmSmallCompounds) -export(samplePaths) export(setAttribute) export(simplifyReactionNetwork) export(stdAttrNames) diff --git a/NetPathMiner.Rproj b/NetPathMiner.Rproj new file mode 100644 index 0000000..21a4da0 --- /dev/null +++ b/NetPathMiner.Rproj @@ -0,0 +1,17 @@ +Version: 1.0 + +RestoreWorkspace: Default +SaveWorkspace: Default +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX + +BuildType: Package +PackageUseDevtools: Yes +PackageInstallArgs: --no-multiarch --with-keep.source diff --git a/R/pathRank.R b/R/pathRank.R index a8b241e..c45fa26 100755 --- a/R/pathRank.R +++ b/R/pathRank.R @@ -194,19 +194,7 @@ getPaths <- function(paths, graph, source.net){ #' } #' #' \subsection{P-value method}{ -#' \code{pathRanker(method="pvalue")} searches all paths between the specified start and end vertices, and if a -#' significant path is found it returns it. However, It doesn't search for the best path between the start and -#' terminal vertices, as there could be many paths which lead to the same terminal vertex, and searching through -#' all of them is time comsuming. We just stop when the first significant path is found. -#' -#' All provided edge weights are recaled from 0-1. Path significance is calculated based on the empirical distribution -#' of random paths of the same length. This can be estimated using \code{\link{samplePaths}} and passed as an argument. -#' -#' The follwing arguments can be passed to \code{pathRanker(method="pvalue")}: -#' \describe{ -#' \item{\code{sampledpaths}}{The emripical results from \code{\link{samplePaths}}.} -#' \item{\code{alpha}}{The P value cut-off. Defualts to 0.01} -#' } +#' \code{pathRanker(method="pvalue")} is deprecated. Please use \code{prob.shortest.path} instead. #' } #' @param graph A weighted igraph object. Weights must be in \code{edge.weights} or \code{weight} #' edge attributes. @@ -245,16 +233,7 @@ getPaths <- function(paths, graph, source.net){ #' ranked.p <- pathRanker(rgraph, method="prob.shortest.path", #' K=20, minPathSize=6) #' -#' ## Get significantly correlated paths using "p-valvue" method. -#' ## First, establish path score distribution by calling "samplePaths" -#' pathsample <- samplePaths(rgraph, max.path.length=10, -#' num.samples=100, num.warmup=10) -#' -#' ## Get all significant paths with p<0.1 -#' significant.p <- pathRanker(rgraph, method = "pvalue", -#' sampledpaths = pathsample ,alpha=0.1) -#' -pathRanker <- function(graph, method=c("prob.shortest.path", "pvalue") ,start, end, verbose=TRUE, ...){ +pathRanker <- function(graph, method="prob.shortest.path" ,start, end, verbose=TRUE, ...){ # Checking the graph if(is.null(E(graph)$edge.weights)){ if(!is.null(E(graph)$weight)) @@ -264,9 +243,6 @@ pathRanker <- function(graph, method=c("prob.shortest.path", "pvalue") ,start, e } } - if(length(method)>1 || !method %in% c("prob.shortest.path", "pvalue")) - stop("Please specify the ranking method 'prob.shortest.path' or 'pvalue'.") - if(method == "prob.shortest.path") return(rankShortestPaths(graph, start=start, end=end, verbose=verbose, ...)) else return(rankPvalue(graph, start=start, end=end, verbose=verbose, ...)) @@ -283,28 +259,30 @@ rankShortestPaths <- function(graph, K=10, minPathSize=1, start, end, normalize else message("Extracting the ",K," most probable paths.") } - # min path size is increased by 2 to include start and end compounds. - ps <- .Call("pathranker", - pg$nodes, #nodes - pg$edges, #Edges - pg$weights[,i], #Edge weights - K=K,minpathsize = minPathSize+2) #add 2 nodes to min path length ("s" & "t") - + # Min path size is increased by 2 to include start and end compounds. + # Currently not in use. + minpathsize = minPathSize + 2 + ps <- igraph::k_shortest_paths(pg$graph, from = "s", to = "t", weights = pg$weights[,i], k = K) + paths <- list() + for (j in 1:length(ps$vpaths)){ + path <- format_path(pg$graph, ps$epath[[j]], ps$vpath[[j]], pg$weights[,1]) + paths[[j]] <- path + } - idx <- which(sapply(ps,is.null)) - if (length(idx)>0) ps <- ps[-idx] - if(length(ps)==0){ + idx <- which(sapply(paths,is.null)) + if (length(idx)>0) paths <- paths[-idx] + if(length(paths)==0){ if(ncol(pg$weights) > 1) message(" Warning:Counldn't find paths matching the criteria for ",graph$y.labels[i]) else message(" Warning:Counldn't find paths matching the criteria.") } - ps <- ps[order(sapply(ps,"[[", "distance"))] #order paths by distance + paths <- paths[order(sapply(paths,"[[", "distance"))] #order paths by distance if (ncol(pg$weights) > 1){ - zret[[i]] <- ps - }else zret <- ps + zret[[i]] <- paths + }else zret <- paths } if(length(zret)==0)return(NULL) @@ -318,164 +296,8 @@ rankShortestPaths <- function(graph, K=10, minPathSize=1, start, end, normalize } rankPvalue <- function(graph, sampledpaths, start, end, alpha = 0.01, verbose) { - # Checking the graph - if(is.null(E(graph)$edge.weights)){ - if(!is.null(E(graph)$weight)) - E(graph)$edge.weights <- E(graph)$weight - else{ - stop("No edge weights provided.") - } - } - - range <- ifelse(missing(sampledpaths), ecount(graph), - if(length(graph$y.labels)==1)nrow(sampledpaths)-1 else nrow(sampledpaths[[1]])-1) - - # Defining start reactions end their scopes. - if(missing(start)){ - if(verbose) message("Start nodes weren't provided. Using entry nodes as start points.") - start <- V(graph)[degree(graph,mode="in")==0]$name - } - if(missing(end)){ - end <- V(graph)[ unique(unlist(neighborhood(graph, order=range, nodes=start, mode="out"))) ] - } - - pg = processNetwork(graph, start, end, scale="rescale", normalize=FALSE) - - zret=NULL - for (i in 1:ncol(pg$weights)) { - if(verbose){ - if (ncol(pg$weights) > 1) message("Extracting non-random path p<",alpha," for ",graph$y.labels[i]) - else message("Extracting non-random path p<",alpha) - } - - p.sample <- if(missing(sampledpaths)) NULL - else if(ncol(pg$weights) > 1) t(sampledpaths[[i]]) - else t(sampledpaths) - - ps <- .Call("scope", - pg$nodes, - pg$edges, - pg$weights[,i], #add column subscript - SAMPLEDPATHS = p.sample, - ALPHA = alpha, - ECHO = as.integer(verbose)) - - idx <- which(sapply(ps$paths,is.null)) - ps$paths <- ps$paths[-idx] - - if(length(ps)==0) stop("couldn't find any significant paths") - - ps$paths <- ps$paths[order(sapply(ps$paths,"[[", "pvalue"))] #order paths by pvalue - - if (ncol(pg$weights) > 1) zret[[i]] <- ps - else zret <- ps - } - if (ncol(pg$weights) > 1) - names(zret) <- graph$y.labels - - zret$y.labels=graph$y.labels - zret$source.net = graph$type - - return(zret) -} - -#' Creates a set of sample path p-values for each length given a weighted network -#' -#' Randomly traverses paths of increasing lengths within a set network to create an -#' empirical pathway distribution for more accurate determination of path significance. -#' -#' Can take a bit of time. -#' -#' @param graph A weighted igraph object. Weights must be in \code{edge.weights} or \code{weight} -#' edge attributes. -#' @param max.path.length The maxmimum path length. -#' @param num.samples The numner of paths to sample -#' @param num.warmup The number of warm up paths to sample. -#' @param verbose Whether to display the progress of the function. -#' -#' @return A matrix where each row is a path length and each column is the number of paths sampled. -#' -#' @author Timothy Hancock -#' @author Ahmed Mohamed -#' @family Path ranking methods -#' @export -#' @examples -#' ## Prepare a weighted reaction network. -#' ## Conver a metabolic network to a reaction network. -#' data(ex_sbml) # bipartite metabolic network of Carbohydrate metabolism. -#' rgraph <- makeReactionNetwork(ex_sbml, simplify=TRUE) -#' -#' ## Assign edge weights based on Affymetrix attributes and microarray dataset. -#' # Calculate Pearson's correlation. -#' data(ex_microarray) # Part of ALL dataset. -#' rgraph <- assignEdgeWeights(microarray = ex_microarray, graph = rgraph, -#' weight.method = "cor", use.attr="miriam.uniprot", -#' y=factor(colnames(ex_microarray)), bootstrap = FALSE) -#' -#' ## Get significantly correlated paths using "p-valvue" method. -#' ## First, establish path score distribution by calling "samplePaths" -#' pathsample <- samplePaths(rgraph, max.path.length=10, -#' num.samples=100, num.warmup=10) -#' -#' ## Get all significant paths with p<0.1 -#' significant.p <- pathRanker(rgraph, method = "pvalue", -#' sampledpaths = pathsample ,alpha=0.1) -#' -samplePaths <- function(graph, max.path.length, num.samples=1000, num.warmup=10, verbose=TRUE){ - # Checking the graph - if(is.null(E(graph)$edge.weights)){ - if(!is.null(E(graph)$weight)) - E(graph)$edge.weights <- E(graph)$weight - else{ - stop("No edge weights provided.") - } - } - - if (max.path.length > vcount(graph)-1) { - if(verbose) message("Maximum Path Length is larger than Number of Network Vertices ... setting them to be equal.") - max.path.length <- vcount(graph)-1 - } - - # Get edge.weights and apply ecdf on each column - edge.weights = do.call("rbind", E(graph)$edge.weights) - edge.probs <- apply(edge.weights, 2, rescale, c(1,0)) - - - # Prepare edgelist as required by PathRanker method. - label = lapply(E(graph)$attr, paste, collapse=' + ') # For edges annotated with >1 compound, concatenate. - edgelist = get.edgelist(graph, names=FALSE) - edgelist = data.frame(from=edgelist[,1], to=edgelist[,2], label=unlist(label), stringsAsFactors=FALSE) - - pg = list(nodes=V(graph)$name, edges=edgelist, weights=edge.probs) - - if(ncol(pg$weights) == 1){ - ps <- .Call("samplepaths", - pg$nodes, - pg$edges, - pg$weights, - MAXPATHLENGTH = as.integer(max.path.length), - SAMPLEPATHS = as.integer(num.samples), - WARMUPSTEPS = as.integer(num.warmup) - ) - - return( matrix(ps,max.path.length+1,num.samples,byrow = TRUE) ) - }else{ - ps <- list() - for (i in 1:ncol(pg$weights)) { - if(verbose) message("Sampling",num.samples," for",graph$y.labels[i],"\n") - p.samplei <- .Call("samplepaths", - pg$nodes, - pg$edges, - pg$weights, - MAXPATHLENGTH = as.integer(max.path.length), - SAMPLEPATHS = as.integer(num.samples), - WARMUPSTEPS = as.integer(num.warmup) - ) - ps[[i]] <- matrix(p.samplei, max.path.length+1, num.samples, byrow = TRUE) - } - names(ps) <- graph$y.labels - return(ps) - } + msg <- "P-value ranking method is deprecated. Please use 'prob.shortest.path' method instead." + .Deprecated(msg=msg) } processNetwork <- function(graph, start, end, scale=c("ecdf", "rescale"), normalize){ @@ -485,7 +307,7 @@ processNetwork <- function(graph, start, end, scale=c("ecdf", "rescale"), normal enodes <- enodes[!enodes %in% snodes] graph <- graph + vertices("s", "t") - graph <- add.edges(graph, + graph <- add_edges(graph, c(rbind("s",snodes), rbind(enodes,"t")), attr=list(edge.weights=list(rep(1, length(unlist(graph$y.labels)) )), @@ -516,16 +338,25 @@ processNetwork <- function(graph, start, end, scale=c("ecdf", "rescale"), normal if(scale=="ecdf") edge.probs <- -log(edge.probs) - # Prepare edgelist as required by PathRanker method. - label = lapply(E(graph)$compound, paste, collapse=' + ') # For edges annotated with >1 compound, concatenate. - edgelist = get.edgelist(graph, names=FALSE) - edgelist = data.frame(from=edgelist[,1], to=edgelist[,2], label=unlist(label), stringsAsFactors=FALSE) - - - return(list(nodes=V(graph)$name, edges=edgelist, weights=edge.probs)) + # E(graph)$edge.probs <- edge.probs + return(list(graph=graph, weights=edge.probs)) } #Adapted from scales package rescale <- function (x, to = c(0, 1), from = range(x, na.rm = TRUE)){ (x - from[1])/diff(from) * diff(to) + to[1] } + +format_path <- function(graph, epath, vpath, edge.probs) { + # Remove S and T nodes + epath = epath[2: (length(epath)-1)] + vpath = vpath[2: (length(vpath)-1)] + + # Apply the edge weights + E(graph)$temp.weights = edge.probs + + compounds = unlist(edge_attr(graph, "compound", epath)) + weights = edge_attr(graph, "temp.weights", epath) + genes = vertex_attr(graph, "name", vpath) + return(list(genes=genes, compounds=compounds, weights=weights, distance=sum(weights))) +} diff --git a/cleanup b/cleanup index 02839d7..b1ae0fa 100755 --- a/cleanup +++ b/cleanup @@ -1,6 +1,5 @@ #!/bin/sh -echo "removing boost headers..." -cd src; rm -rf boost +cd src echo "restoring Makevars.in file..." mv _Makevars.in_ Makevars.in; diff --git a/cleanup.win b/cleanup.win index 310cc03..0867ef7 100755 --- a/cleanup.win +++ b/cleanup.win @@ -1,8 +1,5 @@ #!/bin/sh cd src; -echo "removing boost headers..." -rm -rf boost - echo "restoring handelsegfault file..." diff --git a/configure b/configure index fb7b0c0..7822f0d 100755 --- a/configure +++ b/configure @@ -2850,23 +2850,6 @@ fi -#!/bin/sh -if test "$(uname -m)" == "x86_64"; - then - CPPFLAGS="-I. ${CPPFLAGS}" - if test -d ./src/boost; - then - echo 'found boost header sources and tar archive;\n using what is there.' - else - echo "untarring boost include tree..."; - tar -zxf ./src/boost.tar.gz -C ./src; - fi - else - echo "Non x86_64 architecture. Using system-wide boost installation!" -fi; - - - PKG_LIBS="${LIBS}" diff --git a/configure.ac b/configure.ac index aa880d7..2ec663a 100755 --- a/configure.ac +++ b/configure.ac @@ -25,21 +25,6 @@ AC_CHECK_LIB(xml2, xmlParseFile,, [XML=false]) AC_CHECK_LIB(sbml, readSBML, , [SBML=false]) -#!/bin/sh -if test "$(uname -m)" == "x86_64"; - then - CPPFLAGS="-I. ${CPPFLAGS}" - if test -d ./src/boost; - then - echo 'found boost header sources and tar archive;\n using what is there.' - else - echo "untarring boost include tree..."; - tar -zxf ./src/boost.tar.gz -C ./src; - fi - else - echo "Non x86_64 architecture. Using system-wide boost installation!" -fi; - AC_DEFUN([CHECK_XML],[ AC_PATH_PROGS(XML_CONFIG, xml2-config) LIBXML_INCDIR="-DHAVE_XML `${XML_CONFIG} --cflags`" diff --git a/configure.win b/configure.win index 8c71795..b7663b7 100755 --- a/configure.win +++ b/configure.win @@ -195,16 +195,6 @@ echo "failed" } CPP_COMPILER=`R CMD config CXX` -cd src; -echo -n '* searching for boost headers ... ' -if test -d ./boost; - then - echo 'found.' - else - echo "not found. Untarring boost.tar.gz"; - tar zxf boost.tar.gz; -fi; - echo -n '* searching for NPM_dependencies file ... ' if test -f ${R_HOME}/NPM_dependencies.tar.gz; then diff --git a/man/KGML2igraph.Rd b/man/KGML2igraph.Rd index fdd5322..e20e4f0 100755 --- a/man/KGML2igraph.Rd +++ b/man/KGML2igraph.Rd @@ -4,8 +4,12 @@ \alias{KGML2igraph} \title{Processes KGML files into igraph objects} \usage{ -KGML2igraph(filename, parse.as = c("metabolic", "signaling"), - expand.complexes = FALSE, verbose = TRUE) +KGML2igraph( + filename, + parse.as = c("metabolic", "signaling"), + expand.complexes = FALSE, + verbose = TRUE +) } \arguments{ \item{filename}{A character vector containing the KGML files to be processed. @@ -56,8 +60,9 @@ if(is.loaded("readkgmlfile")){ # This is false if libxml2 wasn't available at in } \seealso{ -Other Database extraction methods: \code{\link{SBML2igraph}}, - \code{\link{biopax2igraph}} +Other Database extraction methods: +\code{\link{SBML2igraph}()}, +\code{\link{biopax2igraph}()} } \author{ Ahmed Mohamed diff --git a/man/MIRIAM.Rd b/man/MIRIAM.Rd index eb8ab18..eb306ea 100755 --- a/man/MIRIAM.Rd +++ b/man/MIRIAM.Rd @@ -7,8 +7,13 @@ \usage{ stdAttrNames(graph, return.value = c("matches", "graph")) -fetchAttribute(graph, organism = "Homo sapiens", target.attr, - source.attr, bridge.web = NPMdefaults("bridge.web")) +fetchAttribute( + graph, + organism = "Homo sapiens", + target.attr, + source.attr, + bridge.web = NPMdefaults("bridge.web") +) } \arguments{ \item{graph}{An annotated igraph object.} @@ -47,7 +52,8 @@ These functions deals with conforming with MIRIAM annotation guidelines, convers } \seealso{ -Other Attribute handling methods: \code{\link{getAttrStatus}} +Other Attribute handling methods: +\code{\link{getAttrStatus}()} } \author{ Ahmed Mohamed diff --git a/man/SBML2igraph.Rd b/man/SBML2igraph.Rd index cf6c806..632648a 100755 --- a/man/SBML2igraph.Rd +++ b/man/SBML2igraph.Rd @@ -4,8 +4,14 @@ \alias{SBML2igraph} \title{Processes SBML files into igraph objects} \usage{ -SBML2igraph(filename, parse.as = c("metabolic", "signaling"), - miriam.attr = "all", gene.attr, expand.complexes, verbose = TRUE) +SBML2igraph( + filename, + parse.as = c("metabolic", "signaling"), + miriam.attr = "all", + gene.attr, + expand.complexes, + verbose = TRUE +) } \arguments{ \item{filename}{A character vector containing the SBML files to be processed. If a directory path @@ -76,8 +82,9 @@ if(is.loaded("readsbmlfile")){ # This is false if libSBML wasn't available at in } } \seealso{ -Other Database extraction methods: \code{\link{KGML2igraph}}, - \code{\link{biopax2igraph}} +Other Database extraction methods: +\code{\link{KGML2igraph}()}, +\code{\link{biopax2igraph}()} } \author{ Ahmed Mohamed diff --git a/man/assignEdgeWeights.Rd b/man/assignEdgeWeights.Rd index 12b3cc3..30970b5 100755 --- a/man/assignEdgeWeights.Rd +++ b/man/assignEdgeWeights.Rd @@ -4,9 +4,18 @@ \alias{assignEdgeWeights} \title{Assigning weights to network edges} \usage{ -assignEdgeWeights(microarray, graph, use.attr, y, weight.method = "cor", - complex.method = "max", missing.method = "median", - same.gene.penalty = "median", bootstrap = 100, verbose = TRUE) +assignEdgeWeights( + microarray, + graph, + use.attr, + y, + weight.method = "cor", + complex.method = "max", + missing.method = "median", + same.gene.penalty = "median", + bootstrap = 100, + verbose = TRUE +) } \arguments{ \item{microarray}{Microarray should be a Dataframe or a matrix, with genes as rownames, and samples as columns.} diff --git a/man/biopax2igraph.Rd b/man/biopax2igraph.Rd index 951d880..91645c3 100755 --- a/man/biopax2igraph.Rd +++ b/man/biopax2igraph.Rd @@ -4,8 +4,13 @@ \alias{biopax2igraph} \title{Processes BioPAX objects into igraph objects} \usage{ -biopax2igraph(biopax, parse.as = c("metabolic", "signaling"), - expand.complexes = FALSE, inc.sm.molecules = FALSE, verbose = TRUE) +biopax2igraph( + biopax, + parse.as = c("metabolic", "signaling"), + expand.complexes = FALSE, + inc.sm.molecules = FALSE, + verbose = TRUE +) } \arguments{ \item{biopax}{BioPAX object generated by \code{\link[rBiopaxParser]{readBiopax}}.} @@ -57,8 +62,9 @@ if(requireNamespace("rBiopaxParser")){ } } \seealso{ -Other Database extraction methods: \code{\link{KGML2igraph}}, - \code{\link{SBML2igraph}} +Other Database extraction methods: +\code{\link{KGML2igraph}()}, +\code{\link{SBML2igraph}()} } \author{ Ahmed Mohamed diff --git a/man/colorVertexByAttr.Rd b/man/colorVertexByAttr.Rd index da517a8..e419276 100755 --- a/man/colorVertexByAttr.Rd +++ b/man/colorVertexByAttr.Rd @@ -28,13 +28,15 @@ This function returns a list of colors for vertices, assigned similar colors if } \seealso{ -Other Plotting methods: \code{\link{layoutVertexByAttr}}, - \code{\link{plotAllNetworks}}, - \code{\link{plotClassifierROC}}, - \code{\link{plotClusterMatrix}}, - \code{\link{plotCytoscapeGML}}, - \code{\link{plotNetwork}}, - \code{\link{plotPathClassifier}}, \code{\link{plotPaths}} +Other Plotting methods: +\code{\link{layoutVertexByAttr}()}, +\code{\link{plotAllNetworks}()}, +\code{\link{plotClassifierROC}()}, +\code{\link{plotClusterMatrix}()}, +\code{\link{plotCytoscapeGML}()}, +\code{\link{plotNetwork}()}, +\code{\link{plotPathClassifier}()}, +\code{\link{plotPaths}()} } \author{ Ahmed Mohamed diff --git a/man/extractPathNetwork.Rd b/man/extractPathNetwork.Rd index a38f0e1..35acbb1 100755 --- a/man/extractPathNetwork.Rd +++ b/man/extractPathNetwork.Rd @@ -43,8 +43,9 @@ Creates a subnetwork from a ranked path list generated by \code{\link{pathRanker } \seealso{ -Other Path ranking methods: \code{\link{getPathsAsEIDs}}, - \code{\link{pathRanker}}, \code{\link{samplePaths}} +Other Path ranking methods: +\code{\link{getPathsAsEIDs}()}, +\code{\link{pathRanker}()} } \author{ Ahmed Mohamed diff --git a/man/getAttr.Rd b/man/getAttr.Rd index 94de740..39e8fca 100755 --- a/man/getAttr.Rd +++ b/man/getAttr.Rd @@ -66,7 +66,8 @@ All functions here target NetPathMiner annotations only. graph <- rmAttribute(ex_kgml_sig, "miriam.ncbigene") } \seealso{ -Other Attribute handling methods: \code{\link{stdAttrNames}} +Other Attribute handling methods: +\code{\link{stdAttrNames}()} } \author{ Ahmed Mohamed diff --git a/man/getGeneSetNetworks.Rd b/man/getGeneSetNetworks.Rd index 648a257..d07013f 100755 --- a/man/getGeneSetNetworks.Rd +++ b/man/getGeneSetNetworks.Rd @@ -4,8 +4,11 @@ \alias{getGeneSetNetworks} \title{Generate geneset networks from an annotated network.} \usage{ -getGeneSetNetworks(graph, use.attr = "pathway", format = c("list", - "pathway-class")) +getGeneSetNetworks( + graph, + use.attr = "pathway", + format = c("list", "pathway-class") +) } \arguments{ \item{graph}{An annotated igraph object..} diff --git a/man/getPathsAsEIDs.Rd b/man/getPathsAsEIDs.Rd index 87bc32c..fdc96bb 100755 --- a/man/getPathsAsEIDs.Rd +++ b/man/getPathsAsEIDs.Rd @@ -44,8 +44,9 @@ edges on a metabolic network). } \seealso{ -Other Path ranking methods: \code{\link{extractPathNetwork}}, - \code{\link{pathRanker}}, \code{\link{samplePaths}} +Other Path ranking methods: +\code{\link{extractPathNetwork}()}, +\code{\link{pathRanker}()} } \author{ Ahmed Mohamed diff --git a/man/layoutVertexByAttr.Rd b/man/layoutVertexByAttr.Rd index 753fe43..ba147d7 100755 --- a/man/layoutVertexByAttr.Rd +++ b/man/layoutVertexByAttr.Rd @@ -4,8 +4,12 @@ \alias{layoutVertexByAttr} \title{A graph layout function, which groups vertices by attribute.} \usage{ -layoutVertexByAttr(graph, attr.name, cluster.strength = 1, - layout = layout.auto) +layoutVertexByAttr( + graph, + attr.name, + cluster.strength = 1, + layout = layout.auto +) } \arguments{ \item{graph}{An annotated igraph object.} @@ -35,13 +39,15 @@ This function generates a layout for igraph objects, keeping vertices with the s } \seealso{ -Other Plotting methods: \code{\link{colorVertexByAttr}}, - \code{\link{plotAllNetworks}}, - \code{\link{plotClassifierROC}}, - \code{\link{plotClusterMatrix}}, - \code{\link{plotCytoscapeGML}}, - \code{\link{plotNetwork}}, - \code{\link{plotPathClassifier}}, \code{\link{plotPaths}} +Other Plotting methods: +\code{\link{colorVertexByAttr}()}, +\code{\link{plotAllNetworks}()}, +\code{\link{plotClassifierROC}()}, +\code{\link{plotClusterMatrix}()}, +\code{\link{plotCytoscapeGML}()}, +\code{\link{plotNetwork}()}, +\code{\link{plotPathClassifier}()}, +\code{\link{plotPaths}()} } \author{ Ahmed Mohamed diff --git a/man/makeGeneNetwork.Rd b/man/makeGeneNetwork.Rd index 1c8469e..758e9fd 100755 --- a/man/makeGeneNetwork.Rd +++ b/man/makeGeneNetwork.Rd @@ -5,12 +5,21 @@ \alias{makeGeneNetwork} \title{Expand reactions / complexes into their gene constituents.} \usage{ -expandComplexes(graph, v.attr, keep.parent.attr = "^pathway", +expandComplexes( + graph, + v.attr, + keep.parent.attr = "^pathway", expansion.method = c("normal", "duplicate"), - missing.method = c("keep", "remove", "reconnect")) + missing.method = c("keep", "remove", "reconnect") +) -makeGeneNetwork(graph, v.attr = "genes", keep.parent.attr = "^pathway", - expansion.method = "duplicate", missing.method = "remove") +makeGeneNetwork( + graph, + v.attr = "genes", + keep.parent.attr = "^pathway", + expansion.method = "duplicate", + missing.method = "remove" +) } \arguments{ \item{graph}{An annotated igraph object.} @@ -66,12 +75,13 @@ vertices by "miriam.kegg.compound" attribute. } \seealso{ -Other Network processing methods: \code{\link{makeMetaboliteNetwork}}, - \code{\link{makeReactionNetwork}}, - \code{\link{reindexNetwork}}, - \code{\link{rmSmallCompounds}}, - \code{\link{simplifyReactionNetwork}}, - \code{\link{vertexDeleteReconnect}} +Other Network processing methods: +\code{\link{makeMetaboliteNetwork}()}, +\code{\link{makeReactionNetwork}()}, +\code{\link{reindexNetwork}()}, +\code{\link{rmSmallCompounds}()}, +\code{\link{simplifyReactionNetwork}()}, +\code{\link{vertexDeleteReconnect}()} } \author{ Ahmed Mohamed diff --git a/man/makeMetaboliteNetwork.Rd b/man/makeMetaboliteNetwork.Rd index 602f745..8e603d8 100644 --- a/man/makeMetaboliteNetwork.Rd +++ b/man/makeMetaboliteNetwork.Rd @@ -23,12 +23,13 @@ network contains metabolite nodes only, where edges indicate that reaction conve } \seealso{ -Other Network processing methods: \code{\link{expandComplexes}}, - \code{\link{makeReactionNetwork}}, - \code{\link{reindexNetwork}}, - \code{\link{rmSmallCompounds}}, - \code{\link{simplifyReactionNetwork}}, - \code{\link{vertexDeleteReconnect}} +Other Network processing methods: +\code{\link{expandComplexes}()}, +\code{\link{makeReactionNetwork}()}, +\code{\link{reindexNetwork}()}, +\code{\link{rmSmallCompounds}()}, +\code{\link{simplifyReactionNetwork}()}, +\code{\link{vertexDeleteReconnect}()} } \author{ Ahmed Mohamed diff --git a/man/makeReactionNetwork.Rd b/man/makeReactionNetwork.Rd index 953df2b..15afe0a 100755 --- a/man/makeReactionNetwork.Rd +++ b/man/makeReactionNetwork.Rd @@ -28,12 +28,13 @@ by one reaction is consumed by the other. } \seealso{ -Other Network processing methods: \code{\link{expandComplexes}}, - \code{\link{makeMetaboliteNetwork}}, - \code{\link{reindexNetwork}}, - \code{\link{rmSmallCompounds}}, - \code{\link{simplifyReactionNetwork}}, - \code{\link{vertexDeleteReconnect}} +Other Network processing methods: +\code{\link{expandComplexes}()}, +\code{\link{makeMetaboliteNetwork}()}, +\code{\link{reindexNetwork}()}, +\code{\link{rmSmallCompounds}()}, +\code{\link{simplifyReactionNetwork}()}, +\code{\link{vertexDeleteReconnect}()} } \author{ Ahmed Mohamed diff --git a/man/pathClassifier.Rd b/man/pathClassifier.Rd index 5830bde..793f3d6 100755 --- a/man/pathClassifier.Rd +++ b/man/pathClassifier.Rd @@ -4,8 +4,16 @@ \alias{pathClassifier} \title{HME3M Markov pathway classifier.} \usage{ -pathClassifier(paths, target.class, M, alpha = 1, lambda = 2, - hme3miter = 100, plriter = 1, init = "random") +pathClassifier( + paths, + target.class, + M, + alpha = 1, + lambda = 2, + hme3miter = 100, + plriter = 1, + init = "random" +) } \arguments{ \item{paths}{The training paths computed by \code{\link{pathsToBinary}}} @@ -84,14 +92,15 @@ Hancock, Timothy, and Mamitsuka, Hiroshi: A Markov Classification Model for Meta Hancock, Timothy, and Mamitsuka, Hiroshi: A Markov Classification Model for Metabolic Pathways, Algorithms for Molecular Biology 2010 } \seealso{ -Other Path clustering & classification methods: \code{\link{pathCluster}}, - \code{\link{pathsToBinary}}, - \code{\link{plotClassifierROC}}, - \code{\link{plotClusterMatrix}}, - \code{\link{plotPathClassifier}}, - \code{\link{plotPathCluster}}, - \code{\link{predictPathClassifier}}, - \code{\link{predictPathCluster}} +Other Path clustering & classification methods: +\code{\link{pathCluster}()}, +\code{\link{pathsToBinary}()}, +\code{\link{plotClassifierROC}()}, +\code{\link{plotClusterMatrix}()}, +\code{\link{plotPathClassifier}()}, +\code{\link{plotPathCluster}()}, +\code{\link{predictPathClassifier}()}, +\code{\link{predictPathCluster}()} } \author{ Timothy Hancock and Ichigaku Takigawa diff --git a/man/pathCluster.Rd b/man/pathCluster.Rd index 4f99246..29f0b53 100755 --- a/man/pathCluster.Rd +++ b/man/pathCluster.Rd @@ -52,14 +52,15 @@ Mamitsuka, H., Okuno, Y., and Yamaguchi, A. 2003. Mining biologically active pat metabolic pathways using microarray expression profiles. SIGKDD Explor. News l. 5, 2 (Dec. 2003), 113-121. } \seealso{ -Other Path clustering & classification methods: \code{\link{pathClassifier}}, - \code{\link{pathsToBinary}}, - \code{\link{plotClassifierROC}}, - \code{\link{plotClusterMatrix}}, - \code{\link{plotPathClassifier}}, - \code{\link{plotPathCluster}}, - \code{\link{predictPathClassifier}}, - \code{\link{predictPathCluster}} +Other Path clustering & classification methods: +\code{\link{pathClassifier}()}, +\code{\link{pathsToBinary}()}, +\code{\link{plotClassifierROC}()}, +\code{\link{plotClusterMatrix}()}, +\code{\link{plotPathClassifier}()}, +\code{\link{plotPathCluster}()}, +\code{\link{predictPathClassifier}()}, +\code{\link{predictPathCluster}()} } \author{ Ichigaku Takigawa diff --git a/man/pathRanker.Rd b/man/pathRanker.Rd index 1756a10..52e9e6b 100755 --- a/man/pathRanker.Rd +++ b/man/pathRanker.Rd @@ -4,8 +4,14 @@ \alias{pathRanker} \title{Extracting and ranking paths from a network} \usage{ -pathRanker(graph, method = c("prob.shortest.path", "pvalue"), start, end, - verbose = TRUE, ...) +pathRanker( + graph, + method = "prob.shortest.path", + start, + end, + verbose = TRUE, + ... +) } \arguments{ \item{graph}{A weighted igraph object. Weights must be in \code{edge.weights} or \code{weight} @@ -60,19 +66,7 @@ before extracting the paths. Defaults to TRUE.} } \subsection{P-value method}{ -\code{pathRanker(method="pvalue")} searches all paths between the specified start and end vertices, and if a -significant path is found it returns it. However, It doesn't search for the best path between the start and -terminal vertices, as there could be many paths which lead to the same terminal vertex, and searching through -all of them is time comsuming. We just stop when the first significant path is found. - -All provided edge weights are recaled from 0-1. Path significance is calculated based on the empirical distribution -of random paths of the same length. This can be estimated using \code{\link{samplePaths}} and passed as an argument. - -The follwing arguments can be passed to \code{pathRanker(method="pvalue")}: -\describe{ -\item{\code{sampledpaths}}{The emripical results from \code{\link{samplePaths}}.} -\item{\code{alpha}}{The P value cut-off. Defualts to 0.01} -} +\code{pathRanker(method="pvalue")} is deprecated. Please use \code{prob.shortest.path} instead. } } \examples{ @@ -92,21 +86,13 @@ The follwing arguments can be passed to \code{pathRanker(method="pvalue")}: ranked.p <- pathRanker(rgraph, method="prob.shortest.path", K=20, minPathSize=6) - ## Get significantly correlated paths using "p-valvue" method. - ## First, establish path score distribution by calling "samplePaths" - pathsample <- samplePaths(rgraph, max.path.length=10, - num.samples=100, num.warmup=10) - - ## Get all significant paths with p<0.1 - significant.p <- pathRanker(rgraph, method = "pvalue", - sampledpaths = pathsample ,alpha=0.1) - } \seealso{ getPathsAsEIDs, extractPathNetwork -Other Path ranking methods: \code{\link{extractPathNetwork}}, - \code{\link{getPathsAsEIDs}}, \code{\link{samplePaths}} +Other Path ranking methods: +\code{\link{extractPathNetwork}()}, +\code{\link{getPathsAsEIDs}()} } \author{ Timothy Hancock, Ichigaku Takigawa, Nicolas Wicker and Ahmed Mohamed diff --git a/man/pathsToBinary.Rd b/man/pathsToBinary.Rd index 3061026..fad739b 100755 --- a/man/pathsToBinary.Rd +++ b/man/pathsToBinary.Rd @@ -52,14 +52,15 @@ wish to reference. } \seealso{ -Other Path clustering & classification methods: \code{\link{pathClassifier}}, - \code{\link{pathCluster}}, - \code{\link{plotClassifierROC}}, - \code{\link{plotClusterMatrix}}, - \code{\link{plotPathClassifier}}, - \code{\link{plotPathCluster}}, - \code{\link{predictPathClassifier}}, - \code{\link{predictPathCluster}} +Other Path clustering & classification methods: +\code{\link{pathClassifier}()}, +\code{\link{pathCluster}()}, +\code{\link{plotClassifierROC}()}, +\code{\link{plotClusterMatrix}()}, +\code{\link{plotPathClassifier}()}, +\code{\link{plotPathCluster}()}, +\code{\link{predictPathClassifier}()}, +\code{\link{predictPathCluster}()} } \author{ Timothy Hancock and Ichigaku Takigawa diff --git a/man/plotAllNetworks.Rd b/man/plotAllNetworks.Rd index 0150add..cb0ba95 100755 --- a/man/plotAllNetworks.Rd +++ b/man/plotAllNetworks.Rd @@ -4,9 +4,17 @@ \alias{plotAllNetworks} \title{Higlighting ranked paths over multiple network representations.} \usage{ -plotAllNetworks(paths, metabolic.net = NULL, reaction.net = NULL, - gene.net = NULL, path.clusters = NULL, plot.clusters = TRUE, - col.palette = palette(), layout = layout.auto, ...) +plotAllNetworks( + paths, + metabolic.net = NULL, + reaction.net = NULL, + gene.net = NULL, + path.clusters = NULL, + plot.clusters = TRUE, + col.palette = palette(), + layout = layout.auto, + ... +) } \arguments{ \item{paths}{The result of \code{\link{pathRanker}}.} @@ -56,13 +64,15 @@ plotAllNetworks(ranked.p, metabolic.net = ex_sbml, reaction.net = rgraph, } \seealso{ -Other Plotting methods: \code{\link{colorVertexByAttr}}, - \code{\link{layoutVertexByAttr}}, - \code{\link{plotClassifierROC}}, - \code{\link{plotClusterMatrix}}, - \code{\link{plotCytoscapeGML}}, - \code{\link{plotNetwork}}, - \code{\link{plotPathClassifier}}, \code{\link{plotPaths}} +Other Plotting methods: +\code{\link{colorVertexByAttr}()}, +\code{\link{layoutVertexByAttr}()}, +\code{\link{plotClassifierROC}()}, +\code{\link{plotClusterMatrix}()}, +\code{\link{plotCytoscapeGML}()}, +\code{\link{plotNetwork}()}, +\code{\link{plotPathClassifier}()}, +\code{\link{plotPaths}()} } \author{ Ahmed Mohamed diff --git a/man/plotClassifierROC.Rd b/man/plotClassifierROC.Rd index 9a83ed3..9d61cf0 100755 --- a/man/plotClassifierROC.Rd +++ b/man/plotClassifierROC.Rd @@ -22,21 +22,25 @@ item{Bottom}{The likelihood convergence history for the HME3M model. If the par Diagnostic plots for \code{\link{pathClassifier}}. } \seealso{ -Other Path clustering & classification methods: \code{\link{pathClassifier}}, - \code{\link{pathCluster}}, \code{\link{pathsToBinary}}, - \code{\link{plotClusterMatrix}}, - \code{\link{plotPathClassifier}}, - \code{\link{plotPathCluster}}, - \code{\link{predictPathClassifier}}, - \code{\link{predictPathCluster}} +Other Path clustering & classification methods: +\code{\link{pathClassifier}()}, +\code{\link{pathCluster}()}, +\code{\link{pathsToBinary}()}, +\code{\link{plotClusterMatrix}()}, +\code{\link{plotPathClassifier}()}, +\code{\link{plotPathCluster}()}, +\code{\link{predictPathClassifier}()}, +\code{\link{predictPathCluster}()} -Other Plotting methods: \code{\link{colorVertexByAttr}}, - \code{\link{layoutVertexByAttr}}, - \code{\link{plotAllNetworks}}, - \code{\link{plotClusterMatrix}}, - \code{\link{plotCytoscapeGML}}, - \code{\link{plotNetwork}}, - \code{\link{plotPathClassifier}}, \code{\link{plotPaths}} +Other Plotting methods: +\code{\link{colorVertexByAttr}()}, +\code{\link{layoutVertexByAttr}()}, +\code{\link{plotAllNetworks}()}, +\code{\link{plotClusterMatrix}()}, +\code{\link{plotCytoscapeGML}()}, +\code{\link{plotNetwork}()}, +\code{\link{plotPathClassifier}()}, +\code{\link{plotPaths}()} } \author{ Timothy Hancock and Ichigaku Takigawa diff --git a/man/plotClusters.Rd b/man/plotClusters.Rd index 9df8ced..3a5a1b3 100755 --- a/man/plotClusters.Rd +++ b/man/plotClusters.Rd @@ -6,8 +6,12 @@ \alias{plotClusters} \title{Plots the structure of all path clusters} \usage{ -plotClusterMatrix(ybinpaths, clusters, col = rainbow(clusters$params$M), - grid = TRUE) +plotClusterMatrix( + ybinpaths, + clusters, + col = rainbow(clusters$params$M), + grid = TRUE +) plotClusterProbs(clusters, col = rainbow(clusters$params$M)) @@ -59,21 +63,25 @@ Plots the structure of all path clusters } \seealso{ -Other Path clustering & classification methods: \code{\link{pathClassifier}}, - \code{\link{pathCluster}}, \code{\link{pathsToBinary}}, - \code{\link{plotClassifierROC}}, - \code{\link{plotPathClassifier}}, - \code{\link{plotPathCluster}}, - \code{\link{predictPathClassifier}}, - \code{\link{predictPathCluster}} +Other Path clustering & classification methods: +\code{\link{pathClassifier}()}, +\code{\link{pathCluster}()}, +\code{\link{pathsToBinary}()}, +\code{\link{plotClassifierROC}()}, +\code{\link{plotPathClassifier}()}, +\code{\link{plotPathCluster}()}, +\code{\link{predictPathClassifier}()}, +\code{\link{predictPathCluster}()} -Other Plotting methods: \code{\link{colorVertexByAttr}}, - \code{\link{layoutVertexByAttr}}, - \code{\link{plotAllNetworks}}, - \code{\link{plotClassifierROC}}, - \code{\link{plotCytoscapeGML}}, - \code{\link{plotNetwork}}, - \code{\link{plotPathClassifier}}, \code{\link{plotPaths}} +Other Plotting methods: +\code{\link{colorVertexByAttr}()}, +\code{\link{layoutVertexByAttr}()}, +\code{\link{plotAllNetworks}()}, +\code{\link{plotClassifierROC}()}, +\code{\link{plotCytoscapeGML}()}, +\code{\link{plotNetwork}()}, +\code{\link{plotPathClassifier}()}, +\code{\link{plotPaths}()} } \author{ Ahmed Mohamed diff --git a/man/plotCytoscape.Rd b/man/plotCytoscape.Rd index 197b6af..cf942f2 100755 --- a/man/plotCytoscape.Rd +++ b/man/plotCytoscape.Rd @@ -4,8 +4,16 @@ \alias{plotCytoscapeGML} \title{Plots an annotated igraph object in Cytoscape.} \usage{ -plotCytoscapeGML(graph, file, layout = layout.auto, vertex.size, - vertex.label, vertex.shape, vertex.color, edge.color) +plotCytoscapeGML( + graph, + file, + layout = layout.auto, + vertex.size, + vertex.label, + vertex.shape, + vertex.color, + edge.color +) } \arguments{ \item{graph}{An annotated igraph object.} @@ -50,13 +58,15 @@ Future plans will use RCy3 for Cytoscape plotting, once RCy3 is supported on Mac } \seealso{ -Other Plotting methods: \code{\link{colorVertexByAttr}}, - \code{\link{layoutVertexByAttr}}, - \code{\link{plotAllNetworks}}, - \code{\link{plotClassifierROC}}, - \code{\link{plotClusterMatrix}}, - \code{\link{plotNetwork}}, - \code{\link{plotPathClassifier}}, \code{\link{plotPaths}} +Other Plotting methods: +\code{\link{colorVertexByAttr}()}, +\code{\link{layoutVertexByAttr}()}, +\code{\link{plotAllNetworks}()}, +\code{\link{plotClassifierROC}()}, +\code{\link{plotClusterMatrix}()}, +\code{\link{plotNetwork}()}, +\code{\link{plotPathClassifier}()}, +\code{\link{plotPaths}()} } \author{ Ahmed Mohamed diff --git a/man/plotNetwork.Rd b/man/plotNetwork.Rd index 455252c..9886500 100755 --- a/man/plotNetwork.Rd +++ b/man/plotNetwork.Rd @@ -4,8 +4,14 @@ \alias{plotNetwork} \title{Plots an annotated igraph object.} \usage{ -plotNetwork(graph, vertex.color, col.palette = palette(), - layout = layout.auto, legend = TRUE, ...) +plotNetwork( + graph, + vertex.color, + col.palette = palette(), + layout = layout.auto, + legend = TRUE, + ... +) } \arguments{ \item{graph}{An annotated igraph object.} @@ -40,13 +46,15 @@ network. } \seealso{ -Other Plotting methods: \code{\link{colorVertexByAttr}}, - \code{\link{layoutVertexByAttr}}, - \code{\link{plotAllNetworks}}, - \code{\link{plotClassifierROC}}, - \code{\link{plotClusterMatrix}}, - \code{\link{plotCytoscapeGML}}, - \code{\link{plotPathClassifier}}, \code{\link{plotPaths}} +Other Plotting methods: +\code{\link{colorVertexByAttr}()}, +\code{\link{layoutVertexByAttr}()}, +\code{\link{plotAllNetworks}()}, +\code{\link{plotClassifierROC}()}, +\code{\link{plotClusterMatrix}()}, +\code{\link{plotCytoscapeGML}()}, +\code{\link{plotPathClassifier}()}, +\code{\link{plotPaths}()} } \author{ Ahmed Mohamed diff --git a/man/plotPathClassifier.Rd b/man/plotPathClassifier.Rd index 45233bd..6b9f902 100755 --- a/man/plotPathClassifier.Rd +++ b/man/plotPathClassifier.Rd @@ -56,21 +56,25 @@ Plots the structure of specified path found by pathClassifier. } \seealso{ -Other Path clustering & classification methods: \code{\link{pathClassifier}}, - \code{\link{pathCluster}}, \code{\link{pathsToBinary}}, - \code{\link{plotClassifierROC}}, - \code{\link{plotClusterMatrix}}, - \code{\link{plotPathCluster}}, - \code{\link{predictPathClassifier}}, - \code{\link{predictPathCluster}} +Other Path clustering & classification methods: +\code{\link{pathClassifier}()}, +\code{\link{pathCluster}()}, +\code{\link{pathsToBinary}()}, +\code{\link{plotClassifierROC}()}, +\code{\link{plotClusterMatrix}()}, +\code{\link{plotPathCluster}()}, +\code{\link{predictPathClassifier}()}, +\code{\link{predictPathCluster}()} -Other Plotting methods: \code{\link{colorVertexByAttr}}, - \code{\link{layoutVertexByAttr}}, - \code{\link{plotAllNetworks}}, - \code{\link{plotClassifierROC}}, - \code{\link{plotClusterMatrix}}, - \code{\link{plotCytoscapeGML}}, - \code{\link{plotNetwork}}, \code{\link{plotPaths}} +Other Plotting methods: +\code{\link{colorVertexByAttr}()}, +\code{\link{layoutVertexByAttr}()}, +\code{\link{plotAllNetworks}()}, +\code{\link{plotClassifierROC}()}, +\code{\link{plotClusterMatrix}()}, +\code{\link{plotCytoscapeGML}()}, +\code{\link{plotNetwork}()}, +\code{\link{plotPaths}()} } \author{ Timothy Hancock and Ichigaku Takigawa diff --git a/man/plotPathCluster.Rd b/man/plotPathCluster.Rd index fa6b586..aac69f6 100755 --- a/man/plotPathCluster.Rd +++ b/man/plotPathCluster.Rd @@ -50,13 +50,15 @@ Plots the structure of specified path found by pathCluster. } \seealso{ -Other Path clustering & classification methods: \code{\link{pathClassifier}}, - \code{\link{pathCluster}}, \code{\link{pathsToBinary}}, - \code{\link{plotClassifierROC}}, - \code{\link{plotClusterMatrix}}, - \code{\link{plotPathClassifier}}, - \code{\link{predictPathClassifier}}, - \code{\link{predictPathCluster}} +Other Path clustering & classification methods: +\code{\link{pathClassifier}()}, +\code{\link{pathCluster}()}, +\code{\link{pathsToBinary}()}, +\code{\link{plotClassifierROC}()}, +\code{\link{plotClusterMatrix}()}, +\code{\link{plotPathClassifier}()}, +\code{\link{predictPathClassifier}()}, +\code{\link{predictPathCluster}()} } \author{ Timothy Hancock and Ichigaku Takigawa diff --git a/man/plotPaths.Rd b/man/plotPaths.Rd index 16b2cfc..baec077 100755 --- a/man/plotPaths.Rd +++ b/man/plotPaths.Rd @@ -4,8 +4,14 @@ \alias{plotPaths} \title{Plots an annotated igraph object higlighting ranked paths.} \usage{ -plotPaths(paths, graph, path.clusters = NULL, col.palette = palette(), - layout = layout.auto, ...) +plotPaths( + paths, + graph, + path.clusters = NULL, + col.palette = palette(), + layout = layout.auto, + ... +) } \arguments{ \item{paths}{The result of \code{\link{pathRanker}}.} @@ -57,14 +63,15 @@ paths in the same cluster are assigned similar colors. } \seealso{ -Other Plotting methods: \code{\link{colorVertexByAttr}}, - \code{\link{layoutVertexByAttr}}, - \code{\link{plotAllNetworks}}, - \code{\link{plotClassifierROC}}, - \code{\link{plotClusterMatrix}}, - \code{\link{plotCytoscapeGML}}, - \code{\link{plotNetwork}}, - \code{\link{plotPathClassifier}} +Other Plotting methods: +\code{\link{colorVertexByAttr}()}, +\code{\link{layoutVertexByAttr}()}, +\code{\link{plotAllNetworks}()}, +\code{\link{plotClassifierROC}()}, +\code{\link{plotClusterMatrix}()}, +\code{\link{plotCytoscapeGML}()}, +\code{\link{plotNetwork}()}, +\code{\link{plotPathClassifier}()} } \author{ Ahmed Mohamed diff --git a/man/predictPathClassifier.Rd b/man/predictPathClassifier.Rd index b493555..ad26109 100755 --- a/man/predictPathClassifier.Rd +++ b/man/predictPathClassifier.Rd @@ -49,13 +49,15 @@ Predicts new paths given a pathClassifier model. } \seealso{ -Other Path clustering & classification methods: \code{\link{pathClassifier}}, - \code{\link{pathCluster}}, \code{\link{pathsToBinary}}, - \code{\link{plotClassifierROC}}, - \code{\link{plotClusterMatrix}}, - \code{\link{plotPathClassifier}}, - \code{\link{plotPathCluster}}, - \code{\link{predictPathCluster}} +Other Path clustering & classification methods: +\code{\link{pathClassifier}()}, +\code{\link{pathCluster}()}, +\code{\link{pathsToBinary}()}, +\code{\link{plotClassifierROC}()}, +\code{\link{plotClusterMatrix}()}, +\code{\link{plotPathClassifier}()}, +\code{\link{plotPathCluster}()}, +\code{\link{predictPathCluster}()} } \author{ Timothy Hancock and Ichigaku Takigawa diff --git a/man/predictPathCluster.Rd b/man/predictPathCluster.Rd index d330fd0..376d8ca 100755 --- a/man/predictPathCluster.Rd +++ b/man/predictPathCluster.Rd @@ -46,13 +46,15 @@ Predicts new paths given a pathCluster model. } \seealso{ -Other Path clustering & classification methods: \code{\link{pathClassifier}}, - \code{\link{pathCluster}}, \code{\link{pathsToBinary}}, - \code{\link{plotClassifierROC}}, - \code{\link{plotClusterMatrix}}, - \code{\link{plotPathClassifier}}, - \code{\link{plotPathCluster}}, - \code{\link{predictPathClassifier}} +Other Path clustering & classification methods: +\code{\link{pathClassifier}()}, +\code{\link{pathCluster}()}, +\code{\link{pathsToBinary}()}, +\code{\link{plotClassifierROC}()}, +\code{\link{plotClusterMatrix}()}, +\code{\link{plotPathClassifier}()}, +\code{\link{plotPathCluster}()}, +\code{\link{predictPathClassifier}()} } \author{ Ichigaku Takigawa diff --git a/man/reindexNetwork.Rd b/man/reindexNetwork.Rd index 9b6aed1..dbb386a 100644 --- a/man/reindexNetwork.Rd +++ b/man/reindexNetwork.Rd @@ -47,12 +47,13 @@ reindexing by chemical name will collapse them into one `ATP` vertex. } \seealso{ -Other Network processing methods: \code{\link{expandComplexes}}, - \code{\link{makeMetaboliteNetwork}}, - \code{\link{makeReactionNetwork}}, - \code{\link{rmSmallCompounds}}, - \code{\link{simplifyReactionNetwork}}, - \code{\link{vertexDeleteReconnect}} +Other Network processing methods: +\code{\link{expandComplexes}()}, +\code{\link{makeMetaboliteNetwork}()}, +\code{\link{makeReactionNetwork}()}, +\code{\link{rmSmallCompounds}()}, +\code{\link{simplifyReactionNetwork}()}, +\code{\link{vertexDeleteReconnect}()} } \author{ Ahmed Mohamed diff --git a/man/rmSmallCompounds.Rd b/man/rmSmallCompounds.Rd index 0133a29..a6d453b 100755 --- a/man/rmSmallCompounds.Rd +++ b/man/rmSmallCompounds.Rd @@ -4,8 +4,11 @@ \alias{rmSmallCompounds} \title{Remove uniquitous compounds from a metabolic network} \usage{ -rmSmallCompounds(graph, method = c("remove", "duplicate"), - small.comp.ls = NPMdefaults("small.comp.ls")) +rmSmallCompounds( + graph, + method = c("remove", "duplicate"), + small.comp.ls = NPMdefaults("small.comp.ls") +) } \arguments{ \item{graph}{A metabolic network.} @@ -34,12 +37,13 @@ ChEBI and CAS identifiers. } \seealso{ -Other Network processing methods: \code{\link{expandComplexes}}, - \code{\link{makeMetaboliteNetwork}}, - \code{\link{makeReactionNetwork}}, - \code{\link{reindexNetwork}}, - \code{\link{simplifyReactionNetwork}}, - \code{\link{vertexDeleteReconnect}} +Other Network processing methods: +\code{\link{expandComplexes}()}, +\code{\link{makeMetaboliteNetwork}()}, +\code{\link{makeReactionNetwork}()}, +\code{\link{reindexNetwork}()}, +\code{\link{simplifyReactionNetwork}()}, +\code{\link{vertexDeleteReconnect}()} } \author{ Ahmed Mohamed diff --git a/man/samplePaths.Rd b/man/samplePaths.Rd deleted file mode 100755 index 7cd84f4..0000000 --- a/man/samplePaths.Rd +++ /dev/null @@ -1,64 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/pathRank.R -\name{samplePaths} -\alias{samplePaths} -\title{Creates a set of sample path p-values for each length given a weighted network} -\usage{ -samplePaths(graph, max.path.length, num.samples = 1000, - num.warmup = 10, verbose = TRUE) -} -\arguments{ -\item{graph}{A weighted igraph object. Weights must be in \code{edge.weights} or \code{weight} -edge attributes.} - -\item{max.path.length}{The maxmimum path length.} - -\item{num.samples}{The numner of paths to sample} - -\item{num.warmup}{The number of warm up paths to sample.} - -\item{verbose}{Whether to display the progress of the function.} -} -\value{ -A matrix where each row is a path length and each column is the number of paths sampled. -} -\description{ -Randomly traverses paths of increasing lengths within a set network to create an -empirical pathway distribution for more accurate determination of path significance. -} -\details{ -Can take a bit of time. -} -\examples{ - ## Prepare a weighted reaction network. - ## Conver a metabolic network to a reaction network. - data(ex_sbml) # bipartite metabolic network of Carbohydrate metabolism. - rgraph <- makeReactionNetwork(ex_sbml, simplify=TRUE) - - ## Assign edge weights based on Affymetrix attributes and microarray dataset. - # Calculate Pearson's correlation. - data(ex_microarray) # Part of ALL dataset. - rgraph <- assignEdgeWeights(microarray = ex_microarray, graph = rgraph, - weight.method = "cor", use.attr="miriam.uniprot", - y=factor(colnames(ex_microarray)), bootstrap = FALSE) - - ## Get significantly correlated paths using "p-valvue" method. - ## First, establish path score distribution by calling "samplePaths" - pathsample <- samplePaths(rgraph, max.path.length=10, - num.samples=100, num.warmup=10) - - ## Get all significant paths with p<0.1 - significant.p <- pathRanker(rgraph, method = "pvalue", - sampledpaths = pathsample ,alpha=0.1) - -} -\seealso{ -Other Path ranking methods: \code{\link{extractPathNetwork}}, - \code{\link{getPathsAsEIDs}}, \code{\link{pathRanker}} -} -\author{ -Timothy Hancock - -Ahmed Mohamed -} -\concept{Path ranking methods} diff --git a/man/simplifyReactionNetwork.Rd b/man/simplifyReactionNetwork.Rd index 50661db..c01aa28 100755 --- a/man/simplifyReactionNetwork.Rd +++ b/man/simplifyReactionNetwork.Rd @@ -4,9 +4,12 @@ \alias{simplifyReactionNetwork} \title{Removes reactions with no gene annotations} \usage{ -simplifyReactionNetwork(reaction.graph, gene.attr = "genes", +simplifyReactionNetwork( + reaction.graph, + gene.attr = "genes", remove.missing.genes = TRUE, - reconnect.threshold = vcount(reaction.graph)) + reconnect.threshold = vcount(reaction.graph) +) } \arguments{ \item{reaction.graph}{A reaction network.} @@ -36,12 +39,13 @@ which are not catalysed by genes. } \seealso{ -Other Network processing methods: \code{\link{expandComplexes}}, - \code{\link{makeMetaboliteNetwork}}, - \code{\link{makeReactionNetwork}}, - \code{\link{reindexNetwork}}, - \code{\link{rmSmallCompounds}}, - \code{\link{vertexDeleteReconnect}} +Other Network processing methods: +\code{\link{expandComplexes}()}, +\code{\link{makeMetaboliteNetwork}()}, +\code{\link{makeReactionNetwork}()}, +\code{\link{reindexNetwork}()}, +\code{\link{rmSmallCompounds}()}, +\code{\link{vertexDeleteReconnect}()} } \author{ Ahmed Mohamed diff --git a/man/vertexDeleteReconnect.Rd b/man/vertexDeleteReconnect.Rd index b9a05cc..1fa0fcd 100755 --- a/man/vertexDeleteReconnect.Rd +++ b/man/vertexDeleteReconnect.Rd @@ -4,8 +4,12 @@ \alias{vertexDeleteReconnect} \title{Network editing: removing vertices and connecting their neighbours} \usage{ -vertexDeleteReconnect(graph, vids, reconnect.threshold = vcount(graph), - copy.attr = NULL) +vertexDeleteReconnect( + graph, + vids, + reconnect.threshold = vcount(graph), + copy.attr = NULL +) } \arguments{ \item{graph}{A reaction network.} @@ -34,12 +38,13 @@ long as the shortest path beween the neighbours are below the \code{reconnect.th } \seealso{ -Other Network processing methods: \code{\link{expandComplexes}}, - \code{\link{makeMetaboliteNetwork}}, - \code{\link{makeReactionNetwork}}, - \code{\link{reindexNetwork}}, - \code{\link{rmSmallCompounds}}, - \code{\link{simplifyReactionNetwork}} +Other Network processing methods: +\code{\link{expandComplexes}()}, +\code{\link{makeMetaboliteNetwork}()}, +\code{\link{makeReactionNetwork}()}, +\code{\link{reindexNetwork}()}, +\code{\link{rmSmallCompounds}()}, +\code{\link{simplifyReactionNetwork}()} } \author{ Ahmed Mohamed diff --git a/src/PathRanker.cpp b/src/PathRanker.cpp deleted file mode 100755 index 3901f79..0000000 --- a/src/PathRanker.cpp +++ /dev/null @@ -1,432 +0,0 @@ -//======================================================================= -// Path Ranker -// -// Author: Ichigaku Takigawa -// a2ps --no-header --landscape --columns=1 --font-size=3.6 -// output.log -o test.ps -//======================================================================= - -#include -#include -#include -#include -#include - -// Disable warnings in boost header code. -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-local-typedefs" -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunused-local-typedef" -#pragma clang diagnostic ignored "-Wdeprecated-declarations" -#endif - -// boost 1.33.1 required -#include -#include -#include -#include - -#pragma GCC diagnostic pop - -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - -#define R_NO_REMAP - -#include "init.h" -#include "hme3m.h" -using namespace boost; - -// ****** base graph ****** // - -typedef adjacency_list< - vecS, // for out-edges - vecS, // for vertices - bidirectionalS, // bidirectional graph - // vertex properties - property, - // edge properties - property - > - > Graph; - -// ****** type definitions ****** // - -typedef graph_traits::vertices_size_type SizeType; -typedef graph_traits::vertex_descriptor Vertex; -typedef graph_traits::edge_descriptor Edge; -typedef pair VertexPair; -typedef graph_traits::vertex_iterator VertexIter; -typedef graph_traits::edge_iterator EdgeIter; -typedef graph_traits::in_edge_iterator InEdgeIter; -typedef graph_traits::adjacency_iterator AdjacencyIter; - -typedef property_map::type VertexNameMap; -typedef property_map::type EdgeNameMap; -typedef property_map::type EdgeWeightMap; -typedef property_map::type VertexIndexMap; - -typedef double WeightType; -typedef unsigned LengthType; - -Graph& get_graph(pair& _data){ - return _data.first; -} - -Vertex& get_start_vertex(pair& _data){ - return _data.second.first; -} - -Vertex& get_end_vertex(pair& _data){ - return _data.second.second; -} - -ifstream& operator>>(ifstream& ifs, VertexPair& vpair){ - ifs >> vpair.first >> vpair.second; - return ifs; -} - -template -bool equal_first_i_nodes(const IndexedSequence& seq1, - const IndexedSequence& seq2, - const int i) { - // seq1[0]...seq1[i] and seq2[0]...seq2[i] equal? - for(int j=0; j<=i; ++j){ - if(seq1[j] != seq2[j]){ return false; } - } - return true; -} - -struct st_path_with_deviation { - deque sequence; - WeightType score; - Vertex deviation; -}; - -inline bool compare(const struct st_path_with_deviation& x, - const struct st_path_with_deviation& y){ - return x.score < y.score; -} - -//option -extern char *optarg; -extern int optind, opterr; - -// ****** dijkstra algorithm ****** // -template -void dijkstra_algorithm(Graph& g, const Vertex& s, - PredecessorMap predecessor, - DistanceMap distance, - Compare compare){ - Vertex u, v; - SizeType n = num_vertices(g); - EdgeWeightMap weight = get(edge_weight, g); - - typedef indirect_cmp IndirectCmp; - IndirectCmp icmp(distance, compare); - - relaxed_heap minheap(n,icmp); - - VertexIter vitr,vend; - for(tie(vitr,vend)=vertices(g); vitr != vend; ++vitr) { - minheap.push(*vitr); - } - - WeightType rhs; - AdjacencyIter aitr, aend; - - while(not minheap.empty()){ - // extract-min - u = minheap.top(); - minheap.pop(); - - for(tie(aitr,aend)=adjacent_vertices(u,g); aitr != aend; ++aitr){ - v = *aitr; - - rhs = distance[u] + weight[edge(u,v,g).first]; - - // edge relaxation - if(distance[v] > rhs){ - distance[v] = rhs; - minheap.update(v); - predecessor[v] = u; - } - } - } -} - -struct st_path_with_deviation -st_shortest_path(const Vertex s, const Vertex t, Graph& g){ - SizeType n_vertices = num_vertices(g); - vector predecessor(n_vertices); - vector distance(n_vertices, numeric_limits::max()); - vector pathlength(n_vertices, numeric_limits::max()); - - distance[s] = 0; - dijkstra_algorithm(g, s, &predecessor[0], &distance[0], std::less()); - - struct st_path_with_deviation p; - if(distance[t] != numeric_limits::max()){ - for(Vertex v = t; v != s; v = predecessor[v]){ - p.sequence.push_front(v); - } - p.sequence.push_front(s); - } - - p.score = distance[t]; - p.deviation = 0; - - return p; -} - -#undef R_NO_REMAP - -pair R_get_st_graph_from(SEXP nodes, SEXP edges,SEXP edge_weights); - -SEXP store_path_R(deque st_path, Graph& g, double p_score); - -SEXP pathranker(SEXP node_list, SEXP edge_list, SEXP edge_weights, SEXP rk,SEXP minpathsize) -{ - Vertex s,t; - Graph g; - unsigned K =(unsigned)(REAL(rk)[0]); - unsigned mps = (int)(REAL(minpathsize)[0]); - SEXP new_path,all_paths; - - Rf_protect(all_paths = Rf_allocVector(VECSXP,K)); - - pair data = R_get_st_graph_from(node_list, edge_list, edge_weights); - - g = get_graph(data); - s = get_start_vertex(data); - t = get_end_vertex(data); - - if(s == numeric_limits::max() or t == numeric_limits::max()){ - Rprintf("No vertex start or end vertices found."); - return R_NilValue; - } - - // ======= Yen-Lawler algorithm ================================== - // [1] Jin Y. Yen, - // Finding the k shortest loopless paths in a network, - // Management science, Vol.17, No. 11, July, 1971. 712-716 - // [2] E. L. Lawler, - // A procedure for computing the k best solutions to discrete - // optimization problems and its application - // to the shortest path problem, - // Management science, vol. 18, no. 7, 1972. 401-405 - // =============================================================== - - deque result, candidates; - - Graph g_copy; - deque prefix; - - WeightType accumulated_score; - EdgeWeightMap edge_weight_map = get(edge_weight, g); - - struct st_path_with_deviation p, q; - - candidates.push_back(st_shortest_path(s, t, g)); - - unsigned k = 0; - unsigned rsize = 0; - while (rsize < K) { - // check if paths exist - if(candidates.empty()){ - //cout << "No more paths." << endl; - break; - } - - // output k-th shortest loopless path - sort(candidates.begin(), candidates.end(), compare); - if(candidates.size() > K-rsize+1){ - candidates.resize(K-rsize+1); - } - - p = candidates.front(); - candidates.pop_front(); - result.push_back(p); - - if(p.score==numeric_limits::max()){ - //cout << "No more paths." << endl; - break; - } - - /* disabled *****/ - // I want to make sure the path involves more than 1 gene - // so the path distance must be greater than 2 times the s-> gene and gene->t - // edges have the same weight. - //Edge e_temp = edge(p.sequence[0],p.sequence[1],g).first; - //double fw = get(edge_weight, g)[e_temp]; - - if (p.sequence.size() > mps) { - new_path = store_path_R(p.sequence,g,p.score); - SET_VECTOR_ELT(all_paths,rsize,new_path); - rsize = rsize + 1; - } - k = k + 1; - - prefix.clear(); - accumulated_score = 0; - - for(unsigned i=0; i < p.sequence.size()-1; ++i){ - if(i >= p.deviation){ - // copy of the graph for editing - g_copy = g; - - // edge deletion - for(unsigned j=0; j < result.size(); ++j){ - if(equal_first_i_nodes(result[j].sequence, p.sequence ,i)){ - remove_edge(result[j].sequence[i], result[j].sequence[i+1], g_copy); - } - } - // vertex deletion - for(unsigned j=0; j < i; ++j){ - clear_vertex(p.sequence[j], g_copy); - } - - // compute shortest path - q = st_shortest_path(p.sequence[i], t, g_copy); - - // concatenate the prefix to the current path - if(q.score!=numeric_limits::max()){ - if(not q.sequence.empty()){ - q.sequence.insert(q.sequence.begin(), prefix.begin(), prefix.end()); - q.score += accumulated_score; - } - q.deviation = i; - candidates.push_back(q); - } - } - - prefix.push_back(p.sequence[i]); - accumulated_score += edge_weight_map[edge(p.sequence[i], p.sequence[i+1],g).first]; - } - } - - Rf_unprotect(1); - return all_paths; -} - -pair R_get_st_graph_from(SEXP nodes, SEXP edges,SEXP edge_weights) { - - Vertex s,t; - s = numeric_limits::max(); - t = numeric_limits::max(); - // read the vertex file - int counter=0; - string line; - vector name; // names of vertices - SEXP from_idxs,to_idxs,labels; - - for (int i = 0;i < LENGTH(nodes);i = i + 1) { - line = CHAR(STRING_ELT(nodes,i)); - name.push_back(line); - if(line=="s"){ - s = counter; - }else if(line=="t"){ - t = counter; - } - counter++; - } - - SizeType n_vertices = name.size(); // # of vertices - - // create a graph object - Graph g(n_vertices); - - // resister vertex names - VertexIter v_iter, v_end; - VertexNameMap vertex_name_map = get(vertex_name, g); - - for ( tie(v_iter,v_end)=vertices(g); v_iter != v_end; ++v_iter ){ - vertex_name_map[*v_iter] = name[*v_iter]; - } - - // read the edgelist file - VertexPair v_pair; - Edge e_temp; - //WeightType d_value; - string edge_label; - - EdgeNameMap edge_name_map = get(edge_name, g); - - // define R types - from_idxs = VECTOR_ELT(edges,0); - to_idxs = VECTOR_ELT(edges,1); - labels = VECTOR_ELT(edges,2); - - for (int i = 0;i < LENGTH(from_idxs);i = i + 1) { - v_pair.first = (int)(REAL(from_idxs)[i] - 1); - v_pair.second = (int)(REAL(to_idxs)[i] - 1); - - add_edge(v_pair.first, v_pair.second , REAL(edge_weights)[i] , g); - e_temp = edge(v_pair.first, v_pair.second , g).first; - edge_name_map[e_temp] = CHAR(STRING_ELT(labels,i)); - } - - pair ret; - ret.first = g; - ret.second.first = s; - ret.second.second = t; - - return ret; -} - -SEXP store_path_R(deque st_path, Graph& g, double p_score) { - SEXP new_path,dimnames; - SEXP genes,compounds,weights,distance; - - st_path.pop_back(); st_path.pop_front(); //delete "s" & "t" nodes - - - if(st_path.empty()){ - return R_NilValue; - } - VertexNameMap vertex_name_map = get(vertex_name, g); - EdgeNameMap edge_name_map = get(edge_name, g); - EdgeWeightMap edge_weight_map = get(edge_weight, g); - Edge e_temp; - - Rf_protect(genes = Rf_allocVector(STRSXP,st_path.size())); - Rf_protect(compounds = Rf_allocVector(STRSXP,st_path.size() - 1)); - Rf_protect(weights = Rf_allocVector(REALSXP,st_path.size()-1)); - Rf_protect(distance = Rf_allocVector(REALSXP,1)); - REAL(distance)[0] = p_score; - - SET_STRING_ELT(genes,0,Rf_mkChar(vertex_name_map[st_path[0]].c_str())); - for (unsigned i = 0; i < st_path.size()-1; ++i) { - e_temp = edge(st_path[i],st_path[i+1],g).first; - - SET_STRING_ELT(compounds,i,Rf_mkChar(edge_name_map[e_temp].c_str())); - SET_STRING_ELT(genes,i+1,Rf_mkChar(vertex_name_map[st_path[i+1]].c_str())); - REAL(weights)[i] = edge_weight_map[e_temp]; - } - - Rf_protect(new_path = Rf_allocVector(VECSXP, 4)); - Rf_protect(dimnames = Rf_allocVector(VECSXP,4)); - - SET_VECTOR_ELT(new_path,0,genes); - SET_VECTOR_ELT(dimnames,0,Rf_mkString("genes")); - - SET_VECTOR_ELT(new_path,1,compounds); - SET_VECTOR_ELT(dimnames,1,Rf_mkString("compounds")); - - SET_VECTOR_ELT(new_path,2,weights); - SET_VECTOR_ELT(dimnames,2,Rf_mkString("weights")); - - SET_VECTOR_ELT(new_path,3,distance); - SET_VECTOR_ELT(dimnames,3,Rf_mkString("distance")); - - Rf_setAttrib(new_path,R_NamesSymbol,dimnames); - - Rf_unprotect(6); - - return new_path; -} diff --git a/src/boost.tar.gz b/src/boost.tar.gz deleted file mode 100755 index a364d9f..0000000 Binary files a/src/boost.tar.gz and /dev/null differ diff --git a/src/init.c b/src/init.c index 608d34b..bd82038 100755 --- a/src/init.c +++ b/src/init.c @@ -14,9 +14,6 @@ static const R_CallMethodDef callMethods[] = { #endif ENTRY(expand_complexes, 5), - ENTRY(pathranker, 5), - ENTRY(scope, 6), - ENTRY(samplepaths, 6), {NULL, NULL, 0} }; diff --git a/src/pathScope.cpp b/src/pathScope.cpp deleted file mode 100755 index 0d78869..0000000 --- a/src/pathScope.cpp +++ /dev/null @@ -1,872 +0,0 @@ - //======================================================================= -// Path Ranker -// -// Author: Ichigaku Takigawa -// a2ps --no-header --landscape --columns=1 --font-size=3.6 -// output.log -o test.ps -//======================================================================= - -#include -#include -#include -#include - -//#define MATHLIB_STANDALONE -#include -#include - -//init -#include "init.h" - -// Disable warnings in boost header code. -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-local-typedefs" -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunused-local-typedef" -#pragma clang diagnostic ignored "-Wdeprecated-declarations" -#endif - - -// boost 1.33.1 required -#include -#include -#include -#include - -#pragma GCC diagnostic pop - -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - - -#define R_NO_REMAP - -using namespace boost; - -// ****** base graph ****** // - -typedef adjacency_list< - vecS, // for out-edges - vecS, // for vertices - bidirectionalS, // bidirectional graph - // vertex properties - property //property added by Nicolas Wicker - >, - // edge properties - property - > - > Graph; - -// ****** type definitions ****** // - -typedef graph_traits::vertices_size_type SizeType; -typedef graph_traits::vertex_descriptor Vertex; -typedef graph_traits::edge_descriptor Edge; -typedef pair VertexPair; -typedef graph_traits::vertex_iterator VertexIter; -typedef graph_traits::edge_iterator EdgeIter; -typedef graph_traits::in_edge_iterator InEdgeIter; -typedef graph_traits::adjacency_iterator AdjacencyIter; - -typedef property_map::type VertexNameMap; -typedef property_map::type EdgeNameMap; -typedef property_map::type EdgeWeightMap; -typedef property_map::type VertexIndexMap; - -typedef double WeightType; -typedef unsigned LengthType; - -// ****** dijkstra algorithm ****** // - -template -void dijkstra_algorithm(Graph& g, const Vertex& s, - PredecessorMap predecessor, - DistanceMap distance, - Compare compare){ - Vertex u, v; - SizeType n = num_vertices(g); - EdgeWeightMap weight = get(edge_weight, g); - - typedef indirect_cmp IndirectCmp; - IndirectCmp icmp(distance, compare); - - relaxed_heap minheap(n,icmp); - - VertexIter vitr,vend; - for(tie(vitr,vend)=vertices(g); vitr != vend; ++vitr){ - minheap.push(*vitr); - } - - WeightType rhs; - AdjacencyIter aitr, aend; - - while(not minheap.empty()){ - // extract-min - u = minheap.top(); - minheap.pop(); - for(tie(aitr,aend)=adjacent_vertices(u,g); aitr != aend; ++aitr){ - v = *aitr; - rhs = distance[u] + weight[edge(u,v,g).first]; - // edge relaxation - if(distance[v] > rhs){ - distance[v] = rhs; - minheap.update(v); - predecessor[v] = u; - } - } - } -} - -namespace std { - template - istream& operator >> (istream& in, pair& p) - { - in >> p.first >> p.second; - return in; - } -} - -Graph& get_graph(pair& _data){ - return _data.first; -} - -Vertex& get_start_vertex(pair& _data){ - return _data.second.first; -} - -Vertex& get_end_vertex(pair& _data){ - return _data.second.second; -} - -struct st_path_with_deviation { - deque sequence; - WeightType score; - Vertex deviation; -}; - -inline bool compare(const struct st_path_with_deviation& x, - const struct st_path_with_deviation& y){ - return x.score < y.score; -} - -struct st_path_with_deviation -st_shortest_path(const Vertex s, const Vertex t, Graph& g){ - SizeType n_vertices = num_vertices(g); - vector predecessor(n_vertices); - vector distance(n_vertices, numeric_limits::max()); - vector pathlength(n_vertices, numeric_limits::max()); - - distance[s] = 0; - dijkstra_algorithm(g, s, &predecessor[0], &distance[0], std::less()); - - struct st_path_with_deviation p; - if(distance[t] != numeric_limits::max()){ - for(Vertex v = t; v != s; v = predecessor[v]){ - p.sequence.push_front(v); - } - p.sequence.push_front(s); - } - - p.score = distance[t]; - p.deviation = 0; - - return p; -} - -pair SCOPE_R_get_st_graph_from(SEXP nodes, SEXP edges,SEXP edge_weights,int *nt); - -/*********************************************************************************/ -/* */ -/* Nicolas Wicker addition */ -/* */ -/*********************************************************************************/ - -/************************************************************************/ -/* */ -/*Procedure compute empirical score distribution for a given path length*/ -/*by random sampling, the sampling is done by Metropolis algorithm */ -/* */ -/************************************************************************/ - -void computeRandomScores(int maximumPathLength,const Vertex s,Graph &g,int nbSamples, - int nbWarmingSteps,double **randomScores) -{ - //int currentIndex,currentLength,precedingVertexIndex,deadEnd,pvalue=0; - int i,j,k,length,noLoop,vindex; - int iterator,randomValue,nbValidNeighbours; - EdgeWeightMap weight = get(edge_weight, g); - AdjacencyIter aitr, aend; - Vertex currentVertex; - VertexIndexMap vertexIndexMap=get(vertex_index, g); - int *indices,validVertexFound,validPath; - int nbVertices; - - int warmingTime; - double logCurrentPathProbability,logProposalPathProbability; - double currentScore,proposalScore; - - indices=new int[maximumPathLength+1]; - /*vertices array to obtain a vertex from an index*/ - nbVertices = num_vertices(g); - Vertex *verticesArray=new Vertex[nbVertices]; - VertexIter vitr,vend; - for(tie(vitr,vend)=vertices(g); vitr != vend; ++vitr) { - verticesArray[vertexIndexMap[*vitr]]=*vitr; - } - - for(length=1;length<=maximumPathLength;length++) { - int nbChanges=0; - currentScore=0; - logCurrentPathProbability=DBL_MAX; - int nbFailures=0; - int currentSampleSize=0; - for(iterator=1;iterator<=nbWarmingSteps*nbSamples;iterator++) { - if((iterator%nbWarmingSteps)==0) { - warmingTime=0; - } else { - warmingTime=1; - } - validPath=0; - while(validPath==0) { - /*here the paths building procedure starts*/ - logProposalPathProbability=0.0; - validPath=1; - proposalScore=0.0; - currentVertex=verticesArray[(int)floor(runif(0,nbVertices))]; - indices[0]=vertexIndexMap[currentVertex]; - for(i=0;i=0;k--) { - if(vindex==indices[k]) { - noLoop=0; - break; - } - } - if(noLoop==1) { - nbValidNeighbours++; - } - } - if(nbValidNeighbours>0) { - logProposalPathProbability-=log((double)nbValidNeighbours); - validVertexFound=0; - while(validVertexFound==0) { - randomValue=(int)floor(runif(0,out_degree(currentVertex,g))); - j=0; - for(tie(aitr,aend)=adjacent_vertices(currentVertex,g); aitr != aend; ++aitr) { - if(j==randomValue) { - proposalScore+=(double)weight[edge(currentVertex,*aitr,g).first]; - /*must verify first if there is no loop*/ - noLoop=1; - vindex=vertexIndexMap[*aitr]; - for(k=i;k>=0;k--) { - if(vindex==indices[k]) { - noLoop=0; - break; - } - } - if(noLoop==1) { - currentVertex=*aitr; - indices[i+1]=vindex; - validVertexFound=1; - } - break; - } - j++; - } - } - } else { - /*the random path has path reached a dead-end*/ - validPath=0; - nbFailures++; - break; - } - } - } - /*end of the path building*/ - if(nbFailures=score) { - return 0; - } - while(true) { - c=(a+b)/2; - if(randomScores[length][c]>=score) { - b=c; - } else { - a=c; - } - if(b==(a+1)) { - break; - } - } - return a/(double)nbSamples; -} - -/***************************************************************************/ -/* */ -/*Procedure to compute pvalues by weights random sampling (does not work !)*/ -/* */ -/***************************************************************************/ - -double computePvalue2(double score,int length,int nbEdges,double *weights) { - - int i; - int iterator,nbIterations,randomValue; - - nbIterations=100000; - int pvalue=0; - double randomScore; - for(iterator=0;iterator-0.5) { - - for(tie(aitr,aend)=adjacent_vertices(u,g); aitr != aend; ++aitr) { - v = *aitr; - vindex=vertexIndexMap[v]; - rhs = scoresMatrix[uindex][length]+(double)weight_map[edge(u,v,g).first]; - - /*must verify first if there is no loop*/ - noLoop=1; - currentIndex=uindex; - currentLength=length; - - while(currentIndex!=sindex) { - - precedingVertexIndex=pathsMatrix[currentIndex][currentLength]; - - if(precedingVertexIndex==vindex) { - noLoop=0; - break; - } else { - currentIndex=precedingVertexIndex; - currentLength--; - } - } - - if ((noLoop==1)&&((scoresMatrix[vindex][length+1] > rhs) || (scoresMatrix[vindex][length+1]<-0.5))) - { - scoresMatrix[vindex][length+1] = rhs; - pathsMatrix[vindex][length+1] = uindex; - - } - } - } - } - } - - /*generate pvalues*/ - double *pvalues; - EdgeIter eitr,eend; - double *weights; - SizeType nbEdges; - - nbEdges=num_edges(g); - weights=new double[nbEdges]; - - i=0; - for(tie(eitr,eend)=edges(g); eitr != eend; ++eitr) { - weights[i]=weight_map[*eitr]; - i++; - } - - pvalues=new double[n]; - /*i below is the number of edges, so that the path length is equal to i+1*/ - /*the first edge is sorted in pathsMatrix[vindex][1] */ - deque path; - deque pathWeights; - Edge e_temp; - - SEXP genes = R_NilValue,compounds = R_NilValue,pweights = R_NilValue,distance = R_NilValue,pp = R_NilValue; - - int allocated = 0; - - for(length=0;length0) { - pvalues[length]=computePvalue(scoresMatrix[tindex][length],length,nbSamples,randomScores); - //cout << "scores: "<< scoresMatrix[tindex][length]<< ",pval: " << pvalues[length] <0.1) { - break; - } - } - } - - /*memory desallocation*/ - for(i=0;i data = SCOPE_R_get_st_graph_from(node_list, edge_list, edge_weights,&nt); - - - g = get_graph(data); - s = get_start_vertex(data); - t = get_end_vertex(data); - - // if sampled paths were not provided, use random edge sampling. - if(SAMPLEDPATHS!=R_NilValue){ - double *rs = REAL(SAMPLEDPATHS); - randomScores= new double *[maxSamplePathLength]; - for (i = 0;i < maxSamplePathLength;i = i + 1) randomScores[i] = &rs[i*numberPathSamples]; - }else{ - maxSamplePathLength = num_vertices(g); - numberPathSamples = 10000; - randomScores= new double *[maxSamplePathLength]; - computeRandomScoresRandomSampling(maxSamplePathLength, num_edges(g), numberPathSamples,REAL(edge_weights), randomScores); - } - - if(s == numeric_limits::max() or t == numeric_limits::max()){ - Rprintf("No vertex start or end vertices found."); - return R_NilValue; - } - - start=0; - end=num_vertices(g); - - VertexNameMap vertex_name_map = get(vertex_name, g); - VertexIter vitr,vend; - AdjacencyIter aitr, aend; - - //struct st_path_with_deviation p, q; - SEXP newpath,allpaths; - Rf_protect(allpaths = Rf_allocVector(VECSXP,nt)); - vector reachedTargets; - vector::iterator it; - - counter=0; - if (echo == 1) Rprintf("There are %d nodes in the neighborhood", nt); - int vectid = 0; - for(tie(vitr,vend)=vertices(g); vitr != vend; ++vitr) { - for(tie(aitr,aend)=adjacent_vertices(*vitr,g); aitr != aend; ++aitr) { - if(*aitr==t) { - string target(vertex_name_map[*vitr]); - string last_compound = target; - - if (echo == 1) Rprintf("TARGET : %s %d/ %d", last_compound.c_str() ,vectid+1 ,nt); - int alreadyreached = 0; - for (it=reachedTargets.begin();it < reachedTargets.end();it++) { - if (last_compound.compare(*it) == 0) { - alreadyreached = 1; - if (echo == 1) Rprintf(" - Already found a path to %s\n", last_compound.c_str()); - } - } - if (alreadyreached == 0) { - if((start<=counter)&&(counter SCOPE_R_get_st_graph_from(SEXP nodes, SEXP edges,SEXP edge_weights,int *nt) { - - Vertex s,t; - s = numeric_limits::max(); - t = numeric_limits::max(); - // read the vertex file - int counter=0; - string line; - vector name; // names of vertices - SEXP from_idxs,to_idxs,labels; - - for (int i = 0;i < LENGTH(nodes);i = i + 1) { - line = CHAR(STRING_ELT(nodes,i)); - name.push_back(line); - if(line=="s"){ - s = counter; - }else if(line=="t"){ - t = counter; - } - counter++; - } - - SizeType n_vertices = name.size(); // # of vertices - - // create a graph object - Graph g(n_vertices); - - // resister vertex names - VertexIter v_iter, v_end; - VertexNameMap vertex_name_map = get(vertex_name, g); - - for ( tie(v_iter,v_end)=vertices(g); v_iter != v_end; ++v_iter ){ - vertex_name_map[*v_iter] = name[*v_iter]; - } - - // read the edgelist file - VertexPair v_pair; - Edge e_temp; - string edge_label; - - EdgeNameMap edge_name_map = get(edge_name, g); - - // define R types - from_idxs = VECTOR_ELT(edges,0); - to_idxs = VECTOR_ELT(edges,1); - labels = VECTOR_ELT(edges,2); - - *nt = 0; - for (int i = 0;i < LENGTH(from_idxs);i = i + 1) { - v_pair.first = (int)(REAL(from_idxs)[i] - 1); - v_pair.second = (int)(REAL(to_idxs)[i] - 1); - if ((int)(REAL(to_idxs)[i] - 1) == (int)t) *nt = *nt + 1; - - add_edge(v_pair.first, v_pair.second , REAL(edge_weights)[i] , g); - e_temp = edge(v_pair.first, v_pair.second , g).first; - edge_name_map[e_temp] = CHAR(STRING_ELT(labels,i)); - } - - pair ret; - ret.first = g; - ret.second.first = s; - ret.second.second = t; - - return ret; -} - -extern "C" SEXP samplepaths(SEXP node_list, - SEXP edge_list, - SEXP edge_weights, - SEXP MAXPATHLENGTH, - SEXP SAMPLEPATHS, - SEXP WARMUPSTEPS) -{ - Vertex s; - Graph g; - - int maximumPathLength=INTEGER(MAXPATHLENGTH)[0]; - int nbSamples=INTEGER(SAMPLEPATHS)[0]; - int nbWarmingSteps=INTEGER(WARMUPSTEPS)[0]; - int i,j; - - SEXP SCORES; - Rf_protect(SCORES = Rf_allocVector(REALSXP,nbSamples*(maximumPathLength+1))); - double *rs = REAL(SCORES); - - double **randomScores= new double *[(maximumPathLength+1)]; - for (i = 0;i < (maximumPathLength+1);i = i + 1) randomScores[i] = &rs[i*(nbSamples)]; - - int nt = 0; - pair data = SCOPE_R_get_st_graph_from(node_list, edge_list, edge_weights,&nt); - - g = get_graph(data); - s = get_start_vertex(data); - - /*compute random scores for length ranging from 1 to maximumPathLength*/ - GetRNGstate(); - computeRandomScores(maximumPathLength,s,g,nbSamples,nbWarmingSteps,randomScores); - PutRNGstate(); - std::vector orderedScores; - for(i=1;i<=maximumPathLength;i++) { - orderedScores.clear(); - for(j=0;j