Skip to content

Commit

Permalink
Merge pull request #89 from YosefLab/yr-cass
Browse files Browse the repository at this point in the history
PhyloVision & version bump
  • Loading branch information
mattjones315 authored Aug 30, 2021
2 parents c8598d9 + b21442f commit 5ef3e10
Show file tree
Hide file tree
Showing 313 changed files with 89,887 additions and 5,233 deletions.
8 changes: 6 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
Package: VISION
Title: Functional interpretation of single cell RNA-seq latent manifolds
Version: 2.1.0
Version: 3.0.0
Authors@R: c(person("Matt", "Jones", email = "[email protected]", role = c("aut", "cre")),
person("David", "Detomaso", email = "[email protected]", role = c("aut", "cre")),
person("Tal", "Ashuach", email = "[email protected]", role = c("aut")),
person("Yanay", "Rosen", email = "[email protected]", role = c("aut")),
person("Nir", "Yosef", email = "[email protected]", role = c("ctb", "cph")))
Author: Matt Jones [aut, cre], David Detomaso [aut, cre], Tal Ashuach [aut], Nir Yosef [ctb]
Maintainer: Matt Jones <[email protected]>
Description: VISION provides functional interpretation of single cell RNA-seq (scRNA-seq) latent manifolds through the use of biological signatures (which can be downloaded from online databases). VISION can operate downstream of other common analyses such as dimensionality reduction, clustering, or trajectory analysis of scRNA-seq data. VISION produces an interactive web-based output report that can be easily shared with other collaborators or the greater scientific community.
Depends: R (>= 3.4)
Imports:
dplyr,
fastICA,
igraph,
irlba,
Expand All @@ -31,14 +33,16 @@ Imports:
Rtsne,
utils,
vegan,
ape,
reticulate,
wordspace
LinkingTo: Rcpp
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
URL: https://yoseflab.github.io/VISION, https://github.com/yoseflab/VISION
BugReports: https://github.com/YosefLab/VISION/issues
RoxygenNote: 6.1.1
RoxygenNote: 7.1.1
Suggests:
Biobase,
BiocStyle,
Expand Down
28 changes: 28 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,24 +1,49 @@
# Generated by roxygen2: do not edit by hand

export(PhyloVision)
export(Vision)
export(addHotspotToVision)
export(addSignatures)
export(addTSNE)
export(addUMAP)
export(analyzeHotspotObjectVision)
export(analyzeLocalCorrelations)
export(analyzeLocalCorrelationsModules)
export(annotateLatentComponents)
export(applyMicroClustering)
export(calcModuleScores)
export(calcSignatureScores)
export(calc_mod_sig_enrichment)
export(calc_set_enrichment)
export(clusterModScores)
export(clusterSigScores)
export(computeLatentSpace)
export(convertGeneIds)
export(createGeneSignature)
export(depthBasedCladewiseTreeCluster)
export(depthBasedTreeCluster)
export(draw_hotspot_heatmap)
export(generateOverlapSignatures)
export(group_modules_enrichment)
export(hsCalculateModuleScores)
export(hsComputeAutoCorrelations)
export(hsComputeLocalCorrelations)
export(hsCreateKnnGraph)
export(hsInit)
export(lca_based_depth)
export(loadHotspotObject)
export(poolMatrixCols)
export(poolMatrixRows)
export(poolMetaData)
export(read_10x)
export(read_10x_h5)
export(read_10x_h5_v2)
export(read_10x_h5_v3)
export(runHotspot)
export(saveHSBytestToPickle)
export(treeClusterMinCladeSize)
export(trivial_dist)
exportMethods(PhyloVision)
exportMethods(Vision)
exportMethods(addProjection)
exportMethods(analyze)
Expand All @@ -31,13 +56,16 @@ exportMethods(getSelections)
exportMethods(getSignatureAutocorrelation)
exportMethods(getSignatureDifferential)
exportMethods(getSignatureScores)
exportMethods(phyloAnalyze)
exportMethods(saveAndViewResults)
exportMethods(viewResults)
import(Matrix)
import(Rcpp)
import(ape)
import(loe)
import(logging)
import(methods)
import(reticulate)
importFrom(Matrix,Diagonal)
importFrom(Matrix,Matrix)
importFrom(Matrix,colMeans)
Expand Down
11 changes: 11 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# VISION 3.0.0

Major version bump!

