Skip to contents

This function is the equivalent of running table on SpatialMap cell-and project-Metadata columns and automatically removing rows with Project Metadata combinations that don't exist or are invalid. So, if you are running table on cell types, Regions, and disease status-this will then remove rows with a combination of Region and disease status that technically don't exist, without removing all rows of zero frequency. Such as in the case of a patient 1 has tonsilitis and patient 2 is a control. You don't want 4 rows of B-cells in your frequency table where the tonsillitis-cohort has data points for both patient 1 and 2

The purpose of this is to be able to create a metadata frequency table without superfluous rows of zero frequency that aren't actual/valid data points. Because there will be rows of zero frequency that are data points, and you want to be able to keep those.

Example output:

if Patient's 1&2 have tonsilititis but patient's 3&4 do not

Running as.data.frame(table(cluster, patient, group)):

clusterpatientgroupFreq
T-cellpatient 1Tonsilitis12
T-cellpatient 2Tonsilitis0
T-cellpatient 3Tonsilitis0
T-cellpatient 4Tonsilitis0
T-cellpatient 1Control0
T-cellpatient 2Control0
T-cellpatient 3Control5
T-cellpatient 4Control3

Running get_valid_metadata_counts(sm, c("cluster", "patient", "group")):

clusterpatientgroupFreq
T-cellpatient 1Tonsilitis12
T-cellpatient 2Tonsilitis0
T-cellpatient 3Control5
T-cellpatient 4Control3

Usage

get_valid_metadata_counts(object, metadata_columns)

Arguments

object

SpatialMap object or Region

metadata_columns

string or character vector of both projectMetadata and cellMetadata column names

Value

data.frame frequency table of same format as the output of as.data.frame(table(...))

Examples

if (FALSE){
  # Load example data
  sm_skin <- load_sm_data("skin")

  # Look at available data
  head(projectMetadata(sm_skin))
  head(cellMetadata(sm_skin))

  # Choose columns to make table out of
  cellMetadata_columns <- c("cell_type","anno392_Phenotype2_neighborhood")
  projectMetadata_columns <- c("dermatitis_status","region_display_label")

  # Run the function and make metadata contingency table
  all_cluster_counts <- get_valid_metadata_counts(
     object = sm_skin,
     metadata_columns = c(cellMetadata_columns, projectMetadata_columns)
  )
}

Scroll to top