Skip to content

Commit f0d9786

Browse files
committed
v1.2.0
1 parent cfa3850 commit f0d9786

File tree

97 files changed

+295
-406
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+295
-406
lines changed

DESCRIPTION

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: scMuffin
22
Title: MUlti-Features INtegrative approach for single-cell data analysis
3-
Version: 1.1.7
4-
Date: 2024-02-26
3+
Version: 1.2.0
4+
Date: 2024-04-10
55
Authors@R:
66
c(person(given = "Valentina",
77
family = "Nale",
@@ -30,34 +30,6 @@ RoxygenNote: 7.2.3
3030
Encoding: UTF-8
3131
Depends:
3232
R (>= 4.0.0)
33-
Imports:
34-
graphics,
35-
parallel,
36-
org.Hs.eg.db,
37-
RColorBrewer,
38-
dendextend,
39-
destiny,
40-
Seurat,
41-
stats,
42-
utils,
43-
DESeq2,
44-
msigdbr,
45-
methods,
46-
cluster,
47-
ComplexHeatmap,
48-
VGAM,
49-
dendsort,
50-
grDevices,
51-
ggplot2,
52-
circlize,
53-
Matrix,
54-
pals,
55-
plotrix,
56-
qvalue
57-
Suggests:
58-
rmarkdown,
59-
knitr,
60-
BiocStyle,
61-
devtools,
62-
sf
33+
Imports: graphics, parallel, org.Hs.eg.db, destiny, Seurat, stats, utils, msigdbr, methods, ComplexHeatmap, grDevices, ggplot2, circlize, Matrix, pals, plotrix, qvalue
34+
Suggests: rmarkdown, knitr, BiocStyle, devtools
6335
VignetteBuilder: knitr

NAMESPACE

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export(boxplot_points)
1212
export(calculate_CNV)
1313
export(calculate_gs_scores)
1414
export(calculate_gs_scores_in_clusters)
15+
export(cel_coocc_partitions)
1516
export(cluster_by_features)
1617
export(cluster_csea)
1718
export(cluster_hyper)
@@ -29,7 +30,6 @@ export(gs_score)
2930
export(gs_scores_in_clusters)
3031
export(heatmap_CNV)
3132
export(inter_dataset_comparison)
32-
export(inter_ds_cluster_sim)
3333
export(keep_strongest_representative)
3434
export(ora)
3535
export(overlap_coefficient)
@@ -52,22 +52,26 @@ export(sc_create_null)
5252
export(sc_data_bin)
5353
export(show_tissues)
5454
export(transcr_compl)
55-
import(ComplexHeatmap)
56-
import(Seurat)
57-
import(grDevices)
58-
import(graphics)
59-
import(grid)
60-
import(pals)
61-
import(parallel)
55+
importFrom(ComplexHeatmap,Heatmap)
56+
importFrom(ComplexHeatmap,anno_mark)
57+
importFrom(ComplexHeatmap,columnAnnotation)
58+
importFrom(ComplexHeatmap,draw)
59+
importFrom(ComplexHeatmap,rowAnnotation)
6260
importFrom(Matrix,Matrix)
6361
importFrom(Matrix,colMeans)
6462
importFrom(Matrix,colSums)
6563
importFrom(Matrix,rowSums)
6664
importFrom(Seurat,AddMetaData)
65+
importFrom(Seurat,CreateSeuratObject)
6766
importFrom(Seurat,DimPlot)
6867
importFrom(Seurat,FeaturePlot)
6968
importFrom(Seurat,FetchData)
69+
importFrom(Seurat,FindClusters)
70+
importFrom(Seurat,FindNeighbors)
71+
importFrom(Seurat,GetAssayData)
7072
importFrom(Seurat,NormalizeData)
73+
importFrom(Seurat,RunPCA)
74+
importFrom(Seurat,ScaleData)
7175
importFrom(circlize,colorRamp2)
7276
importFrom(destiny,DPT)
7377
importFrom(destiny,DiffusionMap)
@@ -77,17 +81,38 @@ importFrom(ggplot2,cut_interval)
7781
importFrom(ggplot2,cut_number)
7882
importFrom(ggplot2,element_text)
7983
importFrom(ggplot2,theme)
84+
importFrom(grDevices,adjustcolor)
8085
importFrom(grDevices,boxplot.stats)
86+
importFrom(grDevices,dev.off)
8187
importFrom(grDevices,jpeg)
8288
importFrom(grDevices,png)
89+
importFrom(graphics,abline)
90+
importFrom(graphics,axis)
91+
importFrom(graphics,barplot)
92+
importFrom(graphics,boxplot)
93+
importFrom(graphics,layout)
94+
importFrom(graphics,legend)
95+
importFrom(graphics,par)
96+
importFrom(graphics,plot.new)
97+
importFrom(graphics,points)
98+
importFrom(graphics,rect)
99+
importFrom(graphics,text)
83100
importFrom(grid,gpar)
101+
importFrom(grid,grid.text)
102+
importFrom(grid,unit)
84103
importFrom(methods,is)
85104
importFrom(msigdbr,msigdbr)
86105
importFrom(org.Hs.eg.db,org.Hs.egCHRLOC)
87106
importFrom(org.Hs.eg.db,org.Hs.egCHRLOCEND)
88107
importFrom(org.Hs.eg.db,org.Hs.egENSEMBL)
89108
importFrom(org.Hs.eg.db,org.Hs.egSYMBOL)
90109
importFrom(pals,alphabet)
110+
importFrom(pals,alphabet2)
111+
importFrom(pals,brewer.accent)
112+
importFrom(pals,brewer.pastel1)
113+
importFrom(pals,brewer.purples)
114+
importFrom(pals,brewer.rdylbu)
115+
importFrom(pals,brewer.ylorrd)
91116
importFrom(parallel,mclapply)
92117
importFrom(plotrix,thigmophobe.labels)
93118
importFrom(qvalue,qvalue)

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
version 1.2.0
2+
- removed null_model as argument of calculate_gs_score;
3+
- addedd the function cell_coocc_partitions
14
version 1.1.7
25
- introduced support for NA values in keep strongest representative
36
version 1.1.6

R/barplot_cluster.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
#' @param units image units
1313
#' @param res image resolution
1414
#' @param legend.pos position of barplot legend
15-
#' @importFrom grDevices jpeg
15+
#' @importFrom grDevices jpeg adjustcolor
1616
#' @importFrom stats setNames
1717
#' @importFrom plotrix thigmophobe.labels
18-
#' @import pals
18+
#' @importFrom pals alphabet2
19+
#' @importFrom graphics barplot text plot.new
1920
#' @description Produce barplots (1 for each cluster) of distribution of cells associated with the values of the selected feature. A png figure for each cluster is saved in dir_out.
2021
#' @export
2122

R/boxplot_cluster.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
#' @param res image resolution
1313
#' @param feature_name the names of the feature that should be considered. It must be one of names(scMuffinList)
1414
#' @description Produce boxplots to visualize the distribution of cell values according to the selected feature A png figure for each cluster is saved in dir_out.
15-
#' @importFrom grDevices png
15+
#' @importFrom grDevices png dev.off
1616
#' @importFrom plotrix thigmophobe.labels
17-
#' @import graphics
17+
#' @importFrom graphics layout par points boxplot legend
1818
#' @export
1919

2020
boxplot_cluster <- function(scMuffinList=NULL, feature_name=NULL, partition_id=NULL, dir_out="./", n_features=10, only_pos_nes=TRUE, do_scale_features=FALSE, cex.axis=0.8, width=180, height=180, units="mm", res=300){
@@ -92,7 +92,7 @@ boxplot_cluster <- function(scMuffinList=NULL, feature_name=NULL, partition_id=N
9292
cbf_cl <- cells_by_features[, match(names(top_features$fdr), colnames(cells_by_features)), drop=FALSE]
9393

9494

95-
png(paste0(dir_out, "/cluster_", cell_clusters_set[cl], ".png"), width=width, height=height, units=units, res=res)
95+
png(file.path(dir_out, paste0("cluster_", cell_clusters_set[cl], ".png")), width=width, height=height, units=units, res=res)
9696
layout(matrix(c(1, 1, 2, 3), nrow = 2, byrow = T))
9797

9898
par(mar = c(3, 3, 2, 1))

R/boxplot_points.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#' @param image_format png or jpeg
1616
#' @param ... further argument to boxplot
1717
#' @importFrom pals alphabet
18-
#' @importFrom grDevices png jpeg
18+
#' @importFrom grDevices png jpeg adjustcolor
1919
#' @export
2020

2121
boxplot_points <- function(x=NULL, f=NULL, col=NULL, amount=0.2, adj.col=1, pch=16, cex=0.6, ylim=NULL, file=NULL, width=180, height=180, units="mm", res=300, image_format="png", ...){

R/calculate_gs_scores.R

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,20 @@
99
#' @param k number of permutations
1010
#' @param kmin minimum number of permutations; due to missing values it is hard to ensure that a gene set score can be compared to k permutations in every cell
1111
#' @param score_type type of score. if "relative", than the score is the difference between the observed gene set average expression and that of a k permutations; if "mean" the score is equal to the observed gene set average expression
12-
#' @param null_model TRUE if permutations have to be used. Required for score_type="relative"
1312
#' @param verbose verbosity
1413
#' @param na.rm whether to use NA or not
1514
#' @param overwrite whether to update or not gene_set_scoring and gene_set_scoring_full elements of scMuffinList.
1615
#' @return scMuffinList with element gene_set_scoring, a list that contains summary and full. The element summary contains a cells-by-gene sets data.frame. The element "full" contains a data.frame for each gene set. See [gs_score()] for further details.
1716
#' @references Tirosh2016 10.1126/science.aad0501
1817
#'
1918
#' @export
20-
#' @import parallel
19+
#' @importFrom parallel mclapply
2120

22-
calculate_gs_scores <- function(scMuffinList=NULL, gs_list=NULL, mc.cores=1, nbins=25, nmark_min = 5, ncells_min = 10, k=100, kmin=50, score_type=c("relative", "mean"), null_model=TRUE, verbose=FALSE, na.rm=TRUE, overwrite=FALSE){
21+
calculate_gs_scores <- function(scMuffinList=NULL, gs_list=NULL, mc.cores=1, nbins=25, nmark_min = 5, ncells_min = 10, k=100, kmin=50, score_type=c("relative", "mean"), verbose=FALSE, na.rm=TRUE, overwrite=FALSE){
2322

2423

24+
score_type <- match.arg(arg = score_type, choices = c("relative", "mean"))
25+
2526
cat("####################################################\n")
2627
cat("nbins:", nbins, "\n")
2728
cat("nmark_min:", nmark_min, "\n")
@@ -30,12 +31,17 @@ calculate_gs_scores <- function(scMuffinList=NULL, gs_list=NULL, mc.cores=1, nbi
3031
kmin <- min(k, kmin)
3132
cat("kmin:", kmin, "\n")
3233
cat("score_type:", score_type, "\n")
33-
cat("null_model:", null_model, "\n")
3434
cat("verbose:", verbose, "\n")
3535
cat("na.rm:", na.rm, "\n")
3636
cat("overwrite:", overwrite, "\n")
3737
cat("####################################################\n")
3838

39+
if(score_type == "relative"){
40+
null_model <- TRUE
41+
}else{
42+
null_model <- FALSE
43+
}
44+
3945
if(length(scMuffinList$normalized)==0){
4046
stop("scMuffinList does not contain genes_by_cells\n")
4147
}

R/calculate_gs_scores_in_clusters.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
#' @param scMuffinList scMuffinList object
44
#' @param partition_id identifier of the partition to be used
55
#' @param ncells_min minimum number of cells required for the calculation of the average signature in the cluster
6-
#' @param null_model TRUE to consider the empirical null based on gene set permutations
76
#' @param alt alterative passed to [wilcox.test()] or [t.test()]
87
#' @param test type of test: t to use [t.test()]; wrs to use [wilcox.test()]
98
#' @param fract_min only clusters with this fraction of cells with not null gene set score will be considered
109
#' @return scMuffinList with cluster level scores in `sMuffinList$cluster_data[[partition_id]]`. The element [summary] contains a clusters-by-gene sets table, while the element [full] the full result
1110
#' @export
1211

13-
calculate_gs_scores_in_clusters <- function(scMuffinList=NULL, partition_id=NULL, ncells_min = 5, null_model = TRUE, alt="g", test="t", fract_min=0.5){
12+
calculate_gs_scores_in_clusters <- function(scMuffinList=NULL, partition_id=NULL, ncells_min = 5, alt="g", test="t", fract_min=0.5){
1413

1514
if(!any(colnames(scMuffinList$partitions) == partition_id)){
1615
stop("Can't find any parition named ", partition_id, "\n")
@@ -19,7 +18,7 @@ calculate_gs_scores_in_clusters <- function(scMuffinList=NULL, partition_id=NULL
1918
cat("Clusters...\n")
2019
print(table(setNames(scMuffinList$partitions[, partition_id], rownames(scMuffinList$partitions))))
2120

22-
res_signatures_clusters <- lapply(scMuffinList$gene_set_scoring$full, function(i_marker_res) gs_scores_in_clusters(i_marker_res, cell_clusters=setNames(scMuffinList$partitions[, partition_id], rownames(scMuffinList$partitions)), ncells_min = ncells_min, fract_min = fract_min, null_model = null_model, alt=alt, test=test))
21+
res_signatures_clusters <- lapply(scMuffinList$gene_set_scoring$full, function(i_marker_res) gs_scores_in_clusters(i_marker_res, cell_clusters=setNames(scMuffinList$partitions[, partition_id], rownames(scMuffinList$partitions)), ncells_min = ncells_min, fract_min = fract_min, alt=alt, test=test))
2322

2423
#signatures-by-clusters matrix
2524
SC_signatures_by_cluster_matrix <- do.call(rbind, lapply(res_signatures_clusters, function(x) array(x$score[order(x$cluster)], dimnames = list(c(x$cluster[order(x$cluster)])))))

R/cell_coocc_partitions.R

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#' Co-occurrence of cells between two partitions
2+
#' @description Calculate, as Jaccard index, the co-occurrence of cells in all the pairs of elements composed by an element from p1 and an element from p2.
3+
#' @param p1 a partition among scMuffinList$partitions, e.g. scML_demo$partitions$global_exp
4+
#' @param p2 a partition among scMuffinList$partitions, e.g. scML_demo$partitions$CNV
5+
#' @return matrix of Jaccard indeces between all levels of p1 and all levels of p2
6+
#' @export
7+
8+
cel_coocc_partitions <- function(p1=NULL, p2=NULL){
9+
10+
stopifnot(length(p1) == length(p2))
11+
12+
p1_by_p2 <- table(p1, p2)
13+
p1_size <- matrix(rep(rowSums(p1_by_p2), ncol(p1_by_p2)), ncol = ncol(p1_by_p2))
14+
p2_size <- matrix(rep(colSums(p1_by_p2), nrow(p1_by_p2)), nrow = nrow(p1_by_p2), byrow = T)
15+
p1_by_p2 <- p1_by_p2 / (p1_size + p2_size - p1_by_p2)
16+
p1_by_p2[is.nan(p1_by_p2)] <- 0
17+
18+
return(p1_by_p2)
19+
}

R/cluster_by_features.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#' @param n_comp numeric, Dimensions of reduction to use as input
66
#' @param ... arguments passed to Seurat::FindCLusters
77
#' @return features_by_cells Seurat Object, object with saved dimension reduction components calculate on features by cells matrix
8-
#' @import Seurat
8+
#' @importFrom Seurat CreateSeuratObject ScaleData RunPCA FindNeighbors FindClusters
99
#' @export
1010

1111
cluster_by_features <- function(features_by_cells=NULL, n_comp = 10, ...){

R/csea.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#' @param min.k minimum number of valid permutations to support empirical nulls
99
#' @param min.size minimum number of cells with a not null value
1010
#' @param fract_min only cluster of size less or equal to this fraction of cell with not null feature values will be analysed
11-
#' @import parallel
11+
#' @importFrom parallel mclapply
1212
#' @importFrom stats p.adjust
1313
#' @importFrom qvalue qvalue
1414
#' @return list with two data.frames, gs_table and leading_edge.

R/gs_scores_in_clusters.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,22 @@
44
#' @param ncells_min minimum number of cells required for the calculation of the average signature in the cluster
55
#' @param alt alterative passed to [wilcox.test()] or [t.test()]
66
#' @param test type of test: t to use [t.test()]; wrs to use [wilcox.test()]
7-
#' @param null_model TRUE to consider the empirical null based on gene set permutations
87
#' @param fract_min only clusters with this fraction of cells with not null gene set score will be considered
98
#' @description Gene set scoring in clusters
109
#' @importFrom stats median wilcox.test t.test p.adjust
1110
#' @export
1211

13-
gs_scores_in_clusters <- function(score_table=NULL, cell_clusters=NULL, ncells_min=5, alt="g", test="t", null_model=TRUE, fract_min=0.5){
12+
gs_scores_in_clusters <- function(score_table=NULL, cell_clusters=NULL, ncells_min=5, alt="g", test="t", fract_min=0.5){
1413

1514
if(!is.factor(cell_clusters)){
1615
cell_clusters <- as.factor(cell_clusters)
1716
}
1817

18+
null_model <- FALSE
19+
if(any(!is.na(score_table$avg_control))){
20+
null_model <- TRUE
21+
}
22+
1923
clusters_size <- table(cell_clusters)
2024
clusters <- levels(cell_clusters)
2125

R/heatmap_CNV.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#' @param legend_fontsize legend fontsize
1414
#' @param genes.labels.fontsize gene labels fontsize
1515
#' @param ... arguments passed to ComplexHeatmap::Heatmap
16-
#' @import ComplexHeatmap
17-
#' @importFrom grid gpar
16+
#' @importFrom ComplexHeatmap rowAnnotation anno_mark Heatmap draw
17+
#' @importFrom grid gpar unit
1818
#' @importFrom grDevices png
1919
#' @export
2020

R/inter_datasets_comparison.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#' Inter-dataset cluster similarity
22
#' @param seu_obj_list list of Seurat objects
33
#' @param gsl gene set list
4-
##' @param genes_min minimum number of genes required among the markers of a cluster
4+
#' @param genes_min minimum number of genes required among the markers of a cluster
55
#' @param genes_max maximum number of genes required among the markers of a cluster
66
#' @param mc.cores number of cores
7-
#' @param null_model whether to use or not the empirical null model. See calculate_signature
87
#' @param ncells_min minim number of cells in a cluster
98
#' @param cluster_rows whether to cluster or not the rows
109
#' @param cluster_columns whether to cluster or not the columns
1110
#' @param ... arguments passed to calculate_gs_scores
11+
#' @importFrom Seurat GetAssayData
1212
#' @export
1313
#' @description Quantify the similarity between clusters of two datasets, on the basis of the average cluster marker expression
1414
#' @return A list with:
@@ -20,7 +20,7 @@
2020
#' \item{markers_2, markers of dataset 2;}
2121
#' }
2222

23-
inter_dataset_comparison <- function(seu_obj_list=NULL, gsl=NULL, genes_min=3, genes_max=500, mc.cores=1, null_model=TRUE, ncells_min=5, cluster_rows = FALSE, cluster_columns = FALSE, ...){
23+
inter_dataset_comparison <- function(seu_obj_list=NULL, gsl=NULL, genes_min=3, genes_max=500, mc.cores=1, ncells_min=5, cluster_rows = FALSE, cluster_columns = FALSE, ...){
2424

2525

2626
if(!all(unlist(lapply(seu_obj_list, function(x) is(x, "Seurat"))))){

0 commit comments

Comments
 (0)