Package 'CancerEvolutionVisualization'

Title: Publication Quality Phylogenetic Tree Plots
Description: Generates tree plots with precise branch lengths, gene annotations, and cellular prevalence. The package handles complex tree structures (angles, lengths, etc.) and can be further refined as needed by the user.
Authors: Paul Boutros [cre], Adriana Salcedo [aut], Dan Knight [aut], Helena Winata [aut], Selina Wu [ctb]
Maintainer: Paul Boutros <[email protected]>
License: GPL-2
Version: 3.0.0
Built: 2025-01-07 18:30:19 UTC
Source: https://github.com/uclahs-cds/package-cancerevolutionvisualization

Help Index


Colour scheme vector

Description

Default colours used by CP polygons, etc.

Format

Character vector


CCF Distribution Heatmap

Description

Creates a heatmap of cancer cell fraction (CCF) distribution across tumour samples. The function is a wrapper around BoutrosLab.plotting.general::create.heatmap() with some changes in the default parameters. All parameter description are the same as in BoutrosLab.plotting.general::create.heatmap() except for ccf.thres.

Usage

create.ccf.heatmap(
    x,
    cluster.dimensions = 'both',
    clustering.method = 'complete',
    distance.method = 'euclidean',
    xaxis.lab = '',
    xlab.label = 'SNVs',
    print.colour.key = FALSE,
    colour.scheme = c('white', 'blue'),
    ...
    )

Arguments

x

Either a data-frame or a matrix from which the heatmap is to created

cluster.dimensions

Defaults to “both”.

clustering.method

Defaults to “complete”.

distance.method

Defaults to “euclidean”.

xaxis.lab

Defaults to an empty string.

xlab.label

Defaults to “SNVs”.

print.colour.key

Defaults to FALSE.

colour.scheme

Defaults to c('white', 'blue').

...

Pass through argument. See BoutrosLab.plotting.general::create.heatmap() for further details.

Value

A 'grob' object of the heatmap.

Author(s)

Helena Winata

See Also

create.heatmap

Examples

set.seed(123);
    arr <- matrix(rnorm(500), nrow = 100, ncol = 5);
    rownames(arr) <- paste0('SNV.', 1:100);
    colnames(arr) <- paste0('Sample.', 1:5);
    create.ccf.heatmap(arr);

CCF Summary Heatmap

Description

Creates a heatmap of cancer cell fraction (CCF) distribution across tumour samples with clone IDs as a covariate beneath the heatmap. Subplot parameters controls the appearance of the heatmap and barplots. See BoutrosLab.plotting.general::create.barplot() or BoutrosLab.plotting.general::create.heatmap() for parameter description. Legend parameters are passed to BoutrosLab.plotting.general::legend.grob().

Usage

create.ccf.summary.heatmap(
    DF,
    ccf.limits = NULL,
    median.col = 'median.ccf.per.sample',
    clone.order = NULL,
    sample.order = NULL,
    colour.scheme = c('white', 'blue'),
    clone.colours = NULL,
    subplot.xlab.cex = 1.2,
    subplot.xaxis.cex = 1,
    subplot.xaxis.fontface = 'bold',
    subplot.xaxis.rot = 90,
    subplot.ylab.cex = 1.2,
    subplot.yaxis.cex = 1,
    subplot.yaxis.fontface = 'bold',
    hm.xaxis.rot = 90,
    legend.size = 3,
    legend.title.cex = 1.2,
    legend.label.cex = 1,
    legend.x = 0.9,
    legend.y = 0.8,
    plot.objects.heights = c(0.3, 1),
    add.median.text = FALSE,
    ...
    );

Arguments

DF

A data-frame with the following column names: 'ID', 'SNV.id', 'clone.id', 'CCF'.

ccf.limits

CCF limits to be applied to the heatmap. Must be a vector of length 2 for min and max thresholds. Defaults to NULL

median.col

Defaults to “median.ccf.per.sample”

clone.order

Defaults to NULL

sample.order

Defaults to NULL

colour.scheme

