Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
Fix a bug in netVisual_hierarchy1
Browse files Browse the repository at this point in the history
  • Loading branch information
sqjin authored Apr 2, 2021
1 parent 0c9f2a3 commit 3567804
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions R/visualization.R
Original file line number Diff line number Diff line change
Expand Up @@ -714,24 +714,24 @@ netVisual_hierarchy1 <- function(net, vertex.receiver, color.use = NULL, title.n
options(warn = -1)
thresh <- stats::quantile(net, probs = 1-top)
net[net < thresh] <- 0
cells.level <- rownames(net)

if ((!is.null(sources.use)) | (!is.null(targets.use))) {
df.net <- reshape2::melt(net, value.name = "value")
colnames(df.net)[1:2] <- c("source","target")
# keep the interactions associated with sources and targets of interest
if (!is.null(sources.use)){
if (is.numeric(sources.use)) {
sources.use <- levels(object@idents)[sources.use]
sources.use <- cells.level[sources.use]
}
df.net <- subset(df.net, source %in% sources.use)
}
if (!is.null(targets.use)){
if (is.numeric(targets.use)) {
targets.use <- levels(object@idents)[targets.use]
targets.use <- cells.level[targets.use]
}
df.net <- subset(df.net, target %in% targets.use)
}
cells.level <- levels(object@idents)
df.net$source <- factor(df.net$source, levels = cells.level)
df.net$target <- factor(df.net$target, levels = cells.level)
df.net$value[is.na(df.net$value)] <- 0
Expand Down Expand Up @@ -897,24 +897,24 @@ netVisual_hierarchy2 <-function(net, vertex.receiver, color.use = NULL, title.na
options(warn = -1)
thresh <- stats::quantile(net, probs = 1-top)
net[net < thresh] <- 0
cells.level <- rownames(net)

if ((!is.null(sources.use)) | (!is.null(targets.use))) {
df.net <- reshape2::melt(net, value.name = "value")
colnames(df.net)[1:2] <- c("source","target")
# keep the interactions associated with sources and targets of interest
if (!is.null(sources.use)){
if (is.numeric(sources.use)) {
sources.use <- levels(object@idents)[sources.use]
sources.use <- cells.level[sources.use]
}
df.net <- subset(df.net, source %in% sources.use)
}
if (!is.null(targets.use)){
if (is.numeric(targets.use)) {
targets.use <- levels(object@idents)[targets.use]
targets.use <- cells.level[targets.use]
}
df.net <- subset(df.net, target %in% targets.use)
}
cells.level <- levels(object@idents)
df.net$source <- factor(df.net$source, levels = cells.level)
df.net$target <- factor(df.net$target, levels = cells.level)
df.net$value[is.na(df.net$value)] <- 0
Expand Down

0 comments on commit 3567804

Please sign in to comment.