CNV Plotting Functions
1 CNV Plotting Functions
1.1 Overview
The plot_cnv.R module provides visualization for copy number variants in the IMPACT Plot. CNVs are displayed as a single horizontal track with color encoding: red for deletions (loss of DNA), blue for duplications (gain of DNA).
Location: app/logic/plot_cnv.R
1.2 Exported Functions
1.2.1 cnv_colors()
Returns a named vector of colors for CNV types.
Parameters: None
Returns: Named character vector - "Deletion" → "red" - "Duplication" → "blue"
Example:
box::use(app/logic/plot_cnv[cnv_colors])
colors <- cnv_colors()1.2.2 cnv_plotly()
Builds the CNV plot as a plotly widget from a CNV file path.
Parameters: - cnv_path (character|NULL): Path to CNV TXT file. If missing/invalid, returns baseline_cnv_plotly(). - selected_chr (character): "All" or chromosome string. - variant_states (list|data.frame|NULL): Optional per-variant annotations keyed by ID or CNV_<ID>. - show_failed_qc (logical): If FALSE, filters out CNVs where QC != "Passed".
Returns: plotly object
Details: - Coordinates are computed in Mb; in genome-wide mode, cumulative chromosome offsets from plot_gds$chr_lengths() are applied. - Type values are normalized (DEL→Deletion, DUP→Duplication) when present.
Example:
box::use(app/logic/plot_cnv[cnv_plotly])
p <- cnv_plotly(
cnv_path = "app/data/sample_1_CNV_IMPACT.txt",
selected_chr = "All",
show_failed_qc = FALSE
)1.2.3 baseline_cnv_plot()
Creates a baseline ggplot object configured for CNV visualization. This is a minimal ggplot with no data points, used as a starting point for building CNV plots.
Parameters: None
Returns: ggplot object (blank, ready for addition of CNV data)
Example:
box::use(app/logic/plot_cnv[baseline_cnv_plot])
p <- baseline_cnv_plot()1.2.4 baseline_cnv_plotly()
Converts the baseline CNV ggplot to an interactive plotly object.
Parameters: None
Returns: plotly object
Example:
box::use(app/logic/plot_cnv[baseline_cnv_plotly])
p <- baseline_cnv_plotly()1.2.5 load_cnv_data()
Loads and parses the CNV TXT file for plotting. Note this is a separate function from data_manager$load_cnv_data() and returns a different column set tailored for plotting.
Parameters: - cnv_path (character): Path to CNV file
Returns: data.frame or NULL
1.3 Internal Functions
The module contains internal helper functions for coordinate transformation and styling (not exported).
1.4 Development Status
Future enhancements to plot_cnv.R may include: - Genome-wide CNV segment plots - Interactive CNV selection and highlighting - Copy number state annotations (DEL, DUP, amplifications) - Integration with CNV confidence metrics