Commit ca5e48c5 authored by Lars Velten's avatar Lars Velten
Browse files

some improvements

parent 36d2f34d
......@@ -85,7 +85,7 @@ RNAMagnetBase <- function(seurat, anchors=NULL,neighborhood.distance=NULL, neigh
out <- new("rnamagnet", celltype = seurat@ident, params = list("neighborhood.distance"=neighborhood.distance, "neighborhood.gradient" =neighborhood.gradient, ".k" = .k, ".x0" = .x0, ".minExpression" = .minExpression, ".cellularCompartment" = .cellularCompartment, ".manualAnnotation" = .manualAnnotation, ".symmetric" = .symmetric))
#compute cell-cell similarity
out@similarity <- as.matrix(1-cor(t(seurat@dr$pca@cell.embeddings[,1:15])))
similarity <- as.matrix(1-cor(t(seurat@dr$pca@cell.embeddings[,1:15])))
#prepare database
ligrec <- getLigandsReceptors(.version, .cellularCompartment, .manualAnnotation)
......@@ -148,7 +148,7 @@ RNAMagnetBase <- function(seurat, anchors=NULL,neighborhood.distance=NULL, neigh
out@specificity <- t(sapply(rownames(out@interaction), function(cell) {
x <- out@interaction[cell,]
beta <- x/sum(x)
if (!is.null(neighborhood.distance)) alpha <- apply(out@interaction * (1-kernel(out@similarity[cell,],neighborhood.gradient,x0=neighborhood.distance )),2,sum) else alpha <- apply(out@interaction,2,mean)
if (!is.null(neighborhood.distance)) alpha <- apply(out@interaction * (1-kernel(similarity[cell,],neighborhood.gradient,x0=neighborhood.distance )),2,sum) else alpha <- apply(out@interaction,2,mean)
alpha <- alpha / sum(alpha)
beta- alpha
}))
......
......@@ -5,9 +5,16 @@
#'@param threshold Threshold interaction strength for including an edge in the network.
#'@param colors A named vector of colors to be used for plotting; names correspond to levels of \code{rnamagnet@class}
#'@param useLabels Plot the population labels on the graph?
#'@param ... Parameters passed to \code{\link[igraph]{plot.igraph}}, e.g. a layout can be stored as described in the example code below
#'@examples
#'\dontrun{
#'network <- PlotSignalingNetwork(rnamagnet_result)
#'layout <- layout_nicely(network)
#'PlotSignalingNetwork(rnamagnet_result, layout = layout)
#'}
#'@return Plots the network and invisibly returns an object of class \code{\link[igraph]{igraph}}
#'@export
PlotSignalingNetwork <- function(rnamagnet, threshold = 0.01, colors = NULL, useLabels=T) {
PlotSignalingNetwork <- function(rnamagnet, threshold = 0.01, colors = NULL, useLabels=T, ...) {
pops <- colnames(rnamagnet@specificity)
mean_by_pop <- sapply(pops, function(id) {
......@@ -30,7 +37,7 @@ if(!is.null(colors)){
graphf$color <- colors[graphf$sender]
}
plotgraph <- igraph::graph_from_data_frame(subset(graphf,value > 0.01 ), vertices = vertices)
if (useLabels) plot(plotgraph,vertex.frame.color=NA, edge.arrow.mode = "-", edge.curved=0.3) else plot(plotgraph,vertex.frame.color=NA, edge.arrow.mode = "-", vertex.label = NA, edge.curved=0.3)
plotgraph <- igraph::graph_from_data_frame(subset(graphf,value > threshold ), vertices = vertices)
if (useLabels) plot(plotgraph,vertex.frame.color=NA, edge.arrow.mode = "-", edge.curved=0.3, ...) else plot(plotgraph,vertex.frame.color=NA, edge.arrow.mode = "-", vertex.label = NA, edge.curved=0.3, ...)
invisible(plotgraph)
}
......@@ -3,7 +3,6 @@
#'
#'This class contains representation for the output of \code{\link{RNAMagnetBase}}.
#'
#'@slot similarity Cell-cell distance matrix
#'@slot anchors Mean gene expression matrix of anchor populations
#'@slot interaction Interaction score matrix between cells and anchor populations
#'@slot specificity Specificity of interaction scores relative to similar cells
......@@ -16,7 +15,6 @@ rnamagnet <- setClass(
"rnamagnet",
slots = c(
anchors = "matrix",
similarity = "matrix",
weight = "matrix",
interaction = "matrix",
specificity = "matrix",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment