Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ docs
^\.github$
.editorconfig
.git
^doc$
^Meta$
4 changes: 2 additions & 2 deletions .github/workflows/check-bioc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ jobs:
# cd preprocessCore
# R CMD INSTALL --configure-args="--disable-threading" .

- name: Manually install latest RforMassSpectrometry/QFeatures
- name: Manually install from a branch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we will just need to revert this change before merging.

run: |
BiocManager::install("RforMassSpectrometry/QFeatures")
remotes::install_github("RforMassSpectrometry/QFeatures", ref = "typeMetadata")
shell: Rscript {0}

- name: Session info
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
*.RData
.Ruserdata
*.Rproj
tests/testthat/_snaps
/doc/
/Meta/
22 changes: 19 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
# scp 1.17

## scp 1.17.0

- New Bioconductor 3.21 devel

## scp 1.17.1

- Deprecate `aggregateFeaturesOverAssays`, use
`QFeatures::aggregateFeatures` instead.

## scp 1.17.0

- New Bioconductor 3.21 devel
## scp 1.17.2

- Recommend the use of `SummarizedExperiment` instead of
`SingleCellExperiment` for performance reasons.
- All functions are now compatible with `SummarizedExperiment`.
- `data("scp1")` now contains `SummarizedExperiment` objects.
- By default, `readSCP` and `readSCPfromDIANN` now create
QFeatures objects that contain `SummarizedExperiment` objects.
- `readSCP` and `readSCPfromDIANN` have a new parameter:
`experimentsAsSce` that indicate if the QFeatures should
contain `SingleCellExperiment`, default is `FALSE`.
- `readSCP` and `readSCPfromDIANN` now return a QFeatures of type
"scp".
- `scpModelWorkflow` now automatically convert a `SummarizedExperiment`
to a `SingleCellExperiment`.

# scp 1.16

