Skip to content

Commit 9becd94

Browse files
authored
Merge pull request #214 from cole-trapnell-lab/develop
0.2.0 release
2 parents 6c31463 + 6dfdd9b commit 9becd94

39 files changed

+1100
-477
lines changed

.travis.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ before_install:
99
r:
1010
- bioc-devel
1111
- bioc-release
12+
r_packages:
13+
- covr
1214
r_github_packages:
1315
- VPetukhov/ggrastr
16+
- cole-trapnell-lab/leidenbase
1417
r_binary_packages:
1518
- assertthat
1619
- dplyr
1720
- ggplot2
1821
- ggrepel
19-
- htmlwidgets
2022
- igraph
2123
- irlba
2224
- lmtest
@@ -33,9 +35,7 @@ r_binary_packages:
3335
- purrr
3436
- RANN
3537
- Rcpp
36-
- RcppParallel
3738
- reshape2
38-
- reticulate
3939
- RhpcBLASctl
4040
- shiny
4141
- slam

DESCRIPTION

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: monocle3
22
Title: Clustering, differential expression, and trajectory analysis for single-
33
cell RNA-Seq
4-
Version: 0.1.3
4+
Version: 0.2.0
55
Authors@R:
66
person(given = "Hannah",
77
family = "Pliner",
@@ -35,16 +35,17 @@ Depends:
3535
SingleCellExperiment
3636
Imports:
3737
assertthat (>= 0.2.1),
38+
batchelor,
3839
BiocGenerics (>= 0.28.0),
3940
DelayedArray (>= 0.8.0),
4041
DelayedMatrixStats (>= 1.4.0),
4142
dplyr (>= 0.8.0.1),
4243
ggplot2 (>= 3.1.1),
4344
ggrepel (>= 0.8.1),
4445
grr,
45-
htmlwidgets (>= 1.3),
4646
igraph (>= 1.2.4),
4747
irlba (>= 2.3.3),
48+
leidenbase,
4849
limma (>= 3.38.3),
4950
lmtest (>= 0.9-36),
5051
MASS (>= 7.3-51.4),
@@ -57,14 +58,12 @@ Imports:
5758
plotly (>= 4.9.0),
5859
plyr (>= 1.8.4),
5960
proxy (>= 0.4-23),
60-
pryr (>= 0.1.4),
6161
pscl (>= 1.5.2),
6262
purrr (>= 0.3.2),
6363
RANN (>= 2.6.1),
64+
RColorBrewer,
6465
Rcpp (>= 1.0.1),
65-
RcppParallel,
6666
reshape2 (>= 1.4.3),
67-
reticulate (>= 1.11.1),
6867
rsample (>= 0.0.5),
6968
RhpcBLASctl,
7069
Rtsne (>= 0.15),
@@ -81,11 +80,14 @@ Imports:
8180
viridis (>= 0.5.1)
8281
Suggests:
8382
testthat (>= 2.1.0),
83+
pryr (>= 0.1.4),
8484
ggrastr,
8585
knitr,
8686
rmarkdown,
87-
spelling
87+
spelling,
88+
scran
8889
VignetteBuilder: knitr
8990
Language: en-US
9091
Remotes:
91-
VPetukhov/ggrastr
92+
VPetukhov/ggrastr,
93+
cole-trapnell-lab/leidenbase

NAMESPACE

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export("pData<-")
55
export("principal_graph<-")
66
export("principal_graph_aux<-")
77
export(aggregate_gene_expression)
8+
export(align_cds)
89
export(choose_cells)
910
export(choose_graph_segments)
1011
export(clear_cds_slots)
@@ -21,6 +22,7 @@ export(fData)
2122
export(find_gene_modules)
2223
export(fit_models)
2324
export(generate_garnett_marker_file)
25+
export(get_citations)
2426
export(graph_test)
2527
export(learn_graph)
2628
export(load_a549)

NEWS.md

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
2+
# monocle3 0.2.0
3+
4+
### Major changes
5+
* Added mutual-nearest-neighbor batch correction (MNNCorrect).
6+
* Switched to leiden-based clustering, dropped reticulate/python dependency.
7+
* Added a mechanism to get the citations used during an analysis get_citations().
8+
9+
### Other Changes
10+
* Added non-standard color options for plot_cell_3d.
11+
* Added norm_method = 'none' option for importing pre-normalized data.
12+
13+
### Bug fixes
14+
* Fixed a bug that effected cell size in plot_cells_3d.
15+
* Added a check for illegal characters in generate_garnett_marker_file.
16+
* Fixed a bug in the alpha parameter in plot_cells.
17+
* Fixed multiple minor reported bugs.
18+
119
# monocle3 0.1.3
220

321
### Changes

R/alignment.R

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#' Align cells from different groups within a cds
2+
#'
3+
#' @description Data sets that contain cells from different groups often
4+
#' benefit from alignment to subtract differences between them. Alignment
5+
#' can be used to remove batch effects, subtract the effects of treatments,
6+
#' or even potentially compare across species.
7+
#' \code{align_cds} executes alignment and stores these adjusted coordinates.
8+
#'
9+
#' This function can be used to subtract both continuous and discrete batch
10+
#' effects. For continuous effects, \code{align_cds} fits a linear model to the
11+
#' cells' PCA or LSI coordinates and subtracts them using Limma. For discrete
12+
#' effects, you must provide a grouping of the cells, and then these groups are
13+
#' aligned using Batchelor, a "mutual nearest neighbor" algorithm described in:
14+
#'
15+
#' Haghverdi L, Lun ATL, Morgan MD, Marioni JC (2018). "Batch effects in
16+
#' single-cell RNA-sequencing data are corrected by matching mutual nearest
17+
#' neighbors." Nat. Biotechnol., 36(5), 421-427. doi: 10.1038/nbt.4091
18+
#'
19+
#' @param cds the cell_data_set upon which to perform this operation
20+
#' @param preprocess_method a string specifying the low-dimensional space
21+
#' in which to perform alignment, currently either PCA or LSI. Default is
22+
#' "PCA".
23+
#' @param residual_model_formula_str NULL or a string model formula specifying
24+
#' any effects to subtract from the data before dimensionality reduction.
25+
#' Uses a linear model to subtract effects. For non-linear effects, use
26+
#' alignment_group. Default is NULL.
27+
#' @param alignment_group String specifying a column of colData to use for
28+
#' aligning groups of cells. The column specified must be a factor.
29+
#' Alignment can be used to subtract batch effects in a non-linear way.
30+
#' For correcting continuous effects, use residual_model_formula_str.
31+
#' Default is NULL.
32+
#' @param alignment_k The value of k used in mutual nearest neighbor alignment
33+
#' @param verbose Whether to emit verbose output during dimensionality
34+
#' reduction
35+
#' @param ... additional arguments to pass to limma::lmFit if
36+
#' residual_model_formula is not NULL
37+
#' @return an updated cell_data_set object
38+
#' @export
39+
align_cds <- function(cds,
40+
preprocess_method = c("PCA", "LSI"),
41+
alignment_group=NULL,
42+
alignment_k=20,
43+
residual_model_formula_str=NULL,
44+
verbose=FALSE,
45+
...){
46+
assertthat::assert_that(
47+
tryCatch(expr = ifelse(match.arg(preprocess_method) == "",TRUE, TRUE),
48+
error = function(e) FALSE),
49+
msg = "preprocess_method must be one of 'PCA' or 'LSI'")
50+
preprocess_method <- match.arg(preprocess_method)
51+
52+
preproc_res <- reducedDims(cds)[[preprocess_method]]
53+
54+
if (!is.null(residual_model_formula_str)) {
55+
if (verbose) message("Removing residual effects")
56+
X.model_mat <- Matrix::sparse.model.matrix(
57+
stats::as.formula(residual_model_formula_str),
58+
data = colData(cds),
59+
drop.unused.levels = TRUE)
60+
61+
fit <- limma::lmFit(Matrix::t(preproc_res), X.model_mat, ...)
62+
beta <- fit$coefficients[, -1, drop = FALSE]
63+
beta[is.na(beta)] <- 0
64+
preproc_res <- Matrix::t(as.matrix(Matrix::t(preproc_res)) -
65+
beta %*% Matrix::t(X.model_mat[, -1]))
66+
}
67+
68+
if(!is.null(alignment_group)) {
69+
message(paste("Aligning cells from different batches using Batchelor.",
70+
"\nPlease remember to cite:\n\t Haghverdi L, Lun ATL,",
71+
"Morgan MD, Marioni JC (2018). 'Batch effects in",
72+
"single-cell RNA-sequencing data are corrected by matching",
73+
"mutual nearest neighbors.' Nat. Biotechnol., 36(5),",
74+
"421-427. doi: 10.1038/nbt.4091"))
75+
corrected_PCA = batchelor::fastMNN(as.matrix(preproc_res),
76+
batch=colData(cds)[,alignment_group],
77+
k=alignment_k,
78+
cos.norm=FALSE,
79+
pc.input = TRUE)
80+
preproc_res = corrected_PCA$corrected
81+
cds <- add_citation(cds, "MNN_correct")
82+
}
83+
84+
reducedDims(cds)[["Aligned"]] <- as.matrix(preproc_res)
85+
86+
cds
87+
}

R/cell_data_set.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,13 @@ new_cell_data_set <- function(expression_data,
104104
"named 'gene_short_name' for certain functions."))
105105
}
106106

107-
sce <- SingleCellExperiment(list(counts=as(expression_data, "dgCMatrix")),
107+
sce <- SingleCellExperiment(list(counts=methods::as(expression_data, "dgCMatrix")),
108108
rowData = gene_metadata,
109109
colData = cell_metadata)
110110

111111
cds <- methods::new("cell_data_set",
112112
assays = SummarizedExperiment::Assays(
113-
list(counts=as(expression_data, "dgCMatrix"))),
113+
list(counts=methods::as(expression_data, "dgCMatrix"))),
114114
colData = colData(sce),
115115
int_elementMetadata =sce@int_elementMetadata,
116116
int_colData = sce@int_colData,

0 commit comments

Comments
 (0)