ktrns / scrnaseq

Workflow for single-cell RNA-seq analysis using Seurat
MIT License
37 stars 15 forks source link

Clean up meta data after filtering #111

Closed ktrns closed 2 years ago

ktrns commented 2 years ago

We need to clean up our cell metadata if samples are dropped. Else they appear in legends of plots later on... This chunk should placed just before ## Normalisation.

# Remove filtered cells from meta data
sc_cell_metadata = sc_cell_metadata %>% dplyr::filter(IS_FILTERED==FALSE)

# Update levels 
idx.factors = sapply(sc_cell_metadata, is.factor) %>% which()
for (n in colnames(sc_cell_metadata[idx.factors])) { 
  levels_new = sc_cell_metadata %>% dplyr::pull(n) %>% as.character() %>% unique()
  sc_cell_metadata[[n]] = factor(sc_cell_metadata[[n]], levels=levels_new)
}

# Update actual colors as well, as they will appear in the plots otherwise
param$col_samples_orig = param$col_samples
param$col_samples = param$col_samples_orig[ -match(param$samples_to_drop, names(param$col_samples_orig)) ]