From 1cd895cd78165dddcf270a2df7307a79eba5df96 Mon Sep 17 00:00:00 2001 From: emosca-cnr Date: Fri, 6 May 2022 13:47:02 +0200 Subject: [PATCH] 0.33 --- DESCRIPTION | Bin 1856 -> 1855 bytes NEWS | 2 + R/add_partitions.R | 2 +- R/assess_cluster_enrichment.R | 9 +-- R/extract_cluster_enrichment_tags.R | 77 ++++++++++++++----------- man/assess_cluster_enrichment.Rd | 12 +--- man/extract_cluster_enrichment_tags.Rd | 2 +- vignettes/scMuffin.Rmd | 2 +- 8 files changed, 50 insertions(+), 56 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 738694966134c00c469e22630b549e4e207121cd..557e3a6356ad0917906b1db2b3a03fc1be381081 100755 GIT binary patch delta 29 kcmX@Wx1Vo9oRBe>OJYf?m4cChk&&)}sjh+9#)9)~0E2A^k^lez delta 31 mcmdnbcYtp~oRAThOJYf?m4cChk&&)}iLRmL#)9)~j0^yjj0lwg diff --git a/NEWS b/NEWS index c3577c4..3cc6332 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,5 @@ +version 0.33 +- various improvements version 0.32 - add requirement for R>=4.0.0 - updated the vignette to clarify the installation steps diff --git a/R/add_partitions.R b/R/add_partitions.R index 8753981..2c95df0 100644 --- a/R/add_partitions.R +++ b/R/add_partitions.R @@ -7,7 +7,7 @@ add_partitions <- function(partitions_obj=NULL, to_add=NULL){ ans <- create_partitions_obj(to_add) - clusterings <- merge(clusterings, ans, by=0, all=T, sort=F) + clusterings <- merge(partitions_obj, ans, by=0, all=T, sort=F) rownames(clusterings) <- clusterings[, 1] clusterings[, 1] <- NULL diff --git a/R/assess_cluster_enrichment.R b/R/assess_cluster_enrichment.R index d11c5f6..0067608 100644 --- a/R/assess_cluster_enrichment.R +++ b/R/assess_cluster_enrichment.R @@ -2,16 +2,9 @@ #' @param features feature list #' @param partitions clustering list #' @param meta_clusters boolean, TRUE if the assessment involves meta clusters -#' @param write_output boolean, TRUE to write the output in the output dir -#' @param out_dir output dir #' @export -#' @importFrom utils write.table -assess_cluster_enrichment <- function(features, partitions, meta_clusters=FALSE, write_output=TRUE, out_dir="./"){ - - if(!dir.exists(out_dir)){ - dir.create(out_dir, recursive=TRUE) - } +assess_cluster_enrichment <- function(features, partitions, meta_clusters=FALSE){ X_fact <- as.matrix(features$df[, features$type=="factor", drop=F]) X_num <- as.matrix(features$df[, !features$type=="factor", drop=F]) diff --git a/R/extract_cluster_enrichment_tags.R b/R/extract_cluster_enrichment_tags.R index 155bebf..23fe767 100644 --- a/R/extract_cluster_enrichment_tags.R +++ b/R/extract_cluster_enrichment_tags.R @@ -11,7 +11,7 @@ #' @param c_sort_desc sorting in decreasing order or ORA #' @export -extract_cluster_enrichment_tags <- function(clust_enrich_res, q_selection_criterion="FDRq", q_selection_threshold=0.1, q_sort_crit="nes", q_sort_desc=FALSE, only_pos_nes=TRUE, c_selection_criterion="p_adj", c_selection_threshold=0.1, c_sort_crit="p", c_sort_desc=FALSE){ +extract_cluster_enrichment_tags <- function(clust_enrich_res, q_selection_criterion="FDRq", q_selection_threshold=0.1, q_sort_crit="nes", q_sort_desc=TRUE, only_pos_nes=TRUE, c_selection_criterion="p_adj", c_selection_threshold=0.1, c_sort_crit="p", c_sort_desc=FALSE){ ans <- vector("list", 2) @@ -20,7 +20,7 @@ extract_cluster_enrichment_tags <- function(clust_enrich_res, q_selection_criter en_table_sel <- extract_cluster_enrichment_table(clust_enrich_res, q_type=q_selection_criterion, c_type=c_selection_criterion) en_table_sort <- extract_cluster_enrichment_table(clust_enrich_res, q_type=q_sort_crit, c_type=c_sort_crit) - if(only_pos_nes & q_sort_crit=="nes"){ + if(only_pos_nes & q_sort_crit=="nes" & length(en_table_sort$cluster_gsea_table) > 0){ for(i in 1:length(en_table_sort$cluster_gsea_table)){ idx_pos_nes <- en_table_sort$cluster_gsea_table[[i]] < 0 en_table_sort$cluster_gsea_table[[i]][idx_pos_nes] <- 0 #negative nes ->0 @@ -29,48 +29,57 @@ extract_cluster_enrichment_tags <- function(clust_enrich_res, q_selection_criter } #selection of per-cluster tags - en_table_sel$cluster_gsea_table <- lapply( en_table_sel$cluster_gsea_table, function(x) apply(x, 1, function(y) colnames(x)[y 0){ + + en_table_sel$cluster_gsea_table <- lapply( en_table_sel$cluster_gsea_table, function(x) apply(x, 1, function(y) colnames(x)[y 0){ + + for(i in 1:length(en_table_sort$cluster_hyper_table)){#clusterings + split_factor <- rownames(en_table_sort$cluster_hyper_table[[i]][[1]]) + en_table_sort$cluster_hyper_table[[i]] <- lapply(en_table_sort$cluster_hyper_table[[i]], function(x) split(t(apply(x, 1, function(y) colnames(x)[order(abs(y), decreasing = c_sort_desc)])), split_factor)) + } + + #keep only those selected + for(i in 1:length(en_table_sort$cluster_hyper_table)){#clusterings + for(j in 1:length(en_table_sort$cluster_hyper_table[[i]])){#features + for(k in 1:length(en_table_sort$cluster_hyper_table[[i]][[j]])){#clusters + en_table_sort$cluster_hyper_table[[i]][[j]][[k]] <- en_table_sort$cluster_hyper_table[[i]][[j]][[k]][en_table_sort$cluster_hyper_table[[i]][[j]][[k]] %in% en_table_sel$cluster_hyper_table[[i]][[j]][[k]] ] + } } } - } - #paste labels - for(i in 1:length(en_table_sort$cluster_hyper_table)){#clusterings - ans$cluster_hyper_tags[[i]] <- vector("list", length(en_table_sort$cluster_hyper_table[[i]][[1]])) #number of clustersfeatures - names(ans$cluster_hyper_tags[[i]]) <- names(en_table_sort$cluster_hyper_table[[i]][[1]]) - for(j in 1:length(ans$cluster_hyper_tags[[i]])){ - ans$cluster_hyper_tags[[i]][[j]] <- lapply(en_table_sort$cluster_hyper_table[[i]], function(x) unlist(x[j])) - ans$cluster_hyper_tags[[i]][[j]] <- paste(names(ans$cluster_hyper_tags[[i]][[j]]), lapply(ans$cluster_hyper_tags[[i]][[j]], function(x) paste0(x, collapse = "_"))) + #paste labels + for(i in 1:length(en_table_sort$cluster_hyper_table)){#clusterings + ans$cluster_hyper_tags[[i]] <- vector("list", length(en_table_sort$cluster_hyper_table[[i]][[1]])) #number of clustersfeatures + names(ans$cluster_hyper_tags[[i]]) <- names(en_table_sort$cluster_hyper_table[[i]][[1]]) + for(j in 1:length(ans$cluster_hyper_tags[[i]])){ + ans$cluster_hyper_tags[[i]][[j]] <- lapply(en_table_sort$cluster_hyper_table[[i]], function(x) unlist(x[j])) + ans$cluster_hyper_tags[[i]][[j]] <- paste(names(ans$cluster_hyper_tags[[i]][[j]]), lapply(ans$cluster_hyper_tags[[i]][[j]], function(x) paste0(x, collapse = "_"))) + } } + } return(ans) diff --git a/man/assess_cluster_enrichment.Rd b/man/assess_cluster_enrichment.Rd index 89d8cd7..35abb16 100644 --- a/man/assess_cluster_enrichment.Rd +++ b/man/assess_cluster_enrichment.Rd @@ -4,13 +4,7 @@ \alias{assess_cluster_enrichment} \title{assess_cluster_enrichment} \usage{ -assess_cluster_enrichment( - features, - partitions, - meta_clusters = FALSE, - write_output = TRUE, - out_dir = "./" -) +assess_cluster_enrichment(features, partitions, meta_clusters = FALSE) } \arguments{ \item{features}{feature list} @@ -18,10 +12,6 @@ assess_cluster_enrichment( \item{partitions}{clustering list} \item{meta_clusters}{boolean, TRUE if the assessment involves meta clusters} - -\item{write_output}{boolean, TRUE to write the output in the output dir} - -\item{out_dir}{output dir} } \description{ assess_cluster_enrichment diff --git a/man/extract_cluster_enrichment_tags.Rd b/man/extract_cluster_enrichment_tags.Rd index 8d010dd..2db3104 100644 --- a/man/extract_cluster_enrichment_tags.Rd +++ b/man/extract_cluster_enrichment_tags.Rd @@ -9,7 +9,7 @@ extract_cluster_enrichment_tags( q_selection_criterion = "FDRq", q_selection_threshold = 0.1, q_sort_crit = "nes", - q_sort_desc = FALSE, + q_sort_desc = TRUE, only_pos_nes = TRUE, c_selection_criterion = "p_adj", c_selection_threshold = 0.1, diff --git a/vignettes/scMuffin.Rmd b/vignettes/scMuffin.Rmd index d2dd814..3e15240 100644 --- a/vignettes/scMuffin.Rmd +++ b/vignettes/scMuffin.Rmd @@ -172,7 +172,7 @@ res_dm <- diff_map(GetAssayData(seu_obj_1), root_cell = "random", n_pcs=50) ## CNV inference -The function calculate_CNV basically retrieves the genomic locations and performs the CNV estimation; `cluster_by_features` (see below) calculates the clustering; `apply_CNV_reference` redefines the CNV levels on the basis of (optional) reference cells; the dedicated plotting function `CNV_heatmap` handles the visualization (based on the R package ComplexHeatmap [@Gu2016]), where the cluster of cells that contains the reference is marked. Here’s an example that illustrates CNV inference using a 100 genes window size and a reference profile from the The Genotype-Tissue Expression project (GTEx) portal (13): +The function calculate_CNV basically retrieves the genomic locations and performs the CNV estimation; `cluster_by_features` (see below) calculates the clustering; `apply_CNV_reference` redefines the CNV levels on the basis of (optional) reference cells; the dedicated plotting function `heatmap_CNV` handles the visualization (based on the R package ComplexHeatmap [@Gu2016]), where the cluster of cells that contains the reference is marked. Here’s an example that illustrates CNV inference using a 100 genes window size and a reference profile from the The Genotype-Tissue Expression project (GTEx) portal (13): ```{r, include=TRUE, eval=FALSE} GTEx_mean <- process_GTEx_gene_reads(geneReads="~/db/GTEx/GTEx_Analysis_2017-06-05_v8_RNASeQCv1.1.9_gene_reads.gct", GTEx_annot="~/db/GTEx/GTEx_Analysis_v8_Annotations_SampleAttributesDS.txt", tissue="Brain")