Plot sample signal over windows spanning a gene (± flanks) as a heatmap using ComplexHeatmap. The gene can be given as a HGNC symbol or Ensembl ID.

plotGeneHeatmap(
  qseaSet,
  gene,
  normMethod = "beta",
  useGroupMeans = FALSE,
  sampleAnnotation = NULL,
  minDensity = 0,
  minEnrichment = 3,
  maxScale = 1,
  clusterNum = NULL,
  annotationColors = NA,
  upstreamDist = 3000,
  scaleRows = FALSE,
  clusterCols = TRUE,
  mart = NULL,
  showSampleNames = NULL,
  downstreamDist = 1000,
  idType = NULL,
  ...
)

Arguments

qseaSet

qseaSet. Input object containing windows and counts/betas.

gene

character(1). Gene identifier to plot (HGNC symbol like "HOXA9" or Ensembl ID like "ENSG000...").

normMethod

character(1). Which measure to plot. One of "beta" or "nrpm". Default: "beta".

useGroupMeans

logical(1). If TRUE, average samples by the group column in the sample table (combine replicates). Default: FALSE.

sampleAnnotation

tidyselect specification or character() or NULL. Columns from the sample table to display as column annotations (e.g., c("tumour","tissue") or bare helpers tumour, tissue). Default: NULL.

minDensity

numeric(1). Minimum CpG_density required to keep a window. Default: 0.

minEnrichment

numeric(1). For "beta", values with enrichment < minEnrichment are set to NA. Default: 3.

maxScale

numeric(1). Upper limit of the colour scale (used for "nrpm"; not applied to "beta"). Default: 1.

clusterNum

integer(1) or NULL. If set, cut the column dendrogram into this many clusters and display cluster labels. Default: NULL.

annotationColors

list or NA. Optional named colour maps for annotations, e.g. list(tumour = c(Tumour = "firebrick4", Normal = "blue")). Default: NA.

upstreamDist

integer(1). Number of base pairs upstream of the gene to include. Default: 3000.

scaleRows

logical(1). Whether to z-score scale rows (windows) before plotting. Default: FALSE.

clusterCols

logical(1). Whether to cluster columns (samples). Default: TRUE.

mart

biomaRt::Mart or NULL. Ensembl mart used to resolve gene coordinates. If NULL, uses the mart stored on the qseaSet (see setMart()); otherwise falls back to a default for GRCh38/hg38 or hg19. Other genomes, such as mouse, need a mart that matches the genome build. Default: NULL.

showSampleNames

logical(1) or NULL. If NULL, names are shown when there are fewer than 50 samples; set TRUE/FALSE to force. Default: NULL.

downstreamDist

integer(1). Number of base pairs downstream of the gene to include. Default: 1000.

idType

character(1) or NULL. Column in the mart to match gene against (needed for non-human/mouse setups). Default: NULL.

...

Additional arguments forwarded to ComplexHeatmap constructors.

Value

Draws a heatmap on the active device and (invisibly) returns the underlying ComplexHeatmap object (e.g., a Heatmap/HeatmapList) for further composition with draw.

Details

The function resolves the gene to genomic coordinates (using mart, or a mart stored on the object, or a built-in default for human builds), expands the interval by upstreamDist/downstreamDist, filters windows by overlap and minDensity, then draws a heatmap of "beta" or "nrpm". For "beta", values below minEnrichment are set to NA. If useGroupMeans = TRUE, samples are aggregated by group prior to plotting. Column annotations can be added via sampleAnnotation; colours can be customized via annotationColors.

The mart's BioMart service is probed first, and the function stops if it does not answer within getOption("mesa_ensemblTimeout", 5) seconds. A mart with its own http_config is not probed.

Examples

data(exampleTumourNormal, package = "mesa")

# Gene heatmap (beta) with sample annotations (tidyselect bare names),
# columns clustered into 2 groups, custom colours and wider flanks.
# (ensemblReachable() skips the example when Ensembl does not answer.)
if (mesa:::ensemblReachable("jul2022.archive.ensembl.org")) {
    tryCatch(
        exampleTumourNormal %>%
            plotGeneHeatmap("HOXA9",
                sampleAnnotation = c(tumour, tissue),
                clusterNum = 2,
                annotationColors = list(
                    tumour = c(Tumour = "firebrick4", Normal = "blue")
                ),
                upstreamDist = 1000,
                downstreamDist = 2000),
        error = function(e) {
            message("Ensembl unavailable: ", conditionMessage(e))
        }
    )
}