runSPROD: De-noise expression data based on position and image...

View source: R/python-wrappers.R

runSPRODR Documentation

De-noise expression data based on position and image information

Description

A wrapper around the algorithm introduced by Wang et al. 2022 to denoise expression data based on position and image information.

Note that this function creates a temporary folder.

Usage

runSPROD(
  object,
  img_name,
  mtr_name,
  mtr_name_new,
  dir_env,
  path_script = NULL,
  path_conda = find_path("conda.sh"),
  dir_temp = paste0("sprod_temp_", object@sample),
  del_temp = TRUE,
  assay_name = activeAssay(object),
  overwrite = FALSE,
  verbose = TRUE
)

Arguments

object

An object of class SPATA2 or, in case of S4 generics, objects of classes for which a method has been defined.

img_name

Character. The name of the image to be used.

mtr_name

Character. The name of the input matrix that is denoised

mtr_name_new

Character. The name for the new processed (de-oised) matrix. Defaults to paste0(mtr_name, "_sprod").

dir_env

Character. The folder directory to the conda environment in which the python library sprod is installed.

path_script

Character. The path to the .../sprod.py script. By default, the directory of dir_env is searched.

path_conda

Character. The path to the conda initialization script .../conda.sh. By default, common paths are checked.

dir_temp

Character. The folder directory for writing temporary files (defaults to "~/sprod_temp_").

del_temp

Logical. If TRUE (default), the temporary directory is deleted after processing.

assay_name

Only relevant if the SPATA2 object contains more than one assay: Denotes the assay of interest and thus the molecular modality to use. Defaults to the active assay as set by activateAssay().

overwrite

Logical value. Must be TRUE to allow overwriting.

verbose

Logical. If TRUE, informative messages regarding the computational progress will be printed.

(Warning messages will always be printed.)

Details

This function runs the SPROD denoising algorithm on a given SPATA2 object by:

  • Creating a temporary directory (dir_temp) to store required input files (counts, spot metadata, and image).

  • Writing the counts matrix, spot metadata, and image to disk in dir_temp.

  • Executing the external SPROD Python script (path_script) via a system command that sources a conda environment (using dir_env).

  • Reading the denoised matrix from the expected output file and adding it to the SPATA2 object.

  • Storing additional results (e.g., intensity and texture features) in the assay’s analysis slot.

  • Deleting the temporary directory if del_temp is TRUE.

Value

The updated input object, containing the added, removed or computed results.

Note

We recommend to set up a conda environment according to the tutorials at https://github.com/yunguan-wang/SPROD.

References

Wang, Y., Song, B., Wang, S. et al. Sprod for de-noising spatially resolved transcriptomics data based on position and image information. Nat Methods 19, 950–958 (2022). https://doi.org/10.1038/s41592-022-01560-w

Examples

## Not run: 
  library(SPATA2)
  library(SPATAData)
  library(ggplot2)
  library(patchwork)

  spata_obj <- downloadSpataObject("T313")

  spata_obj <- normalizeCounts(spata_obj)

  spata_obj <- runSPROD(
    object = spata_obj,
    img_name = "lowres",
    mtr_name = "LogNormalize",
    mtr_name_new = "Sprod",
    dir_env = "dir/to/sprod_env",
    dir_temp = paste0("sprod_temp_", spata_obj@sample),
    del_temp = TRUE,
    overwrite = FALSE,
    verbose = TRUE
  )

  p1 <-
    plotSurface(spata_obj, color_by = "VEGFA", mtr_name = "LogNormalize") +
    labs(subtitle = "LogNormalize")

  p2 <-
    plotSurface(spata_obj, color_by = "VEGFA", mtr_name = "Sprod") +
    labs(subtitle = "Sprod De-Noised")

  plot(p1 + p2)


## End(Not run)


theMILOlab/SPATA2 documentation built on Feb. 8, 2025, 11:41 p.m.