@@ -197,7 +197,8 @@ prioritization_score_plot = function(plot_data){
197197# ' @description \code{make_ligand_activity_target_exprs_plot} Plot the ligand expression in senders plus their activity and target genes in receivers
198198# '
199199# ' @usage
200- # ' make_ligand_activity_target_exprs_plot(receiver_oi, prioritized_tbl_oi, prioritization_tbl_ligand_receptor, prioritization_tbl_ligand_target, exprs_tbl_ligand, exprs_tbl_target, lfc_cutoff, ligand_target_matrix, plot_legend = TRUE, heights = NULL, widths = NULL)
200+ # ' make_ligand_activity_target_exprs_plot(receiver_oi, prioritized_tbl_oi, prioritization_tbl_ligand_receptor, prioritization_tbl_ligand_target,
201+ # ' exprs_tbl_ligand, exprs_tbl_target, lfc_cutoff, ligand_target_matrix, scaled_ligand_activity_limits = "abs_max", plot_legend = TRUE, heights = NULL, widths = NULL)
201202# '
202203# ' @param receiver_oi Name of the receiver cell type of interest
203204# ' @param prioritized_tbl_oi Dataframe with the ligand-receptor interactions that should be visualized
@@ -207,6 +208,7 @@ prioritization_score_plot = function(plot_data){
207208# ' @param exprs_tbl_target Dataframe with the expression values for the targets in the receiver cell types
208209# ' @param lfc_cutoff Cutoff used on the logFC value
209210# ' @param ligand_target_matrix ligand-target matrix
211+ # ' @param scaled_ligand_activity_limits limits used in the heatmap for the scaled ligand activity, one of "abs_max" (-+ absolute maximum), "min_max" (minimum and maximum), or "IQR" (cf. boxplot, outliers are squished to the limits)
210212# ' @param plot_legend TRUE (default): add legend to the plot. FALSE: do not add legend.
211213# ' @param heights automatic determination if default NULL. If not NULL: number given by the user to indicate the requested heights, which are the height proportions of the different row panels in the plot.
212214# ' @param widths automatic determination if default NULL. If not NULL: number given by the user to indicate the requested widths, which are the width proportions of the different columns (side-by-side heatmaps) in the plot.
@@ -215,12 +217,12 @@ prioritization_score_plot = function(plot_data){
215217# '
216218# ' @examples
217219# ' \dontrun{
218- # ' make_ligand_activity_target_exprs_plot(receiver_oi, prioritized_tbl_oi, prioritization_tbl_ligand_receptor, prioritization_tbl_ligand_target, exprs_tbl_ligand, exprs_tbl_target, lfc_cutoff, ligand_target_matrix, plot_legend = TRUE, heights = NULL, widths = NULL)
220+ # ' make_ligand_activity_target_exprs_plot(receiver_oi, prioritized_tbl_oi, prioritization_tbl_ligand_receptor, prioritization_tbl_ligand_target, exprs_tbl_ligand, exprs_tbl_target, lfc_cutoff, ligand_target_matrix, scaled_ligand_activity_limits = "abs_max", plot_legend = TRUE, heights = NULL, widths = NULL)
219221# ' }
220222# '
221223# ' @export
222224# '
223- make_ligand_activity_target_exprs_plot = function (receiver_oi , prioritized_tbl_oi , prioritization_tbl_ligand_receptor , prioritization_tbl_ligand_target , exprs_tbl_ligand , exprs_tbl_target , lfc_cutoff , ligand_target_matrix , plot_legend = TRUE , heights = NULL , widths = NULL ){
225+ make_ligand_activity_target_exprs_plot = function (receiver_oi , prioritized_tbl_oi , prioritization_tbl_ligand_receptor , prioritization_tbl_ligand_target , exprs_tbl_ligand , exprs_tbl_target , lfc_cutoff , ligand_target_matrix , scaled_ligand_activity_limits = " abs_max " , plot_legend = TRUE , heights = NULL , widths = NULL ){
224226 requireNamespace(" dplyr" )
225227 requireNamespace(" ggplot2" )
226228
@@ -382,11 +384,20 @@ make_ligand_activity_target_exprs_plot = function(receiver_oi, prioritized_tbl_o
382384 vis_ligand_pearson = ligand_pearson_matrix [order_ligands %> % generics :: intersect(rownames(ligand_pearson_matrix )), order_receivers %> % make.names()] # %>% as.matrix(ncol = 3) %>% magrittr::set_colnames("Pearson")
383385 p_ligand_pearson = vis_ligand_pearson %> % nichenetr :: make_heatmap_ggplot(" Prioritized ligands" ," Scaled Ligand activity" , color = " purple" ,legend_position = " top" , x_axis_position = " top" , legend_title = " Scaled\n Ligand\n Activity" ) + theme(legend.text = element_text(size = 9 ))
384386
385- # limits = c(min(vis_ligand_pearson, na.rm =TRUE), max(vis_ligand_pearson, na.rm =TRUE))
386- limits = c(- max(abs(vis_ligand_pearson ), na.rm = TRUE ), max(abs(vis_ligand_pearson ), na.rm = TRUE ))
387+ if (scaled_ligand_activity_limits == " min_max" ){
388+ limits = c(min(vis_ligand_pearson , na.rm = TRUE ), max(vis_ligand_pearson , na.rm = TRUE ))
389+ } else if (scaled_ligand_activity_limits == " IQR" ) {
390+ limits = c(quantile(vis_ligand_pearson , 0.25 , na.rm = TRUE ) - (1.5 * IQR(vis_ligand_pearson , na.rm = TRUE )), quantile(vis_ligand_pearson , 0.75 , na.rm = TRUE ) + (1.5 * IQR(vis_ligand_pearson , na.rm = TRUE )))
391+ } else {
392+ if (scaled_ligand_activity_limits != " abs_max" ) {
393+ warning(" scaled_ligand_activity_limits not recognized. Using default abs_max" )
394+ }
395+ limits = c(- max(abs(vis_ligand_pearson ), na.rm = TRUE ), max(abs(vis_ligand_pearson ), na.rm = TRUE ))
396+ }
397+
387398 # print(limits)
388399
389- custom_scale_fill = scale_fill_gradientn(colours = c(" white" ,RColorBrewer :: brewer.pal(n = 7 , name = " PuRd" )),values = c(0 , 0.50 , 0.55 , 0.625 , 0.70 , 0.80 , 0.90 , 1 ), limits = limits )
400+ custom_scale_fill = scale_fill_gradientn(colours = c(" white" ,RColorBrewer :: brewer.pal(n = 7 , name = " PuRd" )),values = c(0 , 0.50 , 0.55 , 0.625 , 0.70 , 0.80 , 0.90 , 1 ), limits = limits , oob = scales :: squish )
390401 p_ligand_pearson_scaled = p_ligand_pearson + custom_scale_fill
391402 p_ligand_pearson_scaled
392403
0 commit comments