Skip to content

Commit 6f17247

Browse files
committed
bump and fix interfaces to decode_communities
1 parent 797988c commit 6f17247

File tree

2 files changed

+58
-26
lines changed

2 files changed

+58
-26
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: ClustIRR
22
Type: Package
33
Title: Clustering of immune receptor repertoires
4-
Version: 1.5.47
4+
Version: 1.5.48
55
Authors@R: c(
66
person("Simo", "Kitanovski", email = "simokitanovski@gmail.com",
77
role = c("aut", "cre"), comment=c(ORCID="0000-0003-2909-5376")),

R/community.R

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,13 @@ decode_communities <- function(community_id,
366366
edge_filter,
367367
node_filter) {
368368

369+
if(missing(edge_filter)) {
370+
edge_filter <- NULL
371+
}
372+
if(missing(node_filter)) {
373+
node_filter <- NULL
374+
}
375+
369376
apply_op <- function(vec, op, val) {
370377
ops <- list("==" = `==`,
371378
"!=" = `!=`,
@@ -392,7 +399,7 @@ decode_communities <- function(community_id,
392399
}
393400

394401
# consider edges
395-
if(nrow(edge_filter)!=0) {
402+
if(is.null(edge_filter)==FALSE) {
396403
# this is where the edge filter results will be kept
397404
etm <- matrix(data = 0,
398405
nrow = nrow(edge_filter),
@@ -416,29 +423,54 @@ decode_communities <- function(community_id,
416423
}
417424

418425
# now partition based on node-attributes
419-
vs <- as_data_frame(x = graph, what = "vertices")
420-
V(graph)$key <- apply(X = vs[, node_filter$name, drop=FALSE],
421-
MARGIN = 1, FUN = paste, collapse = '|')
422-
sgs <- lapply(
423-
X = unique(V(graph)$key), g = graph,
424-
FUN = function(x, g) {
425-
# get a subgraph with shared node attributes
426-
sg <- subgraph(graph = g, vids = which(V(g)$key == x))
427-
428-
# find connected components
429-
V(sg)$components <- components(graph = sg)$membership
430-
V(sg)$component_id <- paste0(V(sg)$key, '|',
431-
V(sg)$components)
432-
V(sg)$component_id <- as.numeric(as.factor(V(sg)$component_id))
433-
return(disjoint_union(lapply(
434-
X = unique(V(sg)$component_id), g = sg,
435-
FUN = function(x, g) {
436-
vids <- which(V(g)$component_id == x)
437-
return(subgraph(graph = g, vids = vids))
438-
})))
439-
})
440-
sgs <- disjoint_union(sgs)
441-
442-
return(sgs)
426+
if(is.null(node_filter)==FALSE) {
427+
vs <- as_data_frame(x = graph, what = "vertices")
428+
V(graph)$key <- apply(X = vs[, node_filter$name, drop=FALSE],
429+
MARGIN = 1, FUN = paste, collapse = '|')
430+
431+
sgs <- lapply(
432+
X = unique(V(graph)$key), g = graph,
433+
FUN = function(x, g) {
434+
# get a subgraph with shared node attributes
435+
sg <- subgraph(graph = g, vids = which(V(g)$key == x))
436+
437+
# find connected components
438+
V(sg)$components <- components(graph = sg)$membership
439+
V(sg)$component_id <- paste0(V(sg)$key, '|',
440+
V(sg)$components)
441+
V(sg)$component_id <- as.numeric(as.factor(V(sg)$component_id))
442+
return(disjoint_union(lapply(
443+
X = unique(V(sg)$component_id), g = sg,
444+
FUN = function(x, g) {
445+
vids <- which(V(g)$component_id == x)
446+
return(subgraph(graph = g, vids = vids))
447+
})))
448+
})
449+
sgs <- disjoint_union(sgs)
450+
return(sgs)
451+
}
452+
else {
453+
sgs <- lapply(
454+
X = unique(V(graph)$community), g = graph,
455+
FUN = function(x, g) {
456+
# get a subgraph with shared node attributes
457+
sg <- subgraph(graph = g, vids = which(V(g)$community == x))
458+
459+
# find connected components
460+
V(sg)$components <- components(graph = sg)$membership
461+
V(sg)$component_id <- paste0(V(sg)$key, '|',
462+
V(sg)$components)
463+
V(sg)$component_id <- as.numeric(as.factor(V(sg)$component_id))
464+
return(disjoint_union(lapply(
465+
X = unique(V(sg)$component_id), g = sg,
466+
FUN = function(x, g) {
467+
vids <- which(V(g)$component_id == x)
468+
return(subgraph(graph = g, vids = vids))
469+
})))
470+
})
471+
sgs <- disjoint_union(sgs)
472+
return(sgs)
473+
474+
}
443475
}
444476

0 commit comments

Comments
 (0)