
Get SpatialMap metadata frequency table
get_valid_metadata_counts.Rd
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))
:
cluster | patient | group | Freq |
T-cell | patient 1 | Tonsilitis | 12 |
T-cell | patient 2 | Tonsilitis | 0 |
T-cell | patient 3 | Tonsilitis | 0 |
T-cell | patient 4 | Tonsilitis | 0 |
T-cell | patient 1 | Control | 0 |
T-cell | patient 2 | Control | 0 |
T-cell | patient 3 | Control | 5 |
T-cell | patient 4 | Control | 3 |
Running get_valid_metadata_counts(sm, c("cluster", "patient", "group"))
:
cluster | patient | group | Freq |
T-cell | patient 1 | Tonsilitis | 12 |
T-cell | patient 2 | Tonsilitis | 0 |
T-cell | patient 3 | Control | 5 |
T-cell | patient 4 | Control | 3 |
Arguments
- object
SpatialMap object or Region
- metadata_columns
string or character vector of both projectMetadata and cellMetadata column names
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)
)
}