Skip to contents

Adds feature metadata to the giotto object

Usage

addFeatMetadata(
  gobject,
  feat_type = NULL,
  spat_unit = NULL,
  new_metadata,
  vector_name = NULL,
  by_column = FALSE,
  column_feat_ID = NULL
)

Arguments

gobject

giotto object

feat_type

feature type

spat_unit

spatial unit

new_metadata

new metadata to use)

vector_name

(optional) custom name if you provide a single vector

by_column

merge metadata based on feat_ID column in fDataDT

column_feat_ID

column name of new metadata to use if by_column = TRUE

Value

giotto object

Details

You can add additional feature metadata in several manners:

  • 1. Provide a data.table or data.frame with feature annotations in the same order as the feat_ID column in fDataDT(gobject) This is a bit risky and not the most recommended.

  • 2. Provide a data.table or data.frame with feature annotations and specify which column contains the feature IDs, these feature IDs need to match with the feat_ID column in fDataDT(gobject)

  • 3. Provide a vector or factor that is named with the feature IDs they correspond to. These names will be matched against the feat_ID column in fDataDT(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

fDataDT(g)
#>     feat_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)
#>  b  g  c  f  h  e  a  d  j  i 
#>  1  2  3  4  5  6  7  8  9 10 

g <- addFeatMetadata(g, new_metadata = v, by_column = TRUE)
fDataDT(g)
#> Key: <feat_ID>
#>     feat_ID     v
#>      <char> <int>
#>  1:       a     7
#>  2:       b     1
#>  3:       c     3
#>  4:       d     8
#>  5:       e     6
#>  6:       f     4
#>  7:       g     2
#>  8:       h     5
#>  9:       i    10
#> 10:       j     9

# 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 <- addFeatMetadata(
    g,
    new_metadata = df,
    by_column = TRUE,
    column_feat_ID = "IDS"
)
fDataDT(g)
#> Key: <feat_ID>
#>     feat_ID     v      l      x
#>      <char> <int> <char> <lgcl>
#>  1:       a     7      J  FALSE
#>  2:       b     1      I  FALSE
#>  3:       c     3      H  FALSE
#>  4:       d     8      G  FALSE
#>  5:       e     6      F  FALSE
#>  6:       f     4      E   TRUE
#>  7:       g     2      D   TRUE
#>  8:       h     5      C   TRUE
#>  9:       i    10      B   TRUE
#> 10:       j     9      A   TRUE