Skip to content

Commit

Permalink
add error checking for SNN plotting
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewwbutler committed Sep 20, 2016
1 parent df737cc commit e486c54
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions R/snn.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ setMethod("BuildSNN", signature = "seurat",
n.cells <- nrow(data.use)
if(n.cells < k.param) {
warning("k.param set larger than number of cells. Setting k.param to number of cells - 1.")
k.param = n.cells - 1
k.param <- n.cells - 1
}

#find the k-nearest neighbors for each single cell
Expand All @@ -64,11 +64,16 @@ setMethod("BuildSNN", signature = "seurat",
print.output)
}
if (plot.SNN) {
net <- graph.adjacency(w, mode = "undirected", weighted = TRUE,
diag = FALSE)
plot.igraph(net, layout = as.matrix(object@tsne.rot),
edge.width = E(net)$weight, vertex.label = NA,
vertex.size = 0)
if(length(object@tsne.rot) < 1) {
warning("Please compute a tSNE for SNN visualization. See RunTSNE().")
}
else{
net <- graph.adjacency(w, mode = "undirected", weighted = TRUE,
diag = FALSE)
plot.igraph(net, layout = as.matrix(object@tsne.rot),
edge.width = E(net)$weight, vertex.label = NA,
vertex.size = 0)
}
}

#only allow one of the snn matrix slots to be filled
Expand Down

0 comments on commit e486c54

Please sign in to comment.