-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b97bece
commit 8b0d6d9
Showing
109 changed files
with
673 additions
and
509 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,36 @@ | ||
#' Cluster by features | ||
#' | ||
#' @description Clustering of the features_by_cell matrix | ||
#' @param features features object or result of CNV calculation | ||
#' @param features_by_cells features by cells | ||
#' @param n_comp numeric, Dimensions of reduction to use as input | ||
#' @param cnv TRUE/FALSE set it to TRUE for clustering CNV results | ||
#' @param plot_umap whether to plot the UMAP | ||
#' @param out_dir output directory | ||
#' @param scale_features whether to scale features | ||
#' @param ... arguments passed to Seurat::DimPlot | ||
#' @param ... arguments passed to Seurat::FindCLusters | ||
#' @return features_by_cells Seurat Object, object with saved dimension reduction components calculate on features by cells matrix | ||
#' @import Seurat | ||
#' @importFrom stats as.hclust | ||
#' @export | ||
|
||
cluster_by_features <- function(features, n_comp = 10, cnv=FALSE, plot_umap=FALSE, out_dir="./", scale_features=TRUE, ...){ | ||
cluster_by_features <- function(features_by_cells=NULL, n_comp = 10, ...){ | ||
|
||
if(!dir.exists(out_dir)){ | ||
dir.create(out_dir) | ||
} | ||
|
||
if(cnv){ | ||
features_by_cells <- features | ||
}else{ | ||
features_by_cells <- t(features$df[, features$type != "factor", drop=F]) | ||
features_by_cells[is.na(features_by_cells)] <- 0 | ||
} | ||
|
||
|
||
features_by_cells <- Seurat::CreateSeuratObject(counts = features_by_cells, min.cells = 0, min.features = 0) | ||
features_by_cells <- CreateSeuratObject(counts = features_by_cells, min.cells = 0, min.features = 0) | ||
all.genes <- rownames(features_by_cells) | ||
#scale data | ||
if(scale_features){ | ||
features_by_cells <- Seurat::ScaleData(features_by_cells, features = all.genes) | ||
} | ||
|
||
features_by_cells <- Seurat::RunPCA(features_by_cells, features = all.genes) | ||
#scale data | ||
features_by_cells <- ScaleData(features_by_cells, features = all.genes) | ||
features_by_cells <- RunPCA(features_by_cells, npcs=n_comp, features = all.genes) | ||
|
||
n_comp <- min(n_comp, ncol(features_by_cells@reductions$pca)) | ||
|
||
features_by_cells <- Seurat::FindNeighbors(features_by_cells, dims = 1:n_comp) | ||
features_by_cells <- Seurat::FindClusters(features_by_cells) | ||
#features_by_cells <- Seurat::RunUMAP(features_by_cells, dims = 1:n_comp) | ||
features_by_cells <- FindNeighbors(features_by_cells, dims = 1:n_comp) | ||
features_by_cells <- FindClusters(features_by_cells, ...) | ||
|
||
if(plot_umap){ | ||
grDevices::jpeg(paste0(out_dir, "/feature_umap.jpg"), width = 180, height = 180, res=300, units="mm") | ||
res <- DimPlot(features_by_cells, ..., combine = F) | ||
plot(res[[1]]) | ||
dev.off() | ||
} | ||
if(cnv){ | ||
#features_by_cells <- Seurat::BuildClusterTree(features_by_cells, features = all.genes, reorder = T) | ||
#hc_cells <- stats::as.hclust(features_by_cells@tools$BuildClusterTree) | ||
#ans <- list([email protected], hc=hc_cells, sobj=features_by_cells) | ||
ans <- list(clusters=features_by_cells@active.ident, sobj=features_by_cells) | ||
|
||
}else{ | ||
# if(cnv){ | ||
# #features_by_cells <- Seurat::BuildClusterTree(features_by_cells, features = all.genes, reorder = T) | ||
# #hc_cells <- stats::as.hclust(features_by_cells@tools$BuildClusterTree) | ||
# #ans <- list([email protected], hc=hc_cells, sobj=features_by_cells) | ||
# ans <- list([email protected], sobj=features_by_cells) | ||
# | ||
# }else{ | ||
ans <- list(clusters=features_by_cells@active.ident, sobj=features_by_cells) | ||
} | ||
# } | ||
|
||
return(ans) | ||
|
||
|
Oops, something went wrong.