
Extract normalised gene expression for plotting
extract_gene_expression.RdExtracts dense normalised (log1p) expression values for a set of genes, optionally with additional observation metadata columns.
Arguments
- object
A single cell class.
- features
Character vector. Gene IDs to extract.
- obs_cols
Optional character vector. Column names from the obs table to include.
- scale
Boolean. Whether to z-score the expression values.
- clip
Optional numeric. If
scale = TRUE, clip z-scores to[-clip, clip].- modality
String. One of
c("rna", "adt"). ADT is only available forSingleCellsMultiModal.- layer
String. One of
c("norm", "magic"). With"magic"the values come from the imputed layerrun_magic_sc()wrote, which only holds the genes it was asked for. Imputation inflates gene-gene correlation, so this is for looking at things, not for measuring them. Note thatextract_dot_plot_data()deliberately has no such argument: group means of imputed values are exactly the quantity MAGIC manufactures.
Examples
# normalised expression of three genes with a cell annotation
sc <- demo_single_cells()
dt <- extract_gene_expression(
sc,
features = get_gene_names(sc)[1:3],
obs_cols = "cell_grp"
)
head(dt, 3)
#> cell_id gene_01 gene_02 gene_03 cell_grp
#> <char> <num> <num> <num> <char>
#> 1: cell_001 6.222656 6.761719 5.531250 cell_type_1
#> 2: cell_002 4.113281 4.511719 4.113281 cell_type_2
#> 3: cell_003 4.300781 4.300781 3.226562 cell_type_3
unlink(sc@dir_data, recursive = TRUE, force = TRUE)