Calculates pairwise distances or correlations between query and reference cells of a specific cell type.

plotPairwiseDistancesDensity(
  query_data,
  reference_data,
  query_cell_type_col,
  ref_cell_type_col,
  cell_type_query,
  cell_type_ref,
  pc_subset = 1:5,
  distance_metric = c("correlation", "euclidean"),
  correlation_method = c("spearman", "pearson"),
  assay_name = "logcounts"
)

Arguments

query_data

A SingleCellExperiment containing the single-cell expression data and metadata.

reference_data

A SingleCellExperiment object containing the single-cell expression data and metadata.

query_cell_type_col

The column name in the colData of query_data that identifies the cell types.

ref_cell_type_col

The column name in the colData of reference_data that identifies the cell types.

cell_type_query

The query cell type for which distances or correlations are calculated.

cell_type_ref

The reference cell type for which distances or correlations are calculated.

pc_subset

A numeric vector specifying which principal components to use in the analysis. Default is 1:5. If set to NULL then no dimensionality reduction is performed and the assay data is used directly for computations.

distance_metric

The distance metric to use for calculating pairwise distances, such as euclidean, manhattan etc. Set it to "correlation" for calculating correlation coefficients.

correlation_method

The correlation method to use when distance_metric is "correlation". Possible values: "pearson", "spearman".

assay_name

Name of the assay on which to perform computations. Default is "logcounts".

Value

A plot generated by ggplot2, showing the density distribution of calculated distances or correlations.

Details

The function works with SingleCellExperiment objects, ensuring compatibility with common single-cell analysis workflows. It subsets the data for specified cell types, computes pairwise distances or correlations, and visualizes these measurements using density plots. By comparing the distances and correlations, one can evaluate the consistency and reliability of annotated cell types within single-cell datasets.

Examples

# Load data
data("reference_data")
data("query_data")

# Example usage of the function
plotPairwiseDistancesDensity(query_data = query_data, 
                             reference_data = reference_data, 
                             query_cell_type_col = "SingleR_annotation", 
                             ref_cell_type_col = "expert_annotation", 
                             cell_type_query = "CD8", 
                             cell_type_ref = "CD8", 
                             pc_subset = 1:5,
                             distance_metric = "euclidean", 
                             correlation_method = "pearson")