From 12733a036124e1f54a7235b533df03dee91c1e98 Mon Sep 17 00:00:00 2001 From: rdmorin Date: Thu, 9 Jan 2025 14:27:57 -0800 Subject: [PATCH 1/5] now showTumorSampleBarcode works in stacked mode --- R/prettyOncoplot.R | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/R/prettyOncoplot.R b/R/prettyOncoplot.R index be94626..9062f82 100644 --- a/R/prettyOncoplot.R +++ b/R/prettyOncoplot.R @@ -273,7 +273,12 @@ prettyOncoplot = function( Hugo_Symbol, Variant_Classification = value ) + maf_df_noncoding <- inner_join(maf_df, nc) + if(verbose){ + print(nc) + print(maf_df_noncoding) + } } else { # Make empty maf_df maf_df_noncoding <- maf_df %>% @@ -1122,7 +1127,7 @@ prettyOncoplot = function( cluster_rows=T, cluster_cols=F, fontsize_row = 6, - show_colnames = F + show_colnames = showTumorSampleBarcode ) if(verbose){ print("Done!") @@ -1135,7 +1140,7 @@ prettyOncoplot = function( cluster_cols=T, cluster_rows=F, fontsize_row = 6, - show_colnames = F + show_colnames = showTumorSampleBarcode ) }else{ message("clustering mutation rows and columns") @@ -1144,7 +1149,7 @@ prettyOncoplot = function( clustering_distance_rows=clustering_distance_rows, clustering_distance_cols=clustering_distance_cols, fontsize_row = 6, - show_colnames = F) + show_colnames = showTumorSampleBarcode) } if(dry_run){ print(h_obj) @@ -1419,7 +1424,7 @@ make_prettyoncoplot = function(mat_input, message("re-clustering columns based on numeric metadata") hh = Heatmap(heat_mat,cluster_columns=T, - clustering_distance_columns = clustering_distance_cols) + clustering_distance_columns = clustering_distance_cols,show_column_names = showTumorSampleBarcode) col_order = NULL col_dend = column_dend(hh) @@ -1437,6 +1442,9 @@ make_prettyoncoplot = function(mat_input, if(verbose){ print(oncoprint_args) } + if(showTumorSampleBarcode){ + heatmap_args[['show_column_names']] = TRUE + } if(numeric_heatmap_location == "top"){ if(!missing(splitColumnName)){ heatmap_args[['column_split']] = column_split @@ -1446,11 +1454,17 @@ make_prettyoncoplot = function(mat_input, } if(verbose){ print(names(heatmap_args)) + print(names(oncoprint_args)) + print(oncoprint_args) + } + if(return_inputs){ + oncoprint_heatmap = do.call("oncoPrint",oncoprint_args) + numeric_heatmap = do.call("Heatmap",heatmap_args) } ht_list = do.call("Heatmap",heatmap_args) %v% - do.call("oncoPrint",oncoprint_args) %v% + ComplexHeatmap::HeatmapAnnotation(df = metadata_df_numeric, show_legend = show_legend, col = colours, @@ -1461,19 +1475,25 @@ make_prettyoncoplot = function(mat_input, col_fun = col_fun, ncol = 1, direction = legend_direction, - labels_gp = gpar(fontsize = legendFontSize))) + labels_gp = gpar(fontsize = legendFontSize))) %v% + do.call("oncoPrint",oncoprint_args) draw(ht_list) if(return_inputs){ - return(list(Heatmap=ht_list,heat_mat=heat_mat,mut_mat=mat_input)) + return(list(Oncoprint=oncoprint_heatmap,Numeric=numeric_heatmap,Full_Heatmap=ht_list,heat_mat=heat_mat,mut_mat=mat_input)) } return() }else if(numeric_heatmap_location == "bottom"){ + if(return_inputs){ + oncoprint_heatmap = do.call("oncoPrint",oncoprint_args) + numeric_heatmap = do.call("Heatmap",heatmap_args) + } + ht_list = do.call("oncoPrint",oncoprint_args) %v% - do.call("Heatmap",heatmap_args) %v% + ComplexHeatmap::HeatmapAnnotation(df = metadata_df_numeric, show_legend = show_legend, col = colours, @@ -1484,13 +1504,14 @@ make_prettyoncoplot = function(mat_input, col_fun = col_fun, ncol = 1, direction = legend_direction, - labels_gp = gpar(fontsize = legendFontSize))) + labels_gp = gpar(fontsize = legendFontSize))) %v% + do.call("Heatmap",heatmap_args) draw(ht_list) if(return_inputs){ - return(list(Heatmap=ht_list,heat_mat=heat_mat,mut_mat=mat_input)) + return(list(Oncoprint=oncoprint_heatmap,Numeric=numeric_heatmap,Full_Heatmap=ht_list,heat_mat=heat_mat,mut_mat=mat_input)) } return() } From bd4e5c46349540fb6d3b108f2b330ad6a846eca7 Mon Sep 17 00:00:00 2001 From: rdmorin Date: Sun, 12 Jan 2025 11:03:08 -0800 Subject: [PATCH 2/5] add some flexiblity and new colour option --- R/plot_sample_circos.R | 73 ++++++++++++++++++++++++++++----------- man/plot_sample_circos.Rd | 6 +++- 2 files changed, 57 insertions(+), 22 deletions(-) diff --git a/R/plot_sample_circos.R b/R/plot_sample_circos.R index 45e2bc5..81b62ab 100644 --- a/R/plot_sample_circos.R +++ b/R/plot_sample_circos.R @@ -20,6 +20,7 @@ #' @param chrom_list List of chromosomes to be plotted. If not stated, chr1-22+X will be used. #' @param label_genes Gene labels (df, list or what type?) #' @param auto_label_sv Default is FALSE +#' @param hide_legend Set to TRUE if you want to suppress the legend. Particularly useful if you are not using GAMBL data/metadata #' #' @return Nothing #' @@ -56,11 +57,11 @@ plot_sample_circos = function(this_sample_id, this_seq_type = "genome", chrom_list, label_genes, - auto_label_sv = FALSE){ + auto_label_sv = FALSE, + auto_colour_links = FALSE, + hide_legend = FALSE){ + - if(this_projection == "hg38"){ - stop("Currently, only grch37 is supported...") - } add_cnv = function(cnv_df){ bed = data.frame(cnv_df[,c("chrom", "start", "end", "log.ratio")]) @@ -72,7 +73,7 @@ plot_sample_circos = function(this_sample_id, cell.xlim = get.cell.meta.data("cell.xlim") }, bg.border = NA) } - if(missing(cnv_df)){ + if(include_cnv & missing(cnv_df)){ cnv_df = get_sample_cn_segments( these_sample_ids = this_sample_id, with_chr_prefix = TRUE, @@ -85,10 +86,17 @@ plot_sample_circos = function(this_sample_id, chrom_list = paste0("chr", c(1:22,"X")) } if(!missing(label_genes)){ - gene_bed = GAMBLR.data::grch37_gene_coordinates %>% - dplyr::filter(gene_name %in% label_genes) %>% - dplyr::select(chromosome, start, end, gene_name) %>% - dplyr::mutate(chromosome = paste0("chr", chromosome)) + if(this_projection=="grch37"){ + gene_bed = GAMBLR.data::grch37_gene_coordinates %>% + dplyr::filter(gene_name %in% label_genes) %>% + dplyr::select(chromosome, start, end, gene_name) %>% + dplyr::mutate(chromosome = paste0("chr", chromosome)) + }else if(this_projection=="hg38"){ + gene_bed = GAMBLR.data::hg38_gene_coordinates %>% + dplyr::filter(gene_name %in% label_genes) %>% + dplyr::select(chromosome, start, end, gene_name) + } + } if(include_sv){ if(missing(sv_df)){ @@ -99,7 +107,7 @@ plot_sample_circos = function(this_sample_id, dplyr::filter(tumour_sample_id == this_sample_id) } } - + #add chr prefixes if grch37 is selcted (expected by circlize) if(this_projection == "grch37"){ @@ -115,7 +123,7 @@ plot_sample_circos = function(this_sample_id, if(auto_label_sv){ #annotate oncogene SVs and label them - annotated_sv = annotate_sv(sv_df, with_chr_prefix = TRUE) %>% + annotated_sv = annotate_sv(sv_df, with_chr_prefix = TRUE,genome_build = this_projection) %>% dplyr::filter(!is.na(partner)) %>% dplyr::filter(tumour_sample_id == this_sample_id) @@ -133,13 +141,24 @@ plot_sample_circos = function(this_sample_id, colnames(anno_bed1) = c("chrom", "start", "end", "sample_id") colnames(anno_bed2) = c("chrom", "start", "end", "sample_id") - bed_mut_partner = GAMBLR.data::grch37_partners %>% - dplyr::filter(gene %in% these_partners) %>% - mutate(chrom = paste0("chr", chrom)) + if(this_projection=="grch37"){ + bed_mut_partner = GAMBLR.data::grch37_partners %>% + dplyr::filter(gene %in% these_partners) %>% + mutate(chrom = paste0("chr", chrom)) + + bed_mut_onco = GAMBLR.data::grch37_oncogene %>% + dplyr::filter(gene %in% these_oncogenes) %>% + mutate(chrom = paste0("chr", chrom)) + }else if(this_projection=="hg38"){ + bed_mut_partner = GAMBLR.data::hg38_partners %>% + dplyr::filter(gene %in% these_partners) %>% + mutate(chrom = paste0("chr", chrom)) + + bed_mut_onco = GAMBLR.data::hg38_oncogene %>% + dplyr::filter(gene %in% these_oncogenes) %>% + mutate(chrom = paste0("chr", chrom)) + } - bed_mut_onco = GAMBLR.data::grch37_oncogene %>% - dplyr::filter(gene %in% these_oncogenes) %>% - mutate(chrom = paste0("chr", chrom)) bed_mut = bind_rows(bed_mut_partner, bed_mut_onco) print(bed_mut) @@ -154,8 +173,17 @@ plot_sample_circos = function(this_sample_id, colnames(bed2) = c("chrom", "start", "end", "sample_id") circos.clear() circos.initializeWithIdeogram(chromosome.index = chrom_list) - add_cnv(cnv_df) - circos.genomicLink(bed1, bed2, col = "#bdbdc1") + if(include_cnv){ + add_cnv(cnv_df) + } + + if(auto_colour_links){ + bed2 = decorate_bed(bed2,colour_by="chrom",colour_mapping = get_gambl_colours("chromosome")) + circos.genomicLink(bed1, bed2, col = bed2$color) + }else{ + circos.genomicLink(bed1, bed2, col = "#bdbdc1") + } + if(!missing(label_genes)){ circos.genomicLabels(gene_bed, labels.column = "gene_name") } @@ -164,16 +192,19 @@ plot_sample_circos = function(this_sample_id, circos.genomicLabels(bed_mut, labels.column = "gene") } text(0.75, this_sample_id, cex = 0.8) + if(hide_legend){ + return() + } if(!missing(legend_metadata_columns)){ samp_meta = GAMBLR.helpers::handle_metadata(this_seq_type = this_seq_type) %>% dplyr::filter(sample_id == this_sample_id) these_meta = samp_meta[legend_metadata_columns] these_cols = GAMBLR.helpers::get_gambl_colours() - + these_meta <- mutate_if(these_meta, is.factor, as.character) vals = as.character(these_meta) - + all_cols = map_metadata_to_colours(legend_metadata_columns, these_meta, verbose = T) cols = all_cols[vals] diff --git a/man/plot_sample_circos.Rd b/man/plot_sample_circos.Rd index 29d86c3..8ad8af0 100644 --- a/man/plot_sample_circos.Rd +++ b/man/plot_sample_circos.Rd @@ -18,7 +18,9 @@ plot_sample_circos( this_seq_type = "genome", chrom_list, label_genes, - auto_label_sv = FALSE + auto_label_sv = FALSE, + auto_colour_links = FALSE, + hide_legend = FALSE ) } \arguments{ @@ -49,6 +51,8 @@ plot_sample_circos( \item{label_genes}{Gene labels (df, list or what type?)} \item{auto_label_sv}{Default is FALSE} + +\item{hide_legend}{Set to TRUE if you want to suppress the legend. Particularly useful if you are not using GAMBL data/metadata} } \value{ Nothing From be9b79c5f6cd12df4de9a3512f68c98c02f8df8a Mon Sep 17 00:00:00 2001 From: rdmorin Date: Mon, 13 Jan 2025 10:20:20 -0800 Subject: [PATCH 3/5] document --- man/circular_CN_plot.Rd | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/man/circular_CN_plot.Rd b/man/circular_CN_plot.Rd index 14e7469..2eb611c 100644 --- a/man/circular_CN_plot.Rd +++ b/man/circular_CN_plot.Rd @@ -14,10 +14,10 @@ circular_CN_plot( gain_col = "#FF000080", calculate_correlations = FALSE, link_transparency = 0.8, - labelTheseGenes = c("CD58", "TLR2", "MCL1", "CDKN2A", "TMEM30A", "RHOA", "B2M", - "PTEN", "FAS", "ETV6", "GRB2", "FCGR2B", "CCND3", "CUX1", "MIR17HG", "TFPT", "CD274", - "JAK2", "CDK14", "BCL6", "EZH2", "HIST1H1E", "REL", "NOL9", "TNFRSF14", "TOX", - "TP53", "RB1", "TCF4", "HNRNPD", "BCL2", "NFKBIZ", "TNFAIP3", "PRDM1", "CD70", "MYC") + labelTheseGenes = c("CD58", "TLR2", "MCL1", "CDKN2A", "TMEM30A", "RHOA", "B2M", "PTEN", + "FAS", "ETV6", "GRB2", "FCGR2B", "CCND3", "CUX1", "MIR17HG", "TFPT", "CD274", "JAK2", + "CDK14", "BCL6", "EZH2", "HIST1H1E", "REL", "NOL9", "TNFRSF14", "TOX", "TP53", "RB1", + "TCF4", "HNRNPD", "BCL2", "NFKBIZ", "TNFAIP3", "PRDM1", "CD70", "MYC") ) } \arguments{ From b45abfb705af87d6825ca32002c1708fbb351cc1 Mon Sep 17 00:00:00 2001 From: Ryan Morin Date: Mon, 13 Jan 2025 11:38:49 -0800 Subject: [PATCH 4/5] update documentation --- R/circular_CN_plot.R | 5 ++++- R/fancy_cnbar.R | 2 +- man/circular_CN_plot.Rd | 5 ++++- man/fancy_cnbar.Rd | 6 +++--- man/fancy_sv_sizedens.Rd | 4 ++-- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/R/circular_CN_plot.R b/R/circular_CN_plot.R index ef6757a..8ed1684 100644 --- a/R/circular_CN_plot.R +++ b/R/circular_CN_plot.R @@ -18,7 +18,10 @@ #' #' @examples #' -#' CN_out = pretty_CN_heatmap(cn_state_matrix=all_states_binned,these_samples_metadata = dlbcl_genome_meta,return_data = T,labelTheseGenes = labelTheseGenes) +#' CN_out = pretty_CN_heatmap(cn_state_matrix=all_states_binned, +#' these_samples_metadata = dlbcl_genome_meta, +#' return_data = T, +#' labelTheseGenes = labelTheseGenes) #' #' circular_CN_plot(CN_out) #' diff --git a/R/fancy_cnbar.R b/R/fancy_cnbar.R index a2d1e0b..8976c43 100644 --- a/R/fancy_cnbar.R +++ b/R/fancy_cnbar.R @@ -1,6 +1,6 @@ #' @title Copy Number states barplot #' -#' @description Generate a bar plot visualizing sample-specific copy number states and affected bases for each CN segment. +#' @description Plot sample-specific CN states and affected bases for each segment #' #' @details `fancy_cnbar` visualizes copy number (CN) states on sample-level. Similarly to other fancy_x_plots this function #' accepts either a sample ID, for which the function will get copy number states with [GAMBLR::get_sample_cn_segments]. The function diff --git a/man/circular_CN_plot.Rd b/man/circular_CN_plot.Rd index 2eb611c..2347486 100644 --- a/man/circular_CN_plot.Rd +++ b/man/circular_CN_plot.Rd @@ -49,7 +49,10 @@ Circular overview of copy number data across a cohort } \examples{ -CN_out = pretty_CN_heatmap(cn_state_matrix=all_states_binned,these_samples_metadata = dlbcl_genome_meta,return_data = T,labelTheseGenes = labelTheseGenes) +CN_out = pretty_CN_heatmap(cn_state_matrix=all_states_binned, + these_samples_metadata = dlbcl_genome_meta, + return_data = T, + labelTheseGenes = labelTheseGenes) circular_CN_plot(CN_out) diff --git a/man/fancy_cnbar.Rd b/man/fancy_cnbar.Rd index 691f495..8bc86c2 100644 --- a/man/fancy_cnbar.Rd +++ b/man/fancy_cnbar.Rd @@ -13,8 +13,8 @@ fancy_cnbar( end_col = 4, cn_col = 7, plot_title = paste0(this_sample_id), - - plot_subtitle = "n CNV Segments (barplots, left y-axis), n Affected bases for each CN state", + plot_subtitle = + "n CNV Segments (barplots, left y-axis), n Affected bases for each CN state", chr_select = paste0("chr", c(1:22)), cutoff = 15, include_cn2 = TRUE, @@ -52,7 +52,7 @@ fancy_cnbar( A plot as a ggplot object (grob). } \description{ -Generate a bar plot visualizing sample-specific copy number states and affected bases for each CN segment. +Plot sample-specific CN states and affected bases for each segment } \details{ `fancy_cnbar` visualizes copy number (CN) states on sample-level. Similarly to other fancy_x_plots this function diff --git a/man/fancy_sv_sizedens.Rd b/man/fancy_sv_sizedens.Rd index 2188047..b7da49d 100644 --- a/man/fancy_sv_sizedens.Rd +++ b/man/fancy_sv_sizedens.Rd @@ -19,8 +19,8 @@ fancy_sv_sizedens( hide_legend = FALSE, chr_select = paste0("chr", c(1:22)), plot_title = paste0(this_sample_id), - - plot_subtitle = paste0("SV sizes for Manta calls.\\n Dashed line annotates mean\\n variant size.\\nVAF cut off:\\n ", + plot_subtitle = + paste0("SV sizes for Manta calls.\\n Dashed line annotates mean\\n variant size.\\nVAF cut off:\\n ", vaf_cutoff, ", SV size\\n cut off: ", size_cutoff), From 7069e50482ebc64a847b809fe9238b7e848e0067 Mon Sep 17 00:00:00 2001 From: Kdreval Date: Thu, 23 Jan 2025 11:08:02 -0800 Subject: [PATCH 5/5] cleanup: documentation --- R/plot_sample_circos.R | 1 + man/circular_CN_plot.Rd | 8 ++++---- man/fancy_cnbar.Rd | 4 ++-- man/fancy_sv_sizedens.Rd | 4 ++-- man/plot_sample_circos.Rd | 2 ++ 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/R/plot_sample_circos.R b/R/plot_sample_circos.R index 81b62ab..fd46302 100644 --- a/R/plot_sample_circos.R +++ b/R/plot_sample_circos.R @@ -20,6 +20,7 @@ #' @param chrom_list List of chromosomes to be plotted. If not stated, chr1-22+X will be used. #' @param label_genes Gene labels (df, list or what type?) #' @param auto_label_sv Default is FALSE +#' @param auto_colour_links Whether to apply authomatic coloring of the links. Default is FALSE. #' @param hide_legend Set to TRUE if you want to suppress the legend. Particularly useful if you are not using GAMBL data/metadata #' #' @return Nothing diff --git a/man/circular_CN_plot.Rd b/man/circular_CN_plot.Rd index 2347486..0bd9c65 100644 --- a/man/circular_CN_plot.Rd +++ b/man/circular_CN_plot.Rd @@ -14,10 +14,10 @@ circular_CN_plot( gain_col = "#FF000080", calculate_correlations = FALSE, link_transparency = 0.8, - labelTheseGenes = c("CD58", "TLR2", "MCL1", "CDKN2A", "TMEM30A", "RHOA", "B2M", "PTEN", - "FAS", "ETV6", "GRB2", "FCGR2B", "CCND3", "CUX1", "MIR17HG", "TFPT", "CD274", "JAK2", - "CDK14", "BCL6", "EZH2", "HIST1H1E", "REL", "NOL9", "TNFRSF14", "TOX", "TP53", "RB1", - "TCF4", "HNRNPD", "BCL2", "NFKBIZ", "TNFAIP3", "PRDM1", "CD70", "MYC") + labelTheseGenes = c("CD58", "TLR2", "MCL1", "CDKN2A", "TMEM30A", "RHOA", "B2M", + "PTEN", "FAS", "ETV6", "GRB2", "FCGR2B", "CCND3", "CUX1", "MIR17HG", "TFPT", "CD274", + "JAK2", "CDK14", "BCL6", "EZH2", "HIST1H1E", "REL", "NOL9", "TNFRSF14", "TOX", + "TP53", "RB1", "TCF4", "HNRNPD", "BCL2", "NFKBIZ", "TNFAIP3", "PRDM1", "CD70", "MYC") ) } \arguments{ diff --git a/man/fancy_cnbar.Rd b/man/fancy_cnbar.Rd index 8bc86c2..92691ab 100644 --- a/man/fancy_cnbar.Rd +++ b/man/fancy_cnbar.Rd @@ -13,8 +13,8 @@ fancy_cnbar( end_col = 4, cn_col = 7, plot_title = paste0(this_sample_id), - plot_subtitle = - "n CNV Segments (barplots, left y-axis), n Affected bases for each CN state", + + plot_subtitle = "n CNV Segments (barplots, left y-axis), n Affected bases for each CN state", chr_select = paste0("chr", c(1:22)), cutoff = 15, include_cn2 = TRUE, diff --git a/man/fancy_sv_sizedens.Rd b/man/fancy_sv_sizedens.Rd index b7da49d..2188047 100644 --- a/man/fancy_sv_sizedens.Rd +++ b/man/fancy_sv_sizedens.Rd @@ -19,8 +19,8 @@ fancy_sv_sizedens( hide_legend = FALSE, chr_select = paste0("chr", c(1:22)), plot_title = paste0(this_sample_id), - plot_subtitle = - paste0("SV sizes for Manta calls.\\n Dashed line annotates mean\\n variant size.\\nVAF cut off:\\n ", + + plot_subtitle = paste0("SV sizes for Manta calls.\\n Dashed line annotates mean\\n variant size.\\nVAF cut off:\\n ", vaf_cutoff, ", SV size\\n cut off: ", size_cutoff), diff --git a/man/plot_sample_circos.Rd b/man/plot_sample_circos.Rd index 8ad8af0..62c0313 100644 --- a/man/plot_sample_circos.Rd +++ b/man/plot_sample_circos.Rd @@ -52,6 +52,8 @@ plot_sample_circos( \item{auto_label_sv}{Default is FALSE} +\item{auto_colour_links}{Whether to apply authomatic coloring of the links. Default is FALSE.} + \item{hide_legend}{Set to TRUE if you want to suppress the legend. Particularly useful if you are not using GAMBL data/metadata} } \value{