Heatmap colour scheme. Defaults to c('white', 'blue')

clone.colours

A named vector specifying the color to use for each clone to generate a covariate heatmap. If NULL, no covariates will be added.

subplot.xlab.cex

Subplot parameter. Defaults to 1.2

subplot.xaxis.cex

Subplot parameter. Defaults to 1

subplot.xaxis.fontface

Subplot parameter. Defaults to “bold”

subplot.xaxis.rot

Subplot parameter. Defaults to 90

subplot.ylab.cex

Subplot parameter. Defaults to 1.2

subplot.yaxis.cex

Subplot parameter. Defaults to 1

subplot.yaxis.fontface

Subplot parameter. Defaults to “bold”

hm.xaxis.rot

Subplot parameter. Defaults to 90

legend.size

Legend parameter. Defaults to 3

legend.title.cex

Legend parameter. Defaults to 1.2

legend.label.cex

Legend parameter. Defaults to 1

legend.x

Legend parameter. Defaults to 0.9

legend.y

Legend parameter. Defaults to 0.8

plot.objects.heights

If clone.colours is specified, this must be an array of length 3. Defaults to c(0.3, 1). See BoutrosLab.plotting.general::create.multipanelplot()

add.median.text

If TRUE, median CCF values will be added to the heatmap. Defaults to FALSE

...

Pass through argument. See BoutrosLab.plotting.general::create.multipanelplot() for further details.

Value

A 'grob' object of the summary plot.

Author(s)

Helena Winata

See Also

legend.grob, create.multipanelplot, create.heatmap

Examples

set.seed(123);
snv <- do.call(rbind, lapply(split(snv, list(snv$ID, snv$clone.id)), function(df) {
    df$median.ccf.per.sample <- median(df$CCF)
    df$total.nsnv <- length(unique(df$SNV.id))
    df
    }));

create.ccf.summary.heatmap(snv);

Create Clone Genome Distribution Plot

Description

This function creates a plot showing the distribution of clones across the genome. It generates a scatter plot of the SNVs colored by clone ID and a density plot showing the density of each clone across the genome. The function can handle both single and multi-sample inputs.

Usage

create.clone.genome.distribution.plot(
    snv.df,
    genome.build = 'GRCh37',
    clone.order = NULL,
    clone.colours = NULL,
    filename = NULL,
    multi.sample = FALSE,
    alpha = 0.25,
    legend.x = 0.1,
    legend.y = 0.55,
    ...
    )

Arguments

snv.df

A data frame containing the SNV data. It must have columns 'chr', 'pos', and 'clone.id'. If multi.sample = TRUE, it must also have a column 'ID' specifying the sample ID for each SNV.

genome.build

The genome build to use. Defaults to “GRCh37”.

clone.order

The order in which to plot the clones. If NULL, clones will be sorted alphabetically.

clone.colours

A named vector specifying the color to use for each clone. If NULL, colors will be automatically assigned.

filename

Directory or filepath to save the plot in. If multi.sample = TRUE, this must be a directory. if multi.sample = FALSE, this must be a filepath. If NULL, the plot will not be saved.

multi.sample

Logical indicating whether the input data contains multiple samples. Defaults to FALSE.

alpha

Transparency level of the points in the scatter plot. Defaults to 0.25.

legend.x

Legend parameter. Defaults to 0.1

legend.y

Legend parameter. Defaults to 0.55

...

Additional arguments to be passed to BoutrosLab.plotting.general::create.multipanelplot().

Details

This function preprocesses the input data frame, extracts chromosome information, and iterates over each sample to create a clone genome distribution plot. For each sample, it calculates the density of each clone across the genome and creates a scatter plot of the SNVs colored by clone ID and a density plot showing the density of each clone.

Value

A 'grob' object.

Author(s)

Helena Winata, Selina Wu

See Also

legend.grob, create.multipanelplot, create.scatterplot, create.densityplot

Examples

set.seed(123);
create.clone.genome.distribution.plot(snv);

Cluster Heatmap

Description