* Added support for Phylogenies as latent spaces in core VISION and integrated with VISION api
* Re-engineered UI into Signature Autocorrelation and Hotspot views
* Integrated [Hotspot](https://yoseflab.github.io/Hotspot/index.html) into VISION analysis and report UI.
* Deprecated support for trajectories and LC Annotator.
* New color-scheme for gene expression values


# VISION 2.1.0

Added parameter `sig_gene_threshold` with **changed default behavior**
Expand Down
31 changes: 30 additions & 1 deletion R/AllClasses.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
# scores, distance matrices, and anything else, is computed
# on the different types of data.


setClassUnion("numericORNULL", members = c("numeric", "NULL"))
setClassUnion("matrixORSparse", members = c("matrix", "dgCMatrix"))
setClassUnion("matrixORNULL", members = c("matrix", "NULL"))
setClassUnion("dataframeORNULL", members = c("data.frame", "NULL"))
setClassUnion("rawORNULL", members = c("raw", "NULL"))


# setClassUnion("treeorNull", members=c("phylo", "NULL"))
# setClassUnion("pythonorNull", members = c("python.builtin.object", "NULL"))

Cluster <- setClass("Cluster",
slots = c(
Expand Down Expand Up @@ -58,6 +64,8 @@ Trajectory <- setClass("Trajectory",
# columns: from (character), to (character), position (numeric, 0 to 1)
))

setClassUnion("trajectoryORNULL", members = c("Trajectory", "NULL"))

TrajectoryProjection <- setClass("TrajectoryProjection",
slots = c(
name = "character", # Name of projection
Expand Down Expand Up @@ -101,17 +109,23 @@ Vision <- setClass("Vision",
unnormalizedData = "matrixORSparse",
sigData = "list",
metaData = "data.frame",
modData = "list",
SigScores = "matrix",
ModScores = "matrix",
LocalAutocorrelation = "list",
TrajectoryAutocorrelation = "list",
ClusterComparisons = "list",
LCAnnotatorData = "LCAnnotatorDataOrNULL",
Projections = "list",
TrajectoryProjections = "list", # list of TrajectoryProjection
SigGeneImportance = "list",
ModGeneImportance = "list",
Pools = "list",
LatentSpace = "matrix",
LatentTrajectory = "Trajectory",
LatentTrajectory = "trajectoryORNULL",
Hotspot = "rawORNULL",
ModuleSignatureEnrichment = "list",
ModuleHotspotScores = "data.frame",
Viewer = "list",
params = "list",
version = "numeric"
Expand All @@ -122,18 +136,33 @@ Vision <- setClass("Vision",
unnormalizedData = matrix(NA, 1, 1),
sigData = list(),
metaData = data.frame(),
modData=list(),
SigScores = matrix(NA, 1, 1),
ModScores = matrix(NA, 1, 1),
LocalAutocorrelation = list(),
TrajectoryAutocorrelation = list(),
ClusterComparisons = list(),
LCAnnotatorData = NULL,
Projections = list(),
TrajectoryProjections = list(),
SigGeneImportance = list(),
ModGeneImportance = list(),
Pools = list(),
LatentSpace = matrix(NA, 1, 1),
LatentTrajectory = NULL,
Hotspot = NULL,
ModuleSignatureEnrichment = list(),
ModuleHotspotScores = data.frame(),
Viewer = list(),
params = list(),
version = 1.2
))

# This is a hack to try and get R to play nice with the phylo class
# Which the Ape package doesn't expose
phylo <- setClass("phylo")

PhyloVision <- setClass("PhyloVision", contains = "Vision",
slots = c(tree = "phylo"),
prototype = list(tree=NULL)
)
10 changes: 10 additions & 0 deletions R/AllGenerics.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@ setGeneric("Vision", function(data, ...) {
standardGeneric("Vision")
})

#' @rdname PhyloVision-class
#' @export
setGeneric("PhyloVision", function(tree, ...) {
standardGeneric("PhyloVision")
})

setGeneric("analyze", function(object, ...) {
standardGeneric("analyze")
})

setGeneric("phyloAnalyze", function(object, ...) {
standardGeneric("phyloAnalyze")
})

setGeneric("addProjection", function(object, ...) {
standardGeneric("addProjection")
})
Expand Down
70 changes: 53 additions & 17 deletions R/AnalysisFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,32 @@
#'
#' @param object the VISION object for which to cluster the cells
#' @return the VISION object modifed as described above
clusterCells <- function(object) {
clusterCells <- function(object, tree=FALSE) {

message("Clustering cells...", appendLF = FALSE)

res <- object@LatentSpace

K <- min(object@params$numNeighbors, 30)
kn <- find_knn_parallel(res, K)

cl <- louvainCluster(kn, res)


if (!tree) {
kn <- find_knn_parallel(res, K)
cl <- louvainCluster(kn, res)
} else {
message("Using Tree to compute clusters...\n")
# Get the MRCA matrix and convert the node indexes to depths
cl <- maxSizeCladewiseTreeCluster(object@tree)
}

names(cl) <- paste('Cluster', seq(length(cl)))

# cl is list of character vector
cluster_variable <- "VISION_Clusters"
if (!tree) {
cluster_variable <- "VISION_Clusters"
} else {
cluster_variable <- "VISION_Clusters_Tree"
}

metaData <- object@metaData

metaData[cluster_variable] <- factor(levels = names(cl))
Expand Down Expand Up @@ -154,7 +165,7 @@ computeProjectionGenes <- function(object,
if (!is.null(projection_genes)){
object@params$latentSpace$projectionGenes <- projection_genes
} else {
object@params$latentSpace$projectionGenes <- NULL
object@params$latentSpace$projectionGenes <- NA
}

if (!is.null(projection_genes_method)){
Expand All @@ -163,7 +174,7 @@ computeProjectionGenes <- function(object,

message("Determining projection genes...")

if (is.null(object@params$latentSpace[["projectionGenes"]])){
if (is.na(object@params$latentSpace[["projectionGenes"]])){

exprData <- matLog2(object@exprData)
projection_genes <- applyFilters(
Expand Down Expand Up @@ -283,22 +294,43 @@ calcSignatureScores <- function(
object@exprData,
object@params$signatures$sigNormMethod
)

sigScores <- batchSigEvalNorm(object@sigData, normExpr)


sigData <- object@sigData

for (sig_name in names(object@sigData)){
signature <- object@sigData[[sig_name]]
directional <- all(c(1, -1) %in% signature@sigDict)
if (directional) {
up <- names(which(signature@sigDict == 1))
down <- names(which(signature@sigDict == -1))

up_name <- paste(signature@name, "_UP", sep = "")
down_name <- paste(signature@name, "_DOWN", sep = "")

up_sig <- Signature(sigDict = signature@sigDict[up], name = up_name, source = signature@source, metaData = signature@metaData)
down_sig <- Signature(sigDict = signature@sigDict[down], name = down_name, source = signature@source, metaData = signature@metaData)
sigData[[up_name]] <- up_sig
sigData[[down_name]] <- down_sig
}
}

object@sigData <- sigData # persist back to the object because of issues with up/down

sigScores <- batchSigEvalNorm(sigData, normExpr)

if (sig_gene_importance) {

if (is(object@exprData, "sparseMatrix")) {
sigGeneImportance <- evalSigGeneImportanceSparse(
sigScores, object@sigData, normExpr
sigScores, sigData, normExpr
)
} else {
normExprDense <- getNormalizedCopy(
object@exprData,
object@params$signatures$sigNormMethod
)
sigGeneImportance <- evalSigGeneImportance(
sigScores, object@sigData, normExprDense
sigScores, sigData, normExprDense
)
}

Expand Down Expand Up @@ -715,7 +747,7 @@ addTSNE <- function(object, perplexity = 30, name = "tSNE", source = "LatentSpac
#' @param object the VISION object
#' @return the VISION object with values set for the analysis results
#' @export
analyzeLocalCorrelations <- function(object) {
analyzeLocalCorrelations <- function(object, tree=FALSE) {

signatureBackground <- generatePermutationNull(
object@exprData, object@sigData, num = 3000
Expand All @@ -726,9 +758,13 @@ analyzeLocalCorrelations <- function(object) {
object@params$signatures$sigNormMethod)

message("Computing KNN Cell Graph in the Latent Space...\n")

weights <- computeKNNWeights(object@LatentSpace, object@params$numNeighbors)

if (!tree) {
weights <- computeKNNWeights(object@LatentSpace, object@params$numNeighbors)
} else {
message("Using Tree to compute neighbors...\n")
weights <- computeKNNWeights(object@tree, object@params$numNeighbors)
}

message("Evaluating local consistency of signatures in latent space...\n")

sigConsistencyScores <- sigConsistencyScores(
Expand Down
Loading

0 comments on commit 5ef3e10

Please sign in to comment.