Skip to content

Commit

Permalink
igraph dfs may signal unreachable nodes with 0
Browse files Browse the repository at this point in the history
* this still seems to be up in the air but at least some preparatory branches
 for igraph 2.0 use a 0 rather than NaN to signal unreachable nodes
* see #517
  • Loading branch information
jefferis committed Jan 16, 2024
1 parent c608307 commit 9481c98
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions R/neuron.R
Original file line number Diff line number Diff line change
Expand Up @@ -1411,15 +1411,16 @@ distal_to <- function(x, node.idx=NULL, node.pointno=NULL, root.idx=NULL,
g=as.directed.usingroot(gorig, root = root.idx)
}

#Step3: For each node id, travese the graph from the given node using depth first search and return the visited
#Step3: For each node id, traverse the graph from the given node using depth first search and return the visited
#nodes..
l=sapply(node.idx, dfs_traversal, g, simplify = FALSE)
if(length(node.idx)==1) l[[1]] else l
}

dfs_traversal <- function(x, g) {
gdfs=igraph::dfs(g, root = x, unreachable = FALSE)
as.integer(gdfs$order)[!is.na(gdfs$order)]
# nb igraph 2.0 may change signalling for unreached nodes
as.integer(gdfs$order)[!(is.na(gdfs$order) | gdfs$order<1)]
}


Expand Down
6 changes: 4 additions & 2 deletions R/ngraph.R
Original file line number Diff line number Diff line change
Expand Up @@ -533,12 +533,14 @@ prune_strahler<-function(x, orderstoprune=1:2, ...) {
prune_vertices<-function(x, verticestoprune, invert=FALSE, ...) {
g=as.ngraph(x)

# because igraph.vs sequences are atttached to a specific graph
# because igraph.vs sequences are attached to a specific graph
if(inherits(verticestoprune, "igraph.vs"))
verticestoprune=as.integer(verticestoprune)
if(invert) {
nvertices=nrow(xyzmatrix(x))
nvertices=igraph::vcount(g)
verticestoprune=setdiff(seq_len(nvertices), verticestoprune)
} else {
verticestoprune=setdiff(verticestoprune, 0)
}
dg=igraph::delete.vertices(g, verticestoprune)
# delete.vertices will return an igraph
Expand Down

0 comments on commit 9481c98

Please sign in to comment.