Conceptually, a QFeatures object holds a set of assays, each
composed of a matrix (or array) containing quantitative data
and row annotations (meta-data). The number and the names of the
columns (samples) must always be the same across the assays, but
the number and the names of the rows (features) can vary. The
assays are typically defined as SummarizedExperiment objects. In
addition, a QFeatures object also uses a single DataFrame to
annotate the samples (columns) represented in all the matrices.
The QFeatures class extends the
MultiAssayExperiment::MultiAssayExperiment and inherits all
the functionality of the
MultiAssayExperiment::MultiAssayExperiment class.
A typical use case for such QFeatures object is to represent
quantitative proteomics (or metabolomics) data, where different
assays represent quantitation data at the PSM (the main assay),
peptide and protein level, and where peptide values are computed
from the PSM data, and the protein-level data is calculated based
on the peptide-level values. The largest assay (the one with the
highest number of features, PSMs in the example above) is
considered the main assay.
The recommended way to create QFeatures objects is the use the
readQFeatures() function, that creates an instance from tabular
data. The QFeatures constructor can be used to create objects
from their bare parts. It is the user's responsability to make
sure that these match the class validity requirements.
Usage
QFeatures(..., assayLinks = NULL)
# S4 method for class 'QFeatures'
show(object)
# S3 method for class 'QFeatures'
plot(x, interactive = FALSE, ...)
# S4 method for class 'QFeatures,ANY,ANY,ANY'
x[i, j, ..., drop = TRUE]
# S4 method for class 'QFeatures,character,ANY,ANY'
x[i, j, k, ..., drop = TRUE]
# S4 method for class 'QFeatures'
c(x, ...)
# S4 method for class 'QFeatures'
dims(x, use.names = TRUE)
# S4 method for class 'QFeatures'
nrows(x, use.names = TRUE)
# S4 method for class 'QFeatures'
ncols(x, use.names = TRUE)
# S4 method for class 'QFeatures'
rowData(x, use.names = TRUE, ...)
# S4 method for class 'QFeatures,DataFrameList'
rowData(x) <- value
# S4 method for class 'QFeatures,ANY'
rowData(x) <- value
rbindRowData(object, i)
selectRowData(x, rowvars)
rowDataNames(x)
# S4 method for class 'QFeatures,character'
names(x) <- value
addAssay(x, y, name, assayLinks)
removeAssay(x, i)
replaceAssay(x, y, i)
# S4 method for class 'QFeatures,ANY,ANY'
x[[i, j, ...]] <- value
# S4 method for class 'QFeatures'
updateObject(object, ..., verbose = FALSE)
dropEmptyAssays(object, dims = 1:2)Arguments
- ...
See
MultiAssayExperimentfor details. Forplot, further arguments passed toigraph::plot.igraph.- assayLinks
An optional AssayLinks.
- object
An instance of class QFeatures.
- x
An instance of class QFeatures.
- interactive
A
logical(1). IfTRUE, an interactive graph is generated usingplotly. Else, a static plot usingigraphis generated. We recommend interactive exploration when theQFeaturesobject contains more than 50 assays.- i
An indexing vector. See the corresponding section in the documentation for more details.
- j
character(),logical(), ornumeric()vector for subsetting bycolDatarows.- drop
logical (default
TRUE) whether to drop empty assay elements in theExperimentList.- k
character(),logical(), ornumeric()vector for subsetting by assays- use.names
A
logical(1)indicating whether the rownames of each assay should be propagated to the correspondingrowData.- value
The values to use as a replacement. See the corresponding section in the documentation for more details.
- rowvars
A
character()with the names of therowDatavariables (columns) to retain in any assay.- y
An object that inherits from
SummarizedExperimentor a named list of assays. Whenyis a list, each element must inherit from aSummarizedExperimentand the names of the list are used as the names of the assays to add. Hence, the list names must be unique and cannot overlap with the names of the assays already present inx.- name
A
character(1)naming the single assay. Ignored ifyis a list of assays.- verbose
logical (default FALSE) whether to print extra messages
- dims
numeric()that defines the dimensions to consider to drop empty assays. 1 for rows (i.e. assays without any features) and 2 for columns (i.e. assays without any samples). Default is1:2. Any value other that 1 and/or 2 will trigger an error.
Constructors
QFeatures(..., assayLinks)allows the manual construction of objects. It is the user's responsability to make sure these comply. The arguments in...are those documented inMultiAssayExperiment::MultiAssayExperiment(). For details aboutassayLinks, see AssayLinks. An example is shown below.The
readQFeatures()function constructs aQFeaturesobject from text-based spreadsheet or adata.frameused to generate an assay. See the function manual page for details and an example.
Accessors
The
QFeaturesclass extends the MultiAssayExperiment::MultiAssayExperiment class and inherits all its accessors and replacement methods.The
rowDatamethod returns aDataFrameListcontaining therowDatafor each assay of theQFeaturesobject. On the other hand,rowDatacan be modified usingrowData(x) <- value, wherevalueis a list of tables that can be coerced toDFrametables. The names ofvaluepoint to the assays for which therowDatamust be replaced. The column names of each table are used to replace the data in the existingrowData. If the column name does not exist, a new column is added to therowData.The
rbindRowDatafunctions returns aDFrametable that contains the row bindedrowDatatables from the selected assays. In this context,iis acharacter(),integer()orlogical()object for subsetting assays. Only rowData variables that are common to all assays are kept.The
rowDataNamesaccessor returns a list with therowDatavariable names.The
longForm()accessor takes aQFeaturesinstance and returns it in a long tidyDataFrame, where each quantitative value is reported on a separate line.
Adding, removing and replacing assays
The
aggregateFeatures()function creates a new assay by aggregating features of an existing assay.addAssay(x, y, name, assayLinks): Adds one or more new assay(s)yto theQFeaturesinstancex.nameis acharacter(1)naming the assay if only one assay is provided, and is ignored ifyis a list of assays.assayLinksis an optional AssayLinks. ThecolData(y)is automatically added tocolData(x)by matching sample names, that iscolnames(y). If the samples are not present inx, the rows ofcolData(x)are extended to account for the new samples. Be aware that conflicting information between thecolData(y)and thecolData(x)will result in an error.removeAssay(x, i): Removes one or more assay(s) from theQFeaturesinstancex. In this context,iis acharacter(),integer()orlogical()that indicates which assay(s) to remove.replaceAssay(x, y, i): Replaces one or more assay(s) from theQFeaturesinstancex. In this context,iis acharacter(),integer()orlogical()that indicates which assay(s) to replace. TheAssayLinksfrom or to any replaced assays are automatically removed, unless the replacement has the same dimension names (columns and row, order agnostic). Be aware that conflicting information betweencolData(y)andcolData(x)will result in an error.x[[i]] <- value: a generic method for adding (wheniis not innames(x)), removing (whenvalueis null) or replacing (wheniis innames(x)). Note that the argumentsjand...from the S4 replacement method signature are not allowed.
Subsetting
QFeatures object can be subset using the
x[i, j, k, drop = TRUE]paradigm. In this context,iis acharacter(),integer(),logical()orGRanges()object for subsetting by rows. See the argument descriptions for details on the remaining arguments.The
subsetByFeature()function can be used to subset aQFeaturesobject using one or multiple feature names that will be matched across different assays, taking the aggregation relation between assays.The
selectRowData(x, rowvars)function can be used to select a limited number ofrowDatacolumns of interest named inrowvarsin thexinstance of classQFeatures. All other variables thanrowvarswill be dropped. In case an element inrowvarsisn't found in anyrowDatavariable, a message is printed.The
dropEmptyAssays(object, dims)function removes empty assays from aQFeatures. Empty assays are defined as having 0 rows and/or 0 columns, as defined by thedimsargument.
See also
The
readQFeatures()constructor and theaggregateFeatures()function. The QFeatures vignette provides an extended example.The QFeatures-filtering manual page demonstrates how to filter features based on their rowData.
The missing-data manual page to manage missing values in
QFeaturesobjects.The QFeatures-processing and
aggregateFeatures()manual pages and Processing vignette describe common quantitative data processing methods using in quantitative proteomics.
Examples
## ------------------------
## An empty QFeatures object
## ------------------------
QFeatures()
#> An empty instance of class QFeatures (type: bulk)
## -----------------------------------
## Creating a QFeatures object manually
## -----------------------------------
## two assays (matrices) with matching column names
m1 <- matrix(1:40, ncol = 4)
m2 <- matrix(1:16, ncol = 4)
sample_names <- paste0("S", 1:4)
colnames(m1) <- colnames(m2) <- sample_names
rownames(m1) <- letters[1:10]
rownames(m2) <- letters[1:4]
## two corresponding feature metadata with appropriate row names
df1 <- DataFrame(Fa = 1:10, Fb = letters[1:10],
row.names = rownames(m1))
df2 <- DataFrame(row.names = rownames(m2))
(se1 <- SummarizedExperiment(m1, df1))
#> class: SummarizedExperiment
#> dim: 10 4
#> metadata(0):
#> assays(1): ''
#> rownames(10): a b ... i j
#> rowData names(2): Fa Fb
#> colnames(4): S1 S2 S3 S4
#> colData names(0):
(se2 <- SummarizedExperiment(m2, df2))
#> class: SummarizedExperiment
#> dim: 4 4
#> metadata(0):
#> assays(1): ''
#> rownames(4): a b c d
#> rowData names(0):
#> colnames(4): S1 S2 S3 S4
#> colData names(0):
## Sample annotation (colData)
cd <- DataFrame(Var1 = rnorm(4),
Var2 = LETTERS[1:4],
row.names = sample_names)
el <- list(assay1 = se1, assay2 = se2)
fts1 <- QFeatures(el, colData = cd)
fts1
#> An instance of class QFeatures (type: bulk) with 2 sets:
#>
#> [1] assay1: SummarizedExperiment with 10 rows and 4 columns
#> [2] assay2: SummarizedExperiment with 4 rows and 4 columns
fts1[[1]]
#> class: SummarizedExperiment
#> dim: 10 4
#> metadata(0):
#> assays(1): ''
#> rownames(10): a b ... i j
#> rowData names(2): Fa Fb
#> colnames(4): S1 S2 S3 S4
#> colData names(0):
fts1[["assay1"]]
#> class: SummarizedExperiment
#> dim: 10 4
#> metadata(0):
#> assays(1): ''
#> rownames(10): a b ... i j
#> rowData names(2): Fa Fb
#> colnames(4): S1 S2 S3 S4
#> colData names(0):
## Rename assay
names(fts1) <- c("se1", "se2")
## Add an assay
fts1 <- addAssay(fts1, se1[1:2, ], name = "se3")
## Get the assays feature metadata
rowData(fts1)
#> DataFrameList of length 3
#> names(3): se1 se2 se3
## Keep only the Fa variable
selectRowData(fts1, rowvars = "Fa")
#> An instance of class QFeatures (type: bulk) with 3 sets:
#>
#> [1] se1: SummarizedExperiment with 10 rows and 4 columns
#> [2] se2: SummarizedExperiment with 4 rows and 4 columns
#> [3] se3: SummarizedExperiment with 2 rows and 4 columns
## -----------------------------------
## See ?readQFeatures to create a
## QFeatures object from a data.frame
## or spreadsheet.
## -----------------------------------
