Skip to content

Commit 7360cf4

Browse files
authored
Merge branch 'main-dev' into fix_factor_plot_colorscale
2 parents d8c7aa2 + f95fb5a commit 7360cf4

32 files changed

+459
-235
lines changed

DESCRIPTION

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Package: MOFA2
22
Type: Package
33
Title: Multi-Omics Factor Analysis v2
4-
Version: 1.7.2
5-
Maintainer: Britta Velten <britta.velten@gmail.com>
6-
Authors@R: c(person("Ricard", "Argelaguet", role = "aut",
4+
Version: 1.21.1
5+
Maintainer: Ricard Argelaguet <ricard.argelaguet@gmail.com>
6+
Authors@R: c(person("Ricard", "Argelaguet", role = c("aut", "cre"),
77
email = "[email protected]",
88
comment = c(ORCID = "http://orcid.org/0000-0003-3199-3722")),
99
person("Damien", "Arnol", role = "aut",
@@ -12,23 +12,23 @@ Authors@R: c(person("Ricard", "Argelaguet", role = "aut",
1212
person("Danila", "Bredikhin", role = "aut",
1313
email = "[email protected]",
1414
comment = c(ORCID = "https://orcid.org/0000-0001-8089-6983")),
15-
person("Britta", "Velten", role = c("aut", "cre"),
15+
person("Britta", "Velten", role = "aut",
1616
email = "[email protected]",
1717
comment = c(ORCID = "http://orcid.org/0000-0002-8397-3515"))
1818
)
19-
Date: 2018-09-03
20-
License: LGPL-3.0
19+
Date: 2023-01-12
20+
License: file LICENSE
2121
Description: The MOFA2 package contains a collection of tools for training and analysing multi-omic factor analysis (MOFA). MOFA is a probabilistic factor model that aims to identify principal axes of variation from data sets that can comprise multiple omic layers and/or groups of samples. Additional time or space information on the samples can be incorporated using the MEFISTO framework, which is part of MOFA2. Downstream analysis functions to inspect molecular features underlying each factor, vizualisation, imputation etc are available.
2222
Encoding: UTF-8
2323
Depends: R (>= 4.0)
2424
Imports: rhdf5, dplyr, tidyr, reshape2, pheatmap, ggplot2, methods, RColorBrewer, cowplot, ggrepel, reticulate, HDF5Array, grDevices, stats, magrittr, forcats, utils, corrplot, DelayedArray, Rtsne, uwot, basilisk, stringi
25-
Suggests: knitr, testthat, Seurat, ggpubr, foreach, psych, MultiAssayExperiment, SummarizedExperiment, SingleCellExperiment, ggrastr, mvtnorm, GGally, rmarkdown, data.table, tidyverse, BiocStyle, Matrix, markdown
25+
Suggests: knitr, testthat, Seurat, SeuratObject, ggpubr, foreach, psych, MultiAssayExperiment, SummarizedExperiment, SingleCellExperiment, ggrastr, mvtnorm, GGally, rmarkdown, data.table, tidyverse, BiocStyle, Matrix, markdown
2626
biocViews: DimensionReduction, Bayesian, Visualization
2727
URL: https://biofam.github.io/MOFA2/index.html
2828
BugReports: https://github.com/bioFAM/MOFA2
2929
VignetteBuilder: knitr
3030
LazyData: false
3131
StagedInstall: no
3232
NeedsCompilation: yes
33-
RoxygenNote: 7.1.1
33+
RoxygenNote: 7.3.3
3434
SystemRequirements: Python (>=3), numpy, pandas, h5py, scipy, argparse, sklearn, mofapy2

NAMESPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ importFrom(dplyr,left_join)
134134
importFrom(dplyr,mutate)
135135
importFrom(dplyr,summarise)
136136
importFrom(dplyr,top_n)
137-
importFrom(forcats,fct_explicit_na)
137+
importFrom(forcats,fct_na_value_to_level)
138138
importFrom(ggrepel,geom_text_repel)
139139
importFrom(grDevices,colorRampPalette)
140140
importFrom(magrittr,"%>%")

R/basilisk.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# .mofapy2_dependencies <- c(
22
# "h5py==3.1.0",
33
# "pandas==1.2.1",
4-
# "scikit-learn==0.24.1",
5-
# "dtw-python==1.1.10"
4+
# "scikit-learn==0.24.1",
5+
# "dtw-python==1.1.10"
66
# )
77

88
.mofapy2_dependencies <- c(
9-
"python=3.10.5",
10-
"numpy=1.23.1",
11-
"scipy=1.8.1",
12-
"pandas=1.4.3",
13-
"h5py=3.6.0",
14-
"scikit-learn=1.1.1",
15-
"dtw-python=1.2.2"
9+
"python=3.12.12",
10+
"numpy=1.26.4",
11+
"scipy=1.12.0",
12+
"pandas=2.2.1",
13+
"h5py=3.10.0",
14+
"scikit-learn=1.4.0",
15+
"dtw-python=1.3.1"
1616
)
1717

18-
.mofapy2_version <- "0.6.6"
18+
.mofapy2_version <- "0.7.2"
1919

2020
#' @importFrom basilisk BasiliskEnvironment
2121
mofa_env <- BasiliskEnvironment("mofa_env", pkgname="MOFA2", packages=.mofapy2_dependencies, pip = paste0("mofapy2==",.mofapy2_version))

R/calculate_variance_explained.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ plot_variance_explained <- function(object, x = "view", y = "factor", split_by =
277277

278278

279279
# Grid plot with the variance explained per factor and view/group
280-
p1 <- ggplot(r2_mk_df, aes_string(x=x, y=y)) +
281-
geom_tile(aes_string(fill="value"), color="black") +
280+
p1 <- ggplot(r2_mk_df, aes(x=.data[[x]], y=.data[[y]])) +
281+
geom_tile(aes(fill=.data$value), color="black") +
282282
facet_wrap(as.formula(sprintf('~%s',split_by)), nrow=1) +
283283
labs(x="", y="", title="") +
284284
scale_fill_gradientn(colors=c("gray97","darkblue"), guide="colorbar", limits=c(min_r2,max_r2)) +
@@ -313,21 +313,21 @@ plot_variance_explained <- function(object, x = "view", y = "factor", split_by =
313313
max_lim_bplt <- max(r2_m_df$R2)
314314

315315
# Barplot with variance explained per view/group (across all factors)
316-
p2 <- ggplot(r2_m_df, aes_string(x=x, y="R2")) +
316+
p2 <- ggplot(r2_m_df, aes(x=.data[[x]], y=.data$R2)) +
317317
# ggtitle(sprintf("%s\nTotal variance explained per %s", i, x)) +
318318
geom_bar(stat="identity", fill="deepskyblue4", color="black", width=0.9) +
319319
facet_wrap(as.formula(sprintf('~%s',split_by)), nrow=1) +
320320
xlab("") + ylab("Variance explained (%)") +
321321
scale_y_continuous(limits=c(min_lim_bplt, max_lim_bplt), expand=c(0.005, 0.005)) +
322322
theme(
323323
axis.ticks.x = element_blank(),
324-
axis.text.x = element_text(size=rel(1.1), color="black"),
325-
axis.text.y = element_text(size=rel(1.0), color="black"),
326-
axis.title.y = element_text(size=rel(1.0), color="black"),
327-
axis.line = element_line(size=rel(1.0), color="black"),
324+
axis.text.x = element_text(color="black"),
325+
axis.text.y = element_text(color="black"),
326+
axis.title.y = element_text(color="black"),
327+
axis.line = element_line(color="black"),
328328
panel.background = element_blank(),
329329
strip.background = element_blank(),
330-
strip.text = element_text(size=rel(1.0))
330+
strip.text = element_text()
331331
)
332332

333333
# remove facet title
@@ -515,8 +515,8 @@ plot_variance_explained_per_feature <- function(object, view, features = 10,
515515
}
516516

517517
# Grid plot with the variance explained per feature in every group
518-
p <- ggplot(r2_df, aes_string(x = "group", y = "feature")) +
519-
geom_tile(aes_string(fill = "value"), color = "black") +
518+
p <- ggplot(r2_df, aes(x = .data$group, y = .data$feature)) +
519+
geom_tile(aes(fill = .data$value), color = "black") +
520520
guides(fill = guide_colorbar("R2 (%)")) +
521521
labs(x = "", y = "", title = "") +
522522
scale_fill_gradientn(colors=c("gray97","darkblue"), guide="colorbar", limits=c(min_r2, max_r2)) +

R/compare_models.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ compare_elbo <- function(models, log = FALSE, return_data = FALSE) {
121121
# return data
122122
if (return_data) return(df)
123123

124-
gg <- ggplot(df, aes_string(x="model", y="ELBO")) +
124+
gg <- ggplot(df, aes(x=.data$model, y=.data$ELBO)) +
125125
geom_bar(stat="identity", color="black", fill="grey70") +
126126
labs(x="", y="Evidence Lower Bound (ELBO)") +
127127
theme_classic()

R/contribution_scores.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ plot_contribution_scores <- function(object, samples = "all", group_by = NULL, r
111111

112112
to.plot <- scores
113113
if (return_data) return(to.plot)
114-
p <- ggplot(to.plot, aes_string(x="view", y="value")) +
114+
p <- ggplot(to.plot, aes(x=.data$view, y=.data$value)) +
115115
geom_bar(aes(fill=view), stat="identity", color="black") +
116116
facet_wrap(~sample) +
117117
labs(x="", y="Contribution score") +
@@ -129,7 +129,7 @@ plot_contribution_scores <- function(object, samples = "all", group_by = NULL, r
129129

130130
to.plot <- merge(scores, object@samples_metadata[,c("sample",group_by)], by="sample")
131131
if (return_data) return(to.plot)
132-
p <- ggplot(to.plot, aes_string(x="view", y="value")) +
132+
p <- ggplot(to.plot, aes(x=.data$view, y=.data$value)) +
133133
geom_boxplot(aes(fill=view)) +
134134
facet_wrap(as.formula(paste("~", group_by))) +
135135
labs(x="", y="Contribution score") +

R/correlate_covariates.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ summarise_factors <- function(object, df, factors = "all", groups = "all", abs =
140140
# Plot
141141
if (length(unique(factors_df$group))>1) {
142142
to.plot$group <- factor(to.plot$group, levels=groups)
143-
p <- ggplot(to.plot, aes_string(x="group", y="level", fill="value")) +
143+
p <- ggplot(to.plot, aes(x=.data$group, y=.data$level, fill=.data$value)) +
144144
facet_wrap(~factor)
145145
} else {
146-
p <- ggplot(to.plot, aes_string(x="factor", y="level", fill="value"))
146+
p <- ggplot(to.plot, aes(x=.data$factor, y=.data$level, fill=.data$value))
147147
}
148148

149149
p <- p +

R/create_mofa.R

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -370,21 +370,24 @@ create_mofa_from_SingleCellExperiment <- function(sce, groups = NULL, assay = "l
370370
#' Alternatively, a character vector with group assignment for every sample.
371371
#' Default is \code{NULL} (no group structure).
372372
#' @param assays assays to use, default is \code{NULL}, it fetched all assays available
373-
#' @param slot assay slot to be used (default is scale.data).
373+
#' @param layer layer to be used (default is data).
374374
#' @param features a list with vectors, which are used to subset features, with names corresponding to assays; a vector can be provided when only one assay is used
375375
#' @param extract_metadata logical indicating whether to incorporate the metadata from the Seurat object into the MOFA object
376376
#' @return Returns an untrained \code{\link{MOFA}} object
377377
#' @export
378-
create_mofa_from_Seurat <- function(seurat, groups = NULL, assays = NULL, slot = "scale.data", features = NULL, extract_metadata = FALSE) {
378+
create_mofa_from_Seurat <- function(seurat, groups = NULL, assays = NULL, layer = "data", features = NULL, extract_metadata = FALSE) {
379379

380380
# Check is Seurat is installed
381381
if (!requireNamespace("Seurat", quietly = TRUE)) {
382382
stop("Package \"Seurat\" is required but is not installed.", call. = FALSE)
383383
} else {
384384

385+
# Check Seurat version
386+
if (SeuratObject::Version(seurat)$major != 5) stop("Please install Seurat v5")
387+
385388
# Define assays
386389
if (is.null(assays)) {
387-
assays <- Seurat::Assays(seurat)
390+
assays <- SeuratObject::Assays(seurat)
388391
message(paste0("No assays specified, using all assays by default: ", paste(assays,collapse=" ")))
389392
} else {
390393
stopifnot(assays%in%Seurat::Assays(seurat))
@@ -429,7 +432,7 @@ create_mofa_from_Seurat <- function(seurat, groups = NULL, assays = NULL, slot =
429432

430433
# Extract data matrices
431434
data_matrices <- lapply(assays, function(i)
432-
.split_seurat_into_groups(seurat, groups = groups, assay = i, slot = slot, features = features[[i]]))
435+
.split_seurat_into_groups(seurat, groups = groups, assay = i, layer = layer, features = features[[i]]))
433436
names(data_matrices) <- assays
434437

435438
# Create MOFA object
@@ -583,10 +586,10 @@ create_mofa_from_matrix <- function(data, groups = NULL) {
583586
}
584587

585588
# (Hidden) function to split data in Seurat object into a list of matrices
586-
.split_seurat_into_groups <- function(seurat, groups, assay = "RNA", slot = "scale.data", features = NULL) {
587-
data <- Seurat::GetAssayData(object = seurat, assay = assay, slot = slot)
589+
.split_seurat_into_groups <- function(seurat, groups, assay = "RNA", layer = "data", features = NULL) {
590+
data <- SeuratObject::GetAssayData(object = seurat, assay = assay, layer = layer)
588591
if(is.null(data) | any(dim(data) == 0)){
589-
stop(paste("No data present in the slot",slot, "of the assay",assay ,"in the Seurat object."))
592+
stop(paste("No data present in the layer",layer, "of the assay",assay ,"in the Seurat object."))
590593
}
591594
if (!is.null(features)) data <- data[features, , drop=FALSE]
592595
.split_data_into_groups(list(data), groups)[[1]]

R/dimensionality_reduction.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,22 +234,22 @@ plot_dimred <- function(object, method = c("UMAP", "TSNE"), groups = "all", show
234234
if (is.null(stroke)) if (length(unique(df$sample))<1000) { stroke <- 0.5 } else { stroke <- 0 }
235235

236236
# Generate plot
237-
p <- ggplot(df, aes_string(x = "x", y = "y")) +
237+
p <- ggplot(df, aes(x = .data$x, y = .data$y)) +
238238
labs(x = latent_dimensions_names[1], y = latent_dimensions_names[2]) +
239239
theme_classic() +
240240
theme(
241241
axis.text = element_blank(),
242242
axis.title = element_blank(),
243-
axis.line = element_line(color = "black", size = 0.5),
243+
axis.line = element_line(color = "black", linewidth = 0.5),
244244
axis.ticks = element_blank()
245245
)
246246

247247
# Add dots
248248
if (rasterize) {
249249
message("for rasterizing the plot we use ggrastr::geom_point_rast()")
250-
p <- p + ggrastr::geom_point_rast(aes_string(fill = "color_by", shape = "shape_by", alpha = "observed"), size = dot_size, stroke = stroke)
250+
p <- p + ggrastr::geom_point_rast(aes(fill = .data$color_by, shape = .data$shape_by, alpha = .data$observed), size = dot_size, stroke = stroke)
251251
} else {
252-
p <- p + geom_point(aes_string(fill = "color_by", shape = "shape_by", alpha = "observed"), size = dot_size, stroke = stroke)
252+
p <- p + geom_point(aes(fill = .data$color_by, shape = .data$shape_by, alpha = .data$observed), size = dot_size, stroke = stroke)
253253

254254
}
255255

@@ -273,7 +273,7 @@ plot_dimred <- function(object, method = c("UMAP", "TSNE"), groups = "all", show
273273
return(data.medians)
274274
}
275275
) %>% do.call("rbind",.)
276-
p <- p + geom_text_repel(aes_string(label="color_by"), data=labels.loc)
276+
p <- p + geom_text_repel(aes(label=.data$color_by), data=labels.loc)
277277
}
278278

279279

R/enrichment.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,11 @@ plot_enrichment <- function(enrichment.results, factor, alpha = 0.1, max.pathway
267267
tmp$pathway <- factor(tmp$pathway <- rownames(tmp), levels = tmp$pathway[order(tmp$pvalue, decreasing = TRUE)])
268268
tmp$start <- 0
269269

270-
p <- ggplot(tmp, aes_string(x="pathway", y="logp")) +
270+
p <- ggplot(tmp, aes(x=.data$pathway, y=.data$logp)) +
271271
geom_point(size=dot_size) +
272272
geom_hline(yintercept=-log10(alpha), linetype="longdash") +
273273
scale_color_manual(values=c("black","red")) +
274-
geom_segment(aes_string(xend="pathway", yend="start")) +
274+
geom_segment(aes(xend=.data$pathway, yend=.data$start)) +
275275
ylab("-log pvalue") +
276276
coord_flip() +
277277
theme(
@@ -406,10 +406,10 @@ plot_enrichment_detailed <- function(enrichment.results, factor,
406406
tmp$pathway_long_name <- factor(tmp$pathway_long_name, levels=order_pathways)
407407
tmp_filt$pathway_long_name <- factor(tmp_filt$pathway_long_name, levels=order_pathways)
408408

409-
p <- ggplot(tmp, aes_string(x="pathway_long_name", y="feature.statistic")) +
410-
geom_text_repel(aes_string(x="pathway_long_name", y="feature.statistic", label="feature"), size=text_size, color="black", force=1, data=tmp_filt) +
409+
p <- ggplot(tmp, aes(x=.data[["pathway_long_name"]], y=.data[["feature.statistic"]])) +
410+
geom_text_repel(aes(x=.data[["pathway_long_name"]], y=.data[["feature.statistic"]], label=.data$feature), size=text_size, color="black", force=1, data=tmp_filt) +
411411
geom_point(size=0.5, color="lightgrey") +
412-
geom_point(aes_string(x="pathway_long_name", y="feature.statistic"), size=1, color="black", data=tmp_filt) +
412+
geom_point(aes(x=.data[["pathway_long_name"]], y=.data[["feature.statistic"]]), size=1, color="black", data=tmp_filt) +
413413
labs(x="", y="Weight (scaled)", title="") +
414414
coord_flip() +
415415
theme(

0 commit comments

Comments
 (0)