View source: R/rnaseq_related.R
get_gene_expression_heatmap | R Documentation |
Heatmap is a common tool to show gene expression pattern across samples in RNA-seq experiments.
During data exploration, it is a common practice to generate several heatmaps to identify interesting
patterns of gene expression across samples. Most heatmap generating tools require data in a tabular format.
However, to prepare such a data requires significant data wrangling such as sub-setting
genes (rows) and samples (columns) from multiple R objects. Such data wrangling creates redundant, and less readable code
which increases the chances of error. Furthermore, because of less readability using the same code for another analysis
requires code cleaning and code rewriting making code less reusable.
Situations complicates even more when RNA-seq studies consist of several samples and several comparisons.
This function cut-downs several steps of data wrangling to create a heatmap of gene expression, z-score or
log2 fold-change. Given an object of the class parcutils
, sample names or sample comparisons, genes to show in the heatmap
and several other arguments, the heatmap can be created quickly. The output heatmap is an output of the function ComplexHeatmap::Heatmap()
which then can be used with other functions of the ComplexHeatmap package.
get_gene_expression_heatmap(
x,
samples,
genes,
repair_genes = FALSE,
convert_log2 = FALSE,
color_default = TRUE,
col = NULL,
convert_zscore = TRUE,
convert_rowmeans = FALSE,
summarise_replicates = TRUE,
summarise_method = "median",
show_row_names = FALSE,
cluster_rows = TRUE,
show_row_dend = TRUE,
row_names_font_size = 10,
label_specific_rows = NULL,
label_specific_rows_gp = gpar(fontface = "plain", fontsize = 10, col = "red"),
show_column_names = TRUE,
cluster_columns = TRUE,
show_heatmap_legend = TRUE,
...
)
get_fold_change_heatmap(
x,
sample_comparisons,
genes,
repair_genes = FALSE,
color_default = TRUE,
col = NULL,
show_row_names = FALSE,
cluster_rows = TRUE,
show_row_dend = TRUE,
row_names_font_size = 10,
show_column_names = TRUE,
cluster_columns = TRUE,
show_heatmap_legend = TRUE,
...
)
x |
an abject of the class |
samples |
a character vector denoting sample names to use in the heatmap. |
genes |
a character vector denoting genes to use in the heatmap. |
repair_genes |
logical, default |
convert_log2 |
logical, default |
color_default |
logical, default |
col |
an output of |
convert_zscore |
logical, default |
convert_rowmeans |
logical, default |
summarise_replicates |
logical, default |
summarise_method |
a character string, either mean or median. |
show_row_names |
logical, default |
cluster_rows |
logical, default |
show_row_dend |
logical, default |
row_names_font_size |
a numeric value, default 10, indicating size of row names in the heatmap. |
label_specific_rows |
a character string denoting set of gene/s to be labelled in the heatmap. Label must match to the rownames of the final matrix supplied. |
label_specific_rows_gp |
pass to |
show_column_names |
logical, default |
cluster_columns |
logical, default |
show_heatmap_legend |
logical, default |
... |
Other parameters to be passes to |
sample_comparisons |
a character vector denoting sample comparisons for which heatmap of log2 fold-change to be plotted. |
The function get_gene_expression_heatmap
is to create a heatmap either for normalised gene expression or z-score values
while the function get_fold_change_heatmap
is to create a heatmap for log2 fold-changes values.
repair_genes
: Internally gene names are stored as a "gene_id:gene_symbol" format. For example, "ENSG00000187634:SAMD11".
When repair_genes
is set to TRUE
the string corresponding to gene_id followed by ":" will be removed. This is useful when gene names
to be revealed in the heatmap.
convert_zscore
: When set to TRUE
values for each gene is converted into z-score. z-score is calculated by baser r function base::scale()
with all default parameters.
an output of the function ComplexHeatmap::Heatmap()
.
count_file <- system.file("extdata","toy_counts.txt" , package = "parcutils")
count_data <- readr::read_delim(count_file, delim = "\t")
sample_info <- count_data %>% colnames() %>% .[-1] %>%
tibble::tibble(samples = . , groups = rep(c("control" ,"treatment1" , "treatment2"), each = 3) )
res <- run_deseq_analysis(counts = count_data ,
sample_info = sample_info,
column_geneid = "gene_id" ,
group_numerator = c("treatment1", "treatment2") ,
group_denominator = c("control"))
genes = parcutils::get_genes_by_regulation(x = res, sample_comparison = "treatment2_VS_control" , "both") %>% names()
get_gene_expression_heatmap(x = res, samples = c("control" ,"treatment1" , "treatment2"), genes = genes, label_specific_rows = c("POU5F1","PTPN18","RABL3","PTPN19"),repair_genes = TRUE,show_row_names = FALSE)
# plot raw expression values
get_gene_expression_heatmap(x = res, samples = c("control" ,"treatment1" , "treatment2"),
genes = genes, convert_zscore = FALSE)
# plot log2 expression values
get_gene_expression_heatmap(x = res, samples = c("control" ,"treatment1" , "treatment2"),
genes = genes, convert_zscore = FALSE,convert_log2 = TRUE)
# plot all replicates
get_gene_expression_heatmap(x = res, samples = c("control" ,"treatment1" , "treatment2"),
genes = genes, convert_zscore = TRUE, summarise_replicates = FALSE)
# show gene names
get_gene_expression_heatmap(x = res, samples = c("control" ,"treatment1" , "treatment2"),
genes = genes[1:10], convert_zscore = TRUE, summarise_replicates = FALSE , show_row_names = TRUE)
# repair gene names
get_gene_expression_heatmap(x = res, samples = c("control" ,"treatment1" , "treatment2"),
genes = genes[1:10], convert_zscore = TRUE, summarise_replicates = FALSE, show_row_names = TRUE, repair_genes = TRUE)
# fold change heatmap
get_fold_change_heatmap(x = res , sample_comparisons = c("treatment2_VS_control" ,"treatment1_VS_control") ,
genes = genes , cluster_columns = FALSE , name = "Log2FC")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.