Browse files

add function adj.get.hops

  • Loading branch information...
1 parent eaaa453 commit e8057e4e4e6f0daf4e23c577a5f343184e646dfd @bhaibeka bhaibeka committed Feb 1, 2012
Showing with 56 additions and 0 deletions.
  1. +9 −0 R/adj.get.hops.R
  2. +47 −0 man/adj.get.hops.Rd
View
9 R/adj.get.hops.R
@@ -0,0 +1,9 @@
+## function to compute the shortest path
+'adj.get.hops' <-
+function(adjmat) {
+ #require(RBGL)
+ hops <- RBGL::floyd.warshall.all.pairs.sp(as(adjmat,"graphNEL"))
+ #dimnames(hops) <- dimnames(adjmat)
+ hops[abs(hops) == Inf] <- NA
+ return(hops)
+}
View
47 man/adj.get.hops.Rd
@@ -0,0 +1,47 @@
+\name{adj.get.hops}
+\alias{adj.get.hops}
+%- Also NEED an '\alias' for EACH other topic documented here.
+\title{
+Function to identify all children of a parent
+}
+\description{
+This function uses a depth-first search algorithm to identify all the children (and their corresponding depth) of a node.
+}
+\usage{
+adj.get.hops(adjmat)
+}
+%- maybe also 'usage' for other objects documented here.
+\arguments{
+ \item{adjmat}{ adjacency matrix; parents in rows, children in columns }
+}
+\details{
+The algorithm is based on the depth-first search.
+}
+\value{
+two-column matrix containing the names of the children in the first column and their corresponding depth in the descent in the second column
+}
+%%\references{
+%% ~put references to the literature/web site here ~
+%%}
+\author{
+Benjamin Haibe-Kains
+}
+%%\note{
+%% ~~further notes~~
+%%}
+
+%% ~Make other sections like Warning with \section{Warning }{....} ~
+
+%%\seealso{
+%% ~~objects to See Also as \code{\link{help}}, ~~~
+%%}
+\examples{
+## check whether a list of two nodes are children of another node
+set.seed(54321)
+mytopo <- matrix(sample(0:1, 100, replace=TRUE, prob=c(0.7,0.3)), nrow=10, dimnames=list(LETTERS[1:10], LETTERS[1:10]))
+adj.get.hops(adjmat=mytopo)
+}
+% Add one or more standard keywords, see file 'KEYWORDS' in the
+% R documentation directory.
+%%\keyword{ ~kwd1 }
+%%\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line

0 comments on commit e8057e4

Please sign in to comment.