Creates a heatmap of cancer cell fraction (CCF) distribution across tumour samples with clone IDs as a covariate beneath the heatmap.

Usage

create.cluster.heatmap(
    DF,
    ccf.limits = NULL,
    clone.colours = NULL,
    height = 6,
    width = 11,
    xaxis.col = NULL,
    legend.size = 3,
    legend.title.cex = 1.2,
    legend.label.cex = 1,
    filename = NULL,
    xlab.label = 'SNVs',
    xlab.cex = 1.2,
    xaxis.cex = 1,
    xaxis.fontface = 'bold',
    y.spacing = 1,
    colour.scheme = c('white', 'blue'),
    ...
    );

Arguments

DF

A data-frame with the following column names: 'ID', 'SNV.id', 'clone.id', 'CCF'.

ccf.limits

CCF limits to be applied to the heatmap. Must be a vector of length 2 for min and max thresholds. Defaults to NULL

clone.colours

Named list to provide a colour scheme for the clone ID covariate bar. If NULL, colours will be randomly generated. Defaults to NULL.

height

Defaults to 6

width

Defaults to 11

xaxis.col

Column in DF to extract x-axis labels from. Defaults to NULL.

legend.size

Width of the legend boxes in 'character' units. Defaults to 3

legend.title.cex

Size of titles in the legends. Defaults to 1.2

legend.label.cex

Size of text labels in the legends. Defaults to 1

filename

Filename for tiff output, or if NULL returns the trellis object itself. Defaults to NULL.

xlab.label

Defaults to “SNVs”.

xlab.cex

Defaults to 1.2

xaxis.cex

Defaults to 1

xaxis.fontface

Defaults to “bold”.

y.spacing

Spacing between heatmap and clone covariate bar. Defaults to 1

colour.scheme

Colour scheme for the heatmap. Defaults to c('white', 'blue').

...

Pass through argument. See BoutrosLab.plotting.general::create.heatmap() for further details.

Value

A 'grob' object of the heatmap.

Author(s)

Helena Winata

See Also

create.ccf.heatmap, create.heatmap

Examples

set.seed(123);

create.cluster.heatmap(
    DF = snv,
    ccf.limits = c(0, 1),
    ylab.label = 'Sample'
    );

Phylogenetic Tree Plot

Description

Create a phylogenetic tree plot using 'SRCGrob'. The 'width', 'heigth', 'units', 'res', and 'bg' arguments are passed to the 'grDevices' function to save the plot to file.

Usage

create.phylogenetic.tree(
    tree,
    filename = NULL,
    width = 5,
    height = 5,
    units = 'in',
    res = 500,
    bg = 'white',
    ...
    )

Arguments

tree

Tree structure data.frame

filename

Filename for plot output, or if NULL displays the tree using grid.draw. Defaults to NULL.

width

Width of the plot. Defaults to 5.

height

Height of the plot. Defaults to 5.

units

Units of the plot. Defaults to “in”.

res

Resolution of the plot. Defaults to 500.

bg

Background colour of the plot. Defaults to “white”.

...

Pass through argument. See SRCGrob() for further details.

Value

A 'grob' of class "SRCGrob".

Author(s)

Helena Winata

See Also

SRCGrob, pdf, png, tiff, svg

Examples

# Simple Tree Plot
simple.tree <- data.frame(
    parent = c(NA, 1, 1)
    );
create.phylogenetic.tree(simple.tree);

# Non-numeric node.id
phy.dt <- data.frame(
    node.id = c('MRCA', 'C01', 'C02', 'C03', 5:7),
    parent = c(NA, 'MRCA', 'MRCA', 'MRCA', 'C02', 'C03', 'C03')
    );
create.phylogenetic.tree(phy.dt);

# Numeric disordered node.id with labels
phy.dt <- data.frame(
    node.id = c(1, 2, 5, 6, 4, 9, 10),
    parent = c(NA, 1, 1, 1, 5, 6, 6),
    label = c('MRCA', 'C01', 'C02', 'C03', 5:7)
    );
