runs a Principal Component Analysis

runPCA(
  gobject,
  spat_unit = NULL,
  feat_type = NULL,
  expression_values = c("normalized", "scaled", "custom"),
  reduction = c("cells", "feats"),
  name = NULL,
  feats_to_use = "hvf",
  return_gobject = TRUE,
  center = TRUE,
  scale_unit = TRUE,
  ncp = 100,
  method = c("irlba", "exact", "random", "factominer"),
  method_params = BiocParallel::SerialParam(),
  rev = FALSE,
  set_seed = TRUE,
  seed_number = 1234,
  verbose = TRUE,
  ...
)

Arguments

gobject

giotto object

spat_unit

spatial unit

feat_type

feature type

expression_values

expression values to use

reduction

cells or genes

name

arbitrary name for PCA run

feats_to_use

subset of features to use for PCA

return_gobject

boolean: return giotto object (default = TRUE)

center

center data first (default = TRUE)

scale_unit

scale features before PCA (default = TRUE)

ncp

number of principal components to calculate (see details)

method

which implementation to use

method_params

BiocParallelParam object

rev

do a reverse PCA

set_seed

use of seed

seed_number

seed number to use

verbose

verbosity of the function

...

additional parameters for PCA (see details)

Value

giotto object with updated PCA dimension recuction

Details

See runPCA and PCA for more information about other parameters. With the feats_to_use param, you can control which features are used to calculate your PCA, which can be useful for making sure that your downstream dimension reduction and clusterings are based on your features of interest.

  • feats_to_use = NULL: will use all features from the selected matrix

  • feats_to_use = <hvg name>: can be used to select a column name of highly variable features, created by (see calculateHVF)

  • feats_to_use = c('geneA', 'geneB', ...): will use all manually provided features

By default the number of principle components that we calculate is 100, which may not encompass all the variation within the dataset. Setting ncp to NULL will calculate all the principle components.

Examples

g <- GiottoData::loadGiottoMini("visium")
#> 1. read Giotto object
#> 2. read Giotto feature information
#> 3. read Giotto spatial information
#> 3.1 read Giotto spatial shape information
#> cell_spatInfo_spatVector.shp
#> cell
#> 
#> 3.2 read Giotto spatial centroid information
#> cell
#> 
#> 3.3 read Giotto spatial overlap information
#> No overlaps were found, overlap loading will be
#>  skipped
#> 
#> 4. read Giotto image information
#> a giotto python environment was found
#> Using python path:
#>  "/Users/yuanlab/Library/r-miniconda/envs/giotto_env/bin/pythonw"

runPCA(g)
#> "hvf" column was found in the feats metadata information and will be
#>  used to select highly variable features
#> Warning: ncp >= minimum dimension of x, will be set to
#>                 minimum dimension of x - 1
#> Warning: You're computing too large a percentage of total singular values, use a standard svd instead.
#> Warning: did not converge--results might be invalid!; try increasing work or maxit
#> > pca already exists and will be replaced with
#>  new dimension reduction object
#> An object of class giotto 
#> >Active spat_unit:  cell 
#> >Active feat_type:  rna 
#> [SUBCELLULAR INFO]
#> polygons      : cell 
#> [AGGREGATE INFO]
#> expression -----------------------
#>   [cell][rna] raw normalized scaled
#> spatial locations ----------------
#>   [cell] raw
#> spatial networks -----------------
#>   [cell] Delaunay_network spatial_network
#> spatial enrichments --------------
#>   [cell][rna] cluster_metagene DWLS
#> dim reduction --------------------
#>   [cell][rna] pca custom_pca umap custom_umap tsne
#> nearest neighbor networks --------
#>   [cell][rna] sNN.pca custom_NN
#> attached images ------------------
#> images      : alignment image 
#> 
#> 
#> Use objHistory() to see steps and params used