Expand Down
10 changes: 5 additions & 5 deletions R/ScpModel-Class.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
##' @description
##'
##' An `ScpModel` object must be always stored in the `metadata()` of
##' an object that inherits from the `SingleCellExperiment` class. The
##' an object that inherits from the `SummarizedExperiment` class. The
##' `ScpModel` object should **never be accessed directly** by the
##' user. Instead, we provide several setter function to retrieve
##' information that may be useful to the user.The `ScpModel` class
Expand All @@ -18,10 +18,10 @@
##' - `scpModelFormula`: a `formula` object controlling which
##' variables are to be modelled.
##' - `scpModelInputIndex`: a `numeric(1)`, selecting the assay to use
##' in the `SingleCellExperiment` object as input matrix. Note that
##' in the `SummarizedExperiment` object as input matrix. Note that
##' this slot serves as a pointer, meaning that the quantitative
##' data is not duplicated. Any change to the assay in the
##' `SingleCellExperiment` will impact the estimation of the
##' `SummarizedExperiment` will impact the estimation of the
##' `ScpModel` object.
##' - `scpModelFilterThreshold`: A `numeric(1)` indicating the minimal
##' n/p ratio required for a feature to be included in further model
Expand All @@ -37,7 +37,7 @@
##' Each slot has a getter function associated:
##'
##' - `scpModelNames()`: returns a vector of names of `ScpModel`
##' objects stored in the `SingleCellExperiment` object.
##' objects stored in the `SummarizedExperiment` object.
##' - `scpModelFormula()`: returns the `formula` slot of the `ScpModel`
##' within an object that inherits from the `SummarizedExperiment`
##' class.
Expand Down Expand Up @@ -354,7 +354,7 @@ scpModelEffectNames <- function(object, name) {
##' @rdname ScpModel-class
##'
##' @param object An object that inherits from the
##' `SingleCellExperiment` class.
##' `SummarizedExperiment` class.
##'
##' @param value An `numeric(1)`, the new value for the n/p ratio
##' threshold
Expand Down
4 changes: 2 additions & 2 deletions R/ScpModel-ComponentAnalysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ NULL
##' @name ScpModel-ComponentAnalysis
##'
##' @param object An object that inherits from the
##' `SingleCellExperiment` class. It must contain an estimated
##' `SummarizedExperiment` class. It must contain an estimated
##' `ScpModel` in its metadata.
##'
##' @param method A `character()` indicating which approach(es) to use
Expand Down Expand Up @@ -234,7 +234,7 @@ scpComponentAnalysis <- function(object,
## will use [base::svd()]. If "auto", the function uses "nipals"
## if the data contain missing values and "svd" otherwise.
## @param object An object that inherits from the
## `SingleCellExperiment` class. It must contain an estimated
## `SummarizedExperiment` class. It must contain an estimated
## `ScpModel` in its metadata. Ignored when pcaFun != "auto".
## @param name A `character(1)` providing the name to use to retrieve
## the model results. When retrieving a model and `name` is
Expand Down
2 changes: 1 addition & 1 deletion R/ScpModel-DifferentialAnalysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ NULL
##' @name ScpModel-DifferentialAnalysis
##'
##' @param object An object that inherits from the
##' `SingleCellExperiment` class. It must contain an estimated
##' `SummarizedExperiment` class. It must contain an estimated
##' `ScpModel` in its metadata.
##'
##' @param coefficients A `character()` vector with coefficient names
Expand Down
17 changes: 9 additions & 8 deletions R/ScpModel-Utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ scpAnnotateResults <- function(tableList,
##'
##' The function uses the data modelling output to generate corrected
##' data that can be used for downstream analysis. The input
##' is expected to be a `SingleCellExperiment` object that contains an
##' is expected to be a `SummarizedExperiment` object that contains an
##' estimated `ScpModel`. There are two approaches:
##'
##' - `scpKeepEffect()`: keep the effects of interests. The
Expand All @@ -95,7 +95,7 @@ scpAnnotateResults <- function(tableList,
##' reconstruct the data are the ones that are not removed when
##' performing batch correction (see examples).
##'
##' The function returns a new `SingleCellExperiment` that contains an
##' The function returns a new `SummarizedExperiment` that contains an
##' assay with the batch corrected data. Note that the 'ScpModel` is
##' erased in this new object.
##'
Expand All @@ -115,7 +115,7 @@ NULL
##' @name ScpModel-DataCorrection
##'
##' @param object An object that inherits from the
##' `SingleCellExperiment` class. It must contain an estimated
##' `SummarizedExperiment` class. It must contain an estimated
##' `ScpModel` in its metadata
##'
##' @param effects A `character()` vector. For `scpKeepEffect()`,
Expand Down Expand Up @@ -191,6 +191,8 @@ scpRemoveBatchEffect <- function(object, effects = NULL,
##'
##' @author Laurent Gatto and Christophe Vanderaa
##'
##' @importFrom methods as
##' @import SingleCellExperiment
##' @export
##'
##' @examples
Expand All @@ -209,11 +211,10 @@ scpRemoveBatchEffect <- function(object, effects = NULL,
##' leduc_minimal <- runTSNE(leduc_minimal, dimred = "ASCA_SampleType")
##' plotTSNE(leduc_minimal, colour_by = "SampleType")
addReducedDims <- function(sce, x) {
if (!inherits(sce, "SingleCellExperiment"))
stop(
"'sce' must be a SingleCellExperiment object. Transform ",
"your data using 'as(sce, \"SingleCellExperiment\")'."
)
if (!inherits(sce, "SingleCellExperiment")) {
sce <- as(sce, "SingleCellExperiment")
message("Convert object to SingleCellExperiment")
}
pcList <- List(lapply(x, .getPCs))
reducedDims(sce) <- c(reducedDims(sce), pcList)
sce
Expand Down
2 changes: 1 addition & 1 deletion R/ScpModel-VarianceAnalysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ NULL
##' @name ScpModel-VarianceAnalysis
##'
##' @param object An object that inherits from the
##' `SingleCellExperiment` class. It must contain an estimated
##' `SummarizedExperiment` class. It must contain an estimated
##' `ScpModel` in its metadata.
##'
##' @param name A `character(1)` providing the name to use to retrieve
Expand Down
8 changes: 6 additions & 2 deletions R/ScpModel-Workflow.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
##' @section Input data:
##'
##' The main input is `object` that inherits from the
##' `SingleCellExperiment` class. The quantitative data will be
##' `SummarizedExperiment` class. The quantitative data will be
##' retrieve using `assay(object)`. If `object` contains multiple
##' assays, you can specify which assay to take as input thanks to the
##' argument `i`, the function will then assume `assay(object, i)` as
Expand Down Expand Up @@ -120,7 +120,7 @@ NULL
##' @name ScpModel-Workflow
##'
##' @param object An object that inherits from the
##' `SingleCellExperiment` class.
##' `SummarizedExperiment` class.
##'
##' @param formula A `formula` object controlling which variables are
##' to be modelled.
Expand All @@ -142,6 +142,10 @@ scpModelWorkflow <- function(object, formula,
i = 1,
name = "model",
verbose = TRUE) {
if (!inherits(object, "SingleCellExperiment")) {
object <- as(object, "SingleCellExperiment")
message("`object` converted to SingleCellExperiment.")
}
if (name %in% names(metadata(object))) {
warning("An element called '", name, "' is already present ",
"in the metadata. The associated content will be ",
Expand Down
10 changes: 5 additions & 5 deletions R/compute_metrics.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@
(cumsum(x[order(x)]) / seq_along(x))[order(order(x))]
}

## @param x A `SingleCellExperiment` object
## @param x A `SummarizedExperiment` object
##
## @param group A `factor()` that indicates how features (rows) should
## be grouped. The CVs are computed for each group separately.
##
## @rdname medianCVperCell
featureCV <- function(x, group, na.rm = TRUE, norm = "none", nobs = 2, ...) {
## Check object
if (!inherits(x, "SingleCellExperiment"))
stop("'x' must inherit from a 'SingleCellExperiment'")
if (!inherits(x, "SummarizedExperiment"))
stop("'x' must inherit from a 'SummarizedExperiment'")
## Optional normalization(s)
if (identical(norm, "SCoPE2")) {
xnorm <- .normalizeSCP(x, method = "div.median")
Expand Down Expand Up @@ -683,14 +683,14 @@ jaccardIndex <- function(object, i, by = NULL) {
##'
##' ## Simulate data
##' ## 1000 features in 100 cells
##' library(SingleCellExperiment)
##' library(SummarizedExperiment)
##' id <- matrix(FALSE, 1000, 1000)
##' id[sample(1:length(id), 5000)] <- TRUE
##' dimnames(id) <- list(
##' paste0("feat", 1:1000),
##' paste0("cell", 1:1000)
##' )
##' sce <- SingleCellExperiment(assays = List(id))
##' sce <- SummarizedExperiment(assays = List(id))
##' sim <- QFeatures(experiments = List(id = sce))
##' sim$batch <- rep(1:100, each = 10)
##' sim$SampleType <- rep(c("A", "B"), each = 500)
Expand Down
32 changes: 21 additions & 11 deletions R/readSCP.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@
##' [readQFeatures()] or [readQFeaturesFromDIANN()]. See these
##' respective manual pages for details.
##'
##' @param experimentsAsSce A `logical(1)` indicating whether the
##' `QFeatures` object should be composed of `SingleCellExperiment`
##' objects. By default: `FALSE`, the `QFeatures` object will be composed
##' of `SummarizedExperiment` objects. Note that using
##' `SingleCellExperiment` can impact the performance.
##'
##' @return An instance of class `SingleCellExperiment` or a
##' `QFeatures`, composed of `SingleCellExperiment` objects.
##' `QFeatures`, composed of `SingleCellExperiment` or
##' `SummarizedExperiment` objects.
##'
##' @note The `SingleCellExperiment` class is built on top of the
##' `RangedSummarizedExperiment` class. This means that some column names
Expand Down Expand Up @@ -67,24 +74,28 @@
##' readSCP(assayData = mqScpData,
##' colData = sampleAnnotation,
##' runCol = "Raw.file")
readSCP <- function(...) {
readSCP <- function(..., experimentsAsSce = FALSE) {
ans <- readQFeatures(...)
el <- ExperimentList(lapply(experiments(ans),
if (experimentsAsSce) {
el <- ExperimentList(lapply(experiments(ans),
as, "SingleCellExperiment"))
experiments(ans) <- el
ans
experiments(ans) <- el
}
setQFeaturesType(ans, "scp")
}


##' @export
##'
##' @rdname readSCP
readSCPfromDIANN <- function(...) {
readSCPfromDIANN <- function(..., experimentsAsSce = FALSE) {
ans <- readQFeaturesFromDIANN(...)
el <- ExperimentList(lapply(experiments(ans),
if (experimentsAsSce) {
el <- ExperimentList(lapply(experiments(ans),
as, "SingleCellExperiment"))
experiments(ans) <- el
ans
experiments(ans) <- el
}
setQFeaturesType(ans, "scp")
}

##' @export
Expand All @@ -93,6 +104,5 @@ readSCPfromDIANN <- function(...) {
readSingleCellExperiment <- function(...) {
## Read data as SummarizedExperiment
sce <- readSummarizedExperiment(...)
sce <- as(sce, "SingleCellExperiment")
return(sce)
as(sce, "SingleCellExperiment")
}
6 changes: 3 additions & 3 deletions R/transform.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

####---- Internal functions ----####

## Internal function that normalizes SingleCellExperiment object using
## Internal function that normalizes SummarizedExperiment object using
## proteomics normalization methods available in MsCoreUtils::normalize_matrix
##' @importFrom MsCoreUtils normalize_matrix
.normalizeSCP <- function(x, method, ...) {
if(!inherits(x, "SingleCellExperiment"))
stop("The assay must be a 'SingleCellExperiment' object.")
if(!inherits(x, "SummarizedExperiment"))
stop("The assay must be a 'SummarizedExperiment' object.")
e <- normalize_matrix(assay(x), method, ...)
rownames(e) <- rownames(assay(x))
colnames(e) <- colnames(assay(x))
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ spectrometry-based single cell proteomics data. It relies on the
[`QFeatures`](https://rformassspectrometry.github.io/QFeatures/)
package to manage and process
[`SingleCellExperiment`](http://bioconductor.org/packages/release/bioc/html/SingleCellExperiment.html)
or [`SummarizedExperiment`](http://bioconductor.org/packages/release/bioc/html/SummarizedExperiment.html)
objects.

<img
Expand Down
Binary file modified data/scp1.rda
Binary file not shown.
Loading
Loading