create.phylogenetic.tree(phy.dt);

Convert Data Frame to Array

Description

Converts a long-format data frame into a 2D matrix/array where: - Rows correspond to unique values from the x.axis column - Columns correspond to unique values from the y.axis column - Cell values are taken from the value column - NA values are replaced with 0

Usage

data.frame.to.array(
    DF,
    value = 'CCF',
    x.axis = 'SNV.id',
    y.axis = 'ID'
    );

Arguments

DF

A data frame in long format containing the data to be reshaped.

value

The name of the column containing the values to be reshaped. Defaults to 'CCF'.

x.axis

The name of the column to be used as row names in the output matrix. Defaults to 'SNV.id'.

y.axis

The name of the column to be used as column names in the output matrix. Defaults to 'ID'.

Value

A 2D 'matrix'.

Author(s)

Helena Winata

Examples

df <- data.frame(
    SNV.id = c(rep(paste0('snv', 1:3), 3)),
    ID = c(rep('S1', 3), rep('S2', 3), rep('S3', 3)),
    CCF = runif(9)
    );

arr <- data.frame.to.array(df);

GRCh37 Chromosom Information

Description

Chromosome information for the GRCh37 genome build. Used for plotting.

Format

data.frame


GRCh38 Chromosom Information

Description

Chromosome information for the GRCh38 genome build. Used for plotting.

Format

data.frame


SNV dataframe

Description

Dataframe containing the following columns: 'ID', 'SNV.id', 'CCF', 'clone.id', 'chr', 'pos'. Used to generate plot examples.

Format

data.frame


Subclone Tree Plot

Description

Creates a phylogenetic tree using subclonal reconstruction data. An optional node text data.frame can be used to annotate notable genes alonside branches.

Usage

SRCGrob(
    tree,
    node.text = NULL,
    main = NULL,
    horizontal.padding = 0.1,
    scale1 = 1,
    scale2 = 1,
    yat = NULL,
    yaxis1.label = NULL,
    yaxis2.label = NULL,
    xlab.cex = 1.55,
    ylab.cex = 1.55,
    xaxis.cex = 1.45,
    yaxis.cex = 1.45,
    xaxis.label = 'CCF',
    label.cex = NA,
    node.text.cex = 0.85,
    main.y = NULL,
    main.cex = 1.7,
    node.text.line.dist = 0.1,
    polygon.colour.scheme = 'grey',
    polygon.scale = 1,
    add.normal = FALSE,
    use.radians = FALSE,
    normal.cex = 1,
    label.nodes = TRUE,
    disable.polygons = FALSE,
    length.from.node.edge = TRUE,
    size.units = 'npc',
    scale.bar = FALSE,
    scale.bar.coords = c(0.5, 1),
    scale.size.1 = NA,
    scale.size.2 = NA,
    scale.padding = 1
    );

Arguments

tree

Tree structure data.frame

node.text

Dataframe for text labels to be displayed next to nodes

main

Main plot title

horizontal.padding

Increase/reduce the plot's horizontal padding proportionally. A positive value will expand the padding, and a negative value will reduce it.

scale1

Proportionally scale the values of the first branch length column in the tree input.

scale2

Proportionally scale the values of the second branch length column in the tree input.

yat

Specific values to be used for the y-axis ticks. A list is required, with each element corresponding to an axis.

yaxis1.label

Text label for the first, leftmost y-axis

yaxis2.label

Text label for the second, rightmost y-axis

xlab.cex

Font size for the x-axis label

ylab.cex

Font size for the y-axis labels

xaxis.cex

Font size for the x-axis tick labels

yaxis.cex

Font size for the y-axis tick labels

xaxis.label

Text label for the x-axis

label.cex

Font size for the node labels

node.text.cex

Font size for the node text

main.y

Move the main plot title position up or down

main.cex

Font size for the main plot title

node.text.line.dist

Distance between node text and tree branches (as a value between 0 and 1)

add.normal

Adds a normal

use.radians

Unit to be used for 'angle' column (degrees or radians)

normal.cex

