Creates a known spatial pattern for selected genes one-by-one and runs the different spatial gene detection tests

runPatternSimulation(
  gobject,
  pattern_name = "pattern",
  pattern_colors = c(`in` = "green", out = "red"),
  pattern_cell_ids = NULL,
  gene_names = NULL,
  spatial_probs = c(0.5, 1),
  reps = 2,
  spatial_network_name = "kNN_network",
  spat_methods = c("binSpect_single", "binSpect_multi", "spatialDE", "spark",
    "silhouetteRank"),
  spat_methods_params = list(NA, NA, NA, NA, NA),
  spat_methods_names = c("binSpect_single", "binSpect_multi", "spatialDE", "spark",
    "silhouetteRank"),
  scalefactor = 6000,
  save_plot = TRUE,
  save_raw = TRUE,
  save_norm = TRUE,
  save_dir = "~",
  max_col = 4,
  height = 7,
  width = 7,
  run_simulations = TRUE,
  ...
)

Arguments

gobject

giotto object

pattern_name

name of spatial pattern

pattern_colors

2 color vector for the spatial pattern

pattern_cell_ids

cell ids that make up the spatial pattern

gene_names

selected genes

spatial_probs

probabilities to test for a high expressing gene value to be part of the spatial pattern

reps

number of random simulation repetitions

spatial_network_name

which spatial network to use for binSpectSingle

spat_methods

vector of spatial methods to test

spat_methods_params

list of parameters list for each element in the vector of spatial methods to test

spat_methods_names

name for each element in the vector of spatial elements to test

scalefactor

library size scaling factor when re-normalizing dataset

save_plot

save intermediate random simulation plots or not

save_raw

save the raw expression matrix of the simulation

save_norm

save the normalized expression matrix of the simulation

save_dir

directory to save results to

max_col

maximum number of columns for final plots

height

height of final plots

width

width of final plots

run_simulations

run simulations (default = TRUE)

...

additional parameters for renormalization

Value

data.table with results

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
#> 3.2 read Giotto spatial centroid information
#> 3.3 read Giotto spatial overlap information
#> 4. read Giotto image information
#> python already initialized in this session
#>  active environment : '/usr/bin/python3'
#>  python version : 3.10
#> checking default envname 'giotto_env'
#> a system default python environment was found
#> Using python path:
#>  "/usr/bin/python3"

runPatternSimulation(
    gobject = g, pattern_cell_ids = c(
        "AAAGGGATGTAGCAAG-1",
        "TCAAACAACCGCGTCG-1", "ACGATCATACATAGAG-1", "TATGCTCCCTACTTAC-1"
    ),
    spatial_network_name = "spatial_network",
    gene_names = c("Gna12", "Ccnd2")
)

#> > raw already exists and will be replaced with new values
#> Setting expression [cell][rna] raw
#> first scale feats and then cells
#> > normalized already exists and will be replaced with new values
#> Setting expression [cell][rna] normalized
#> > scaled already exists and will be replaced with new values
#> Setting expression [cell][rna] scaled
#> feat statistics has already been applied once; overwriting
#> cells statistics has already been applied once; overwriting

#> start with 0.5
#> repetition = 1
#> > raw already exists and will be replaced with new values
#> Setting expression [cell][rna] raw
#> first scale feats and then cells
#> > normalized already exists and will be replaced with new values
#> Setting expression [cell][rna] normalized
#> > scaled already exists and will be replaced with new values
#> Setting expression [cell][rna] scaled
#> feat statistics has already been applied once; overwriting
#> cells statistics has already been applied once; overwriting
#> 
#> This is the single parameter version of binSpect
#> 
#> 1. matrix binarization complete
#> 
#> 2. spatial enrichment test completed
#> This is the multi parameter version of binSpect
#> Run for k =  5
#> 
#> This is the single parameter version of binSpect
#> 
#> 1. matrix binarization complete
#> 
#> 2. spatial enrichment test completed
#> Run for k =  10
#> 
#> This is the single parameter version of binSpect
#> 
#> 1. matrix binarization complete
#> 
#> 2. spatial enrichment test completed
#> Run for k =  20
#> 
#> This is the single parameter version of binSpect
#> 
#> 1. matrix binarization complete
#> 
#> 2. spatial enrichment test completed
#> Warning: SpatialDE python module is not installed:
#>             install in the right environment or python path with:
#> 
#>             'pip install spatialde'
#> 
#>             or from within R in the Giotto environment with:
#> 
#>             conda_path = reticulate::miniconda_path()
#>             conda_full_path = paste0(conda_path,'/','bin/conda')
#>             full_envname = paste0(conda_path,'/envs/giotto_env')
#>             reticulate::py_install(packages = c('NaiveDE', 'patsy', 'SpatialDE'),
#>                                    envname = full_envname,
#>                                    method = 'conda',
#>                                    conda = conda_full_path,
#>                                    pip = TRUE,
#>                                    python_version = '3.6')
#> using 'SpatialDE' for spatial gene/pattern detection. If used in
#>     published research, please cite:
#>     Svensson, Valentine, Sarah A. Teichmann, and Oliver Stegle.
#>     'SpatialDE: Identification of Spatially Variable Genes.'
#>     Nature Methods 15, no. 5 (May 2018): 343-46.
#>     https://doi.org/10.1038/nmeth.4636.
#> Error in py_run_file_impl(file, local, convert): ModuleNotFoundError: No module named 'pandas'
#> Run `reticulate::py_last_error()` for details.