![](../logo.png)
Add cell metadata
addCellMetadata.Rd
Adds cell metadata to the giotto object
Usage
addCellMetadata(
gobject,
spat_unit = NULL,
feat_type = NULL,
new_metadata,
vector_name = NULL,
by_column = FALSE,
column_cell_ID = NULL
)
Arguments
- gobject
giotto object
- spat_unit
spatial unit
- feat_type
feature type
- new_metadata
new cell metadata to use (data.table, data.frame, vector, factor, ...)
- vector_name
(optional) custom name for new metadata column if single vector or factor is provided
- by_column
merge metadata based on cell_ID column in
pDataDT
(default = FALSE)- column_cell_ID
column name of new metadata to use if
by_column = TRUE
Details
You can add additional cell metadata in several manners:
1. Provide a data.frame-like object, vector, or factor with cell annotations in the same order as the cell_ID column in pDataDT(gobject). This is a bit risky and not the most recommended.
2. Provide a data.frame-like object with cell annotations and specify which column contains the cell IDs, these cell IDs need to match with the cell_ID column in pDataDT(gobject)
3. Provide a vector or factor that is named with the cell IDs they correspond to. These names will be matched against the cell_ID column in pDataDT(gobject).
Examples
# dummy matrix
m <- readRDS(system.file("extdata/toy_matrix.RDS", package = "GiottoClass"))
g <- createGiottoObject(m)
#>
#> no external python path or giotto environment was specified, will check if a
#> default python path is available
#>
#> A default python path was found: /usr/bin/python3 and will be used
#> If this is not the correct python path, either
#>
#> 1. use installGiottoEnvironment() to install a local miniconda python
#> environment along with required modules
#>
#> 2. provide an existing python path to python_path to use your own python path
#> which has all modules installed
#> Set options("giotto.use_conda" = FALSE) if python functionalities are not
#> needed
#> Warning: module: pandas was not found with python path: /usr/bin/python3
#> Warning: module: igraph was not found with python path: /usr/bin/python3
#> Warning: module: leidenalg was not found with python path: /usr/bin/python3
#> Warning: module: community was not found with python path: /usr/bin/python3
#> Warning: module: networkx was not found with python path: /usr/bin/python3
#> Warning: module: sklearn was not found with python path: /usr/bin/python3
#> Consider to install these (optional) packages to run all possible Giotto
#> commands for spatial analyses: scran MAST tiff biomaRt trendsceek multinet
#> FactoMineR
#> Giotto does not automatically install all these packages as they are not
#> absolutely required and this reduces the number of dependencies
#> There are non numeric or integer columns for the spatial location input at
#> column position(s): 1
#> The first non-numeric column will be considered as a cell ID to test for
#> consistency with the expression matrix
#> Other non numeric columns will be removed
#> Warning: module: pandas was not found with python path: /usr/bin/python3
#> Warning: module: igraph was not found with python path: /usr/bin/python3
#> Warning: module: leidenalg was not found with python path: /usr/bin/python3
#> Warning: module: community was not found with python path: /usr/bin/python3
#> Warning: module: networkx was not found with python path: /usr/bin/python3
#> Warning: module: sklearn was not found with python path: /usr/bin/python3
pDataDT(g)
#> cell_ID
#> <char>
#> 1: A
#> 2: B
#> 3: C
#> 4: D
#> 5: E
#> 6: F
#> 7: G
#> 8: H
#> 9: I
#> 10: J
# appending a character vector, merge on vector names
v <- seq(10)
names(v) <- sample(LETTERS[seq(10)])
force(v)
#> G E F J D A I H C B
#> 1 2 3 4 5 6 7 8 9 10
g <- addCellMetadata(g, new_metadata = v, by_column = TRUE)
pDataDT(g)
#> Key: <cell_ID>
#> cell_ID v
#> <char> <int>
#> 1: A 6
#> 2: B 10
#> 3: C 9
#> 4: D 5
#> 5: E 2
#> 6: F 3
#> 7: G 1
#> 8: H 8
#> 9: I 7
#> 10: J 4
# appending a data.frame, merge on specified column "ID"
df <- data.frame(
IDS = rev(LETTERS[seq(10)]), # reversed
l = letters[seq(10)],
x = c(rep(TRUE, 5), rep(FALSE, 5))
)
force(df)
#> IDS l x
#> 1 J a TRUE
#> 2 I b TRUE
#> 3 H c TRUE
#> 4 G d TRUE
#> 5 F e TRUE
#> 6 E f FALSE
#> 7 D g FALSE
#> 8 C h FALSE
#> 9 B i FALSE
#> 10 A j FALSE
g <- addCellMetadata(
g,
new_metadata = df,
by_column = TRUE,
column_cell_ID = "IDS"
)
pDataDT(g)
#> Key: <cell_ID>
#> cell_ID v l x
#> <char> <int> <char> <lgcl>
#> 1: A 6 j FALSE
#> 2: B 10 i FALSE
#> 3: C 9 h FALSE
#> 4: D 5 g FALSE
#> 5: E 2 f FALSE
#> 6: F 3 e TRUE
#> 7: G 1 d TRUE
#> 8: H 8 c TRUE
#> 9: I 7 b TRUE
#> 10: J 4 a TRUE