Font size within the normal 'box'

label.nodes

Enable/disable node labels

disable.polygons

Disables CCF polygon drawing (even when CCF values are provided)

polygon.colour.scheme

Vector of colour values to be used for CCF polygons. Creates a gradient color scheme.

polygon.scale

Multiplier to scale CCF polygons (must be positive).

length.from.node.edge

Sets the branch length to be calculated from the edge of the node instead of the centre

size.units

Grid units to be used for all specific size/length parameters

scale.bar

Set to TRUE to add a scale bar instead of y-axis

scale.bar.coords

Coordinates for the scale bar placement c(x.pos, y.pos)

scale.size.1

Overide size of the first scale bar

scale.size.2

Overide size of the second scale bar

scale.padding

Padding between scale bars if more than 1 is present

Value

A ‘grob' of class ’SRCGrob'

Author(s)

Dan Knight

Examples

# Simple Tree Plot
simple.tree <- data.frame(
    parent = c(NA, 1, 1)
    );

SRCGrob(simple.tree);


# Specify Branch Lengths
branch.lengths.tree <- data.frame(
    simple.tree,
    length1 = c(10, 20, 15)
    );

SRCGrob(branch.lengths.tree);


# Cellular Prevalence
CCF.tree <- data.frame(
    branch.lengths.tree,
    CCF = c(1, 0.3, 0.5)
    );

SRCGrob(CCF.tree);


# Scaled Branch Lengths
SRCGrob(
    branch.lengths.tree,
    scale1 = 0.8
    );


# Override Branch Angles in Degrees
degrees.tree <- data.frame(
    parent = c(NA, 1, 2),
    angle = c(NA, NA, 90)
    );

SRCGrob(degrees.tree);


# Override Branch Angles in Radians
radians.tree <- data.frame(
    parent = c(NA, 1, 2),
    angle = c(NA, NA, pi / 2)
    );

SRCGrob(
    radians.tree,
    use.radians = TRUE
    );


# Plot Title
SRCGrob(
    simple.tree,
    main = 'Example Plot'
    );


# Y-Axis Label
SRCGrob(
    branch.lengths.tree,
    yaxis1.label = 'SNVs'
    );


# Y-Axis Ticks
yaxis1.ticks <- seq(0, 10, 2);

SRCGrob(
    branch.lengths.tree,
    yat = list(yaxis1.ticks)
    );


# Scale Bar
SRCGrob(
    branch.lengths.tree,
    yaxis1.label = 'SNVs',
    scale.bar = TRUE
    );


# Normal
SRCGrob(
    simple.tree,
    add.normal = TRUE
    );


# Nodeless Mode
nodeless.tree <- data.frame(
    parent = c(NA, 1, 2, 2),
    draw.node = c(TRUE, FALSE, TRUE, TRUE)
    );

SRCGrob(nodeless.tree);

Update Tree Descendant Property

Description

Function to iteratively update a specified property for all descendants of a given parent node(s) in a tree structure. The function works recursively, meaning it will update values for all descendants, not just immediate children. If a parent_id has no children, the original data frame is returned unchanged.

Usage

update.descendant.property(
    x,
    parent.id,
    property,
    value,
    overwrite = TRUE
    );

Arguments

x

A data frame representing a tree structure with at least the following columns: parent (parent node identifiers), and the column specified by property

parent.id

Character or numeric vector specifying the identifier(s) of the parent node(s)

property

Character string specifying the name of the column/property to be updated

value

The value to assign to the property column

overwrite

Logical; if TRUE, overwrites existing values; if FALSE, only fills in NA values. Defaults to TRUE

Value

A 'data.frame' with modified columns.

Author(s)

Helena Winata

Examples

tree <- data.frame(
    node.id = c('A', 'B', 'C', 'D', 'E', 'F'),
    parent = c(NA, 'A', 'B', 'A', 'C', 'E'),
    node.size = 1
    );

tree2 <- update.descendant.property(
    x = tree,
    parent.id = 'B',
    property = 'node.size',
    value = 2
    );