Package 'SpaTalk'

Title: Spatially Resolved Cell-Cell Communication Inference for Spatial Transcriptomics
Description: Infers spatially resolved cell-cell communications from spatial transcriptomics data using graph network and knowledge graph approaches. Supports both single-cell resolution and spot-based spatial transcriptomics platforms. Provides cell type deconvolution, ligand-receptor interaction analysis, and downstream pathway inference.
Authors: Zaoqu Liu [aut, cre] (ORCID: <https://orcid.org/0000-0002-0452-742X>), Xin Shao [aut] (ORCID: <https://orcid.org/0000-0002-1928-3878>)
Maintainer: Zaoqu Liu <[email protected]>
License: GPL (>= 3)
Version: 2.0.0
Built: 2026-05-28 14:37:17 UTC
Source: https://github.com/Zaoqu-Liu/SpaTalk

Help Index


Use Rcpp for fast permutation if available

Description

Use Rcpp for fast permutation if available

Usage

.use_cpp_permutation()

Use Rcpp for fast random walk if available

Description

Use Rcpp for fast random walk if available

Usage

.use_cpp_random_walk()

Calculate co-expression for multiple gene pairs

Description

Calculate co-expression for multiple gene pairs

Usage

cpp_batch_coexp(st_data_mat, src_genes, dest_genes, cell_indices)

Arguments

st_data_mat

Expression matrix

src_genes

Source gene indices (1-based)

dest_genes

Destination gene indices (1-based)

cell_indices

Cell indices to use (1-based)

Value

Co-expression ratios


Calculate correlation between a vector and matrix columns

Description

Calculate correlation between a vector and matrix columns

Usage

cpp_batch_cor(vec1, mat)

Arguments

vec1

Reference vector

mat

Matrix where each column is compared to vec1

Value

Pearson correlation coefficients


Calculate co-expression ratios

Description

Calculate co-expression ratios

Usage

cpp_coexp_fast(ligand_expr, receptor_expr)

Arguments

ligand_expr

Ligand expression matrix (n_genes x n_cells)

receptor_expr

Receptor expression matrix (n_genes x n_cells)

Value

Co-expression ratios


Calculate Euclidean distance matrix

Description

Calculate Euclidean distance matrix

Usage

cpp_fast_dist(x, y)

Arguments

x

X coordinates

y

Y coordinates

Value

Distance matrix


Sample cells to reconstruct spot expression

Description

Sample cells to reconstruct spot expression

Usage

cpp_fast_sampling(
  spot_ndata,
  sc_ndata_mat,
  cell_indices_by_type,
  spot_celltypes,
  iter_num = 200L,
  tolerance = 0.001,
  seed = 123L
)

Arguments

spot_ndata

Spot expression vector

sc_ndata_mat

Single-cell expression matrix

cell_indices_by_type

List of cell indices for each cell type

spot_celltypes

Cell types to sample for this spot

iter_num

Maximum number of iterations

tolerance

Convergence tolerance (unused, kept for API compatibility)

seed

Random seed for reproducibility

Value

Best cell combination and correlation


Find K nearest neighbors

Description

Find K nearest neighbors

Usage

cpp_knn(dist_mat, query_idx, k)

Arguments

dist_mat

Distance matrix

query_idx

Query index (0-based)

k

Number of neighbors

Value

Neighbor indices (0-based)


Permutation test for LR co-expression significance

Description

Permutation test for LR co-expression significance

Usage

cpp_permutation_test(
  st_data_mat,
  ligand_genes,
  receptor_genes,
  sender_cells,
  receiver_cells,
  per_num = 1000L,
  seed = 123L
)

Arguments

st_data_mat

Expression matrix

ligand_genes

Ligand gene indices (1-based R indexing)

receptor_genes

Receptor gene indices (1-based R indexing)

sender_cells

Sender cell indices (1-based)

receiver_cells

Receiver cell indices (1-based)

per_num

Number of permutations

seed

Random seed for reproducibility

Value

List with real_ratios and pvalues


Random walk on gene-gene interaction network

Description

Random walk on gene-gene interaction network

Usage

cpp_random_walk(
  ggi_src,
  ggi_dest,
  receptor_name,
  tf_names,
  n_walks = 10000L,
  max_hop = 10L,
  seed = 123L
)

Arguments

ggi_src

Source gene names

ggi_dest

Destination gene names

receptor_name

Starting receptor name

tf_names

TF names to score

n_walks

Number of random walks

max_hop

Maximum number of hops per walk

seed

Random seed for reproducibility

Value

TF visit frequency scores


SpaTalk object

Description

create SpaTalk object using spatial transcriptomics data.

Usage

createSpaTalk(
  st_data,
  st_meta,
  species,
  if_st_is_sc,
  spot_max_cell,
  celltype = NULL
)

Arguments

st_data

A data.frame or matrix or dgCMatrix containing counts of spatial transcriptomics, each column representing a spot or a cell, each row representing a gene.

st_meta

A data.frame containing coordinate of spatial transcriptomics with three columns, namely 'spot', 'x', 'y' for spot-based spatial transcriptomics data or 'cell', 'x', 'y' for single-cell spatial transcriptomics data.

species

A character meaning species of the spatial transcriptomics data.'Human' or 'Mouse'.

if_st_is_sc

A logical meaning if it is single-cell spatial transcriptomics data. TRUE is FALSE.

spot_max_cell

A integer meaning max cell number for each plot to predict. If if_st_sc is FALSE, please determine the spot_max_cell. For 10X (55um), we recommend 30. For Slide-seq, we recommend 1.

celltype

A character containing the cell type of ST data. To skip the deconvolution step and directly infer cell-cell communication, please define the cell type. Default is NULL.

Value

SpaTalk object


Decomposing cell-cell communications for spatial transciptomics data

Description

Identify the cell-cell communications for single-cell or spot-based spatial transciptomics data with proximal ligand-receptor-target interactions.

Usage

dec_cci(
  object,
  celltype_sender,
  celltype_receiver,
  n_neighbor = 10,
  min_pairs = 5,
  min_pairs_ratio = 0,
  per_num = 1000,
  pvalue = 0.05,
  co_exp_ratio = 0.1,
  if_doParallel = T,
  use_n_cores = NULL
)

Arguments

object

SpaTalk object after find_lr_path.

celltype_sender

Name of celltype_sender.

celltype_receiver

Name of celltype_receiver.

n_neighbor

Number of neighbor cells to select as the proximal cell-cell pair. Default is 10.

min_pairs

Min proximal cell-cell pairs between for sending and receiving cell types. Default is 5.

min_pairs_ratio

Min proximal cell-cell pairs ratio between for sending and receiving cell types. Default is 0.

per_num

Number of repeat times for permutation test. Default is 1000.

pvalue

Include the significantly proximal LR pairs with this cutoff of p value from permutation test. Default is 0.05.

co_exp_ratio

Min cell ratio in receiving cells with co-expressed source and target genes for predicting the downstream pathway activity.

if_doParallel

Use doParallel. Default is TRUE.

use_n_cores

Number of CPU cores to use. Default is all cores - 2.

Value

SpaTalk object containing the inferred LR pairs and pathways.


Decomposing cell-cell communications for spatial transciptomics data

Description

Identify the all cell-cell communications for single-cell or spot-based spatial transciptomics data with proximal ligand-receptor-target interactions.

Usage

dec_cci_all(
  object,
  n_neighbor = 10,
  min_pairs = 5,
  min_pairs_ratio = 0,
  per_num = 1000,
  pvalue = 0.05,
  co_exp_ratio = 0.1,
  if_doParallel = T,
  use_n_cores = NULL
)

Arguments

object

SpaTalk object after find_lr_path.

n_neighbor

Number of neighbor cells to select as the proximal cell-cell pair. Default is 10.

min_pairs

Min proximal cell-cell pairs between for sending and receiving cell types. Default is 5.

min_pairs_ratio

Min proximal cell-cell pairs ratio between for sending and receiving cell types. Default is 0.

per_num

Number of repeat times for permutation test. Default is 1000.

pvalue

Include the significantly proximal LR pairs with this cutoff of p value from permutation test. Default is 0.05.

co_exp_ratio

Min cell ratio in receiving cells with co-expressed source and target genes for predicting the downstream pathway activity.

if_doParallel

Use doParallel. Default is TRUE.

use_n_cores

Number of CPU cores to use. Default is all cores - 2.

Value

SpaTalk object containing the inferred LR pairs and pathways.


Decomposing cell type for spatial transcriptomics data

Description

Identify the cellular composition for single-cell or spot-based spatial transcriptomics data with non-negative regression.

Usage

dec_celltype(
  object,
  sc_data,
  sc_celltype,
  min_percent = 0.5,
  min_nFeatures = 10,
  if_use_normalize_data = T,
  if_use_hvg = F,
  if_retain_other_genes = F,
  if_doParallel = T,
  use_n_cores = NULL,
  iter_num = 1000,
  method = 1,
  env = "base",
  anaconda_path = "~/anaconda3",
  dec_result = NULL
)

Arguments

object

SpaTalk object generated from createSpaTalk.

sc_data

A A data.frame or matrix or dgCMatrix containing counts of single-cell RNA-seq data as the reference, each column representing a cell, each row representing a gene.

sc_celltype

A character containing the cell type of the reference single-cell RNA-seq data.

min_percent

Min percent to predict new cell type for single-cell st_data or predict new cell for spot-based st_data. Default is 0.5.

min_nFeatures

Min number of expressed features/genes for each spot/cell in st_data. Default is 10.

if_use_normalize_data

Whether to use normalized st_data and sc_data with Seurat normalization. Default is TRUE. set it FALSE when the st_data and sc_data are already normalized matrix with other methods.

if_use_hvg

Whether to use highly variable genes for non-negative regression. Default is FALSE.

if_retain_other_genes

Whether to retain other genes which are not overlapped between sc_data and st_data when reconstructing the single-cell ST data. Default is FALSE. Set it TRUE to obtain the constructed single-cell ST data with genes consistent with that in sc_data.

if_doParallel

Use doParallel. Default is TRUE.

use_n_cores

Number of CPU cores to use. Default is all cores - 2.

iter_num

Number of iteration to generate the single-cell data for spot-based data. Default is 1000.

method

1 means using the SpaTalk deconvolution method, 2 means using RCTD, 3 means using Seurat, 4 means using SPOTlight, 5 means using deconvSeq, 6 means using stereoscope, 7 means using cell2location

env

When method set to 6, namely use stereoscope python package to deconvolute, please define the python environment of installed stereoscope. Default is the 'base' environment. Anaconda is recommended. When method set to 7, namely use cell2location python package to deconvolute, please install cell2location to "base" environment.

anaconda_path

When using stereoscope, please define the env parameter as well as the path to anaconda. Default is "~/anaconda3"

dec_result

A matrix of deconvolution result from other upcoming methods, row represents spots or cells, column represents cell types of scRNA-seq reference. See demo_dec_result

Value

SpaTalk object containing the decomposing results.


Demo data of dec_result

Description

Demo data of dec_result

Usage

demo_dec_result()

Details

dec_result used in dec_celltype must be a matrix object, each row representing a spot, each column representing a cell type.

Value

A matrix.

Examples

dec_result_demo <- demo_dec_result()

Demo data of geneinfo

Description

Demo data of geneinfo

Usage

demo_geneinfo()

Details

geneinfo used in dec_celltype must be a data.frame object with three columns, namely 'symbol', 'synonyms', 'species'.

Examples

geneinfo_demo <- demo_geneinfo()

Demo data of lrpairs

Description

Demo data of lrpairs

Usage

demo_lrpairs()

Details

lrpairs used in dec_cci must be a data.frame object with three columns, namely 'ligand', 'receptor', 'species'.

Value

A data.frame.

Examples

lrpairs_demo <- demo_lrpairs()

Demo data of pathways

Description

Demo data of pathways

Usage

demo_pathways()

Details

pathways used in dec_cci must be a data.frame object with seven columns, namely 'src', 'dest', 'pathway', 'source', 'type', 'src_tf', 'dest_tf', 'species'.

Value

A data.frame.

Examples

pathways_demo <- demo_pathways()

Demo data of sc_data

Description

Demo data of sc_data.

Usage

demo_sc_data()

Details

sc_data used in dec_celltype must be a matrix object, each column representing a cell, each row representing a gene.

Value

A matrix.

Examples

sc_data_demo <- demo_sc_data()

Demo data of st_data

Description

Demo data of st_data.

Usage

demo_st_data()

Details

st_data used in dec_celltype must be a matrix object, each column representing a spot, each row representing a gene.

Value

A matrix.

Examples

st_data_demo <- demo_st_data()

Demo data of st_meta

Description

Demo data of st_meta

Usage

demo_st_meta()

Details

st_meta used in dec_celltype must be a data.frame object with three columns, namely 'spot', 'x', 'y' for spot-based spatial transcriptomics data.

Value

A data.frame.

Examples

st_meta_demo <- demo_st_meta()

Demo data of single-cell st_data

Description

Demo data of single-cell st_data.

Usage

demo_st_sc_data()

Details

st_data used in dec_celltype must be a matrix object, each column representing a cell, each row representing a gene.

Value

A matrix.

Examples

st_data_demo <- demo_st_sc_data()

Demo data of st_sc_meta

Description

Demo data of st_sc_meta

Usage

demo_st_sc_meta()

Details

st_sc_meta used in dec_celltype must be a data.frame object with three columns, namely 'cell', 'x', 'y' for single-cell spatial transcriptomics data.

Value

A data.frame.

Examples

st_sc_meta_demo <- demo_st_sc_meta()

Find lrpairs and pathways

Description

Find lrpairs and pathways with receptors having downstream targets and transcriptional factors.

Usage

find_lr_path(
  object,
  lrpairs,
  pathways,
  max_hop = NULL,
  if_doParallel = T,
  use_n_cores = NULL
)

Arguments

object

SpaTalk object generated from dec_celltype.

lrpairs

A data.frame of the system data containing ligand-receptor pairs of 'Human' and 'Mouse' from CellTalkDB.

pathways

A data.frame of the system data containing gene-gene interactions and pathways from KEGG and Reactome as well as the information of transcriptional factors.

max_hop

Max hop from the receptor to the downstream target transcriptional factor to find for receiving cells. Default is 3 for human and 4 for mouse.

if_doParallel

Use doParallel. Default is TRUE.

use_n_cores

Number of CPU cores to use. Default is all cores - 2.

Value

SpaTalk object containing the filtered lrpairs and pathways.


geneinfo

Description

Gene symbols of 'Human' and 'Mouse' updated on June 30, 2021 for revising count matrix.

Usage

geneinfo

Format

An object of class data.frame with 250934 rows and 3 columns.

Source

https://www.ncbi.nlm.nih.gov/gene


Generate pseudo spot st_data

Description

Generate pseudo spot st_data with single-cell st_data

Usage

generate_spot(st_data, st_meta, x_min, x_res, x_max, y_min, y_res, y_max)

Arguments

st_data

A data.frame or matrix or dgCMatrix containing counts of spatial transcriptomics, each column representing a cell, each row representing a gene.

st_meta

A data.frame containing coordinate of spatial transcriptomics with three columns, 'cell', 'x', 'y', and celltype.

x_min

Min value of x axis.

x_res

Resolution of x coordinate.

x_max

Max value of x axis.

y_min

Min value of y axis.

y_res

Resolution of y coordinate.

y_max

Max value of y axis.

Value

A list of spot st_data and st_meta


Get LR and downstream pathways

Description

Get LR and downstream pathways and get p value of receptor-related pathways with LR-target genes by the Fisher-exact test.

Usage

get_lr_path(
  object,
  celltype_sender,
  celltype_receiver,
  ligand,
  receptor,
  min_gene_num = 5
)

Arguments

object

SpaTalk object generated from dec_cci.

celltype_sender

Name of celltype_sender.

celltype_receiver

Name of celltype_receiver.

ligand

Name of ligand from celltype_sender.

receptor

Name of receptor from celltype_receiver.

min_gene_num

Min genes number for each pathway.

Value

A list containing two data.frame. One is LR and downstream pathways, another is the p value of receptor-related pathways with LR-target genes.


lrpairs

Description

Ligand-receptor pairs of 'Human' and 'Mouse' containing 3398 human and 2033 mouse pairs.

Usage

lrpairs

Format

An object of class data.frame with 5427 rows and 3 columns.

Source

http://tcm.zju.edu.cn/celltalkdb/


pathways

Description

KEGG pathways and Reactomes of 'Human' and 'Mouse' for intra-cellular genes and transcription factors.

Usage

pathways

Format

An object of class data.frame with 669197 rows and 8 columns.

Source

https://www.genome.jp/kegg/pathway.html

https://reactome.org/

http://bioinfo.life.hust.edu.cn/AnimalTFDB/#!/


Plot cell-cell distribution

Description

Point plot with spatial distribution of celltype_sender and celltype_receiver

Usage

plot_ccdist(
  object,
  celltype_sender,
  celltype_receiver,
  color = NULL,
  size = 1,
  if_plot_others = T,
  if_plot_density = T,
  if_plot_edge = T,
  if_show_arrow = T,
  arrow_length = 0.05,
  plot_cells = NULL
)

Arguments

object

SpaTalk object generated from dec_celltype.

celltype_sender

Name of celltype_sender.

celltype_receiver

Name of celltype_receiver.

color

Color for celltype_sender, celltype_receiver, and others. Three values.

size

Point size. Default is 1.

if_plot_others

Whether to plot others. Default is TRUE.

if_plot_density

Whether to plot marginal density plots. Default is TRUE.

if_plot_edge

Whether to plot edge between neighbors. Default is TRUE.

if_show_arrow

Whether to show the arrow of the plotted edge. Default is TRUE.

arrow_length

Arrow length.

plot_cells

Which cells to plot. Default is all cells. Input a character vector of cell names to plot.


Plot LR pairs

Description

Heatmap with LR pairs of celltype_sender and celltype_receiver

Usage

plot_cci_lrpairs(
  object,
  celltype_sender,
  celltype_receiver,
  top_lrpairs = 20,
  color = NULL,
  border_color = "black",
  type = "sig",
  fontsize_number = 5,
  number_color = "black",
  color_low = NULL,
  color_high = NULL
)

Arguments

object

SpaTalk object generated from dec_cci.

celltype_sender

Name of celltype_sender.

celltype_receiver

Name of celltype_receiver.

top_lrpairs

Number of top lrpairs for plotting. Default is 20.

color

Color for the cells in heatmap.

border_color

color of cell borders on heatmap, use NA if no border should be drawn.

type

Set 'sig' to plot significant LRI pairs or set 'number' to plot the number of spatial LRI pairs.

fontsize_number

fontsize of the numbers displayed in cells.

number_color

color of the text.

color_low

For 'number' type, define the color for the lowest value.

color_high

For 'number' type, define the color for the highest value.


Plot LR and downstream pathways

Description

Plot network with LR and downstream pathways

Usage

plot_lr_path(
  object,
  celltype_sender,
  celltype_receiver,
  ligand,
  receptor,
  color = NULL,
  size = 5,
  arrow_length = 0.1
)

Arguments

object

SpaTalk object generated from dec_cci.

celltype_sender

Name of celltype_sender.

celltype_receiver

Name of celltype_receiver.

ligand

Name of ligand from celltype_sender.

receptor

Name of receptor from celltype_receiver.

color

Color for points Two values.

size

Size of points.

arrow_length

Arrow length.


Plot LR pair

Description

Point plot with LR pair from celltype_sender to celltype_receiver

Usage

plot_lrpair(
  object,
  celltype_sender,
  celltype_receiver,
  ligand,
  receptor,
  color = NULL,
  size = 1,
  if_plot_density = T,
  if_plot_edge = T,
  if_show_arrow = T,
  arrow_length = 0.05,
  plot_cells = NULL
)

Arguments

object

SpaTalk object generated from dec_celltype.

celltype_sender

Name of celltype_sender.

celltype_receiver

Name of celltype_receiver.

ligand

Name of ligand from celltype_sender.

receptor

Name of receptor from celltype_receiver.

color

Color for ligand, receptor, and others. Three values.

size

Point size. Default is 1.

if_plot_density

Whether to plot marginal density plots. Default is TRUE.

if_plot_edge

Whether to plot edge between neighbors. Default is TRUE.

if_show_arrow

Whether to show the arrow of the plotted edge. Default is TRUE.

arrow_length

Arrow length.

plot_cells

Which cells to plot. Default is all cells. Input a character vector of cell names to plot.


Plot spatial distance of LR pair with vlnplot

Description

Violin plot spatial distance of LR pair between expressed senders and receivers and between expressed cell-cell pairs.

Usage

plot_lrpair_vln(
  object,
  celltype_sender,
  celltype_receiver,
  ligand,
  receptor,
  vln_color = NULL,
  if_plot_boxplot = T,
  box_width = 0.2
)

Arguments

object

SpaTalk object generated from dec_celltype.

celltype_sender

Name of celltype_sender.

celltype_receiver

Name of celltype_receiver.

ligand

Name of ligand from celltype_sender.

receptor

Name of receptor from celltype_receiver.

vln_color

Color for violins. Two values.

if_plot_boxplot

Whether to plot boxplot. Default is TRUE.

box_width

Box width. Default is 0.2.


River plot of significantly activated pathways and related downstream genes of receptors.

Description

River plot of significantly activated pathways and related downstream genes of receptors.

Usage

plot_path2gene(
  object,
  celltype_sender,
  celltype_receiver,
  ligand,
  receptor,
  min_gene_num = 5,
  pvalue = 0.5,
  color = NULL,
  color_flow = "blue"
)

Arguments

object

SpaTalk object generated from dec_cci.

celltype_sender

Name of celltype_sender.

celltype_receiver

Name of celltype_receiver.

ligand

Name of ligand from celltype_sender.

receptor

Name of receptor from celltype_receiver.

min_gene_num

Min genes number for each pathway.

pvalue

P value of the Fisher-exact test.

color

Color of pathways and genes. Two values.

color_flow

Color of the flow.


Plot spatial distribution of a single cell type

Description

Ponit plot with spatial distribution of a single predicted cell type for transcriptomics data

Usage

plot_st_celltype(
  object,
  celltype,
  size = 1,
  color_celltype = "blue",
  color_others = "grey"
)

Arguments

object

SpaTalk object generated from dec_celltype.

celltype

Name of cell type in the sc_celltype.

size

Point size. Default is 1.

color_celltype

Color for the celltype of interest.

color_others

Color for the others.


Plot spatial distribution of all cell types

Description

Plot spatial distribution of all predicted cell types for transcriptomics data

Usage

plot_st_celltype_all(object, size = 1, color = NULL)

Arguments

object

SpaTalk object generated from dec_celltype.

size

Point size. Default is 1.

color

Color for all predicted cell types.


Plot spatial density of a single cell type

Description

Plot spatial density of a single predicted cell type for transcriptomics data

Usage

plot_st_celltype_density(
  object,
  celltype,
  type,
  if_plot_point = T,
  point_color = NULL,
  point_size = 1,
  color_low = "grey",
  color_mid = NULL,
  color_high = "blue",
  color_midpoint = NULL,
  size = 1
)

Arguments

object

SpaTalk object generated from dec_celltype.

celltype

Name of cell type in the sc_celltype.

type

Select 'contour' or 'raster'.

if_plot_point

Whether to plot points when type is 'contour'.

point_color

Point color.

point_size

Point size. Default is 1.

color_low

Color for the lowest value.

color_mid

Color for the middle value for using scale_color_gradient2. Default is NULL.

color_high

Color for the highest value.

color_midpoint

Value for the middle scale. Default is NULL.

size

Line size when type is 'contour'. Default is 1.


Plot spatial distribution of a single cell type percent

Description

Plot spatial distribution of a single predicted cell type percent for transcriptomics data

Usage

plot_st_celltype_percent(
  object,
  celltype,
  size = 1,
  color_low = NULL,
  color_mid = NULL,
  color_high = NULL,
  color_midpoint = NULL
)

Arguments

object

SpaTalk object generated from dec_celltype.

celltype

Name of cell type in the sc_celltype.

size

Point size. Default is 1.

color_low

Color for the lowest value.

color_mid

Color for the middle value for using scale_color_gradient2. Default is NULL.

color_high

Color for the highest value.

color_midpoint

Value for the middle scale. Default is NULL.


Plot heatpmap of correlation between marker genes and cell types

Description

Plot heatpmap of correlation between the expression of marker genes and the predicted score of cell types among all spatial cells or spots.

Usage

plot_st_cor_heatmap(
  object,
  marker_genes,
  celltypes,
  color_low = NULL,
  color_mid = NULL,
  color_high = NULL,
  scale = "none",
  if_show_top = T,
  top_direction = "row",
  border_color = NA
)

Arguments

object

SpaTalk object generated from dec_celltype.

marker_genes

A character containing the known marker genes to plot, provide at least two marker genes of interest.

celltypes

A character containing name of cell type in the sc_celltype. Default is to plot all cell types.

color_low

Color for the lowest value.

color_mid

Color for the middle value for using scale_color_gradient2. Default is NULL.

color_high

Color for the highest value.

scale

Character indicating if the values should be centered and scaled in either the row direction or the column direction, or none. Corresponding values are 'row', 'column' and 'none'.

if_show_top

Whether to plot a symbol to the highest value across rows or columns. Default is TRUE.

top_direction

Direction to identify the highest value, select 'row' or 'column'.

border_color

Color of the cell border. Default is 'NA'.


Plot spatial distribution of gene

Description

Point plot with spatial distribution of a gene for transcriptomics data

Usage

plot_st_gene(
  object,
  gene,
  size = 1,
  color_low = "grey",
  color_mid = NULL,
  color_high = "blue",
  color_midpoint = NULL,
  if_use_newmeta = T,
  celltype = NULL,
  if_plot_others = T
)

Arguments

object

SpaTalk object generated from dec_celltype.

gene

Symbol of gene, e.g., 'AKT1'.

size

Point size. Default is 1.

color_low

Color for the lowest value.

color_mid

Color for the middle value for using scale_color_gradient2. Default is NULL.

color_high

Color for the highest value.

color_midpoint

Value for the middle scale. Default is NULL.

if_use_newmeta

Whether to use newmeta o plot the spatial distribution of gene after dec_celltype for spot-based data. Default is TRUE.

celltype

gene in which celltype to plot. Default is NULL. Set if_use_newmeta TRUE when using this parameter.

if_plot_others

Whether to plot other cells when to use defined celltype.

Details

Please set if_use_newmeta as FALSE to plot the spatial distribution of gene before dec_celltype for spot-based data.


Plot spatial transcriptomics data

Description

Plot scatterpie for spatial transcriptomics data

Usage

plot_st_pie(object, pie_scale = 1, xy_ratio = 1, color = NULL)

Arguments

object

SpaTalk object generated from dec_celltype.

pie_scale

Scale of each pie to plot. Default is 1.

xy_ratio

Ratio of y and x coordinates. Default is 1.

color

Filled of colors for pie plot, length of color must be equal to the number of unique cell types in sc_celltype.


Plot spatial transcriptomics data

Description

Plot scatterpie for spot-based ST data

Usage

plot_st_pie_generate(st_meta, pie_scale = 1, xy_ratio = 1, color = NULL)

Arguments

st_meta

st_meta generated from generate_spot

pie_scale

Scale of each pie to plot. Default is 1.

xy_ratio

Ratio of y and x coordinates. Default is 1.

color

Filled of colors for pie plot, length of color must be equal to the number of unique cell types in sc_celltype.


Pre-processing step: revising gene symbols

Description

Revise genes according to NCBI Gene symbols updated in June 30, 2021 for count matrix, user-custom lrpairs data.frame, and user-custom pathways data.frame.

Usage

rev_gene(data = NULL, data_type = NULL, species = NULL, geneinfo = NULL)

Arguments

data

A data.frame or matrix or dgCMatrix containing count data each column representing a spot or a cell, each row representing a gene; Or a data.frame containing ligand-receptor pairs; Or a data.frame containing gene-gene interactions and pathways from KEGG and Reactome as well as the information of transcriptional factors.

data_type

A character to define the type of data, select 'count' for the data matrix, 'lrpairs' for the data.frame containing lrpairs, 'pathways' for the data.frame containing pathways.

species

Species of the data.'Human' or 'Mouse'.

geneinfo

A data.frame of the system data containing gene symbols of 'Human' and 'Mouse' updated on June 30, 2021 for revising count matrix.

Value

A new matrix or data.frame.


Set the expected cell

Description

Set the expected cell in SpaTalk object

Usage

set_expected_cell(object, value)

Arguments

object

SpaTalk object

value

Th number of expected cell for each spot, must be equal to the spot number.

Value

SpaTalk object


Show SpaTalk object

Description

Show SpaTalk object

Usage

## S4 method for signature 'SpaTalk'
show(object)

Arguments

object

A SpaTalk object

Value

Invisible NULL, prints summary information


Definition of 'SpaTalk' class

Description

An S4 class containing the data, meta, and results of inferred cell type compositions, LR pairs, and pathways.

Slots

data

A list containing the raw and normalized data.

meta

A list containing the raw and new meta data.

para

A list containing the parameters.

coef

A matrix containing the results of deconvolution.

cellpair

A list containing the cell-cell pairs based on the spatial distance.

dist

A matrix containing the Euclidean distance among cells.

lrpair

A data frame containing the inferred LR pairs.

tf

A data frame containing the TFs of receptors.

lr_path

A list containing the lrpairs and pathways.