diff --git a/DESCRIPTION b/DESCRIPTION index 6072a3f..34a977b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -76,20 +76,18 @@ Collate: 'aux_output.R' 'aux_save.R' 'aux_visuals.R' + 'package_imports.R' + 'colorRamp2.R' 'color_palettes.R' 'dd.R' 'gg_info_layers.R' 'globals.R' - 'package_imports.R' 'plot_dendrogram.R' 'plot_heatmap.R' 'plot_scatter.R' 'plot_violin.R' 'spatialDE_visuals.R' - 'vis_hvf.R' - 'vis_pc.R' 'vis_spatial.R' 'vis_spatial_in_situ.R' - 'vis_spatial_interaction.R' 'viz_spatial_network.R' 'zzz.R' diff --git a/NAMESPACE b/NAMESPACE index 9a0913d..017df2c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,19 +1,9 @@ # Generated by roxygen2: do not edit by hand export(FSV_show) -export(cellProximityBarplot) -export(cellProximityHeatmap) -export(cellProximityNetwork) -export(cellProximitySpatPlot) -export(cellProximitySpatPlot2D) -export(cellProximitySpatPlot3D) -export(cellProximityVisPlot) -export(create_calc_var_HVF_plot) +export(addGiottoImageToSpatPlot) +export(colorRamp2) export(create_cluster_dendrogram) -export(create_cov_group_HVF_plot) -export(create_cov_loess_HVF_plot) -export(create_jackstrawplot) -export(create_screeplot) export(dimCellPlot) export(dimCellPlot2D) export(dimFeatPlot2D) @@ -24,25 +14,15 @@ export(dimPlot3D) export(expand_feature_info) export(getColors) export(getDistinctColors) +export(get_continuous_colors) export(gg_simple_scatter) -export(plotCCcomDotplot) -export(plotCCcomHeatmap) -export(plotCPF) -export(plotCellProximityFeats) -export(plotCombineCCcom) -export(plotCombineCellCellCommunication) -export(plotCombineICF) -export(plotCombineInteractionChangedFeats) +export(pal_names) export(plotHeatmap) -export(plotICF) -export(plotInteractionChangedFeats) export(plotMetaDataCellsHeatmap) export(plotMetaDataHeatmap) export(plotPCA) export(plotPCA_2D) export(plotPCA_3D) -export(plotRankSpatvsExpr) -export(plotRecovery) export(plotStatDelaunayNetwork) export(plotTSNE) export(plotTSNE_2D) @@ -51,10 +31,23 @@ export(plotUMAP) export(plotUMAP_2D) export(plotUMAP_3D) export(plot_output_handler) +export(set_default_color_continuous) +export(set_default_color_continuous_CCcom_dotplot) +export(set_default_color_continuous_CCcom_heatmap) +export(set_default_color_continuous_cell) +export(set_default_color_continuous_heatmap) +export(set_default_color_continuous_poly) +export(set_default_color_discrete) +export(set_default_color_discrete_cell) +export(set_default_color_discrete_feat) +export(set_default_color_discrete_heatmap_clus) +export(set_default_color_discrete_poly) +export(set_default_cow_n_col) export(showClusterDendrogram) export(showClusterHeatmap) export(showColorInstructions) export(showSaveParameters) +export(simple_palette_factory) export(spatCellPlot) export(spatCellPlot2D) export(spatDeconvPlot) @@ -83,6 +76,7 @@ import(GiottoUtils) import(ggplot2) import(utils) importClassesFrom(data.table,data.table) +importFrom(colorRamp2,colorRamp2) importFrom(data.table,dcast) importFrom(data.table,dcast.data.table) importFrom(methods,slot) diff --git a/R/aux_defaults.R b/R/aux_defaults.R index 93a7873..369a886 100644 --- a/R/aux_defaults.R +++ b/R/aux_defaults.R @@ -4,8 +4,13 @@ # default plot n cols #### #' @title Set default ncols in plotting grid #' @name set_default_cow_n_col -#' @keywords internal -#' @noRd +#' @description +#' Determine a default cow_n_col param value for cowplot based on the number of +#' items to plot. +#' @param cow_n_col number of columns for cowplot to use. A default number is +#' calculated if `NULL` is passed. +#' @param nr_plots number of plots to use with cowplot +#' @export set_default_cow_n_col = function(cow_n_col = NULL, nr_plots) { @@ -20,17 +25,59 @@ set_default_cow_n_col = function(cow_n_col = NULL, # default plotting fill color #### + + + + + + + +## discrete #### + + # -------------------------------------------------------------------------- # -# internal function to provide a function that will generate 'n' hexadecimal -# color codes for discrete colors -# inputs are INTENDED to be provided via instructions and options -# # FUNCTION input to 'color' are also permitted, but REQUIRE an 'n' param # for downstream functionality. 'giotto.color_discrete_pal' and # 'giotto.color_discrete_strategy' are additionally ignored # -------------------------------------------------------------------------- # -# framework function. Wrap this for specific things that need defaults setting +#' @name set_default_color_discrete +#' @title Set a discrete coloring scheme +#' @description +#' Provides a palette function that will generate 'n' hexadecimal color codes for +#' discrete colors. Sets a default coloring palette if `NULL` is passed to `colors` +#' param.\cr\cr +#' +#' Supports colors setting at three levels: +#' - **global options** (general session setting with blanket color palette type effects) +#' - options('giotto.color_d_pal) - palette to use +#' - options('giotto.color_d_rev) - whether colors should be reversed +#' - options('giotto.color_d_strategy) - strategy to use when making colors continuous. See [get_continuous_colors()] +#' - **giotto instructions** (gobject specific and effects specific types of plots) +#' - run `showColorInstructions()` for details on options/params to set in the `giottoInstructions` object +#' - **function specific** (directly pass desired colors to plotting function) +#' \cr\cr +#' +#' If a character vector of length 1 input is provided then it will be assumed +#' that a known color palette is being requested from [pal_names()].\cr +#' If a longer character input is provided then they will be expected to be +#' a vector of colors to use. These values will be passed to [simple_palette_factory] +#' which will generate a palette function that interpolates between the colors +#' provided by default and has a `n` param for number of requested colors.\cr +#' Custom function inputs to `colors` is also supported but these custom functions +#' should have a `n` param for number of requested colors. +#' @param colors accepts color inputs +#' @param instrs `giottoInstructions` object (output of `instructions(gobject)`) +#' @param \dots additional params to pass +NULL + + + + +#' @describeIn set_default_color_discrete Framework function. Direct use should be minimal. +#' Wrap this for specific things (plots or types of features) that need defaults setting. +#' @param instr_pal,instr_rev,instr_strategy used by upstream function to pass specific `giottoInstructions` params +#' @export set_default_color_discrete = function( colors = NULL, instr_pal, @@ -67,6 +114,9 @@ set_default_color_discrete = function( } } + +#' @rdname set_default_color_discrete +#' @export set_default_color_discrete_cell = function( colors = NULL, instrs, @@ -87,6 +137,8 @@ set_default_color_discrete_cell = function( ) } +#' @rdname set_default_color_discrete +#' @export set_default_color_discrete_poly = function( colors = NULL, instrs, @@ -107,6 +159,8 @@ set_default_color_discrete_poly = function( ) } +#' @rdname set_default_color_discrete +#' @export set_default_color_discrete_feat = function( colors = NULL, instrs, @@ -127,6 +181,8 @@ set_default_color_discrete_feat = function( ) } +#' @rdname set_default_color_discrete +#' @export set_default_color_discrete_heatmap_clus = function( colors = NULL, instrs, @@ -155,25 +211,47 @@ set_default_color_discrete_heatmap_clus = function( + +## continuous #### + + #' @name set_default_color_continuous #' @title Set a default color for continuous values #' @description -#' Framework function. Should not be used directly. Specific wrapper functions -#' should be used for each item that needs defaults setting. -#' midpoint param only supplied when using color scale with 3 colors.\cr -#' This function sets a default color continuous color gradient to use. It takes +#' Generates a gradient color palette based on input to `colors` param. Sets a +#' default gradient if `NULL` is passed. +#' `midpoint` param only supplied when using color scale with 3 colors.\cr\cr +#' +#' Supports colors setting at four levels: +#' - **type specific defaults** - defaults for a sepecific feature or type of +#' plot can be passed through `type_default` param +#' - **global options** (general session setting with blanket color palette type effects) +#' - options('giotto.color_c_pal) - palette to use. Default for 'divergent' +#' data is blue, white, red, for sequential, it is 'viridis' +#' - options('giotto.color_c_rev) - whether colors should be reversed +#' - **giotto instructions** (gobject specific and effects specific types of plots) +#' - run `showColorInstructions()` for details on options/params to set in the `giottoInstructions` object +#' - **function specific** (directly pass desired colors to plotting function) +#' \cr\cr #' -#' @param colors character or NULL. 2 to n number of hex color codes or 1 single +#' @param colors character or `NULL`. 2 to n number of hex color codes or 1 single #' name of a palette to use can be passed -#' @param instr_pal instructions default: palette -#' @param instr_rev instructions default: reverse palette -#' @param midpoint midpoint value of color gradient -#' @param style scale color scale around midpoint (divergent) or starting from +#' @param instrs `giottoInstructions` object (output of `instructions(gobject)`) +#' @param midpoint numeric. midpoint value of color gradient +#' @param style scale color scale around `midpoint` (divergent) or starting from #' minimum value (sequential) -#' @param type_default data type specific defaults +#' @param type_default data type specific default to use #' @param type whether setting is for ggplot2 'fill' or 'color' type function #' @param \dots additional params to pass to respective ggplot fill_gradient functions -#' @keywords internal +NULL + + + +#' @describeIn set_default_color_continuous Framework function. Direct use should +#' be minimal. Specific wrapper functions should be used for each item that needs +#' defaults setting (plots or types of features). +#' @param instr_pal,instr_rev used by upstream function to pass specific `giottoInstructions` params +#' @export set_default_color_continuous <- function( colors = NULL, # used for function inputs instr_pal, @@ -317,7 +395,8 @@ evaluate_color_gradient_sequential = function(colors, } - +#' @rdname set_default_color_continuous +#' @export set_default_color_continuous_cell <- function( colors = NULL, instrs, @@ -342,6 +421,8 @@ set_default_color_continuous_cell <- function( ) } +#' @rdname set_default_color_continuous +#' @export set_default_color_continuous_poly <- function( colors = NULL, instrs, @@ -365,7 +446,8 @@ set_default_color_continuous_poly <- function( } - +#' @rdname set_default_color_continuous +#' @export set_default_color_continuous_heatmap = function( colors = NULL, instrs, @@ -388,6 +470,8 @@ set_default_color_continuous_heatmap = function( ) } +#' @rdname set_default_color_continuous +#' @export set_default_color_continuous_CCcom_heatmap = function( colors = NULL, instrs, @@ -413,6 +497,8 @@ set_default_color_continuous_CCcom_heatmap = function( ) } +#' @rdname set_default_color_continuous +#' @export set_default_color_continuous_CCcom_dotplot = function( colors = NULL, instrs, diff --git a/R/colorRamp2.R b/R/colorRamp2.R new file mode 100644 index 0000000..e441f38 --- /dev/null +++ b/R/colorRamp2.R @@ -0,0 +1,6 @@ +#' @include package_imports.R + +# nocov start +#' @export +colorRamp2::colorRamp2 +# nocov end diff --git a/R/color_palettes.R b/R/color_palettes.R index cff0a38..fe0fbe7 100644 --- a/R/color_palettes.R +++ b/R/color_palettes.R @@ -310,11 +310,22 @@ get_rcarto_colors = function(n, pal, strategy) { # helpers #### -#' @noRd -#' @param col character vector. colors to interpolate +#' @name get_continuous_colors +#' @title Generate a continuous set of colors +#' @description +#' Based on a vector of colors provided to `col`, make these colors continuous +#' (i.e. make it possible for an arbitrary `n` number of colors to be requested) +#' then return those `n` colors.\cr +#' `strategy` describes how to make these colors continuous: +#' - **'interpolate'** interpolates provided colors using [grDevices::colorRampPalette()] +#' - **'recycle'** - recycles the input color vector across the `n` requested. +#' - **'cutoff'** - supply only a maximum of as many colors as exist within the +#' originally supplied vector. +#' @param col character vector. colors to make continuous #' @param n integer. number of colors to get #' @param strategy one of 'cutoff', 'recycle', or 'interpolate'. #' strategy to use when more colors are requested than exist +#' @export get_continuous_colors = function(col, n, strategy) { strategy = g_match_arg(strategy, choices = c('interpolate', 'recycle', 'cutoff')) @@ -326,16 +337,19 @@ get_continuous_colors = function(col, n, strategy) { } -#' @noRd -#' @param col character vector. Hexadecimal color codes -#' @param rev whether to reverse order of vector -#' @param strategy policy when insufficient colors are available + +#' @name simple_palette_factory +#' @title Generate a simple palette function #' @seealso [set_default_color_discrete()] #' @description #' Simple palette function generator. Creates a function with param n that #' dictates how many colors to return from the provided vector of hexadecimal #' color values. Generated functions send warning if there are not enough colors #' to use and it needs to recycle values. +#' @param col character vector. Hexadecimal color codes +#' @param rev whether to reverse order of vector +#' @param strategy policy when insufficient colors are available +#' @export simple_palette_factory = function(col, rev = FALSE, strategy = 'interpolate') { checkmate::assert_character(col) checkmate::assert_logical(rev) @@ -364,6 +378,14 @@ get_palette_factory = function(pal, rev = FALSE, strategy = 'interpolate') { # * palette names list #### +#' @title Color palette names +#' @name pal_names +#' @description +#' Known color palettes info provided as named list of character vectors. +#' List names correspond to the name of the palette package. The character vectors +#' list the palettes that are available within. These palettes can be passed to +#' the default color setting functions +#' @export pal_names = list( hcl = grDevices::hcl.pals(), base = c( diff --git a/R/gg_info_layers.R b/R/gg_info_layers.R index 70c200e..ccd86d1 100644 --- a/R/gg_info_layers.R +++ b/R/gg_info_layers.R @@ -1857,3 +1857,73 @@ plot_point_layer_ggplot_noFILL = function(ggobject, } return(pl) } + + + + + + +# image #### + +# TODO - needs update and completion of overlay option + + +#' @title addGiottoImageToSpatPlot +#' @name addGiottoImageToSpatPlot +#' @description Add a giotto image to a spatial ggplot object post creation +#' @param spatpl a spatial ggplot object +#' @param gimage a giotto image, see \code{\link{createGiottoImage}} +#' @param layer numeric layer on which to add the giotto image. OR takes 'bg' or +#' 'overlay' as input to designate last (bottom/background) or first (top/overlay) +#' @param alpha (optional) add giotto image to plot with transparency. Numeric. From 0 +#' (transparent) to 1 (fully visible) +#' @return an updated spatial ggplot object +#' @export +addGiottoImageToSpatPlot = function(spatpl = NULL, + gimage = NULL, + layer = c('bg', 'overlay'), + alpha = NULL) { + + layer = match.arg(arg = layer, choices = c('bg', 'overlay')) + + if(is.null(spatpl) | is.null(gimage)) { + stop('A spatial ggplot object and a giotto image need to be given') + } + + # extract min and max from object + my_xmax = gimage@minmax[1] + my_xmin = gimage@minmax[2] + my_ymax = gimage@minmax[3] + my_ymin = gimage@minmax[4] + + # convert giotto image object into array + img_array = as.numeric(gimage@mg_object[[1]]) + + # add transparency if needed + if(!is.null(alpha) & is.numeric(alpha)) { + img_array = add_img_array_alpha(x = img_array, + alpha = alpha) + } + + # extract adjustments from object + xmax_b = gimage@boundaries[1] + xmin_b = gimage@boundaries[2] + ymax_b = gimage@boundaries[3] + ymin_b = gimage@boundaries[4] + + newpl = spatpl + annotation_raster(img_array, + xmin = my_xmin-xmin_b, xmax = my_xmax+xmax_b, + ymin = my_ymin-ymin_b, ymax = my_ymax+ymax_b) + + # position new layer + if(layer == 'bg') { + # move image to background + nr_layers = length(newpl$layers) + newpl$layers = c(newpl$layers[[nr_layers]], newpl$layers[1:(nr_layers-1)]) + } else if(layer == 'overlay') {} # keep image on top + + + return(newpl) + +} + diff --git a/R/package_imports.R b/R/package_imports.R index a43d5cf..d86ab9a 100644 --- a/R/package_imports.R +++ b/R/package_imports.R @@ -3,6 +3,7 @@ #' @importFrom data.table dcast dcast.data.table #' @importFrom stats cov var #' @importFrom methods slot +#' @importFrom colorRamp2 colorRamp2 #' @import GiottoUtils #' @import GiottoClass #' @import ggplot2 diff --git a/R/vis_hvf.R b/R/vis_hvf.R deleted file mode 100644 index c7c37c5..0000000 --- a/R/vis_hvf.R +++ /dev/null @@ -1,63 +0,0 @@ - -# Create plots for whether features can be considered highly variable. - -#' @name hvf_visualizations -#' @title Highly Variable Feature plots -#' @description -#' Create plots that report the highly variable features detected -#' @keywords internal -NULL - - - - -#' @rdname hvf_visualizations -#' @export -create_cov_group_HVF_plot = function(feat_in_cells_detected, nr_expression_groups) { - pl <- ggplot2::ggplot() - pl <- pl + ggplot2::theme_classic() + - ggplot2::theme(axis.title = ggplot2::element_text(size = 14), - axis.text = ggplot2::element_text(size = 12)) - pl <- pl + ggplot2::geom_point(data = feat_in_cells_detected, ggplot2::aes_string(x = 'mean_expr', y = 'cov', color = 'selected')) - pl <- pl + ggplot2::scale_color_manual(values = c(no = 'lightgrey', yes = 'orange'), - guide = ggplot2::guide_legend(title = 'HVF', - override.aes = list(size=5))) - pl <- pl + ggplot2::facet_wrap(~expr_groups, ncol = nr_expression_groups, scales = 'free_x') - pl <- pl + ggplot2::theme(axis.text.x = ggplot2::element_blank(), - strip.text = ggplot2::element_text(size = 4)) - pl <- pl + ggplot2::labs(x = 'expression groups', y = 'cov') - pl -} - -#' @rdname hvf_visualizations -#' @export -create_cov_loess_HVF_plot = function(feat_in_cells_detected, difference_in_cov, var_col) { - pl <- ggplot2::ggplot() - pl <- pl + ggplot2::theme_classic() + - ggplot2::theme(axis.title = ggplot2::element_text(size = 14), - axis.text = ggplot2::element_text(size = 12)) - pl <- pl + ggplot2::geom_point(data = feat_in_cells_detected, ggplot2::aes_string(x = 'log(mean_expr)', y = var_col, color = 'selected')) - pl <- pl + ggplot2::geom_line(data = feat_in_cells_detected, ggplot2::aes_string(x = 'log(mean_expr)', y = 'pred_cov_feats'), color = 'blue') - hvg_line = paste0('pred_cov_feats+',difference_in_cov) - pl <- pl + ggplot2::geom_line(data = feat_in_cells_detected, ggplot2::aes_string(x = 'log(mean_expr)', y = hvg_line), linetype = 2) - pl <- pl + ggplot2::labs(x = 'log(mean expression)', y = var_col) - pl <- pl + ggplot2::scale_color_manual(values = c(no = 'lightgrey', yes = 'orange'), - guide = ggplot2::guide_legend(title = 'HVF', - override.aes = list(size=5))) - pl -} - -#' @rdname hvf_visualizations -#' @export -create_calc_var_HVF_plot = function(dt_res) { - pl = ggplot2::ggplot() - pl = pl + ggplot2::geom_point(data = dt_res, aes_string(x = 'rank', y = 'var', color = 'selected')) - pl = pl + ggplot2::scale_x_reverse() - pl = pl + ggplot2::theme_classic() + ggplot2::theme(axis.title = ggplot2::element_text(size = 14), - axis.text = ggplot2::element_text(size = 12)) - pl = pl + ggplot2::scale_color_manual(values = c(no = 'lightgrey', yes = 'orange'), - guide = ggplot2::guide_legend(title = 'HVF', - override.aes = list(size=5))) - pl = pl + ggplot2::labs(x = 'feature rank', y = 'variance') - pl -} diff --git a/R/vis_pc.R b/R/vis_pc.R deleted file mode 100644 index 643292b..0000000 --- a/R/vis_pc.R +++ /dev/null @@ -1,119 +0,0 @@ - - -## * PC estimates #### -# ------------------ # - -#' @title create_screeplot -#' @name create_screeplot -#' @description create screeplot with ggplot -#' @param eigs numeric. Vector of pca eigenvalues -#' @param ncp numeric. max number of principal components to plot -#' @param ylim numeric. y-axis limits on scree plot -#' @return ggplot -#' @examples -#' \dontrun{ -#' dr = GiottoData::loadSubObjectMini('dimObj') -#' scree = create_screeplot(methods::slot(dr, 'misc')$eigenvalues) -#' scree -#' } -#' @export -create_screeplot = function(eigs, ncp = 20, ylim = c(0, 20)) { - - checkmate::assert_numeric(eigs) - checkmate::assert_numeric(ncp, len = 1L) - checkmate::assert_numeric(ylim, len = 2L) - - # DT vars - PC = NULL - - eigs = sort(eigs, decreasing = TRUE) - - # variance explained - var_expl = eigs/sum(eigs)*100 - var_expl_cum = cumsum(eigs)/sum(eigs)*100 - - # create data.table - screeDT = data.table::data.table('PC' = paste0('PC.', 1:length(var_expl)), - 'var_expl' = var_expl, - 'var_expl_cum' = var_expl_cum) - screeDT[, 'PC' := factor(PC, levels = PC)] - - max_ncp = length(eigs) - ncp = ifelse(ncp > max_ncp, max_ncp, ncp) - - pl = ggplot2::ggplot() - pl = pl + ggplot2::theme_bw() - pl = pl + ggplot2::geom_bar(data = screeDT[1:ncp], ggplot2::aes(x = PC, y = var_expl), stat = 'identity') - pl = pl + ggplot2::coord_cartesian(ylim = ylim) - pl = pl + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 45, hjust = 1, vjust = 1)) - pl = pl + ggplot2::labs(x = '', y = '% of variance explained per PC') - - cpl = ggplot2::ggplot() - cpl = cpl + ggplot2::theme_bw() - cpl = cpl + ggplot2::geom_bar(data = screeDT[1:ncp], ggplot2::aes(x = PC, y = var_expl_cum), stat = 'identity') - cpl = cpl + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 45, hjust = 1, vjust = 1)) - cpl = cpl + ggplot2::labs(x = '', y = 'cumulative % of variance explained') - - savelist = list(pl, cpl) - - ## combine plots with cowplot - combo_plot <- cowplot::plot_grid(plotlist = savelist, - ncol = 1, - rel_heights = c(1), - rel_widths = c(1), - align = 'v') - - return(combo_plot) -} - - - - - - -#' @title create_jackstrawplot -#' @name create_jackstrawplot -#' @description create jackstrawplot with ggplot -#' @param jackstraw_data result from jackstraw function (`testresult$p`) -#' @param ncp number of principal components to calculate -#' @param ylim y-axis limits on jackstraw plot -#' @param threshold p.value threshold to call a PC significant -#' @keywords internal -#' @return ggplot -#' @export -create_jackstrawplot = function(jackstraw_data, - ncp = 20, - ylim = c(0, 1), - threshold = 0.01) { - - checkmate::assert_numeric(ncp, len = 1L) - checkmate::assert_numeric(ylim, len = 2L) - checkmate::assert_numeric(threshold, len = 1L) - - # data.table variables - PC = p.val = NULL - - testDT = data.table::data.table( - PC = paste0('PC.', 1:length(jackstraw_data)), - p.val = jackstraw_data - ) - testDT[, 'PC' := factor(PC, levels = PC)] - testDT[, 'sign' := ifelse(p.val <= threshold, 'sign', 'n.s.')] - - pl = ggplot2::ggplot() - pl = pl + ggplot2::theme_bw() - pl = pl + ggplot2::geom_point(data = testDT[1:ncp], ggplot2::aes(x = PC, y = p.val, fill = sign), shape = 21) - pl = pl + ggplot2::scale_fill_manual(values = c('n.s.' = 'lightgrey', 'sign' = 'darkorange')) - pl = pl + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 45, hjust = 1, vjust = 1)) - pl = pl + ggplot2::coord_cartesian(ylim = ylim) - pl = pl + ggplot2::theme(panel.grid.major.x = ggplot2::element_blank()) - pl = pl + ggplot2::labs(x = '', y = 'p-value per PC') - - return(pl) - -} - - - - - diff --git a/R/vis_spatial_interaction.R b/R/vis_spatial_interaction.R deleted file mode 100644 index ab8ed0c..0000000 --- a/R/vis_spatial_interaction.R +++ /dev/null @@ -1,2940 +0,0 @@ -#' @title cellProximityBarplot -#' @name cellProximityBarplot -#' @description Create barplot from cell-cell proximity scores -#' @inheritParams data_access_params -#' @inheritParams plot_output_params -#' @param CPscore CPscore, output from cellProximityEnrichment() -#' @param min_orig_ints filter on minimum original cell-cell interactions -#' @param min_sim_ints filter on minimum simulated cell-cell interactions -#' @param p_val p-value -#' @return ggplot barplot -#' @details This function creates a barplot that shows the spatial proximity -#' enrichment or depletion of cell type pairs. -#' @export -cellProximityBarplot = function(gobject, - CPscore, - min_orig_ints = 5, - min_sim_ints = 5, - p_val = 0.05, - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = 'cellProximityBarplot') { - - - table_mean_results_dc = CPscore$enrichm_res - - ## filter to remove low number of cell-cell proximity interactions ## - - # data.table variables - original = simulations = p_higher_orig = p_lower_orig = enrichm = type_int = unified_int = NULL - - table_mean_results_dc_filter = table_mean_results_dc[original >= min_orig_ints & simulations >= min_sim_ints,] - table_mean_results_dc_filter = table_mean_results_dc_filter[p_higher_orig <= p_val | p_lower_orig <= p_val,] - - pl <- ggplot2::ggplot() - pl <- pl + ggplot2::geom_bar(data = table_mean_results_dc_filter, ggplot2::aes(x = unified_int, y = enrichm, fill = type_int), stat = 'identity', show.legend = F) - pl <- pl + ggplot2::coord_flip() - pl <- pl + ggplot2::theme_bw() - pl <- pl + ggplot2::labs(y = 'enrichment/depletion') - pl - - bpl <- ggplot2::ggplot() - bpl <- bpl + ggplot2::geom_bar(data = table_mean_results_dc_filter, ggplot2::aes(x = unified_int, y = original, fill = type_int), stat = 'identity', show.legend = T) - bpl <- bpl + ggplot2::coord_flip() - bpl <- bpl + ggplot2::theme_bw() + ggplot2::theme(axis.text.y = element_blank()) - bpl <- bpl + ggplot2::labs(y = '# of interactions') - bpl - - combo_plot <- cowplot::plot_grid(pl, bpl, ncol = 2, rel_heights = c(1), rel_widths = c(3,1.5), align = 'h') - - - # print, return and save parameters - show_plot = ifelse(is.na(show_plot), readGiottoInstructions(gobject, param = 'show_plot'), show_plot) - save_plot = ifelse(is.na(save_plot), readGiottoInstructions(gobject, param = 'save_plot'), save_plot) - return_plot = ifelse(is.na(return_plot), readGiottoInstructions(gobject, param = 'return_plot'), return_plot) - - ## print plot - if(show_plot == TRUE) { - print(combo_plot) - } - - ## save plot - if(save_plot == TRUE) { - do.call('all_plots_save_function', c(list(gobject = gobject, plot_object = combo_plot, default_save_name = default_save_name), save_param)) - } - - ## return plot - if(return_plot == TRUE) { - return(combo_plot) - } - -} - -#' @title cellProximityHeatmap -#' @name cellProximityHeatmap -#' @description Create heatmap from cell-cell proximity scores -#' @inheritParams data_access_params -#' @inheritParams plot_output_params -#' @param CPscore CPscore, output from cellProximityEnrichment() -#' @param scale scale cell-cell proximity interaction scores -#' @param order_cell_types order cell types based on enrichment correlation -#' @param color_breaks numerical vector of length 3 to represent min, mean and maximum -#' @param color_names character color vector of length 3 -#' @return ggplot heatmap -#' @details This function creates a heatmap that shows the spatial proximity -#' enrichment or depletion of cell type pairs. -#' @export -cellProximityHeatmap = function(gobject, - CPscore, - scale = T, - order_cell_types = T, - color_breaks = NULL, - color_names = NULL, - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = 'cellProximityHeatmap') { - - - enrich_res = CPscore$enrichm_res - - # data.table variables - first_type = second_type = unified_int = NULL - - enrich_res[, first_type := strsplit(x = as.character(unified_int), split = '--')[[1]][1], by = 1:nrow(enrich_res)] - enrich_res[, second_type := strsplit(x = as.character(unified_int), split = '--')[[1]][2], by = 1:nrow(enrich_res)] - - # create matrix - enrich_mat = data.table::dcast.data.table(data = enrich_res,formula = first_type~second_type, value.var = 'enrichm') - matrix_d <- as.matrix(enrich_mat[,-1]); rownames(matrix_d) = as.vector(enrich_mat[[1]]) - t_matrix_d <- t_flex(matrix_d) - - # fill in NAs based on values in upper and lower matrix triangle - t_matrix_d[upper.tri(t_matrix_d)][is.na(t_matrix_d[upper.tri(t_matrix_d)])] = matrix_d[upper.tri(matrix_d)][is.na(t_matrix_d[upper.tri(t_matrix_d)])] - t_matrix_d[lower.tri(t_matrix_d)][is.na(t_matrix_d[lower.tri(t_matrix_d)])] = matrix_d[lower.tri(matrix_d)][is.na(t_matrix_d[lower.tri(t_matrix_d)])] - t_matrix_d[is.na(t_matrix_d)] = 0 - final_matrix = t_matrix_d - - # scale data - if(scale == TRUE) { - final_matrix <- t_flex(scale(t_flex(final_matrix))) - final_matrix <- t_flex(final_matrix) - final_matrix[lower.tri(final_matrix)] <- t_flex(final_matrix)[lower.tri(final_matrix)] - } - - # # if NA values, impute as mean - #if(any(is.na(final_matrix)) == TRUE) { - # myrowmeans = apply(X = final_matrix, MARGIN = 1, FUN = function(x) mean(na.omit(x))) - # mymatrixmeans = matrix(data = rep(myrowmeans, ncol(final_matrix)), nrow = nrow(final_matrix), ncol = ncol(final_matrix)) - # final_matrix[is.na(final_matrix)] = mymatrixmeans[which(is.na(final_matrix))] - #} - - # order cell types - if(order_cell_types == TRUE) { - - cordist = stats::as.dist(1-cor_flex(final_matrix)) - clus = stats::hclust(cordist) - myorder = clus$order - mylabels = clus$labels - names(mylabels) = 1:length(mylabels) - sample_order = mylabels[myorder] - - final_matrix = final_matrix[sample_order, sample_order] - } - - # create custom colors or not - if(!is.null(color_breaks) & !is.null(color_names)) { - - if(length(color_breaks) != 3 | !is.numeric(color_breaks)) { - stop('\n color_breaks needs to be a numerical vector of length 3 \n') - } - - if(length(color_names) != 3 | !is.character(color_names)) { - stop('\n color_names needs to be a character vector of length 3 \n') - } - - heatm = ComplexHeatmap::Heatmap(matrix = final_matrix, cluster_rows = F, cluster_columns = F, - col = colorRamp2::colorRamp2(breaks = color_breaks, colors = color_names)) - } else { - heatm = ComplexHeatmap::Heatmap(matrix = final_matrix, cluster_rows = F, cluster_columns = F) - } - - return(plot_output_handler( - gobject = gobject, - plot_object = heatm, - save_plot = save_plot, - return_plot = return_plot, - show_plot = show_plot, - default_save_name = default_save_name, - save_param = save_param, - else_return = NULL - )) - -} - - -#' @title cellProximityNetwork -#' @name cellProximityNetwork -#' @description Create network from cell-cell proximity scores -#' @inheritParams data_access_params -#' @inheritParams plot_output_params -#' @param CPscore CPscore, output from cellProximityEnrichment() -#' @param remove_self_edges remove enrichment/depletion edges with itself -#' @param self_loop_strength size of self-loops -#' @param color_depletion color for depleted cell-cell interactions -#' @param color_enrichment color for enriched cell-cell interactions -#' @param rescale_edge_weights rescale edge weights (boolean) -#' @param edge_weight_range_depletion numerical vector of length 2 to rescale depleted edge weights -#' @param edge_weight_range_enrichment numerical vector of length 2 to rescale enriched edge weights -#' @param layout layout algorithm to use to draw nodes and edges -#' @param only_show_enrichment_edges show only the enriched pairwise scores -#' @param edge_width_range range of edge width -#' @param node_size size of nodes -#' @param node_color_code color code for the nodes (e.g. cell labels) -#' @param node_text_size size of node labels -#' @return igraph plot -#' @details This function creates a network that shows the spatial proximity -#' enrichment or depletion of cell type pairs. -#' @export -cellProximityNetwork = function(gobject, - CPscore, - remove_self_edges = FALSE, - self_loop_strength = 0.1, - color_depletion = 'lightgreen', - color_enrichment = 'red', - rescale_edge_weights = TRUE, - edge_weight_range_depletion = c(0.1, 1), - edge_weight_range_enrichment = c(1, 5), - layout = c('Fruchterman', 'DrL', 'Kamada-Kawai'), - only_show_enrichment_edges = F, - edge_width_range = c(0.1, 2), - node_size = 4, - node_color_code = NULL, - node_text_size = 6, - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = 'cellProximityNetwork') { - - # extract scores - - # data.table variables - cell_1 = cell_2 = unified_int = color = size = name = NULL - - CPscores = CPscore[['enrichm_res']] - CPscores[, cell_1 := strsplit(as.character(unified_int), split = '--')[[1]][1], by = 1:nrow(CPscores)] - CPscores[, cell_2 := strsplit(as.character(unified_int), split = '--')[[1]][2], by = 1:nrow(CPscores)] - - # create igraph with enrichm as weight edges - igd = igraph::graph_from_data_frame(d = CPscores[,c('cell_1', 'cell_2', 'enrichm')], directed = F) - - if(remove_self_edges == TRUE) { - igd = igraph::simplify(graph = igd, remove.loops = TRUE, remove.multiple = FALSE) - } - - edges_sizes = igraph::get.edge.attribute(igd, 'enrichm') - post_edges_sizes = edges_sizes[edges_sizes > 0] - neg_edges_sizes = edges_sizes[edges_sizes <= 0] - - # rescale if wanted - if(rescale_edge_weights == TRUE) { - pos_edges_sizes_resc = scales::rescale(x = post_edges_sizes, to = edge_weight_range_enrichment) - neg_edges_sizes_resc = scales::rescale(x = neg_edges_sizes, to = edge_weight_range_depletion) - edges_sizes_resc = c(pos_edges_sizes_resc, neg_edges_sizes_resc) - } else { - edges_sizes_resc = c(post_edges_sizes, neg_edges_sizes) - } - - # colors - edges_colors = ifelse(edges_sizes > 0, 'enriched', 'depleted') - - - # create coordinates for layout - if(inherits(layout, c('data.frame', 'data.table'))) { - if(ncol(layout) < 2) { - stop('custom layout needs to have at least 2 columns') - } - - if(nrow(layout) != length(igraph::E(igd))) { - stop('rows of custom layout need to be the same as number of edges') - } - - } else { - layout = match.arg(arg = layout, choices = c('Fruchterman', 'DrL', 'Kamada-Kawai')) - } - - - - - #iplot = igraph::plot.igraph(igd, edge.color = edges_colors, edge.width = edges_sizes_resc, layout = coords) - - igd = igraph::set.edge.attribute(graph = igd, index = igraph::E(igd), name = 'color', value = edges_colors) - igd = igraph::set.edge.attribute(graph = igd, index = igraph::E(igd), name = 'size', value = as.numeric(edges_sizes_resc)) - - ## only show attractive edges - if(only_show_enrichment_edges == TRUE) { - colors = igraph::get.edge.attribute(igd, name = 'color') - subvertices_ids = which(colors == 'enriched') - igd = igraph::subgraph.edges(graph = igd, eids = subvertices_ids) - - # get new rescale vector (in case vector id is lost) - edges_sizes_resc = igraph::E(igd)$size - } - - ## get coordinates layouts - if(layout == 'Fruchterman') { - coords = igraph::layout_with_fr(graph = igd, weights = edges_sizes_resc) - } else if(layout == 'DrL') { - coords = igraph::layout_with_drl(graph = igd, weights = edges_sizes_resc) - } else if(layout == 'Kamada-Kawai') { - coords = igraph::layout_with_kk(graph = igd, weights = edges_sizes_resc) - } else { - stop('\n Currently no other layouts have been implemented \n') - } - - - #longDT = as.data.table(igraph::as_long_data_frame(igd)) - #return(longDT) - #return(list(igd, coords)) - - ## create plot - gpl = ggraph::ggraph(graph = igd, layout = coords) - gpl = gpl + ggraph::geom_edge_link(ggplot2::aes(color = factor(color), edge_width = size, edge_alpha = size), show.legend = F) - - if(remove_self_edges == FALSE) { - gpl = gpl + ggraph::geom_edge_loop(ggplot2::aes(color = factor(color), edge_width = size, edge_alpha = size, strength = self_loop_strength), show.legend = F) - } - - gpl = gpl + ggraph::scale_edge_color_manual(values = c('enriched' = color_enrichment, 'depleted' = color_depletion)) - gpl = gpl + ggraph::scale_edge_width(range = edge_width_range) - gpl = gpl + ggraph::scale_edge_alpha(range = c(0.1,1)) - gpl = gpl + ggraph::geom_node_text(ggplot2::aes(label = name), repel = TRUE, size = node_text_size) - gpl = gpl + ggraph::geom_node_point(ggplot2::aes(color = name), size = node_size) - if(!is.null(node_color_code)) { - gpl = gpl + ggplot2::scale_color_manual(values = node_color_code) - } - gpl = gpl + ggplot2::theme_bw() + ggplot2::theme(panel.grid = ggplot2::element_blank(), - panel.border = ggplot2::element_blank(), - axis.title = ggplot2::element_blank(), - axis.text = ggplot2::element_blank(), - axis.ticks = ggplot2::element_blank()) - - return(plot_output_handler( - gobject = gobject, - plot_object = gpl, - save_plot = save_plot, - return_plot = return_plot, - show_plot = show_plot, - default_save_name = default_save_name, - save_param = save_param, - else_return = NULL - )) - -} - - -#' @title cellProximityVisPlot_2D_ggplot -#' @name cellProximityVisPlot_2D_ggplot -#' @description Visualize 2D cell-cell interactions according to spatial coordinates in ggplot mode -#' @return ggplot -#' @details Description of parameters. -#' @keywords internal -cellProximityVisPlot_2D_ggplot <- function(gobject, - interaction_name = NULL, - cluster_column = NULL, - sdimx = NULL, - sdimy = NULL, - cell_color = NULL, - cell_color_code = NULL, - color_as_factor = TRUE, - show_other_cells = FALSE, - show_network = FALSE, - show_other_network = FALSE, - network_color = NULL, - spatial_network_name = 'Delaunay_network', - show_grid = FALSE, - grid_color = NULL, - spatial_grid_name = 'spatial_grid', - coord_fix_ratio = 1, - show_legend = TRUE, - point_size_select = 2, - point_select_border_col = 'black', - point_select_border_stroke = 0.05, - point_size_other = 1, - point_alpha_other = 0.3, - point_other_border_col = 'lightgrey', - point_other_border_stroke = 0.01, - ...){ - - # data.table variables - unified_int = sdimx_begin = sdimy_begin = sdimx_end = sdimy_end = x_start = x_end = NULL - y_start = y_end = cell_ID = NULL - - if(is.null(interaction_name)) { - stop('\n you need to specific at least one interaction name, run cellProximityEnrichment \n') - } - - - cell_locations = gobject@spatial_locs - spatial_grid = gobject@spatial_grid[[spatial_grid_name]] - cell_metadata = gobject@cell_metadata - - - - spatial_network = annotateSpatialNetwork(gobject = gobject, - spatial_network_name = spatial_network_name, - cluster_column = cluster_column) - - cell_IDs_to_keep = unique(c(spatial_network[unified_int %in% interaction_name]$to, - spatial_network[unified_int %in% interaction_name]$from)) - - #print(cell_IDs_to_keep) - - if(show_other_cells){ - CellType <- strsplit(interaction_name,"--") - all_cell_IDs = cell_metadata[cell_metadata[[cluster_column]] == CellType[[1]][1] | - cell_metadata[[cluster_column]] == CellType[[1]][2],]$cell_ID - other_cell_IDs <- setdiff(all_cell_IDs, cell_IDs_to_keep) - } - - - # annotated cell data - if(nrow(cell_metadata) == 0) { - cell_locations_metadata = cell_locations - } else { - cell_locations_metadata <- merge(cell_locations, cell_metadata,by = "cell_ID") - } - - - # first 2 dimensions need to be defined - if(is.null(sdimx) | is.null(sdimy)) { - cat('first and second dimenion need to be defined, default is first 2 \n') - sdimx = 'sdimx' - sdimy = 'sdimy' - } - - pl <- ggplot2::ggplot() - pl <- pl + ggplot2::theme_classic() - - if(!is.null(spatial_network) & show_network == TRUE) { - if(is.null(network_color)) network_color = 'red' - if(show_other_network){ - pl <- pl + ggplot2::geom_segment(data = spatial_network[!unified_int %in% interaction_name], - aes(x = sdimx_begin, y = sdimy_begin, xend = sdimx_end, yend = sdimy_end), - color = 'lightgrey', size = 0.5, alpha = 0.5) - } - pl <- pl + ggplot2::geom_segment(data = spatial_network[unified_int %in% interaction_name], - aes(x = sdimx_begin, y = sdimy_begin, xend = sdimx_end, yend = sdimy_end), - color = network_color, size = 0.5, alpha = 0.5) - } - - if(!is.null(spatial_grid) & show_grid == TRUE) { - if(is.null(grid_color)) grid_color = 'black' - pl <- pl + ggplot2::geom_rect(data = spatial_grid, aes(xmin = x_start, xmax = x_end, ymin = y_start, ymax = y_end), - color = grid_color, fill = NA) - } - - # cell color default - if(is.null(cell_color)) { - cell_color = 'lightblue' - pl <- pl + ggplot2::geom_point(data = cell_locations[!cell_ID %in% cell_IDs_to_keep], aes_string(x = sdimx, y = sdimy), - show.legend = show_legend, shape = 21, fill = 'lightgrey', size = point_size_other) - pl <- pl + ggplot2::geom_point(data = cell_locations[cell_ID %in% cell_IDs_to_keep], aes_string(x = sdimx, y = sdimy), - show.legend = show_legend, shape = 21, fill = cell_color, size = point_size_select) - if(show_other_cells){ - pl <- pl + ggplot2::geom_point(data = cell_locations[cell_ID %in% other_cell_IDs], aes_string(x = sdimx, y = sdimy), - show.legend = show_legend, shape = 21, fill = cell_color, alpha = point_alpha_other, - size = point_size_select * 0.5) - } - } - else if (is.character(cell_color)) { - if(cell_color %in% colnames(cell_locations_metadata)) { - - if(color_as_factor == TRUE) { - factor_data = factor(cell_locations_metadata[[cell_color]]) - cell_locations_metadata[[cell_color]] <- factor_data - } - - pl <- pl + ggplot2::geom_point(data = cell_locations_metadata[!cell_ID %in% cell_IDs_to_keep], aes_string(x = sdimx, y = sdimy), - fill = 'lightgrey', shape = 21, size = point_size_other, - color = point_other_border_col, stroke = point_other_border_stroke) - pl <- pl + ggplot2::geom_point(data = cell_locations_metadata[cell_ID %in% cell_IDs_to_keep], aes_string(x = sdimx, y = sdimy, fill = cell_color), - show.legend = show_legend, shape = 21, size = point_size_select, - color = point_select_border_col, stroke = point_select_border_stroke) - if(show_other_cells){ - pl <- pl + ggplot2::geom_point(data = cell_locations_metadata[cell_ID %in% other_cell_IDs], aes_string(x = sdimx, y = sdimy,fill = cell_color), - show.legend = show_legend, shape = 21, alpha = point_alpha_other, - size = point_size_select * 0.5) - } - - - - if(!is.null(cell_color_code)) { - pl <- pl + ggplot2::scale_fill_manual(values = cell_color_code) - } else if(color_as_factor == T) { - number_colors = length(unique(factor_data)) - cell_color_code = set_default_color_discrete_cell(instrs = instructions(gobject))(n = number_colors) - names(cell_color_code) = unique(factor_data) - pl <- pl + ggplot2::scale_fill_manual(values = cell_color_code) - } else if(color_as_factor == F){ - pl <- pl + set_default_color_continuous_cell( - colors = cell_color_code, - instrs = instructions(gobject), - midpoint = NULL, - style = 'sequential', - type_default = list( - pal = c('blue', 'red') - ) - ) - } - - } else { - pl <- pl + ggplot2::geom_point(data = cell_locations_metadata[!cell_ID %in% cell_IDs_to_keep], aes_string(x = sdimx, y = sdimy), - show.legend = show_legend, shape = 21, fill = 'lightgrey', size = point_size_other, - color = point_other_border_col, stroke = point_other_border_stroke) - pl <- pl + ggplot2::geom_point(data = cell_locations_metadata[cell_ID %in% cell_IDs_to_keep], aes_string(x = sdimx, y = sdimy), - show.legend = show_legend, shape = 21, fill = cell_color, size = point_size_select, - color = point_select_border_col, stroke = point_select_border_stroke) - } - - } - - pl <- pl + ggplot2::theme_bw() + ggplot2::theme(plot.title = element_text(hjust = 0.5), - legend.title = element_text(size = 10), - legend.text = element_text(size = 10)) - - # fix coord ratio - if(!is.null(coord_fix_ratio)) { - pl <- pl + ggplot2::coord_fixed(ratio = coord_fix_ratio) - } - - pl <- pl + ggplot2::labs(x = 'x coordinates', y = 'y coordinates') - - return(pl) -} - - -#' @title cellProximityVisPlot_2D_plotly -#' @name cellProximityVisPlot_2D_plotly -#' @description Visualize 2D cell-cell interactions according to spatial coordinates in plotly mode -#' @keywords internal -cellProximityVisPlot_2D_plotly <- function(gobject, - interaction_name = NULL, - cluster_column = NULL, - sdimx = NULL, - sdimy = NULL, - cell_color = NULL, - cell_color_code = NULL, - color_as_factor = T, - show_other_cells = F, - show_network = F, - show_other_network = F, - network_color = NULL, - spatial_network_name = 'Delaunay_network', - show_grid = F, - grid_color = NULL, - spatial_grid_name = 'spatial_grid', - show_legend = T, - point_size_select = 2, - point_size_other = 1, - point_alpha_other = 0.3, - axis_scale = c("cube","real","custom"), - custom_ratio = NULL, - x_ticks = NULL, - y_ticks = NULL, - ...){ - - - # data.table variables - cell_ID = unified_int = NULL - - if(is.null(interaction_name)) { - stop('\n you need to specific at least one interaction name, run cellProximityEnrichment \n') - } - - - cell_locations = gobject@spatial_locs - spatial_grid = gobject@spatial_grid[[spatial_grid_name]] - cell_metadata = gobject@cell_metadata - - - spatial_network = annotateSpatialNetwork(gobject = gobject, spatial_network_name = spatial_network_name, cluster_column = cluster_column) - - cell_IDs_to_keep = unique(c(spatial_network[unified_int %in% interaction_name]$to, spatial_network[unified_int %in% interaction_name]$from)) - - if(show_other_cells){ - CellType <- strsplit(interaction_name,"-") - all_cell_IDs = cell_metadata[cell_metadata[[cluster_column]] == CellType[[1]][1] | - cell_metadata[[cluster_column]] == CellType[[1]][2],]$cell_ID - other_cell_IDs <- setdiff(all_cell_IDs, cell_IDs_to_keep) - } - - # annotated cell data - if(nrow(cell_metadata) == 0) { - cell_locations_metadata = cell_locations - } else { - cell_locations_metadata <- merge(cell_locations, cell_metadata, by = "cell_ID") - } - - - - - # first 2 dimensions need to be defined - if(is.null(sdimx) | is.null(sdimy)) { - cat('first and second dimenion need to be defined, default is first 2 \n') - sdimx = 'sdimx' - sdimy = 'sdimy' - } - - - #create 2D plotly plot - - axis_scale = match.arg(axis_scale, c("cube","real","custom")) - - ratio = plotly_axis_scale_2D(cell_locations_metadata,sdimx = sdimx,sdimy = sdimy, - mode = axis_scale,custom_ratio = custom_ratio) - - pl <- plotly::plot_ly() - - if(show_network == TRUE) { - if(is.null(network_color)){ - network_color = "red" - } - if(show_other_network){ - pl <- pl %>% plotly::add_segments(name = paste("unselected",spatial_network_name,sep = " "), - type = "scatter", - data = spatial_network[!unified_int %in% interaction_name], - x = ~sdimx_begin, - y =~sdimy_begin, - xend = ~sdimx_end, - yend = ~sdimy_end, - line = list(color = "lightgrey", - width = 0.5), - opacity=0.3) - } - pl <- pl %>% plotly::add_segments(name = spatial_network_name, - type = "scatter", - data = spatial_network[unified_int %in% interaction_name], - x = ~sdimx_begin, - y = ~sdimy_begin, - xend = ~sdimx_end, - yend = ~sdimy_end, - line = list(color = network_color, - width = 0.5), - opacity=0.8) - - } - if(show_grid == TRUE){ - if(is.null(grid_color)) { - grid_color = 'black' - } - edges <- plotly_grid(spatial_grid) - spl <- spl %>% plotly::add_segments(name = "spatial_grid", - type = "scatter", - data = edges, - x = ~x, - y = ~y, - xend = ~x_end, - yend = ~y_end, - line = list(color = grid_color, - width = 1), - opacity=1) - - } - - - if(!is.null(cell_color)) { - if(cell_color %in% colnames(cell_locations_metadata)){ - if(is.null(cell_color_code)) { - number_colors=length(unique(cell_locations_metadata[[cell_color]])) - cell_color_code = set_default_color_discrete_cell(instrs = instructions(gobject))(n = number_colors) - } - cell_locations_metadata[[cell_color]] <- as.factor(cell_locations_metadata[[cell_color]]) - - pl <- pl %>% plotly::add_trace(type = 'scatter',mode = 'markers', - #name = "selected cells", - data=cell_locations_metadata[cell_ID %in% cell_IDs_to_keep], - x = ~sdimx, y = ~sdimy, - color = cell_locations_metadata[cell_ID %in% cell_IDs_to_keep][[cell_color]], - colors = cell_color_code, - marker = list(size = point_size_select)) - if(show_other_cells){ - pl <- pl %>% plotly::add_trace(type = 'scatter',mode = 'markers', - #name = "selected cells outside network", - data=cell_locations_metadata[cell_ID %in% other_cell_IDs], - x = ~sdimx, y = ~sdimy, - color = cell_locations_metadata[cell_ID %in% other_cell_IDs][[cell_color]], - colors = cell_color_code, - opacity = point_alpha_other, - marker = list(size = point_size_select * 0.7)) - } - pl <- pl %>% plotly::add_trace(type = 'scatter',mode = "markers", - name = "unselected cells", - data=cell_locations_metadata[!cell_ID %in% cell_IDs_to_keep], - x = ~sdimx, y = ~sdimy, - marker = list(size = point_size_other,color = "lightgray",colors = "lightgray"), - opacity = point_alpha_other) - - } - else{ - cat('cell_color not exist!\n') - } - } - else { - pl <- pl %>% plotly::add_trace(type = 'scatter',mode = 'markers', - name = "selected cells", - data=cell_locations_metadata[cell_ID %in% cell_IDs_to_keep], - x = ~sdimx, y = ~sdimy, - marker = list(size = point_size_select,color = "lightblue",colors = "lightblue")) - if(show_other_cells){ - pl <- pl %>% plotly::add_trace(type = 'scatter',mode = 'markers', - data=cell_locations_metadata[cell_ID %in% other_cell_IDs], - x = ~sdimx, y = ~sdimy, - name = "selected cells outside network", - marker = list(size = point_size_select*0.7,color = "lightblue",colors = "lightblue"), - opacity = point_alpha_other) - } - pl <- pl %>% plotly::add_trace(type = 'scatter',mode = "markers", - name = "unselected cells", - data=cell_locations_metadata[!cell_ID %in% cell_IDs_to_keep], - x = ~sdimx, y = ~sdimy, - marker = list(size = point_size_other,color = "lightgray",colors = "lightgray"), - opacity = point_alpha_other) - - } - - pl <- pl %>% - plotly::layout(list(xaxis = list(title = 'X',nticks = x_ticks), - yaxis = list(title = 'Y',nticks = y_ticks)), - legend = list(x = 100, y = 0.5, - font = list(family = "sans-serif",size = 12))) - return((pl)) - -} - -#' @title cellProximityVisPlot_3D_plotly -#' @name cellProximityVisPlot_3D_plotly -#' @description Visualize 3D cell-cell interactions according to spatial coordinates in plotly mode -#' @keywords internal -cellProximityVisPlot_3D_plotly <- function(gobject, - interaction_name = NULL, - cluster_column = NULL, - sdimx = NULL, - sdimy = NULL, - sdimz = NULL, - cell_color = NULL, - cell_color_code = NULL, - color_as_factor = T, - show_other_cells = F, - show_network = F, - show_other_network = F, - network_color = NULL, - spatial_network_name = 'Delaunay_network', - show_grid = F, - grid_color = NULL, - spatial_grid_name = 'spatial_grid', - show_legend = T, - point_size_select = 2, - point_size_other = 1, - point_alpha_other = 0.5, - axis_scale = c("cube","real","custom"), - custom_ratio = NULL, - x_ticks = NULL, - y_ticks = NULL, - z_ticks = NULL, - ...){ - - # data.table variables - cell_ID = unified_int = NULL - - if(is.null(interaction_name)) { - stop('\n you need to specific at least one interaction name, run cellProximityEnrichment \n') - } - - - cell_locations = gobject@spatial_locs - spatial_grid = gobject@spatial_grid[[spatial_grid_name]] - cell_metadata = gobject@cell_metadata - - - spatial_network = annotateSpatialNetwork(gobject = gobject, spatial_network_name = spatial_network_name, cluster_column = cluster_column) - - cell_IDs_to_keep = unique(c(spatial_network[unified_int %in% interaction_name]$to, spatial_network[unified_int %in% interaction_name]$from)) - - if(show_other_cells){ - CellType <- strsplit(interaction_name,"-") - all_cell_IDs = cell_metadata[cell_metadata[[cluster_column]] == CellType[[1]][1] | - cell_metadata[[cluster_column]] == CellType[[1]][2],]$cell_ID - other_cell_IDs <- setdiff(all_cell_IDs, cell_IDs_to_keep) - } - - # annotated cell data - if(nrow(cell_metadata) == 0) { - cell_locations_metadata = cell_locations - } else { - cell_locations_metadata <- merge(cell_locations, cell_metadata, by = "cell_ID") - } - - - - - # first 2 dimensions need to be defined - if(is.null(sdimx) | is.null(sdimy)) { - cat('first and second dimenion need to be defined, default is first 2 \n') - sdimx = 'sdimx' - sdimy = 'sdimy' - } - - - - - - # if 3 dimensions are defined create a 3D plot - - # create 3D plotly plot - - pl <- plotly::plot_ly() - - axis_scale = match.arg(axis_scale, c("cube","real","custom")) - - ratio = plotly_axis_scale_3D(cell_locations_metadata,sdimx = sdimx,sdimy = sdimy,sdimz = sdimz, - mode = axis_scale,custom_ratio = custom_ratio) - - if(!is.null(cell_color)) { - if(cell_color %in% colnames(cell_locations_metadata)){ - if(is.null(cell_color_code)) { - number_colors=length(unique(cell_locations_metadata[[cell_color]])) - cell_color_code = set_default_color_discrete_cell(instrs = instructions(gobject))(n = number_colors) - } - cell_locations_metadata[[cell_color]] <- as.factor(cell_locations_metadata[[cell_color]]) - - pl <- pl %>% plotly::add_trace(type = 'scatter3d',mode = 'markers', - #name = "selected cells", - data=cell_locations_metadata[cell_ID %in% cell_IDs_to_keep], - x = ~sdimx, y = ~sdimy, z = ~sdimz, - color = cell_locations_metadata[cell_ID %in% cell_IDs_to_keep][[cell_color]], - colors = cell_color_code, - marker = list(size = point_size_select))%>% - plotly::add_trace(type = 'scatter3d',mode = "markers", - name = "unselected cells", - data=cell_locations_metadata[!cell_ID %in% cell_IDs_to_keep], - x = ~sdimx, y = ~sdimy, z = ~sdimz, - marker = list(size = point_size_other,color = "lightgray",colors = "lightgray"), - opacity = point_alpha_other) - if(show_other_cells){ - pl <- pl %>% plotly::add_trace(type = 'scatter3d',mode = 'markers', - #name = "selected cells outside network", - data=cell_locations_metadata[cell_ID %in% other_cell_IDs], - x = ~sdimx, y = ~sdimy, z = ~sdimz, - color = cell_locations_metadata[cell_ID %in% other_cell_IDs][[cell_color]], - colors = cell_color_code, - opacity = point_alpha_other, - marker = list(size = point_size_select*0.7)) - } - } - else{ - cat('cell_color not exist!\n') - } - } - else { - pl <- pl %>% plotly::add_trace(type = 'scatter3d',mode = 'markers', - name = "selected cells", - data=cell_locations_metadata[cell_ID %in% cell_IDs_to_keep], - x = ~sdimx, y = ~sdimy, z = ~sdimz, - marker = list(size = point_size_select,color = "lightblue",colors = "lightblue"))%>% - plotly::add_trace(type = 'scatter3d',mode = "markers", - name = "unselected cells", - data=cell_locations_metadata[!cell_ID %in% cell_IDs_to_keep], - x = ~sdimx, y = ~sdimy, z = ~sdimz, - marker = list(size = point_size_other,color = "lightgray",colors = "lightgray"), - opacity = point_alpha_other) - if(show_other_cells){ - pl <- pl %>% plotly::add_trace(type = 'scatter3d',mode = 'markers', - data=cell_locations_metadata[cell_ID %in% other_cell_IDs], - x = ~sdimx, y = ~sdimy, z = ~sdimz, - name = "selected cells outside network", - marker = list(size = point_size_select*0.7,color = "lightblue",colors = "lightblue"), - opacity = point_alpha_other) - } - } - if(!is.null(spatial_network) & show_network == TRUE) { - if(is.null(network_color)) { - network_color = 'red' - } - unselect_network <- spatial_network[!unified_int %in% interaction_name] - select_network <- spatial_network[unified_int %in% interaction_name] - pl <- pl %>% plotly::add_trace(name = "sptial network",mode = "lines", type = "scatter3d",opacity=0.5, - data = plotly_network(select_network), - x = ~x,y=~y,z=~z,inherit = F,line=list(color=network_color)) - if(show_other_network == T){ - pl <- pl %>% plotly::add_trace(name = "unselected sptial network",mode = "lines", type = "scatter3d",opacity=0.1, - data = plotly_network(unselect_network), - x = ~x,y=~y,z=~z,inherit = F,line=list(color="lightgray")) - } - - - } - - pl <- pl %>% plotly::layout(scene = list( - xaxis = list(title = "X",nticks = x_ticks), - yaxis = list(title = "Y",nticks = y_ticks), - zaxis = list(title = "Z",nticks = z_ticks), - aspectmode='manual', - aspectratio = list(x=ratio[[1]], - y=ratio[[2]], - z=ratio[[3]]))) - return(pl) - - -} - -#' @title cellProximityVisPlot -#' @name cellProximityVisPlot -#' @description Visualize cell-cell interactions according to spatial coordinates -#' @param gobject giotto object -#' @param interaction_name cell-cell interaction name -#' @param cluster_column cluster column with cell clusters -#' @param sdimx x-axis dimension name (default = 'sdimx') -#' @param sdimy y-axis dimension name (default = 'sdimy') -#' @param sdimz z-axis dimension name (default = 'sdimz') -#' @param cell_color color for cells (see details) -#' @param cell_color_code named vector with colors -#' @param color_as_factor convert color column to factor -#' @param show_other_cells show not selected cells -#' @param show_network show underlying spatial network -#' @param show_other_network show underlying spatial network of other cells -#' @param network_color color of spatial network -#' @param spatial_network_name name of spatial network to use -#' @param show_grid show spatial grid -#' @param grid_color color of spatial grid -#' @param spatial_grid_name name of spatial grid to use -#' @param coord_fix_ratio fix ratio between x and y-axis -#' @param show_legend show legend -#' @param point_size_select size of selected points -#' @param point_select_border_col border color of selected points -#' @param point_select_border_stroke stroke size of selected points -#' @param point_size_other size of other points -#' @param point_alpha_other alpha of other points -#' @param point_other_border_col border color of other points -#' @param point_other_border_stroke stroke size of other points -#' @param axis_scale scale of axis -#' @param custom_ratio custom ratio of scales -#' @param x_ticks x ticks -#' @param y_ticks y ticks -#' @param z_ticks z ticks -#' @param plot_method method to plot -#' @param \dots additional parameters -#' @return ggplot or plotly -#' @details Description of parameters. -#' @export -cellProximityVisPlot <- function(gobject, - interaction_name = NULL, - cluster_column = NULL, - sdimx = NULL, - sdimy = NULL, - sdimz = NULL, - cell_color = NULL, - cell_color_code = NULL, - color_as_factor = T, - show_other_cells = F, - show_network = F, - show_other_network = F, - network_color = NULL, - spatial_network_name = 'Delaunay_network', - show_grid = F, - grid_color = NULL, - spatial_grid_name = 'spatial_grid', - coord_fix_ratio = 1, - show_legend = T, - point_size_select = 2, - point_select_border_col = 'black', - point_select_border_stroke = 0.05, - point_size_other = 1, - point_alpha_other = 0.3, - point_other_border_col = 'lightgrey', - point_other_border_stroke = 0.01, - axis_scale = c("cube","real","custom"), - custom_ratio = NULL, - x_ticks = NULL, - y_ticks = NULL, - z_ticks = NULL, - plot_method = c('ggplot', 'plotly'), - ...) { - - - ## decide plot method - plot_method = match.arg(plot_method, choices = c('ggplot', 'plotly')) - axis_scale = match.arg(axis_scale, c("cube","real","custom")) - - - if(plot_method == 'ggplot') { - - if(is.null(sdimx) | is.null(sdimy)) { - - warning("plot_method = ggplot, but spatial dimensions for sdimx and sdimy for 2D plotting are not given. \n - It will default to the 'sdimx' and 'sdimy' ") - sdimx = 'sdimx' - sdimy = 'sdimy' - #stop('\n ggplot is in 2D and you need to define sdimx and sdimy \n') - } - - if(length(c(sdimx, sdimy, sdimz)) == 3){ - warning("ggplot is not able to produce 3D plot! Please choose plotly method\n") - } - result = cellProximityVisPlot_2D_ggplot(gobject = gobject, - interaction_name = interaction_name, - cluster_column = cluster_column, - sdimx = sdimx, - sdimy = sdimy, - cell_color = cell_color, - cell_color_code = cell_color_code, - color_as_factor = color_as_factor, - show_other_cells = show_other_cells, - show_network = show_network, - show_other_network = show_other_network, - network_color = network_color, - spatial_network_name = spatial_network_name, - show_grid = show_grid, - grid_color = grid_color, - spatial_grid_name = spatial_grid_name, - coord_fix_ratio = coord_fix_ratio, - show_legend = show_legend, - point_size_select = point_size_select, - point_select_border_col = point_select_border_col, - point_select_border_stroke = point_select_border_stroke, - point_size_other = point_size_other, - point_alpha_other =point_alpha_other, - point_other_border_col = point_other_border_col, - point_other_border_stroke = point_other_border_stroke, - ...) - - } - else if(plot_method == 'plotly') { - - if(length(c(sdimx, sdimy, sdimz)) == 3) { - - result = cellProximityVisPlot_3D_plotly(gobject = gobject, - interaction_name = interaction_name, - cluster_column = cluster_column, - sdimx = sdimx, - sdimy = sdimy, - sdimz = sdimz, - cell_color = cell_color, - cell_color_code = cell_color_code, - color_as_factor = color_as_factor, - show_other_cells = show_other_cells, - show_network = show_network, - show_other_network = show_other_network, - network_color = network_color, - spatial_network_name = spatial_network_name, - show_grid = show_grid, - grid_color = grid_color, - spatial_grid_name = spatial_grid_name, - show_legend = show_legend, - point_size_select = point_size_select, - point_size_other = point_size_other, - point_alpha_other = point_alpha_other, - axis_scale = axis_scale, - custom_ratio = custom_ratio, - x_ticks = x_ticks, - y_ticks = y_ticks, - z_ticks = z_ticks, - ...) - - } - else { - - if(is.null(sdimx) | is.null(sdimy)) { - stop('\n plotly in 2D requires you to define sdimx and sdimy \n') - } - - ## run: visPlot_2D_plotly - result = cellProximityVisPlot_2D_plotly(gobject = gobject, - interaction_name = interaction_name, - cluster_column = cluster_column, - sdimx = sdimx, - sdimy = sdimy, - cell_color = cell_color, - cell_color_code = cell_color_code, - color_as_factor = color_as_factor, - show_other_cells = show_other_cells, - show_network = show_network, - show_other_network = show_other_network, - network_color = network_color, - spatial_network_name = spatial_network_name, - show_grid = show_grid, - grid_color = grid_color, - spatial_grid_name = spatial_grid_name, - show_legend = show_legend, - point_size_select = point_size_select, - point_size_other = point_size_other, - point_alpha_other = point_alpha_other, - axis_scale = axis_scale, - custom_ratio = custom_ratio, - x_ticks = x_ticks, - y_ticks = y_ticks, - ...) - - - } - - } - return(result) - -} - - - - - - - -# * #### -# NEW plots #### - - - - -#' @title plotCellProximityFeats -#' @name plotCellProximityFeats -#' @description Create visualization for cell proximity feature scores -#' @inheritParams data_access_params -#' @inheritParams plot_output_params -#' @inheritParams plot_cell_params -#' @param icfObject ICF (interaction changed feature) score object -#' @param method plotting method to use -#' @param min_cells minimum number of source cell type -#' @param min_cells_expr minimum expression level for source cell type -#' @param min_int_cells minimum number of interacting neighbor cell type -#' @param min_int_cells_expr minimum expression level for interacting neighbor cell type -#' @param min_fdr minimum adjusted p-value -#' @param min_spat_diff minimum absolute spatial expression difference -#' @param min_log2_fc minimum log2 fold-change -#' @param min_zscore minimum z-score change -#' @param zscores_column calculate z-scores over cell types or featuress -#' @param direction differential expression directions to keep -#' @return plot -#' @export -plotCellProximityFeats = function(gobject, - icfObject, - method = c('volcano', 'cell_barplot', 'cell-cell', 'cell_sankey', 'heatmap', 'dotplot'), - min_cells = 4, - min_cells_expr = 1, - min_int_cells = 4, - min_int_cells_expr = 1, - min_fdr = 0.1, - min_spat_diff = 0.2, - min_log2_fc = 0.2, - min_zscore = 2, - zscores_column = c('cell_type', 'feats'), - direction = c('both', 'up', 'down'), - cell_color_code = NULL, - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = 'plotCellProximityFeats') { - - - if(!'icfObject' %in% class(icfObject)) { - stop('\n icfObject needs to be the output from findInteractionChangedFeats() or findICF() \n') - } - - # print, return and save parameters - show_plot = ifelse(is.na(show_plot), readGiottoInstructions(gobject, param = 'show_plot'), show_plot) - save_plot = ifelse(is.na(save_plot), readGiottoInstructions(gobject, param = 'save_plot'), save_plot) - return_plot = ifelse(is.na(return_plot), readGiottoInstructions(gobject, param = 'return_plot'), return_plot) - - - ## first filter - filter_icf = filterInteractionChangedFeats(icfObject = icfObject, - min_cells = min_cells, - min_cells_expr = min_cells_expr, - min_int_cells = min_int_cells, - min_int_cells_expr = min_int_cells_expr, - min_fdr = min_fdr, - min_spat_diff = min_spat_diff, - min_log2_fc = min_log2_fc, - min_zscore = min_zscore, - zscores_column = zscores_column, - direction = direction) - - complete_part = filter_icf[['ICFscores']] - - ## other parameters - method = match.arg(method, choices = c('volcano', 'cell_barplot', 'cell-cell', 'cell_sankey', 'heatmap', 'dotplot')) - - - # variables - log2fc = p.adj = unif_int = N = cell_type = int_cell_type = NULL - - ## create data.table for visualization - if(method == 'volcano') { - - ## volcanoplot - pl = ggplot2::ggplot() - pl = pl + ggplot2::geom_point(data = complete_part, ggplot2::aes(x = log2fc, y = ifelse(is.infinite(-log10(p.adj)), 1000, -log10(p.adj)))) - pl = pl + ggplot2::theme_classic() - pl = pl + ggplot2::geom_vline(xintercept = 0, linetype = 2) - pl = pl + ggplot2::labs(x = 'log2 fold-change', y = '-log10(p.adjusted)') - - - ## print plot - if(show_plot == TRUE) { - print(pl) - } - - ## save plot - if(save_plot == TRUE) { - do.call('all_plots_save_function', c(list(gobject = gobject, plot_object = pl, default_save_name = default_save_name), save_param)) - } - - ## return plot - if(return_plot == TRUE) { - return(pl) - } - - - } else if(method == 'cell-cell') { - - nr_int_selection_scores = complete_part[, .N, by = unif_int] - order_interactions = nr_int_selection_scores[order(N)]$unif_int - - complete_part[, unif_int := factor(unif_int, order_interactions)] - - pl <- ggplot2::ggplot() - pl <- pl + ggplot2::geom_bar(data = complete_part, ggplot2::aes(x = unif_int, fill = unif_int)) - pl <- pl + ggplot2::theme_classic() + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90, hjust = 1, vjust = 1)) - pl <- pl + ggplot2::coord_flip() - - ## print plot - if(show_plot == TRUE) { - print(pl) - } - - ## save plot - if(save_plot == TRUE) { - do.call('all_plots_save_function', c(list(gobject = gobject, plot_object = pl, default_save_name = default_save_name), save_param)) - } - - ## return plot - if(return_plot == TRUE) { - return(pl) - } - - - } else if(method == 'cell_barplot') { - - - # by source cell type plot - nr_source_selection_scores = complete_part[, .N, by = cell_type] - order_source = nr_source_selection_scores[order(N)]$cell_type - - complete_part[, cell_type := factor(cell_type, order_source)] - - pl <- ggplot2::ggplot() - pl <- pl + ggplot2::geom_bar(data = complete_part, ggplot2::aes(x = cell_type, fill = int_cell_type)) - if(!is.null(cell_color_code)) { - pl <- pl + ggplot2::scale_fill_manual(values = cell_color_code) - } - pl <- pl + ggplot2::theme_classic() + ggplot2::theme(axis.text.x = element_text(angle = 45, hjust = 1, vjust = 1)) - pl <- pl + ggplot2::labs(x = '', y = '# of features influenced by cell neighborhood') - - - ## print plot - if(show_plot == TRUE) { - print(pl) - } - - ## save plot - if(save_plot == TRUE) { - do.call('all_plots_save_function', c(list(gobject = gobject, plot_object = pl, default_save_name = default_save_name), save_param)) - } - - ## return plot - if(return_plot == TRUE) { - return(pl) - } - - } else if(method == 'cell_sankey') { - - testalluv = complete_part[, .N, by = c('int_cell_type', 'cell_type')] - - # package check for ggalluvial - # verify if optional package is installed - package_check(pkg_name = "ggalluvial", repository = "CRAN") - - pl <- ggplot2::ggplot(testalluv, - ggplot2::aes(y = N, axis1 = cell_type, axis2 = int_cell_type)) + - ggalluvial::geom_alluvium(aes(fill = cell_type), width = 1/12) + - ggalluvial::geom_stratum(width = 1/12, fill = "black", color = "grey") + - ggplot2::scale_x_discrete(limits = c("cell type", "neighbours"), expand = c(.05, .05)) + - ggplot2::geom_label(stat = "stratum", label.strata = TRUE, size = 3) + - ggplot2::theme_classic() + ggplot2::labs(x = '', y = '# of features influenced by cell neighborhood') - - if(!is.null(cell_color_code)) { - pl <- pl + ggplot2::scale_fill_manual(values = cell_color_code) - } - - - - ## print plot - if(show_plot == TRUE) { - print(pl) - } - - ## save plot - if(save_plot == TRUE) { - do.call('all_plots_save_function', c(list(gobject = gobject, plot_object = pl, default_save_name = default_save_name), save_param)) - } - - ## return plot - if(return_plot == TRUE) { - return(pl) - } - - } else if(method == 'dotplot') { - - changed_feats = complete_part[, .N, by = c('cell_type', 'int_cell_type')] - - changed_feats[, cell_type := factor(cell_type, unique(cell_type))] - changed_feats[, int_cell_type := factor(int_cell_type, unique(int_cell_type))] - - pl = ggplot2::ggplot() - pl = pl + ggplot2::theme_classic() - pl = pl + ggplot2::geom_point(data = changed_feats, ggplot2::aes(x = cell_type, y = int_cell_type, size = N)) - pl = pl + ggplot2::scale_size_continuous(guide=guide_legend(title = '# of ICFs')) - pl = pl + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90, vjust = 1, hjust = 1)) - pl = pl + ggplot2::labs(x = 'source cell type', y = 'neighbor cell type') - - ## print plot - if(show_plot == TRUE) { - print(pl) - } - - ## save plot - if(save_plot == TRUE) { - do.call('all_plots_save_function', c(list(gobject = gobject, plot_object = pl, default_save_name = default_save_name), save_param)) - } - - ## return plot - if(return_plot == TRUE) { - return(pl) - } - - } else if(method == 'heatmap') { - - changed_feats = complete_part[, .N, by = c('cell_type', 'int_cell_type')] - - changed_feats[, cell_type := factor(cell_type, unique(cell_type))] - changed_feats[, int_cell_type := factor(int_cell_type, unique(int_cell_type))] - - changed_feats_d = data.table::dcast.data.table(changed_feats, cell_type~int_cell_type, value.var = 'N', fill = 0) - changed_feats_m = dt_to_matrix(changed_feats_d) - - col_fun = colorRamp2::colorRamp2(breaks = stats::quantile(log2(changed_feats_m+1)), - colors = c("white", 'white', "blue", "yellow", "red")) - - heatm = ComplexHeatmap::Heatmap(log2(changed_feats_m+1), col = col_fun, - row_title = 'cell_type', column_title = 'int_cell_type', heatmap_legend_param = list(title = 'log2(# DEGs)')) - - ## print plot - if(show_plot == TRUE) { - print(heatm) - } - - ## save plot - if(save_plot == TRUE) { - do.call('all_plots_save_function', c(list(gobject = gobject, plot_object = heatm, default_save_name = default_save_name), save_param)) - } - - ## return plot - if(return_plot == TRUE) { - return(heatm) - } - - } - -} - - - - - -#' @title plotCPF -#' @name plotCPF -#' @description Create visualization for cell proximity feature scores -#' @inheritParams data_access_params -#' @inheritParams plot_output_params -#' @inheritParams plot_cell_params -#' @param icfObject ICF (interaction changed feature) score object -#' @param method plotting method to use -#' @param min_cells minimum number of source cell type -#' @param min_cells_expr minimum expression level for source cell type -#' @param min_int_cells minimum number of interacting neighbor cell type -#' @param min_int_cells_expr minimum expression level for interacting neighbor cell type -#' @param min_fdr minimum adjusted p-value -#' @param min_spat_diff minimum absolute spatial expression difference -#' @param min_log2_fc minimum log2 fold-change -#' @param min_zscore minimum z-score change -#' @param zscores_column calculate z-scores over cell types or features -#' @param direction differential expression directions to keep -#' @return plot -#' @export -plotCPF = function(gobject, - icfObject, - method = c('volcano', 'cell_barplot', 'cell-cell', 'cell_sankey', 'heatmap', 'dotplot'), - min_cells = 5, - min_cells_expr = 1, - min_int_cells = 3, - min_int_cells_expr = 1, - min_fdr = 0.05, - min_spat_diff = 0.2, - min_log2_fc = 0.2, - min_zscore = 2, - zscores_column = c('cell_type', 'feats'), - direction = c('both', 'up', 'down'), - cell_color_code = NULL, - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = 'plotCPG') { - - - plotCellProximityFeats(gobject = gobject, - icfObject = icfObject, - method = method, - min_cells = min_cells, - min_cells_expr = min_cells_expr, - min_int_cells = min_int_cells, - min_int_cells_expr = min_int_cells_expr, - min_fdr = min_fdr, - min_spat_diff = min_spat_diff, - min_log2_fc = min_log2_fc, - min_zscore = min_zscore, - zscores_column = zscores_column, - direction = direction, - cell_color_code = cell_color_code, - show_plot = show_plot, - return_plot = return_plot, - save_plot = save_plot, - save_param = save_param, - default_save_name = default_save_name) - - -} - - - -#' @title Plot interaction changed features -#' @name plotInteractionChangedFeats -#' @description Create barplot to visualize interaction changed features -#' @inheritParams data_access_params -#' @inheritParams plot_output_params -#' @inheritParams plot_cell_params -#' @param icfObject ICF (interaction changed feature) score object -#' @param source_type cell type of the source cell -#' @param source_markers markers for the source cell type -#' @param ICF_feats named character vector of ICF features -#' @return plot -#' @export -plotInteractionChangedFeats = function(gobject, - icfObject, - source_type, - source_markers, - ICF_feats, - cell_color_code = NULL, - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = 'plotInteractionChangedFeats') { - - - # data.table variables - cell_type = int_cell_type = log2fc = NULL - - - if(!'icfObject' %in% class(icfObject)) { - stop('\n icfObject needs to be the output from findInteractionChangedFeats() or findICF() \n') - } - - ICFscores = icfObject[['ICFscores']] - - # combine feats - names(source_markers) = rep('marker', length(source_markers)) - neighbor_types = names(ICF_feats) - all_feats = c(source_markers, ICF_feats) - - # warning if there are feats selected that are not detected - detected_feats = unique(ICFscores[['feats']]) - not_detected_feats = all_feats[!all_feats %in% detected_feats] - if(length(not_detected_feats) > 0) { - cat('These selected features are not in the icfObject: \n', - not_detected_feats, '\n') - } - - # data.table set column names - feats = group = NULL - - tempDT = ICFscores[feats %in% all_feats][cell_type == source_type][int_cell_type %in% neighbor_types] - tempDT[, feats := factor(feats, levels = all_feats)] - tempDT[, group := names(all_feats[all_feats == feats]), by = 1:nrow(tempDT)] - - - if(is.null(cell_color_code)) { - mycolors = set_default_color_discrete_cell(instrs = instructions(gobject))(n = length(unique(tempDT$int_cell_type))) - names(mycolors) = unique(tempDT$int_cell_type) - } else { - mycolors = cell_color_code - } - - - pl = ggplot2::ggplot() - pl = pl + ggplot2::theme_classic() + ggplot2::theme(axis.text.x = ggplot2::element_text(size = 14, angle = 45, vjust = 1, hjust = 1), - axis.text.y = ggplot2::element_text(size = 14), - axis.title = ggplot2::element_text(size = 14)) - pl = pl + ggplot2::geom_bar(data = tempDT, ggplot2::aes(x = feats, y = log2fc, fill = int_cell_type), stat = 'identity', position = ggplot2::position_dodge()) - pl = pl + ggplot2::scale_fill_manual(values = mycolors) - pl = pl + ggplot2::labs(x = '', title = paste0('fold-change z-scores in ' ,source_type)) - - - - # print, return and save parameters - show_plot = ifelse(is.na(show_plot), readGiottoInstructions(gobject, param = 'show_plot'), show_plot) - save_plot = ifelse(is.na(save_plot), readGiottoInstructions(gobject, param = 'save_plot'), save_plot) - return_plot = ifelse(is.na(return_plot), readGiottoInstructions(gobject, param = 'return_plot'), return_plot) - - - ## print plot - if(show_plot == TRUE) { - print(pl) - } - - ## save plot - if(save_plot == TRUE) { - do.call('all_plots_save_function', c(list(gobject = gobject, plot_object = pl, default_save_name = default_save_name), save_param)) - } - - ## return plot - if(return_plot == TRUE) { - return(pl) - } - - -} - - - - - - - -#' @title Plot interaction changed features -#' @name plotICF -#' @description Create barplot to visualize interaction changed features -#' @inheritParams data_access_params -#' @inheritParams plot_output_params -#' @inheritParams plot_cell_params -#' @param icfObject ICF (interaction changed feature) score object -#' @param source_type cell type of the source cell -#' @param source_markers markers for the source cell type -#' @param ICF_feats named character vector of ICF features -#' @return plot -#' @export -plotICF = function(gobject, - icfObject, - source_type, - source_markers, - ICF_feats, - cell_color_code = NULL, - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = 'plotICF') { - - - plotInteractionChangedFeats(gobject = gobject, - icfObject = icfObject, - source_type = source_type, - source_markers = source_markers, - ICF_feats = ICF_feats, - cell_color_code = cell_color_code, - show_plot = show_plot, - return_plot = return_plot, - save_plot = save_plot, - save_param = save_param, - default_save_name = default_save_name) - -} - - - - - - - - -#' @title plotCombineInteractionChangedFeats -#' @name plotCombineInteractionChangedFeats -#' @description Create visualization for combined (pairwise) ICF scores -#' @inheritParams data_access_params -#' @inheritParams plot_output_params -#' @param combIcfObject ICFscores, output from combineInteractionChangedFeats() -#' @param selected_interactions interactions to show -#' @param selected_feat_to_feat pairwise feature combinations to show -#' @param detail_plot show detailed info in both interacting cell types -#' @param simple_plot show a simplified plot -#' @param simple_plot_facet facet on interactions or feats with simple plot -#' @param facet_scales ggplot facet scales paramter -#' @param facet_ncol ggplot facet ncol parameter -#' @param facet_nrow ggplot facet nrow parameter -#' @param colors vector with two colors to use -#' @return ggplot -#' @export -plotCombineInteractionChangedFeats <- function(gobject, - combIcfObject, - selected_interactions = NULL, - selected_feat_to_feat = NULL, - detail_plot = T, - simple_plot = F, - simple_plot_facet = c('interaction', 'feats'), - facet_scales = 'fixed', - facet_ncol = length(selected_feat_to_feat), - facet_nrow = length(selected_interactions), - colors = c('#9932CC', '#FF8C00'), - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = 'plotCombineICF') { - - - - ## check validity - if(!'combIcfObject' %in% class(combIcfObject)) { - stop('\n combIcfObject needs to be the output from combineInteractionChangedFeats() or combineICF() \n') - } - combIcfscore = copy(combIcfObject[['combIcfscores']]) - - if(is.null(selected_interactions) | is.null(selected_feat_to_feat)) { - stop('\n You need to provide a selection of cell-cell interactions and features-features to plot \n') - } - - - # data.table variables - unif_feat_feat = unif_int = other_2 = sel_2 = other_1 = sel_1 = cols = NULL - - - subDT = combIcfscore[unif_feat_feat %in% selected_feat_to_feat & unif_int %in% selected_interactions] - - # order interactions and feat-to-feat according to input - subDT[, unif_feat_feat := factor(unif_feat_feat, levels = selected_feat_to_feat)] - subDT[, unif_int := factor(unif_int, levels = selected_interactions)] - - if(simple_plot == F) { - - pl <- ggplot2::ggplot() - pl <- pl + ggplot2::theme_bw() - - if(detail_plot == TRUE) { - pl <- pl + ggplot2::geom_point(data = subDT, aes(x = 0, y = other_2, colour = "other cell expression"),shape = 1) - pl <- pl + ggplot2::geom_point(data = subDT, aes(x = 0, y = sel_2, colour = "selected cell expression"), shape = 1) - pl <- pl + ggplot2::geom_point(data = subDT, aes(x = other_1, y = 0, colour = "other cell expression"), shape = 1) - pl <- pl + ggplot2::geom_point(data = subDT, aes(x = sel_1, y = 0,colour ="selected cell expression"), shape = 1) - } - - pl <- pl + ggplot2::geom_point(data = subDT, aes(x = other_1, y = other_2, colour = "other cell expression"),size = 2) - pl <- pl + ggplot2::geom_point(data = subDT, aes(x = sel_1, y = sel_2, colour ="selected cell expression"), size = 2) - pl <- pl + ggplot2::geom_segment(data = subDT, aes(x = other_1, xend = sel_1, - y = other_2, yend = sel_2), linetype = 2) - #pl <- pl + ggplot2::labs(x = 'feat 1 in celltype 1', y = 'feat 2 in celltype 2') - pl <- pl + ggplot2::labs(x = paste(subDT$feats_1, subDT$cell_type_1, sep = " in ") - , y = paste(subDT$feats_2, subDT$cell_type_2, sep = " in ")) - pl <- pl + ggplot2::scale_colour_manual(name="expression source",values = colors) - pl <- pl + ggplot2::facet_wrap(~unif_feat_feat+unif_int, nrow = facet_nrow, ncol = facet_ncol, - scales = facet_scales) - - }else { - - simple_plot_facet = match.arg(arg = simple_plot_facet, choices = c('interaction', 'feats')) - - if(simple_plot_facet == 'interaction') { - pl <- ggplot2::ggplot() - pl <- pl + ggplot2::theme_bw() - pl <- pl + ggplot2::geom_segment(data = subDT, aes(x = sum(c(other_1, other_2)), xend = sum(c(sel_1, sel_2)), - y = unif_feat_feat, yend = unif_feat_feat), linetype = 2) - pl <- pl + ggplot2::geom_point(data = subDT, aes(x = sum(c(other_1, other_2)), y = unif_feat_feat,colour = "other cell expression")) - pl <- pl + ggplot2::geom_point(data = subDT, aes(x = sum(c(sel_1, sel_2)), y = unif_feat_feat,colour ="selected cell expression")) - pl <- pl + ggplot2::scale_colour_manual(name="expression source",values=cols) - pl <- pl + ggplot2::facet_wrap(~unif_int, scales = facet_scales) - pl <- pl + ggplot2::labs(x = 'interactions', y = 'feat-feat') - } else { - pl <- ggplot2::ggplot() - pl <- pl + ggplot2::theme_bw() - pl <- pl + ggplot2::geom_segment(data = subDT, aes(x = sum(c(other_1, other_2)), xend = sum(c(sel_1, sel_2)), - y = unif_int, yend = unif_int), linetype = 2) - pl <- pl + ggplot2::geom_point(data = subDT, aes(x = sum(c(other_1, other_2)), y = unif_int, colour = "other cell expression")) - pl <- pl + ggplot2::geom_point(data = subDT, aes(x = sum(c(sel_1, sel_2)), y = unif_int, colour ="selected cell expression")) - pl <- pl + ggplot2::scale_colour_manual(name="expression source",values=cols) - pl <- pl + ggplot2::facet_wrap(~unif_feat_feat, scales = facet_scales) - pl <- pl + ggplot2::labs(x = 'feat-feat', y = 'interactions') - } - } - - # print, return and save parameters - show_plot = ifelse(is.na(show_plot), readGiottoInstructions(gobject, param = 'show_plot'), show_plot) - save_plot = ifelse(is.na(save_plot), readGiottoInstructions(gobject, param = 'save_plot'), save_plot) - return_plot = ifelse(is.na(return_plot), readGiottoInstructions(gobject, param = 'return_plot'), return_plot) - - ## print plot - if(show_plot == TRUE) { - print(pl) - } - - ## save plot - if(save_plot == TRUE) { - do.call('all_plots_save_function', c(list(gobject = gobject, plot_object = pl, default_save_name = default_save_name), save_param)) - } - - ## return plot - if(return_plot == TRUE) { - return(pl) - } - -} - - - - - - - -#' @title plotCombineICF -#' @name plotCombineICF -#' @description Create visualization for combined (pairwise) ICF scores -#' @inheritParams data_access_params -#' @inheritParams plot_output_params -#' @param combIcfObject ICFscores, output from combineInteractionChangedFeats() -#' @param selected_interactions interactions to show -#' @param selected_feat_to_feat pairwise feature combinations to show -#' @param detail_plot show detailed info in both interacting cell types -#' @param simple_plot show a simplified plot -#' @param simple_plot_facet facet on interactions or feats with simple plot -#' @param facet_scales ggplot facet scales paramter -#' @param facet_ncol ggplot facet ncol parameter -#' @param facet_nrow ggplot facet nrow parameter -#' @param colors vector with two colors to use -#' @return ggplot -#' @export -plotCombineICF <- function(gobject, - combIcfObject, - selected_interactions = NULL, - selected_feat_to_feat = NULL, - detail_plot = T, - simple_plot = F, - simple_plot_facet = c('interaction', 'feats'), - facet_scales = 'fixed', - facet_ncol = length(selected_feat_to_feat), - facet_nrow = length(selected_interactions), - colors = c('#9932CC', '#FF8C00'), - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = 'plotCombineICF') { - - plotCombineInteractionChangedFeats(combIcfObject = combIcfObject, - selected_interactions = selected_interactions, - selected_feat_to_feat = selected_feat_to_feat, - detail_plot = detail_plot, - simple_plot = simple_plot, - simple_plot_facet = simple_plot_facet, - facet_scales = facet_scales, - facet_ncol = facet_ncol, - facet_nrow = facet_nrow, - colors = colors, - show_plot = show_plot, - return_plot = return_plot, - save_plot = save_plot, - save_param = save_param, - default_save_name = default_save_name) -} - - - - - - -## helper #### - -# TODO - -#' @title filterInteractionChangedFeats -#' @name filterInteractionChangedFeats -#' @description Filter Interaction Changed Feature scores. -#' @param icfObject ICF (interaction changed feature) score object -#' @param min_cells minimum number of source cell type -#' @param min_cells_expr minimum expression level for source cell type -#' @param min_int_cells minimum number of interacting neighbor cell type -#' @param min_int_cells_expr minimum expression level for interacting neighbor cell type -#' @param min_fdr minimum adjusted p-value -#' @param min_spat_diff minimum absolute spatial expression difference -#' @param min_log2_fc minimum log2 fold-change -#' @param min_zscore minimum z-score change -#' @param zscores_column calculate z-scores over cell types or genes -#' @param direction differential expression directions to keep -#' @return icfObject that contains the filtered differential feature scores -#' @keywords internal -filterInteractionChangedFeats = function(icfObject, - min_cells = 4, - min_cells_expr = 1, - min_int_cells = 4, - min_int_cells_expr = 1, - min_fdr = 0.1, - min_spat_diff = 0.2, - min_log2_fc = 0.2, - min_zscore = 2, - zscores_column = c('cell_type', 'feats'), - direction = c('both', 'up', 'down')) { - - # data.table variables - nr_select = int_nr_select = zscores = log2fc = sel = other = p.adj = NULL - - if(!'icfObject' %in% class(icfObject)) { - stop('\n icfObject needs to be the output from findInteractionChangedFeats() or findICF() \n') - } - - zscores_column = match.arg(zscores_column, choices = c('cell_type', 'feats')) - - ICFscore = copy(icfObject[['ICFscores']]) - - # other parameters - direction = match.arg(direction, choices = c('both', 'up', 'down')) - - - ## sequential filter steps ## - # 1. minimum number of source and target cells - selection_scores = ICFscore[nr_select >= min_cells & int_nr_select >= min_int_cells] - - # 2. create z-scores for log2fc per cell type - selection_scores[, zscores := scale(log2fc), by = c(zscores_column)] - - # 3. filter based on z-scores and minimum levels - comb_DT = rbind(selection_scores[zscores >= min_zscore & abs(diff) >= min_spat_diff & log2fc >= min_log2_fc & sel >= min_cells_expr], - selection_scores[zscores <= -min_zscore & abs(diff) >= min_spat_diff & log2fc <= -min_log2_fc & other >= min_int_cells_expr]) - - # 4. filter based on adjusted p-value (fdr) - comb_DT = comb_DT[p.adj < min_fdr] - - - if(direction == 'both') { - selection_scores = selection_scores - } else if(direction == 'up') { - selection_scores = selection_scores[log2fc >= min_log2_fc] - } else if(direction == 'down') { - selection_scores = selection_scores[log2fc <= -min_log2_fc] - } - - - newobj = copy(icfObject) - newobj[['ICFscores']] = comb_DT - - return(newobj) - -} - - - - - - -# * #### -# cell communication plots #### - -#' @title plotCombineCellCellCommunication -#' @name plotCombineCellCellCommunication -#' @description Create visualization for combined (pairwise) cell proximity gene scores -#' @inheritParams data_access_params -#' @inheritParams plot_output_params -#' @param combCCcom combined communcation scores, output from combCCcom() -#' @param selected_LR selected ligand-receptor pair -#' @param selected_cell_LR selected cell-cell interaction pair for ligand-receptor pair -#' @param detail_plot show detailed info in both interacting cell types -#' @param simple_plot show a simplified plot -#' @param simple_plot_facet facet on interactions or genes with simple plot -#' @param facet_scales ggplot facet scales paramter -#' @param facet_ncol ggplot facet ncol parameter -#' @param facet_nrow ggplot facet nrow parameter -#' @param colors vector with two colors to use -#' @return ggplot -#' @export -plotCombineCellCellCommunication <- function(gobject, - combCCcom, - selected_LR = NULL, - selected_cell_LR = NULL, - detail_plot = T, - simple_plot = F, - simple_plot_facet = c('interaction', 'genes'), - facet_scales = 'fixed', - facet_ncol = length(selected_LR), - facet_nrow = length(selected_cell_LR), - colors = c('#9932CC', '#FF8C00'), - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = 'plotCombineCellCellCommunication') { - - - - # data.table variables - LR_comb = LR_cell_comb = lig_expr = lig_expr_spat = rec_expr = rec_expr_spat = LR_expr = LR_expr_spat = NULL - - ## check validity - if(is.null(selected_cell_LR) | is.null(selected_LR)) { - stop('\n You need to provide a selection of cell-cell interactions and genes-genes to plot \n') - } - - subDT = combCCcom[LR_comb %in% selected_LR & LR_cell_comb %in% selected_cell_LR] - - # order interactions and gene-to-gene according to input - subDT[, LR_comb := factor(LR_comb, levels = selected_LR)] - subDT[, LR_cell_comb := factor(LR_cell_comb, levels = selected_cell_LR)] - - if(simple_plot == F) { - - pl <- ggplot2::ggplot() - pl <- pl + ggplot2::theme_bw() - - if(detail_plot == TRUE) { - pl <- pl + ggplot2::geom_point(data = subDT, aes(x = 0, y = lig_expr, colour = "overall cell expression"),shape = 1) - pl <- pl + ggplot2::geom_point(data = subDT, aes(x = 0, y = lig_expr_spat, colour = "spatial cell expression"), shape = 1) - pl <- pl + ggplot2::geom_point(data = subDT, aes(x = rec_expr, y = 0, colour = "overall cell expression"), shape = 1) - pl <- pl + ggplot2::geom_point(data = subDT, aes(x = rec_expr_spat, y = 0,colour ="spatial cell expression"), shape = 1) - } - - pl <- pl + ggplot2::geom_point(data = subDT, aes(x = rec_expr, y = lig_expr, colour = "overall cell expression"),size = 2) - pl <- pl + ggplot2::geom_point(data = subDT, aes(x = rec_expr_spat, y = lig_expr_spat, colour ="spatial cell expression"), size = 2) - pl <- pl + ggplot2::geom_segment(data = subDT, aes(x = rec_expr, xend = rec_expr_spat, - y = lig_expr, yend = lig_expr_spat), linetype = 2) - #pl <- pl + ggplot2::labs(x = 'gene 1 in celltype 1', y = 'gene 2 in celltype 2') - pl <- pl + ggplot2::labs(x = paste(subDT$receptor, subDT$rec_cell_type, sep = " in ") - , y = paste(subDT$ligand, subDT$lig_cell_type, sep = " in ")) - pl <- pl + ggplot2::scale_colour_manual(name="expression source",values = colors) - pl <- pl + ggplot2::facet_wrap(~LR_comb+LR_cell_comb, nrow = facet_nrow, ncol = facet_ncol, - scales = facet_scales) - - }else { - - simple_plot_facet = match.arg(arg = simple_plot_facet, choices = c('interaction', 'genes')) - - if(simple_plot_facet == 'interaction') { - pl <- ggplot2::ggplot() - pl <- pl + ggplot2::theme_bw() - pl <- pl + ggplot2::geom_segment(data = subDT, aes(x = LR_expr, xend = LR_expr_spat, - y = LR_comb, yend = LR_comb), linetype = 2) - pl <- pl + ggplot2::geom_point(data = subDT, aes(x = LR_expr, y = LR_comb, colour = "overall cell expression")) - pl <- pl + ggplot2::geom_point(data = subDT, aes(x = LR_expr_spat, y = LR_comb,colour ="spatial cell expression")) - pl <- pl + ggplot2::scale_colour_manual(name="expression source",values=colors) - pl <- pl + ggplot2::facet_wrap(~LR_cell_comb, scales = 'fixed') - pl <- pl + ggplot2::labs(x = 'interactions', y = 'gene-gene') - pl - - } else { - pl <- ggplot2::ggplot() - pl <- pl + ggplot2::theme_bw() - pl <- pl + ggplot2::geom_segment(data = subDT, aes(x = LR_expr, xend = LR_expr_spat, - y = LR_cell_comb, yend = LR_cell_comb), linetype = 2) - pl <- pl + ggplot2::geom_point(data = subDT, aes(x = LR_expr, y = LR_cell_comb, colour = "overall cell expression")) - pl <- pl + ggplot2::geom_point(data = subDT, aes(x = LR_expr_spat, y = LR_cell_comb, colour ="spatial cell expression")) - pl <- pl + ggplot2::scale_colour_manual(name="expression source",values=colors) - pl <- pl + ggplot2::facet_wrap(~LR_comb, scales = facet_scales) - pl <- pl + ggplot2::labs(x = 'gene-gene', y = 'interactions') - } - } - - # print, return and save parameters - show_plot = ifelse(is.na(show_plot), readGiottoInstructions(gobject, param = 'show_plot'), show_plot) - save_plot = ifelse(is.na(save_plot), readGiottoInstructions(gobject, param = 'save_plot'), save_plot) - return_plot = ifelse(is.na(return_plot), readGiottoInstructions(gobject, param = 'return_plot'), return_plot) - - ## print plot - if(show_plot == TRUE) { - print(pl) - } - - ## save plot - if(save_plot == TRUE) { - do.call('all_plots_save_function', c(list(gobject = gobject, plot_object = pl, default_save_name = default_save_name), save_param)) - } - - ## return plot - if(return_plot == TRUE) { - return(pl) - } - -} - - - -#' @title plotCombineCCcom -#' @name plotCombineCCcom -#' @description Create visualization for combined (pairwise) cell proximity gene scores -#' @inheritParams data_access_params -#' @inheritParams plot_output_params -#' @param combCCcom combined communcation scores, output from combCCcom() -#' @param selected_LR selected ligand-receptor pair -#' @param selected_cell_LR selected cell-cell interaction pair for ligand-receptor pair -#' @param detail_plot show detailed info in both interacting cell types -#' @param simple_plot show a simplified plot -#' @param simple_plot_facet facet on interactions or genes with simple plot -#' @param facet_scales ggplot facet scales paramter -#' @param facet_ncol ggplot facet ncol parameter -#' @param facet_nrow ggplot facet nrow parameter -#' @param colors vector with two colors to use -#' @return ggplot -#' @export -plotCombineCCcom = function(gobject, - combCCcom, - selected_LR = NULL, - selected_cell_LR = NULL, - detail_plot = T, - simple_plot = F, - simple_plot_facet = c('interaction', 'genes'), - facet_scales = 'fixed', - facet_ncol = length(selected_LR), - facet_nrow = length(selected_cell_LR), - colors = c('#9932CC', '#FF8C00'), - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = 'plotCombineCCcom') { - - - plotCombineCellCellCommunication(gobject = gobject, - combCCcom = combCCcom, - selected_LR = selected_LR, - selected_cell_LR = selected_cell_LR, - detail_plot = detail_plot, - simple_plot = simple_plot, - simple_plot_facet = simple_plot_facet, - facet_scales = facet_scales, - facet_ncol = facet_ncol, - facet_nrow = facet_nrow, - colors = colors, - show_plot = show_plot, - return_plot = return_plot, - save_plot = save_plot, - save_param = save_param, - default_save_name = default_save_name) - -} - - - -#' @title plotCCcomHeatmap -#' @name plotCCcomHeatmap -#' @description Plots heatmap for ligand-receptor communication scores in cell-cell interactions -#' @inheritParams data_access_params -#' @inheritParams plot_output_params -#' @inheritParams plot_params -#' @param comScores communinication scores from \code{\link{exprCellCellcom}} or \code{\link{spatCellCellcom}} -#' @param selected_LR selected ligand-receptor combinations -#' @param selected_cell_LR selected cell-cell combinations for ligand-receptor combinations -#' @param show_LR_names show ligand-receptor names -#' @param show_cell_LR_names show cell-cell names -#' @param show values to show on heatmap -#' @param cor_method correlation method used for clustering -#' @param aggl_method agglomeration method used by hclust -#' @return ggplot -#' @export -plotCCcomHeatmap = function(gobject, - comScores, - selected_LR = NULL, - selected_cell_LR = NULL, - show_LR_names = TRUE, - show_cell_LR_names = TRUE, - show = c('PI', 'LR_expr', 'log2fc'), - cor_method = c("pearson", "kendall", "spearman"), - aggl_method = c("ward.D", "ward.D2", "single", "complete", "average", "mcquitty", "median", "centroid"), - gradient_color = NULL, - gradient_style = c('divergent', 'sequential'), - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = 'plotCCcomHeatmap') { - - - # get parameters - cor_method = match.arg(cor_method, choices = c("pearson", "kendall", "spearman")) - aggl_method = match.arg(aggl_method, choices = c("ward.D", "ward.D2", "single", "complete", - "average", "mcquitty", "median", "centroid")) - - - # data.table variables - LR_comb = LR_cell_comb = NULL - - # plot method - if(!is.null(selected_LR) & !is.null(selected_cell_LR)) { - selDT = comScores[LR_comb %in% selected_LR & LR_cell_comb %in% selected_cell_LR] - } else if(!is.null(selected_LR)) { - selDT = comScores[LR_comb %in% selected_LR] - } else if(!is.null(selected_cell_LR)) { - selDT = comScores[LR_cell_comb %in% selected_cell_LR] - } else { - selDT = comScores - } - - # creat matrix - show = match.arg(show, choices = c('PI', 'LR_expr', 'log2fc')) - selDT_d = data.table::dcast.data.table(selDT, LR_cell_comb~LR_comb, value.var = show, fill = 0) - selDT_m = dt_to_matrix(selDT_d) - - ## cells - corclus_cells_dist = stats::as.dist(1-cor_flex(x = t_flex(selDT_m), method = cor_method)) - hclusters_cells = stats::hclust(d = corclus_cells_dist, method = aggl_method) - clus_names = rownames(selDT_m) - names(clus_names) = 1:length(clus_names) - clus_sort_names = clus_names[hclusters_cells$order] - selDT[, LR_cell_comb := factor(LR_cell_comb, clus_sort_names)] - - ## genes - corclus_genes_dist = stats::as.dist(1-cor_flex(x = selDT_m, method = cor_method)) - hclusters_genes = stats::hclust(d = corclus_genes_dist, method = aggl_method) - clus_names = colnames(selDT_m) - names(clus_names) = 1:length(clus_names) - clus_sort_names = clus_names[hclusters_genes$order] - selDT[, LR_comb := factor(LR_comb, clus_sort_names)] - - - - pl = ggplot2::ggplot() - pl = pl + ggplot2::geom_raster(data = selDT, aes_string(x = 'LR_cell_comb', - y = 'LR_comb', fill = show)) - - pl = pl + ggplot2::theme_classic() + ggplot2::theme(axis.text.x = element_blank(), - axis.ticks = element_blank(), - axis.text.y = element_blank()) - if(show_LR_names == TRUE) pl <- pl + ggplot2::theme(axis.text.y = element_text(), - axis.ticks.y = element_line()) - if(show_cell_LR_names == TRUE) pl <- pl + ggplot2::theme(axis.text.x = element_text(angle = 90, vjust = 1, hjust = 1), - axis.ticks.x = element_line()) - pl = pl + set_default_color_continuous_CCcom_heatmap( - colors = gradient_color, - instrs = instructions(gobject), - style = gradient_style - ) - pl = pl + ggplot2::labs(x = 'cell-cell', y = 'ligand-receptor') - - return(plot_output_handler( - gobject = gobject, - plot_object = pl, - save_plot = save_plot, - return_plot = return_plot, - show_plot = show_plot, - default_save_name = default_save_name, - save_param = save_param, - else_return = NULL - )) - -} - - - -#' @title plotCCcomDotplot -#' @name plotCCcomDotplot -#' @description Plots dotplot for ligand-receptor communication scores in cell-cell interactions -#' @inheritParams data_access_params -#' @inheritParams plot_output_params -#' @inheritParams plot_params -#' @param comScores communication scores from \code{\link{exprCellCellcom}} or \code{\link{spatCellCellcom}} -#' @param selected_LR selected ligand-receptor combinations -#' @param selected_cell_LR selected cell-cell combinations for ligand-receptor combinations -#' @param show_LR_names show ligand-receptor names -#' @param show_cell_LR_names show cell-cell names -#' @param cluster_on values to use for clustering of cell-cell and ligand-receptor pairs -#' @param cor_method correlation method used for clustering -#' @param aggl_method agglomeration method used by hclust -#' @param dot_color_gradient character. continuous colors to use. palette to -#' use or vector of colors to use (minimum of 2). -#' @return ggplot -#' @export -plotCCcomDotplot = function(gobject, - comScores, - selected_LR = NULL, - selected_cell_LR = NULL, - show_LR_names = TRUE, - show_cell_LR_names = TRUE, - cluster_on = c('PI', 'LR_expr', 'log2fc'), - cor_method = c("pearson", "kendall", "spearman"), - aggl_method = c("ward.D", "ward.D2", "single", "complete", "average", "mcquitty", "median", "centroid"), - dot_color_gradient = NULL, - gradient_style = c('divergent', 'sequential'), - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = 'plotCCcomDotplot') { - - # get parameters - cor_method = match.arg(cor_method, choices = c("pearson", "kendall", "spearman")) - aggl_method = match.arg(aggl_method, choices = c("ward.D", "ward.D2", "single", "complete", - "average", "mcquitty", "median", "centroid")) - - - # data.table variables - LR_comb = LR_cell_comb = sd = NULL - - # plot method - if(!is.null(selected_LR) & !is.null(selected_cell_LR)) { - selDT = comScores[LR_comb %in% selected_LR & LR_cell_comb %in% selected_cell_LR] - } else if(!is.null(selected_LR)) { - selDT = comScores[LR_comb %in% selected_LR] - } else if(!is.null(selected_cell_LR)) { - selDT = comScores[LR_cell_comb %in% selected_cell_LR] - } else { - selDT = comScores - } - - # creat matrix - cluster_on = match.arg(cluster_on, choices = c('PI', 'LR_expr', 'log2fc')) - selDT_d = data.table::dcast.data.table(selDT, LR_cell_comb~LR_comb, value.var = cluster_on, fill = 0) - selDT_m = dt_to_matrix(selDT_d) - - # remove zero variance - sd_rows = apply(selDT_m, 1, sd) - sd_rows_zero = names(sd_rows[sd_rows == 0]) - if(length(sd_rows_zero) > 0) selDT_m = selDT_m[!rownames(selDT_m) %in% sd_rows_zero, ] - - sd_cols = apply(selDT_m, 2, sd) - sd_cols_zero = names(sd_cols[sd_cols == 0]) - if(length(sd_cols_zero) > 0) selDT_m = selDT_m[, !colnames(selDT_m) %in% sd_cols_zero] - - - - ## cells - corclus_cells_dist = stats::as.dist(1-cor_flex(x = t_flex(selDT_m), method = cor_method)) - hclusters_cells = stats::hclust(d = corclus_cells_dist, method = aggl_method) - clus_names = rownames(selDT_m) - names(clus_names) = 1:length(clus_names) - clus_sort_names = clus_names[hclusters_cells$order] - selDT[, LR_cell_comb := factor(LR_cell_comb, clus_sort_names)] - - ## genes - corclus_genes_dist = stats::as.dist(1-cor_flex(x = selDT_m, method = cor_method)) - hclusters_genes = stats::hclust(d = corclus_genes_dist, method = aggl_method) - clus_names = colnames(selDT_m) - names(clus_names) = 1:length(clus_names) - clus_sort_names = clus_names[hclusters_genes$order] - selDT[, LR_comb := factor(LR_comb, clus_sort_names)] - - - - pl = ggplot2::ggplot() - pl = pl + ggplot2::geom_point(data = selDT, aes_string(x = 'LR_cell_comb', - y = 'LR_comb', size = 'pvalue', color = 'log2fc')) - pl = pl + ggplot2::theme_classic() - if(show_LR_names == TRUE) pl = pl + ggplot2::theme(axis.text.y = element_text(), - axis.ticks.y = element_line()) - if(show_cell_LR_names == TRUE) pl = pl + ggplot2::theme(axis.text.x = element_text(angle = 90, vjust = 1, hjust = 1), - axis.ticks.x = element_line()) - pl = pl + set_default_color_continuous_CCcom_dotplot( - colors = dot_color_gradient, - instrs = instructions(gobject), - midpoint = NULL, - style = gradient_style, - type = 'fill' - ) - pl = pl + ggplot2::scale_size_continuous(range = c(5, 0.5)) + - set_default_color_continuous_CCcom_dotplot( - colors = dot_color_gradient, - instrs = instructions(gobject), - midpoint = NULL, - style = gradient_style, - type = 'color' - ) - pl = pl + ggplot2::labs(x = 'cell-cell', y = 'ligand-receptor') - - # print, return and save parameters - show_plot = ifelse(is.na(show_plot), readGiottoInstructions(gobject, param = 'show_plot'), show_plot) - save_plot = ifelse(is.na(save_plot), readGiottoInstructions(gobject, param = 'save_plot'), save_plot) - return_plot = ifelse(is.na(return_plot), readGiottoInstructions(gobject, param = 'return_plot'), return_plot) - - ## print plot - if(show_plot == TRUE) { - print(pl) - } - - ## save plot - if(save_plot == TRUE) { - do.call('all_plots_save_function', c(list(gobject = gobject, plot_object = pl, default_save_name = default_save_name), save_param)) - } - - ## return plot - if(return_plot == TRUE) { - return(pl) - } - -} - - - -#' @title plotRankSpatvsExpr -#' @name plotRankSpatvsExpr -#' @description Plots dotplot to compare ligand-receptor rankings from spatial and expression information -#' @inheritParams data_access_params -#' @inheritParams plot_output_params -#' @param combCC combined communication scores from \code{\link{combCCcom}} -#' @param expr_rnk_column column with expression rank information to use -#' @param spat_rnk_column column with spatial rank information to use -#' @param gradient_midpoint numeric. default = 10. midpoint of colors -#' @param dot_color_gradient character. continuous colors to use. palette to -#' use or vector of colors to use (minimum of 2). -#' @param gradient_style either 'divergent' (midpoint is used in color scaling) -#' or 'sequential' (scaled based on data range) -#' @param midpoint deprecated -#' @param size_range size ranges of dotplot -#' @param xlims x-limits, numerical vector of 2 -#' @param ylims y-limits, numerical vector of 2 -#' @param selected_ranks numerical vector, will be used to print out the percentage of top spatial ranks are recovered -#' @return ggplot -#' @export -plotRankSpatvsExpr = function(gobject, - combCC, - expr_rnk_column = 'LR_expr_rnk', - spat_rnk_column = 'LR_spat_rnk', - dot_color_gradient = NULL, - midpoint = deprecated(), - gradient_midpoint = 10, - gradient_style = c('divergent', 'sequential'), - size_range = c(0.01, 1.5), - xlims = NULL, - ylims = NULL, - selected_ranks = c(1, 10, 20), - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = 'plotRankSpatvsExpr') { - - # deprecate - if (GiottoUtils::is_present(midpoint)) { - deprecate_warn('0.0.0.9000', - 'GiottoVisuals::plotRankSpatvsExpr(midpoint = )', - 'GiottoVisuals::plotRankSpatvsExpr(gradient_midpoint = )') - gradient_midpoint <- midpoint - } - - - # data.table variables - spt_rank = variable = value = NULL - - total_rnks = max(unique(combCC[[expr_rnk_column]])) - - rnk_list = list() - spt_list = list() - for(rnk in 1:total_rnks) { - - mytab = table(cut(sort(combCC[get(expr_rnk_column) == rnk][[spat_rnk_column]]), breaks = seq(0,total_rnks,1), labels = c(1:total_rnks))) - rnk_list[[rnk]] = mytab - spt_list[[rnk]] = names(mytab) - } - - rnk_res = data.table::as.data.table(do.call('rbind', rnk_list)) - rnk_res[, spt_rank := 1:total_rnks] - - rnk_res_m = data.table::melt.data.table(rnk_res, id.vars = 'spt_rank') - rnk_res_m[, spt_rank := as.numeric(spt_rank)] - rnk_res_m[, variable := as.numeric(variable)] - - rnk_res_m[, diff := variable - spt_rank] - - for(i in selected_ranks) { - perc_recovered = 100*(sum(rnk_res_m[abs(diff) < i]$value)/sum(rnk_res_m$value)) - cat('for top ', i, ' expression ranks, you recover ', round(perc_recovered, 2), '% of the highest spatial rank \n') - } - - - # full plot - pl = ggplot2::ggplot() - pl = pl + ggplot2::theme_classic() + ggplot2::theme(axis.text = element_blank()) - pl = pl + ggplot2::geom_point(data = rnk_res_m, ggplot2::aes(x = variable, y = spt_rank, size = value, color = value)) - pl = pl + set_default_color_continuous_CCcom_dotplot( - colors = dot_color_gradient, - instrs = instructions(gobject), - midpoint = gradient_midpoint, - style = gradient_style, - type = 'color', - type_default = list( - pal = c('blue', 'yellow', 'red') - ), - guide = guide_legend(title = '') - ) - pl = pl + ggplot2::scale_size_continuous(range = size_range, guide = "none") - pl = pl + ggplot2::labs(x = 'expression rank', y = 'spatial rank') - - if(!is.null(xlims)) { - pl = pl + xlim(xlims) - } - - if(!is.null(ylims)) { - pl = pl + ylim(ylims) - } - - return(plot_output_handler( - gobject = gobject, - plot_object = pl, - save_plot = save_plot, - return_plot = return_plot, - show_plot = show_plot, - default_save_name = default_save_name, - save_param = save_param, - else_return = NULL - )) - -} - - - - -#' @title plotRecovery_sub -#' @name plotRecovery_sub -#' @description Plots recovery plot to compare ligand-receptor rankings from spatial and expression information -#' @param combCC combined communinication scores from \code{\link{combCCcom}} -#' @param first_col first column to use -#' @param second_col second column to use -#' @keywords internal -plotRecovery_sub = function(combCC, - first_col = 'LR_expr_rnk', - second_col = 'LR_spat_rnk') { - - - # data.table variables - concord = perc = not_concord = secondrank = secondrank_perc = NULL - - mergeDT_filt = combCC[get(first_col) == 1] - - mymat = matrix(data = NA, nrow = max(combCC[[second_col]]), ncol = 2) - for(i in 1:max(combCC[[second_col]])) { - - mergeDT_filt[, concord := ifelse(get(second_col) <= i, 'yes', 'no')] - mytable = table(mergeDT_filt$concord) - - matching = mytable['yes'] - if(is.na(matching)) matching = 0 - mymat[i, 1] = matching - - non_matching = mytable['no'] - if(is.na(non_matching)) non_matching = 0 - mymat[i, 2] = non_matching - - } - - mymatDT = data.table::as.data.table(mymat); colnames(mymatDT) = c('concord', 'not_concord') - mymatDT[, perc := 100*(concord / (concord+not_concord))] - mymatDT[, secondrank := 1:nrow(mymatDT)] - mymatDT[, secondrank_perc := (secondrank/max(secondrank))*100] - - # percentage explained - perc_explained = mymatDT[, sum(perc)]/(100*nrow(mymat)) - cat('percentage explained = ', perc_explained) - - - pl = ggplot2::ggplot() - pl = pl + ggplot2::theme_classic() - pl = pl + ggplot2::geom_point(data = mymatDT, aes(x = secondrank_perc, y = perc)) - pl = pl + ggplot2::scale_x_continuous(expand = c(0,0), limits = c(0,100)) - pl = pl + ggplot2::scale_y_continuous(expand = c(0,0), limits = c(0, 100)) - pl = pl + ggplot2::geom_abline(slope = 1, intercept = 0, color = 'blue') - - return(pl) - -} - - - - - -#' @title plotRecovery -#' @name plotRecovery -#' @description Plots recovery plot to compare ligand-receptor rankings from spatial and expression information -#' @inheritParams data_access_params -#' @inheritParams plot_output_params -#' @param combCC combined communication scores from \code{\link{combCCcom}} -#' @param expr_rnk_column column with expression rank information to use -#' @param spat_rnk_column column with spatial rank information to use -#' @param ground_truth what to consider as ground truth (default: spatial) -#' @return ggplot -#' @export -plotRecovery = function(gobject, - combCC, - expr_rnk_column = 'exprPI_rnk', - spat_rnk_column = 'spatPI_rnk', - ground_truth = c('spatial', 'expression'), - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = 'plotRecovery') { - - ground_truth = match.arg(ground_truth, choices = c('spatial', 'expression')) - - - if(ground_truth == 'spatial') { - - pl = plotRecovery_sub(combCC = combCC, - first_col = spat_rnk_column, - second_col = expr_rnk_column) - pl = pl + ggplot2::labs(x = '% expression rank included', y = '% highest spatial rank recovered') - - } else if(ground_truth == 'expression') { - - pl = plotRecovery_sub(combCC = combCC, - first_col = expr_rnk_column, - second_col = spat_rnk_column) - pl = pl + ggplot2::labs(x = '% spatial rank included', y = '% highest expression rank recovered') - - } - - return(plot_output_handler( - gobject = gobject, - plot_object = pl, - save_plot = save_plot, - return_plot = return_plot, - show_plot = show_plot, - default_save_name = default_save_name, - save_param = save_param, - else_return = NULL - )) -} - - - - - - - - - -# * #### -# cell proximity spatplots #### - -#' @title cellProximitySpatPlot2D -#' @name cellProximitySpatPlot2D -#' @description Visualize 2D cell-cell interactions according to spatial coordinates in ggplot mode -#' @inheritParams data_access_params -#' @inheritParams plot_output_params -#' @inheritParams plot_cell_params -#' @inheritParams plot_spatnet_params -#' @inheritParams plot_params -#' @param spat_loc_name spatial locations to use -#' @param interaction_name cell-cell interaction name -#' @param cluster_column cluster column with cell clusters -#' @param sdimx x-axis dimension name (default = 'sdimx') -#' @param sdimy y-axis dimension name (default = 'sdimy') -#' @param show_other_cells decide if show cells not in network -#' @param show_network show spatial network of selected cells -#' @param show_other_network show spatial network of not selected cells -#' @param network_color color of spatial network -#' @param show_grid show spatial grid -#' @param grid_color color of spatial grid -#' @param spatial_grid_name name of spatial grid to use -#' @param coord_fix_ratio fix ratio between x and y-axis -#' @param point_size_select size of selected points -#' @param point_select_border_col border color of selected points -#' @param point_select_border_stroke stroke size of selected points -#' @param point_size_other size of other points -#' @param point_alpha_other opacity of other points -#' @param point_other_border_col border color of other points -#' @param point_other_border_stroke stroke size of other points -#' @return ggplot -#' @details Description of parameters. -#' @export -cellProximitySpatPlot2D <- function(gobject, - spat_unit = NULL, - feat_type = NULL, - spat_loc_name = NULL, - interaction_name = NULL, - cluster_column = NULL, - sdimx = 'sdimx', - sdimy = 'sdimy', - cell_color = NULL, - cell_color_code = NULL, - color_as_factor = T, - show_other_cells = F, - show_network = F, - show_other_network = F, - network_color = NULL, - spatial_network_name = 'Delaunay_network', - show_grid = F, - grid_color = NULL, - spatial_grid_name = 'spatial_grid', - coord_fix_ratio = 1, - show_legend = T, - point_size_select = 2, - point_select_border_col = 'black', - point_select_border_stroke = 0.05, - point_size_other = 1, - point_alpha_other = 0.3, - point_other_border_col = 'lightgrey', - point_other_border_stroke = 0.01, - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = 'cellProximitySpatPlot2D') { - if(is.null(interaction_name)) { - stop('\n you need to specific at least one interaction name, run cellProximityEnrichment \n') - } - - - # Set feat_type and spat_unit - spat_unit = set_default_spat_unit(gobject = gobject, - spat_unit = spat_unit) - feat_type = set_default_feat_type(gobject = gobject, - spat_unit = spat_unit, - feat_type = feat_type) - - # get information from all slots - cell_locations = get_spatial_locations(gobject = gobject, - spat_unit = spat_unit, - spat_loc_name = spat_loc_name, - output = 'data.table', - copy_obj = FALSE) - - spatial_grid = get_spatialGrid(gobject = gobject, - spat_unit = spat_unit, - feat_type = feat_type, - name = spatial_grid_name, - return_grid_Obj = FALSE) - - cell_metadata = get_cell_metadata(gobject, - spat_unit = spat_unit, - feat_type = feat_type, - output = 'data.table', - copy_obj = TRUE) - - spatial_network = annotateSpatialNetwork(gobject = gobject, - feat_type = feat_type, - spat_unit = spat_unit, - spatial_network_name = spatial_network_name, - cluster_column = cluster_column) - - - # data.table variables - unified_int = sdimx_begin = sdimy_begin = sdimx_end = sdimy_end = x_start = x_end = y_start = y_end = cell_ID = NULL - - cell_IDs_to_keep = unique(c(spatial_network[unified_int %in% interaction_name]$to, - spatial_network[unified_int %in% interaction_name]$from)) - - #print(cell_IDs_to_keep) - - if(show_other_cells){ - CellType <- strsplit(interaction_name,"--") - all_cell_IDs = cell_metadata[cell_metadata[[cluster_column]] == CellType[[1]][1] | - cell_metadata[[cluster_column]] == CellType[[1]][2],]$cell_ID - other_cell_IDs = setdiff(all_cell_IDs, cell_IDs_to_keep) - } - - - # annotated cell data () - if(nrow(cell_metadata) == 0) { - cell_locations_metadata = cell_locations - } else { - cell_locations_metadata = merge(cell_locations, cell_metadata, by = "cell_ID") - } - - - # first 2 dimensions need to be defined - if(is.null(sdimx) | is.null(sdimy)) { - cat('first and second dimenion need to be defined, default is first 2 \n') - sdimx = 'sdimx' - sdimy = 'sdimy' - } - - pl <- ggplot2::ggplot() - pl <- pl + ggplot2::theme_classic() - - if(!is.null(spatial_network) & show_network == TRUE) { - if(is.null(network_color)) network_color = 'red' - if(show_other_network){ - pl <- pl + ggplot2::geom_segment(data = spatial_network[!unified_int %in% interaction_name], - aes(x = sdimx_begin, y = sdimy_begin, xend = sdimx_end, yend = sdimy_end), - color = 'lightgrey', size = 0.5, alpha = 0.5) - } - pl <- pl + ggplot2::geom_segment(data = spatial_network[unified_int %in% interaction_name], - aes(x = sdimx_begin, y = sdimy_begin, xend = sdimx_end, yend = sdimy_end), - color = network_color, size = 0.5, alpha = 0.5) - } - - if(!is.null(spatial_grid) & show_grid == TRUE) { - if(is.null(grid_color)) grid_color = 'black' - pl <- pl + ggplot2::geom_rect(data = spatial_grid, aes(xmin = x_start, xmax = x_end, ymin = y_start, ymax = y_end), - color = grid_color, fill = NA) - } - - # cell color default - if(is.null(cell_color)) { - cell_color = 'lightblue' - pl <- pl + ggplot2::geom_point(data = cell_locations[!cell_ID %in% cell_IDs_to_keep], aes_string(x = sdimx, y = sdimy), - show.legend = show_legend, shape = 21, fill = 'lightgrey', size = point_size_other) - pl <- pl + ggplot2::geom_point(data = cell_locations[cell_ID %in% cell_IDs_to_keep], aes_string(x = sdimx, y = sdimy), - show.legend = show_legend, shape = 21, fill = cell_color, size = point_size_select) - if(show_other_cells){ - pl <- pl + ggplot2::geom_point(data = cell_locations[cell_ID %in% other_cell_IDs], aes_string(x = sdimx, y = sdimy), - show.legend = show_legend, shape = 21, fill = cell_color, alpha = point_alpha_other, - size = point_size_select * 0.5) - } - } - else if (is.character(cell_color)) { - if(cell_color %in% colnames(cell_locations_metadata)) { - - if(color_as_factor == TRUE) { - factor_data = factor(cell_locations_metadata[[cell_color]]) - cell_locations_metadata[[cell_color]] <- factor_data - } - - pl <- pl + ggplot2::geom_point(data = cell_locations_metadata[!cell_ID %in% cell_IDs_to_keep], aes_string(x = sdimx, y = sdimy), - fill = 'lightgrey', shape = 21, size = point_size_other, - color = point_other_border_col, stroke = point_other_border_stroke) - pl <- pl + ggplot2::geom_point(data = cell_locations_metadata[cell_ID %in% cell_IDs_to_keep], aes_string(x = sdimx, y = sdimy, fill = cell_color), - show.legend = show_legend, shape = 21, size = point_size_select, - color = point_select_border_col, stroke = point_select_border_stroke) - if(show_other_cells){ - pl <- pl + ggplot2::geom_point(data = cell_locations_metadata[cell_ID %in% other_cell_IDs], aes_string(x = sdimx, y = sdimy,fill = cell_color), - show.legend = show_legend, shape = 21, alpha = point_alpha_other, - size = point_size_select * 0.5) - } - - - - if(!is.null(cell_color_code)) { - pl <- pl + ggplot2::scale_fill_manual(values = cell_color_code) - } else if(color_as_factor == T) { - number_colors = length(unique(factor_data)) - cell_color_code = set_default_color_discrete_cell(instrs = instructions(gobject))(n = number_colors) - names(cell_color_code) = unique(factor_data) - pl <- pl + ggplot2::scale_fill_manual(values = cell_color_code) - } else if(color_as_factor == F){ - pl <- pl + set_default_color_continuous_cell( - colors = cell_color_code, - instrs = instructions(gobject), - midpoint = NULL, - style = 'sequential', - type_default = list( - pal = c('blue', 'red') - ) - ) - } - - } else { - pl <- pl + ggplot2::geom_point(data = cell_locations_metadata[!cell_ID %in% cell_IDs_to_keep], aes_string(x = sdimx, y = sdimy), - show.legend = show_legend, shape = 21, fill = 'lightgrey', size = point_size_other, - color = point_other_border_col, stroke = point_other_border_stroke) - pl <- pl + ggplot2::geom_point(data = cell_locations_metadata[cell_ID %in% cell_IDs_to_keep], aes_string(x = sdimx, y = sdimy), - show.legend = show_legend, shape = 21, fill = cell_color, size = point_size_select, - color = point_select_border_col, stroke = point_select_border_stroke) - } - - } - - pl <- pl + ggplot2::theme_bw() + ggplot2::theme(plot.title = element_text(hjust = 0.5), - legend.title = element_text(size = 10), - legend.text = element_text(size = 10)) - - # fix coord ratio - if(!is.null(coord_fix_ratio)) { - pl <- pl + ggplot2::coord_fixed(ratio = coord_fix_ratio) - } - - pl <- pl + ggplot2::labs(x = 'x coordinates', y = 'y coordinates') - - - - # print, return and save parameters - show_plot = ifelse(is.na(show_plot), readGiottoInstructions(gobject, param = 'show_plot'), show_plot) - save_plot = ifelse(is.na(save_plot), readGiottoInstructions(gobject, param = 'save_plot'), save_plot) - return_plot = ifelse(is.na(return_plot), readGiottoInstructions(gobject, param = 'return_plot'), return_plot) - - ## print plot - if(show_plot == TRUE) { - print(pl) - } - - ## save plot - if(save_plot == TRUE) { - do.call('all_plots_save_function', c(list(gobject = gobject, plot_object = pl, default_save_name = default_save_name), save_param)) - } - - ## return plot - if(return_plot == TRUE) { - return(pl) - } -} - - -#' @title cellProximitySpatPlot -#' @name cellProximitySpatPlot -#' @description Visualize 2D cell-cell interactions according to spatial coordinates in ggplot mode -#' @param gobject giotto object -#' @inheritDotParams cellProximitySpatPlot2D -gobject -#' @return ggplot -#' @details Description of parameters. -#' @export -#' @seealso \code{\link{cellProximitySpatPlot2D}} and \code{\link{cellProximitySpatPlot3D}} for 3D -cellProximitySpatPlot = function(gobject, ...) { - - cellProximitySpatPlot2D(gobject = gobject, ...) - -} - - -#' @title cellProximitySpatPlot3D -#' @name cellProximitySpatPlot3D -#' @description Visualize 3D cell-cell interactions according to spatial coordinates in plotly mode -#' @inheritParams data_access_params -#' @inheritParams plot_output_params -#' @inheritParams plot_spatnet_params -#' @inheritParams plot_cell_params -#' @inheritParams plot_params -#' @param interaction_name cell-cell interaction name -#' @param cluster_column cluster column with cell clusters -#' @param sdimx x-axis dimension name (default = 'sdimx') -#' @param sdimy y-axis dimension name (default = 'sdimy') -#' @param sdimz z-axis dimension name (default = 'sdimz') -#' @param show_other_cells decide if show cells not in network -#' @param show_network show spatial network of selected cells -#' @param show_other_network show spatial network of not selected cells -#' @param network_color color of spatial network -#' @param show_grid show spatial grid -#' @param grid_color color of spatial grid -#' @param spatial_grid_name name of spatial grid to use -#' @param point_size_select size of selected points -#' @param point_size_other size of other points -#' @param point_alpha_other opacity of other points -#' @param axis_scale scale of axis -#' @param x_ticks ticks on x-axis -#' @param y_ticks ticks on y-axis -#' @param z_ticks ticks on z-axis -#' @param custom_ratio custom ratio of axes -#' @param \dots additional parameters -#' @return plotly -#' @details Description of parameters. -#' @export -cellProximitySpatPlot3D = function(gobject, - interaction_name = NULL, - cluster_column = NULL, - sdimx = "sdimx", - sdimy = "sdimy", - sdimz = "sdimz", - cell_color = NULL, - cell_color_code = NULL, - color_as_factor = T, - show_other_cells = T, - show_network = T, - show_other_network = F, - network_color = NULL, - spatial_network_name = 'Delaunay_network', - show_grid = F, - grid_color = NULL, - spatial_grid_name = 'spatial_grid', - show_legend = T, - point_size_select = 4, - point_size_other = 2, - point_alpha_other = 0.5, - axis_scale = c("cube","real","custom"), - custom_ratio = NULL, - x_ticks = NULL, - y_ticks = NULL, - z_ticks = NULL, - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = 'cellProximitySpatPlot3D', - ...){ - if(is.null(sdimz)){ - pl = cellProximityVisPlot_2D_plotly(gobject = gobject, - interaction_name = interaction_name, - cluster_column = cluster_column, - sdimx = sdimx, - sdimy = sdimy, - cell_color = cell_color, - cell_color_code = cell_color_code, - color_as_factor = color_as_factor, - show_other_cells = show_other_cells, - show_network = show_network, - show_other_network = show_other_network, - network_color = network_color, - spatial_network_name = spatial_network_name, - show_grid = show_grid, - grid_color = grid_color, - spatial_grid_name = spatial_grid_name, - show_legend = show_legend, - point_size_select = point_size_select, - point_size_other = point_size_other, - point_alpha_other = point_alpha_other, - axis_scale = axis_scale, - custom_ratio = custom_ratio, - x_ticks = x_ticks, - y_ticks = y_ticks, - ...) - } - else{ - pl = cellProximityVisPlot_3D_plotly(gobject = gobject, - interaction_name = interaction_name, - cluster_column = cluster_column, - sdimx = sdimx, - sdimy = sdimy, - sdimz = sdimz, - cell_color = cell_color, - cell_color_code = cell_color_code, - color_as_factor = color_as_factor, - show_other_cells = show_other_cells, - show_network = show_network, - show_other_network = show_other_network, - network_color = network_color, - spatial_network_name = spatial_network_name, - show_grid = show_grid, - grid_color = grid_color, - spatial_grid_name = spatial_grid_name, - show_legend = show_legend, - point_size_select = point_size_select, - point_size_other = point_size_other, - point_alpha_other = point_alpha_other, - axis_scale = axis_scale, - custom_ratio = custom_ratio, - x_ticks = x_ticks, - y_ticks = y_ticks, - z_ticks = z_ticks, - ...) - } - # print, return and save parameters - show_plot = ifelse(is.na(show_plot), readGiottoInstructions(gobject, param = 'show_plot'), show_plot) - save_plot = ifelse(is.na(save_plot), readGiottoInstructions(gobject, param = 'save_plot'), save_plot) - return_plot = ifelse(is.na(return_plot), readGiottoInstructions(gobject, param = 'return_plot'), return_plot) - - ## print plot - if(show_plot == TRUE) { - print(pl) - } - - ## save plot - if(save_plot == TRUE) { - do.call('all_plots_save_function', c(list(gobject = gobject, plot_object = pl, default_save_name = default_save_name), save_param)) - } - - ## return plot - if(return_plot == TRUE) { - return(pl) - } -} diff --git a/R/viz_spatial_network.R b/R/viz_spatial_network.R index 818bd5f..fca1a94 100644 --- a/R/viz_spatial_network.R +++ b/R/viz_spatial_network.R @@ -123,7 +123,7 @@ spatNetwDistributionsKneighbors = function(gobject, stop('spatial network ', spatial_network_name, ' was not found') } - spatial_network_dt = as.data.table(spatial_network[, table(source)]) + spatial_network_dt = data.table::as.data.table(spatial_network[, table(source)]) pl = ggplot2::ggplot() pl = pl + ggplot2::labs(title = 'k-neighbor distribution for all cells', x = 'k-neighbors/cell') diff --git a/man/addGiottoImageToSpatPlot.Rd b/man/addGiottoImageToSpatPlot.Rd new file mode 100644 index 0000000..5e91641 --- /dev/null +++ b/man/addGiottoImageToSpatPlot.Rd @@ -0,0 +1,30 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/gg_info_layers.R +\name{addGiottoImageToSpatPlot} +\alias{addGiottoImageToSpatPlot} +\title{addGiottoImageToSpatPlot} +\usage{ +addGiottoImageToSpatPlot( + spatpl = NULL, + gimage = NULL, + layer = c("bg", "overlay"), + alpha = NULL +) +} +\arguments{ +\item{spatpl}{a spatial ggplot object} + +\item{gimage}{a giotto image, see \code{\link{createGiottoImage}}} + +\item{layer}{numeric layer on which to add the giotto image. OR takes 'bg' or +'overlay' as input to designate last (bottom/background) or first (top/overlay)} + +\item{alpha}{(optional) add giotto image to plot with transparency. Numeric. From 0 +(transparent) to 1 (fully visible)} +} +\value{ +an updated spatial ggplot object +} +\description{ +Add a giotto image to a spatial ggplot object post creation +} diff --git a/man/cellProximityBarplot.Rd b/man/cellProximityBarplot.Rd deleted file mode 100644 index 7abd4bf..0000000 --- a/man/cellProximityBarplot.Rd +++ /dev/null @@ -1,50 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/vis_spatial_interaction.R -\name{cellProximityBarplot} -\alias{cellProximityBarplot} -\title{cellProximityBarplot} -\usage{ -cellProximityBarplot( - gobject, - CPscore, - min_orig_ints = 5, - min_sim_ints = 5, - p_val = 0.05, - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = "cellProximityBarplot" -) -} -\arguments{ -\item{gobject}{giotto object} - -\item{CPscore}{CPscore, output from cellProximityEnrichment()} - -\item{min_orig_ints}{filter on minimum original cell-cell interactions} - -\item{min_sim_ints}{filter on minimum simulated cell-cell interactions} - -\item{p_val}{p-value} - -\item{show_plot}{logical. show plot} - -\item{return_plot}{logical. return ggplot object} - -\item{save_plot}{logical. save the plot} - -\item{save_param}{list of saving parameters, see \code{\link{showSaveParameters}}} - -\item{default_save_name}{default save name for saving, don't change, change save_name in save_param} -} -\value{ -ggplot barplot -} -\description{ -Create barplot from cell-cell proximity scores -} -\details{ -This function creates a barplot that shows the spatial proximity -enrichment or depletion of cell type pairs. -} diff --git a/man/cellProximityHeatmap.Rd b/man/cellProximityHeatmap.Rd deleted file mode 100644 index db0181e..0000000 --- a/man/cellProximityHeatmap.Rd +++ /dev/null @@ -1,53 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/vis_spatial_interaction.R -\name{cellProximityHeatmap} -\alias{cellProximityHeatmap} -\title{cellProximityHeatmap} -\usage{ -cellProximityHeatmap( - gobject, - CPscore, - scale = T, - order_cell_types = T, - color_breaks = NULL, - color_names = NULL, - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = "cellProximityHeatmap" -) -} -\arguments{ -\item{gobject}{giotto object} - -\item{CPscore}{CPscore, output from cellProximityEnrichment()} - -\item{scale}{scale cell-cell proximity interaction scores} - -\item{order_cell_types}{order cell types based on enrichment correlation} - -\item{color_breaks}{numerical vector of length 3 to represent min, mean and maximum} - -\item{color_names}{character color vector of length 3} - -\item{show_plot}{logical. show plot} - -\item{return_plot}{logical. return ggplot object} - -\item{save_plot}{logical. save the plot} - -\item{save_param}{list of saving parameters, see \code{\link{showSaveParameters}}} - -\item{default_save_name}{default save name for saving, don't change, change save_name in save_param} -} -\value{ -ggplot heatmap -} -\description{ -Create heatmap from cell-cell proximity scores -} -\details{ -This function creates a heatmap that shows the spatial proximity -enrichment or depletion of cell type pairs. -} diff --git a/man/cellProximityNetwork.Rd b/man/cellProximityNetwork.Rd deleted file mode 100644 index 88b4784..0000000 --- a/man/cellProximityNetwork.Rd +++ /dev/null @@ -1,80 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/vis_spatial_interaction.R -\name{cellProximityNetwork} -\alias{cellProximityNetwork} -\title{cellProximityNetwork} -\usage{ -cellProximityNetwork( - gobject, - CPscore, - remove_self_edges = FALSE, - self_loop_strength = 0.1, - color_depletion = "lightgreen", - color_enrichment = "red", - rescale_edge_weights = TRUE, - edge_weight_range_depletion = c(0.1, 1), - edge_weight_range_enrichment = c(1, 5), - layout = c("Fruchterman", "DrL", "Kamada-Kawai"), - only_show_enrichment_edges = F, - edge_width_range = c(0.1, 2), - node_size = 4, - node_color_code = NULL, - node_text_size = 6, - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = "cellProximityNetwork" -) -} -\arguments{ -\item{gobject}{giotto object} - -\item{CPscore}{CPscore, output from cellProximityEnrichment()} - -\item{remove_self_edges}{remove enrichment/depletion edges with itself} - -\item{self_loop_strength}{size of self-loops} - -\item{color_depletion}{color for depleted cell-cell interactions} - -\item{color_enrichment}{color for enriched cell-cell interactions} - -\item{rescale_edge_weights}{rescale edge weights (boolean)} - -\item{edge_weight_range_depletion}{numerical vector of length 2 to rescale depleted edge weights} - -\item{edge_weight_range_enrichment}{numerical vector of length 2 to rescale enriched edge weights} - -\item{layout}{layout algorithm to use to draw nodes and edges} - -\item{only_show_enrichment_edges}{show only the enriched pairwise scores} - -\item{edge_width_range}{range of edge width} - -\item{node_size}{size of nodes} - -\item{node_color_code}{color code for the nodes (e.g. cell labels)} - -\item{node_text_size}{size of node labels} - -\item{show_plot}{logical. show plot} - -\item{return_plot}{logical. return ggplot object} - -\item{save_plot}{logical. save the plot} - -\item{save_param}{list of saving parameters, see \code{\link{showSaveParameters}}} - -\item{default_save_name}{default save name for saving, don't change, change save_name in save_param} -} -\value{ -igraph plot -} -\description{ -Create network from cell-cell proximity scores -} -\details{ -This function creates a network that shows the spatial proximity -enrichment or depletion of cell type pairs. -} diff --git a/man/cellProximitySpatPlot.Rd b/man/cellProximitySpatPlot.Rd deleted file mode 100644 index 5a86659..0000000 --- a/man/cellProximitySpatPlot.Rd +++ /dev/null @@ -1,63 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/vis_spatial_interaction.R -\name{cellProximitySpatPlot} -\alias{cellProximitySpatPlot} -\title{cellProximitySpatPlot} -\usage{ -cellProximitySpatPlot(gobject, ...) -} -\arguments{ -\item{gobject}{giotto object} - -\item{...}{ - Arguments passed on to \code{\link[=cellProximitySpatPlot2D]{cellProximitySpatPlot2D}} - \describe{ - \item{\code{spat_loc_name}}{spatial locations to use} - \item{\code{interaction_name}}{cell-cell interaction name} - \item{\code{cluster_column}}{cluster column with cell clusters} - \item{\code{sdimx}}{x-axis dimension name (default = 'sdimx')} - \item{\code{sdimy}}{y-axis dimension name (default = 'sdimy')} - \item{\code{show_other_cells}}{decide if show cells not in network} - \item{\code{show_network}}{show spatial network of selected cells} - \item{\code{show_other_network}}{show spatial network of not selected cells} - \item{\code{network_color}}{color of spatial network} - \item{\code{show_grid}}{show spatial grid} - \item{\code{grid_color}}{color of spatial grid} - \item{\code{spatial_grid_name}}{name of spatial grid to use} - \item{\code{coord_fix_ratio}}{fix ratio between x and y-axis} - \item{\code{point_size_select}}{size of selected points} - \item{\code{point_select_border_col}}{border color of selected points} - \item{\code{point_select_border_stroke}}{stroke size of selected points} - \item{\code{point_size_other}}{size of other points} - \item{\code{point_alpha_other}}{opacity of other points} - \item{\code{point_other_border_col}}{border color of other points} - \item{\code{point_other_border_stroke}}{stroke size of other points} - \item{\code{spat_unit}}{spatial unit (e.g. "cell")} - \item{\code{feat_type}}{feature type (e.g. "rna", "dna", "protein")} - \item{\code{show_plot}}{logical. show plot} - \item{\code{return_plot}}{logical. return ggplot object} - \item{\code{save_plot}}{logical. save the plot} - \item{\code{save_param}}{list of saving parameters, see \code{\link{showSaveParameters}}} - \item{\code{default_save_name}}{default save name for saving, don't change, change save_name in save_param} - \item{\code{cell_color}}{character. what to color cells by (e.g. metadata col or -spatial enrichment col)} - \item{\code{color_as_factor}}{logical. convert color column to factor. discrete colors -are used when this is TRUE. continuous colors when FALSE.} - \item{\code{cell_color_code}}{character. discrete colors to use. palette to use or -named vector of colors} - \item{\code{spatial_network_name}}{name of spatial network to use} - \item{\code{show_legend}}{logical. show legend} - }} -} -\value{ -ggplot -} -\description{ -Visualize 2D cell-cell interactions according to spatial coordinates in ggplot mode -} -\details{ -Description of parameters. -} -\seealso{ -\code{\link{cellProximitySpatPlot2D}} and \code{\link{cellProximitySpatPlot3D}} for 3D -} diff --git a/man/cellProximitySpatPlot2D.Rd b/man/cellProximitySpatPlot2D.Rd deleted file mode 100644 index 5e0fdcb..0000000 --- a/man/cellProximitySpatPlot2D.Rd +++ /dev/null @@ -1,121 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/vis_spatial_interaction.R -\name{cellProximitySpatPlot2D} -\alias{cellProximitySpatPlot2D} -\title{cellProximitySpatPlot2D} -\usage{ -cellProximitySpatPlot2D( - gobject, - spat_unit = NULL, - feat_type = NULL, - spat_loc_name = NULL, - interaction_name = NULL, - cluster_column = NULL, - sdimx = "sdimx", - sdimy = "sdimy", - cell_color = NULL, - cell_color_code = NULL, - color_as_factor = T, - show_other_cells = F, - show_network = F, - show_other_network = F, - network_color = NULL, - spatial_network_name = "Delaunay_network", - show_grid = F, - grid_color = NULL, - spatial_grid_name = "spatial_grid", - coord_fix_ratio = 1, - show_legend = T, - point_size_select = 2, - point_select_border_col = "black", - point_select_border_stroke = 0.05, - point_size_other = 1, - point_alpha_other = 0.3, - point_other_border_col = "lightgrey", - point_other_border_stroke = 0.01, - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = "cellProximitySpatPlot2D" -) -} -\arguments{ -\item{gobject}{giotto object} - -\item{spat_unit}{spatial unit (e.g. "cell")} - -\item{feat_type}{feature type (e.g. "rna", "dna", "protein")} - -\item{spat_loc_name}{spatial locations to use} - -\item{interaction_name}{cell-cell interaction name} - -\item{cluster_column}{cluster column with cell clusters} - -\item{sdimx}{x-axis dimension name (default = 'sdimx')} - -\item{sdimy}{y-axis dimension name (default = 'sdimy')} - -\item{cell_color}{character. what to color cells by (e.g. metadata col or -spatial enrichment col)} - -\item{cell_color_code}{character. discrete colors to use. palette to use or -named vector of colors} - -\item{color_as_factor}{logical. convert color column to factor. discrete colors -are used when this is TRUE. continuous colors when FALSE.} - -\item{show_other_cells}{decide if show cells not in network} - -\item{show_network}{show spatial network of selected cells} - -\item{show_other_network}{show spatial network of not selected cells} - -\item{network_color}{color of spatial network} - -\item{spatial_network_name}{name of spatial network to use} - -\item{show_grid}{show spatial grid} - -\item{grid_color}{color of spatial grid} - -\item{spatial_grid_name}{name of spatial grid to use} - -\item{coord_fix_ratio}{fix ratio between x and y-axis} - -\item{show_legend}{logical. show legend} - -\item{point_size_select}{size of selected points} - -\item{point_select_border_col}{border color of selected points} - -\item{point_select_border_stroke}{stroke size of selected points} - -\item{point_size_other}{size of other points} - -\item{point_alpha_other}{opacity of other points} - -\item{point_other_border_col}{border color of other points} - -\item{point_other_border_stroke}{stroke size of other points} - -\item{show_plot}{logical. show plot} - -\item{return_plot}{logical. return ggplot object} - -\item{save_plot}{logical. save the plot} - -\item{save_param}{list of saving parameters, see \code{\link{showSaveParameters}}} - -\item{default_save_name}{default save name for saving, don't change, change save_name in save_param} -} -\value{ -ggplot -} -\description{ -Visualize 2D cell-cell interactions according to spatial coordinates in ggplot mode -} -\details{ -Description of parameters. -} diff --git a/man/cellProximitySpatPlot3D.Rd b/man/cellProximitySpatPlot3D.Rd deleted file mode 100644 index 3057342..0000000 --- a/man/cellProximitySpatPlot3D.Rd +++ /dev/null @@ -1,118 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/vis_spatial_interaction.R -\name{cellProximitySpatPlot3D} -\alias{cellProximitySpatPlot3D} -\title{cellProximitySpatPlot3D} -\usage{ -cellProximitySpatPlot3D( - gobject, - interaction_name = NULL, - cluster_column = NULL, - sdimx = "sdimx", - sdimy = "sdimy", - sdimz = "sdimz", - cell_color = NULL, - cell_color_code = NULL, - color_as_factor = T, - show_other_cells = T, - show_network = T, - show_other_network = F, - network_color = NULL, - spatial_network_name = "Delaunay_network", - show_grid = F, - grid_color = NULL, - spatial_grid_name = "spatial_grid", - show_legend = T, - point_size_select = 4, - point_size_other = 2, - point_alpha_other = 0.5, - axis_scale = c("cube", "real", "custom"), - custom_ratio = NULL, - x_ticks = NULL, - y_ticks = NULL, - z_ticks = NULL, - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = "cellProximitySpatPlot3D", - ... -) -} -\arguments{ -\item{gobject}{giotto object} - -\item{interaction_name}{cell-cell interaction name} - -\item{cluster_column}{cluster column with cell clusters} - -\item{sdimx}{x-axis dimension name (default = 'sdimx')} - -\item{sdimy}{y-axis dimension name (default = 'sdimy')} - -\item{sdimz}{z-axis dimension name (default = 'sdimz')} - -\item{cell_color}{character. what to color cells by (e.g. metadata col or -spatial enrichment col)} - -\item{cell_color_code}{character. discrete colors to use. palette to use or -named vector of colors} - -\item{color_as_factor}{logical. convert color column to factor. discrete colors -are used when this is TRUE. continuous colors when FALSE.} - -\item{show_other_cells}{decide if show cells not in network} - -\item{show_network}{show spatial network of selected cells} - -\item{show_other_network}{show spatial network of not selected cells} - -\item{network_color}{color of spatial network} - -\item{spatial_network_name}{name of spatial network to use} - -\item{show_grid}{show spatial grid} - -\item{grid_color}{color of spatial grid} - -\item{spatial_grid_name}{name of spatial grid to use} - -\item{show_legend}{logical. show legend} - -\item{point_size_select}{size of selected points} - -\item{point_size_other}{size of other points} - -\item{point_alpha_other}{opacity of other points} - -\item{axis_scale}{scale of axis} - -\item{custom_ratio}{custom ratio of axes} - -\item{x_ticks}{ticks on x-axis} - -\item{y_ticks}{ticks on y-axis} - -\item{z_ticks}{ticks on z-axis} - -\item{show_plot}{logical. show plot} - -\item{return_plot}{logical. return ggplot object} - -\item{save_plot}{logical. save the plot} - -\item{save_param}{list of saving parameters, see \code{\link{showSaveParameters}}} - -\item{default_save_name}{default save name for saving, don't change, change save_name in save_param} - -\item{\dots}{additional parameters} -} -\value{ -plotly -} -\description{ -Visualize 3D cell-cell interactions according to spatial coordinates in plotly mode -} -\details{ -Description of parameters. -} diff --git a/man/cellProximityVisPlot.Rd b/man/cellProximityVisPlot.Rd deleted file mode 100644 index fb0b484..0000000 --- a/man/cellProximityVisPlot.Rd +++ /dev/null @@ -1,118 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/vis_spatial_interaction.R -\name{cellProximityVisPlot} -\alias{cellProximityVisPlot} -\title{cellProximityVisPlot} -\usage{ -cellProximityVisPlot( - gobject, - interaction_name = NULL, - cluster_column = NULL, - sdimx = NULL, - sdimy = NULL, - sdimz = NULL, - cell_color = NULL, - cell_color_code = NULL, - color_as_factor = T, - show_other_cells = F, - show_network = F, - show_other_network = F, - network_color = NULL, - spatial_network_name = "Delaunay_network", - show_grid = F, - grid_color = NULL, - spatial_grid_name = "spatial_grid", - coord_fix_ratio = 1, - show_legend = T, - point_size_select = 2, - point_select_border_col = "black", - point_select_border_stroke = 0.05, - point_size_other = 1, - point_alpha_other = 0.3, - point_other_border_col = "lightgrey", - point_other_border_stroke = 0.01, - axis_scale = c("cube", "real", "custom"), - custom_ratio = NULL, - x_ticks = NULL, - y_ticks = NULL, - z_ticks = NULL, - plot_method = c("ggplot", "plotly"), - ... -) -} -\arguments{ -\item{gobject}{giotto object} - -\item{interaction_name}{cell-cell interaction name} - -\item{cluster_column}{cluster column with cell clusters} - -\item{sdimx}{x-axis dimension name (default = 'sdimx')} - -\item{sdimy}{y-axis dimension name (default = 'sdimy')} - -\item{sdimz}{z-axis dimension name (default = 'sdimz')} - -\item{cell_color}{color for cells (see details)} - -\item{cell_color_code}{named vector with colors} - -\item{color_as_factor}{convert color column to factor} - -\item{show_other_cells}{show not selected cells} - -\item{show_network}{show underlying spatial network} - -\item{show_other_network}{show underlying spatial network of other cells} - -\item{network_color}{color of spatial network} - -\item{spatial_network_name}{name of spatial network to use} - -\item{show_grid}{show spatial grid} - -\item{grid_color}{color of spatial grid} - -\item{spatial_grid_name}{name of spatial grid to use} - -\item{coord_fix_ratio}{fix ratio between x and y-axis} - -\item{show_legend}{show legend} - -\item{point_size_select}{size of selected points} - -\item{point_select_border_col}{border color of selected points} - -\item{point_select_border_stroke}{stroke size of selected points} - -\item{point_size_other}{size of other points} - -\item{point_alpha_other}{alpha of other points} - -\item{point_other_border_col}{border color of other points} - -\item{point_other_border_stroke}{stroke size of other points} - -\item{axis_scale}{scale of axis} - -\item{custom_ratio}{custom ratio of scales} - -\item{x_ticks}{x ticks} - -\item{y_ticks}{y ticks} - -\item{z_ticks}{z ticks} - -\item{plot_method}{method to plot} - -\item{\dots}{additional parameters} -} -\value{ -ggplot or plotly -} -\description{ -Visualize cell-cell interactions according to spatial coordinates -} -\details{ -Description of parameters. -} diff --git a/man/cellProximityVisPlot_2D_ggplot.Rd b/man/cellProximityVisPlot_2D_ggplot.Rd deleted file mode 100644 index d666188..0000000 --- a/man/cellProximityVisPlot_2D_ggplot.Rd +++ /dev/null @@ -1,45 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/vis_spatial_interaction.R -\name{cellProximityVisPlot_2D_ggplot} -\alias{cellProximityVisPlot_2D_ggplot} -\title{cellProximityVisPlot_2D_ggplot} -\usage{ -cellProximityVisPlot_2D_ggplot( - gobject, - interaction_name = NULL, - cluster_column = NULL, - sdimx = NULL, - sdimy = NULL, - cell_color = NULL, - cell_color_code = NULL, - color_as_factor = TRUE, - show_other_cells = FALSE, - show_network = FALSE, - show_other_network = FALSE, - network_color = NULL, - spatial_network_name = "Delaunay_network", - show_grid = FALSE, - grid_color = NULL, - spatial_grid_name = "spatial_grid", - coord_fix_ratio = 1, - show_legend = TRUE, - point_size_select = 2, - point_select_border_col = "black", - point_select_border_stroke = 0.05, - point_size_other = 1, - point_alpha_other = 0.3, - point_other_border_col = "lightgrey", - point_other_border_stroke = 0.01, - ... -) -} -\value{ -ggplot -} -\description{ -Visualize 2D cell-cell interactions according to spatial coordinates in ggplot mode -} -\details{ -Description of parameters. -} -\keyword{internal} diff --git a/man/cellProximityVisPlot_2D_plotly.Rd b/man/cellProximityVisPlot_2D_plotly.Rd deleted file mode 100644 index 10e5394..0000000 --- a/man/cellProximityVisPlot_2D_plotly.Rd +++ /dev/null @@ -1,38 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/vis_spatial_interaction.R -\name{cellProximityVisPlot_2D_plotly} -\alias{cellProximityVisPlot_2D_plotly} -\title{cellProximityVisPlot_2D_plotly} -\usage{ -cellProximityVisPlot_2D_plotly( - gobject, - interaction_name = NULL, - cluster_column = NULL, - sdimx = NULL, - sdimy = NULL, - cell_color = NULL, - cell_color_code = NULL, - color_as_factor = T, - show_other_cells = F, - show_network = F, - show_other_network = F, - network_color = NULL, - spatial_network_name = "Delaunay_network", - show_grid = F, - grid_color = NULL, - spatial_grid_name = "spatial_grid", - show_legend = T, - point_size_select = 2, - point_size_other = 1, - point_alpha_other = 0.3, - axis_scale = c("cube", "real", "custom"), - custom_ratio = NULL, - x_ticks = NULL, - y_ticks = NULL, - ... -) -} -\description{ -Visualize 2D cell-cell interactions according to spatial coordinates in plotly mode -} -\keyword{internal} diff --git a/man/cellProximityVisPlot_3D_plotly.Rd b/man/cellProximityVisPlot_3D_plotly.Rd deleted file mode 100644 index 8130f7e..0000000 --- a/man/cellProximityVisPlot_3D_plotly.Rd +++ /dev/null @@ -1,40 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/vis_spatial_interaction.R -\name{cellProximityVisPlot_3D_plotly} -\alias{cellProximityVisPlot_3D_plotly} -\title{cellProximityVisPlot_3D_plotly} -\usage{ -cellProximityVisPlot_3D_plotly( - gobject, - interaction_name = NULL, - cluster_column = NULL, - sdimx = NULL, - sdimy = NULL, - sdimz = NULL, - cell_color = NULL, - cell_color_code = NULL, - color_as_factor = T, - show_other_cells = F, - show_network = F, - show_other_network = F, - network_color = NULL, - spatial_network_name = "Delaunay_network", - show_grid = F, - grid_color = NULL, - spatial_grid_name = "spatial_grid", - show_legend = T, - point_size_select = 2, - point_size_other = 1, - point_alpha_other = 0.5, - axis_scale = c("cube", "real", "custom"), - custom_ratio = NULL, - x_ticks = NULL, - y_ticks = NULL, - z_ticks = NULL, - ... -) -} -\description{ -Visualize 3D cell-cell interactions according to spatial coordinates in plotly mode -} -\keyword{internal} diff --git a/man/create_jackstrawplot.Rd b/man/create_jackstrawplot.Rd deleted file mode 100644 index c6eff45..0000000 --- a/man/create_jackstrawplot.Rd +++ /dev/null @@ -1,29 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/vis_pc.R -\name{create_jackstrawplot} -\alias{create_jackstrawplot} -\title{create_jackstrawplot} -\usage{ -create_jackstrawplot( - jackstraw_data, - ncp = 20, - ylim = c(0, 1), - threshold = 0.01 -) -} -\arguments{ -\item{jackstraw_data}{result from jackstraw function (\code{testresult$p})} - -\item{ncp}{number of principal components to calculate} - -\item{ylim}{y-axis limits on jackstraw plot} - -\item{threshold}{p.value threshold to call a PC significant} -} -\value{ -ggplot -} -\description{ -create jackstrawplot with ggplot -} -\keyword{internal} diff --git a/man/create_screeplot.Rd b/man/create_screeplot.Rd deleted file mode 100644 index 57b20e3..0000000 --- a/man/create_screeplot.Rd +++ /dev/null @@ -1,28 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/vis_pc.R -\name{create_screeplot} -\alias{create_screeplot} -\title{create_screeplot} -\usage{ -create_screeplot(eigs, ncp = 20, ylim = c(0, 20)) -} -\arguments{ -\item{eigs}{numeric. Vector of pca eigenvalues} - -\item{ncp}{numeric. max number of principal components to plot} - -\item{ylim}{numeric. y-axis limits on scree plot} -} -\value{ -ggplot -} -\description{ -create screeplot with ggplot -} -\examples{ -\dontrun{ -dr = GiottoData::loadSubObjectMini('dimObj') -scree = create_screeplot(methods::slot(dr, 'misc')$eigenvalues) -scree -} -} diff --git a/man/filterInteractionChangedFeats.Rd b/man/filterInteractionChangedFeats.Rd deleted file mode 100644 index ec4377f..0000000 --- a/man/filterInteractionChangedFeats.Rd +++ /dev/null @@ -1,50 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/vis_spatial_interaction.R -\name{filterInteractionChangedFeats} -\alias{filterInteractionChangedFeats} -\title{filterInteractionChangedFeats} -\usage{ -filterInteractionChangedFeats( - icfObject, - min_cells = 4, - min_cells_expr = 1, - min_int_cells = 4, - min_int_cells_expr = 1, - min_fdr = 0.1, - min_spat_diff = 0.2, - min_log2_fc = 0.2, - min_zscore = 2, - zscores_column = c("cell_type", "feats"), - direction = c("both", "up", "down") -) -} -\arguments{ -\item{icfObject}{ICF (interaction changed feature) score object} - -\item{min_cells}{minimum number of source cell type} - -\item{min_cells_expr}{minimum expression level for source cell type} - -\item{min_int_cells}{minimum number of interacting neighbor cell type} - -\item{min_int_cells_expr}{minimum expression level for interacting neighbor cell type} - -\item{min_fdr}{minimum adjusted p-value} - -\item{min_spat_diff}{minimum absolute spatial expression difference} - -\item{min_log2_fc}{minimum log2 fold-change} - -\item{min_zscore}{minimum z-score change} - -\item{zscores_column}{calculate z-scores over cell types or genes} - -\item{direction}{differential expression directions to keep} -} -\value{ -icfObject that contains the filtered differential feature scores -} -\description{ -Filter Interaction Changed Feature scores. -} -\keyword{internal} diff --git a/man/get_continuous_colors.Rd b/man/get_continuous_colors.Rd new file mode 100644 index 0000000..0acd96e --- /dev/null +++ b/man/get_continuous_colors.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/color_palettes.R +\name{get_continuous_colors} +\alias{get_continuous_colors} +\title{Generate a continuous set of colors} +\usage{ +get_continuous_colors(col, n, strategy) +} +\arguments{ +\item{col}{character vector. colors to make continuous} + +\item{n}{integer. number of colors to get} + +\item{strategy}{one of 'cutoff', 'recycle', or 'interpolate'. +strategy to use when more colors are requested than exist} +} +\description{ +Based on a vector of colors provided to \code{col}, make these colors continuous +(i.e. make it possible for an arbitrary \code{n} number of colors to be requested) +then return those \code{n} colors.\cr +\code{strategy} describes how to make these colors continuous: +\itemize{ +\item \strong{'interpolate'} interpolates provided colors using \code{\link[grDevices:colorRamp]{grDevices::colorRampPalette()}} +\item \strong{'recycle'} - recycles the input color vector across the \code{n} requested. +\item \strong{'cutoff'} - supply only a maximum of as many colors as exist within the +originally supplied vector. +} +} diff --git a/man/hvf_visualizations.Rd b/man/hvf_visualizations.Rd deleted file mode 100644 index deedff1..0000000 --- a/man/hvf_visualizations.Rd +++ /dev/null @@ -1,19 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/vis_hvf.R -\name{hvf_visualizations} -\alias{hvf_visualizations} -\alias{create_cov_group_HVF_plot} -\alias{create_cov_loess_HVF_plot} -\alias{create_calc_var_HVF_plot} -\title{Highly Variable Feature plots} -\usage{ -create_cov_group_HVF_plot(feat_in_cells_detected, nr_expression_groups) - -create_cov_loess_HVF_plot(feat_in_cells_detected, difference_in_cov, var_col) - -create_calc_var_HVF_plot(dt_res) -} -\description{ -Create plots that report the highly variable features detected -} -\keyword{internal} diff --git a/man/pal_names.Rd b/man/pal_names.Rd new file mode 100644 index 0000000..6af0874 --- /dev/null +++ b/man/pal_names.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/color_palettes.R +\docType{data} +\name{pal_names} +\alias{pal_names} +\title{Color palette names} +\format{ +An object of class \code{list} of length 11. +} +\usage{ +pal_names +} +\description{ +Known color palettes info provided as named list of character vectors. +List names correspond to the name of the palette package. The character vectors +list the palettes that are available within. These palettes can be passed to +the default color setting functions +} +\keyword{datasets} diff --git a/man/plotCCcomDotplot.Rd b/man/plotCCcomDotplot.Rd deleted file mode 100644 index 7e0b052..0000000 --- a/man/plotCCcomDotplot.Rd +++ /dev/null @@ -1,67 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/vis_spatial_interaction.R -\name{plotCCcomDotplot} -\alias{plotCCcomDotplot} -\title{plotCCcomDotplot} -\usage{ -plotCCcomDotplot( - gobject, - comScores, - selected_LR = NULL, - selected_cell_LR = NULL, - show_LR_names = TRUE, - show_cell_LR_names = TRUE, - cluster_on = c("PI", "LR_expr", "log2fc"), - cor_method = c("pearson", "kendall", "spearman"), - aggl_method = c("ward.D", "ward.D2", "single", "complete", "average", "mcquitty", - "median", "centroid"), - dot_color_gradient = NULL, - gradient_style = c("divergent", "sequential"), - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = "plotCCcomDotplot" -) -} -\arguments{ -\item{gobject}{giotto object} - -\item{comScores}{communication scores from \code{\link{exprCellCellcom}} or \code{\link{spatCellCellcom}}} - -\item{selected_LR}{selected ligand-receptor combinations} - -\item{selected_cell_LR}{selected cell-cell combinations for ligand-receptor combinations} - -\item{show_LR_names}{show ligand-receptor names} - -\item{show_cell_LR_names}{show cell-cell names} - -\item{cluster_on}{values to use for clustering of cell-cell and ligand-receptor pairs} - -\item{cor_method}{correlation method used for clustering} - -\item{aggl_method}{agglomeration method used by hclust} - -\item{dot_color_gradient}{character. continuous colors to use. palette to -use or vector of colors to use (minimum of 2).} - -\item{gradient_style}{either 'divergent' (midpoint is used in color scaling) -or 'sequential' (scaled based on data range)} - -\item{show_plot}{logical. show plot} - -\item{return_plot}{logical. return ggplot object} - -\item{save_plot}{logical. save the plot} - -\item{save_param}{list of saving parameters, see \code{\link{showSaveParameters}}} - -\item{default_save_name}{default save name for saving, don't change, change save_name in save_param} -} -\value{ -ggplot -} -\description{ -Plots dotplot for ligand-receptor communication scores in cell-cell interactions -} diff --git a/man/plotCCcomHeatmap.Rd b/man/plotCCcomHeatmap.Rd deleted file mode 100644 index 818c888..0000000 --- a/man/plotCCcomHeatmap.Rd +++ /dev/null @@ -1,67 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/vis_spatial_interaction.R -\name{plotCCcomHeatmap} -\alias{plotCCcomHeatmap} -\title{plotCCcomHeatmap} -\usage{ -plotCCcomHeatmap( - gobject, - comScores, - selected_LR = NULL, - selected_cell_LR = NULL, - show_LR_names = TRUE, - show_cell_LR_names = TRUE, - show = c("PI", "LR_expr", "log2fc"), - cor_method = c("pearson", "kendall", "spearman"), - aggl_method = c("ward.D", "ward.D2", "single", "complete", "average", "mcquitty", - "median", "centroid"), - gradient_color = NULL, - gradient_style = c("divergent", "sequential"), - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = "plotCCcomHeatmap" -) -} -\arguments{ -\item{gobject}{giotto object} - -\item{comScores}{communinication scores from \code{\link{exprCellCellcom}} or \code{\link{spatCellCellcom}}} - -\item{selected_LR}{selected ligand-receptor combinations} - -\item{selected_cell_LR}{selected cell-cell combinations for ligand-receptor combinations} - -\item{show_LR_names}{show ligand-receptor names} - -\item{show_cell_LR_names}{show cell-cell names} - -\item{show}{values to show on heatmap} - -\item{cor_method}{correlation method used for clustering} - -\item{aggl_method}{agglomeration method used by hclust} - -\item{gradient_color}{character. continuous colors to use. palette to -use or vector of colors to use (minimum of 2).} - -\item{gradient_style}{either 'divergent' (midpoint is used in color scaling) -or 'sequential' (scaled based on data range)} - -\item{show_plot}{logical. show plot} - -\item{return_plot}{logical. return ggplot object} - -\item{save_plot}{logical. save the plot} - -\item{save_param}{list of saving parameters, see \code{\link{showSaveParameters}}} - -\item{default_save_name}{default save name for saving, don't change, change save_name in save_param} -} -\value{ -ggplot -} -\description{ -Plots heatmap for ligand-receptor communication scores in cell-cell interactions -} diff --git a/man/plotCPF.Rd b/man/plotCPF.Rd deleted file mode 100644 index 056e504..0000000 --- a/man/plotCPF.Rd +++ /dev/null @@ -1,74 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/vis_spatial_interaction.R -\name{plotCPF} -\alias{plotCPF} -\title{plotCPF} -\usage{ -plotCPF( - gobject, - icfObject, - method = c("volcano", "cell_barplot", "cell-cell", "cell_sankey", "heatmap", "dotplot"), - min_cells = 5, - min_cells_expr = 1, - min_int_cells = 3, - min_int_cells_expr = 1, - min_fdr = 0.05, - min_spat_diff = 0.2, - min_log2_fc = 0.2, - min_zscore = 2, - zscores_column = c("cell_type", "feats"), - direction = c("both", "up", "down"), - cell_color_code = NULL, - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = "plotCPG" -) -} -\arguments{ -\item{gobject}{giotto object} - -\item{icfObject}{ICF (interaction changed feature) score object} - -\item{method}{plotting method to use} - -\item{min_cells}{minimum number of source cell type} - -\item{min_cells_expr}{minimum expression level for source cell type} - -\item{min_int_cells}{minimum number of interacting neighbor cell type} - -\item{min_int_cells_expr}{minimum expression level for interacting neighbor cell type} - -\item{min_fdr}{minimum adjusted p-value} - -\item{min_spat_diff}{minimum absolute spatial expression difference} - -\item{min_log2_fc}{minimum log2 fold-change} - -\item{min_zscore}{minimum z-score change} - -\item{zscores_column}{calculate z-scores over cell types or features} - -\item{direction}{differential expression directions to keep} - -\item{cell_color_code}{character. discrete colors to use. palette to use or -named vector of colors} - -\item{show_plot}{logical. show plot} - -\item{return_plot}{logical. return ggplot object} - -\item{save_plot}{logical. save the plot} - -\item{save_param}{list of saving parameters, see \code{\link{showSaveParameters}}} - -\item{default_save_name}{default save name for saving, don't change, change save_name in save_param} -} -\value{ -plot -} -\description{ -Create visualization for cell proximity feature scores -} diff --git a/man/plotCellProximityFeats.Rd b/man/plotCellProximityFeats.Rd deleted file mode 100644 index dacbfa6..0000000 --- a/man/plotCellProximityFeats.Rd +++ /dev/null @@ -1,74 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/vis_spatial_interaction.R -\name{plotCellProximityFeats} -\alias{plotCellProximityFeats} -\title{plotCellProximityFeats} -\usage{ -plotCellProximityFeats( - gobject, - icfObject, - method = c("volcano", "cell_barplot", "cell-cell", "cell_sankey", "heatmap", "dotplot"), - min_cells = 4, - min_cells_expr = 1, - min_int_cells = 4, - min_int_cells_expr = 1, - min_fdr = 0.1, - min_spat_diff = 0.2, - min_log2_fc = 0.2, - min_zscore = 2, - zscores_column = c("cell_type", "feats"), - direction = c("both", "up", "down"), - cell_color_code = NULL, - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = "plotCellProximityFeats" -) -} -\arguments{ -\item{gobject}{giotto object} - -\item{icfObject}{ICF (interaction changed feature) score object} - -\item{method}{plotting method to use} - -\item{min_cells}{minimum number of source cell type} - -\item{min_cells_expr}{minimum expression level for source cell type} - -\item{min_int_cells}{minimum number of interacting neighbor cell type} - -\item{min_int_cells_expr}{minimum expression level for interacting neighbor cell type} - -\item{min_fdr}{minimum adjusted p-value} - -\item{min_spat_diff}{minimum absolute spatial expression difference} - -\item{min_log2_fc}{minimum log2 fold-change} - -\item{min_zscore}{minimum z-score change} - -\item{zscores_column}{calculate z-scores over cell types or featuress} - -\item{direction}{differential expression directions to keep} - -\item{cell_color_code}{character. discrete colors to use. palette to use or -named vector of colors} - -\item{show_plot}{logical. show plot} - -\item{return_plot}{logical. return ggplot object} - -\item{save_plot}{logical. save the plot} - -\item{save_param}{list of saving parameters, see \code{\link{showSaveParameters}}} - -\item{default_save_name}{default save name for saving, don't change, change save_name in save_param} -} -\value{ -plot -} -\description{ -Create visualization for cell proximity feature scores -} diff --git a/man/plotCombineCCcom.Rd b/man/plotCombineCCcom.Rd deleted file mode 100644 index a920f31..0000000 --- a/man/plotCombineCCcom.Rd +++ /dev/null @@ -1,64 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/vis_spatial_interaction.R -\name{plotCombineCCcom} -\alias{plotCombineCCcom} -\title{plotCombineCCcom} -\usage{ -plotCombineCCcom( - gobject, - combCCcom, - selected_LR = NULL, - selected_cell_LR = NULL, - detail_plot = T, - simple_plot = F, - simple_plot_facet = c("interaction", "genes"), - facet_scales = "fixed", - facet_ncol = length(selected_LR), - facet_nrow = length(selected_cell_LR), - colors = c("#9932CC", "#FF8C00"), - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = "plotCombineCCcom" -) -} -\arguments{ -\item{gobject}{giotto object} - -\item{combCCcom}{combined communcation scores, output from combCCcom()} - -\item{selected_LR}{selected ligand-receptor pair} - -\item{selected_cell_LR}{selected cell-cell interaction pair for ligand-receptor pair} - -\item{detail_plot}{show detailed info in both interacting cell types} - -\item{simple_plot}{show a simplified plot} - -\item{simple_plot_facet}{facet on interactions or genes with simple plot} - -\item{facet_scales}{ggplot facet scales paramter} - -\item{facet_ncol}{ggplot facet ncol parameter} - -\item{facet_nrow}{ggplot facet nrow parameter} - -\item{colors}{vector with two colors to use} - -\item{show_plot}{logical. show plot} - -\item{return_plot}{logical. return ggplot object} - -\item{save_plot}{logical. save the plot} - -\item{save_param}{list of saving parameters, see \code{\link{showSaveParameters}}} - -\item{default_save_name}{default save name for saving, don't change, change save_name in save_param} -} -\value{ -ggplot -} -\description{ -Create visualization for combined (pairwise) cell proximity gene scores -} diff --git a/man/plotCombineCellCellCommunication.Rd b/man/plotCombineCellCellCommunication.Rd deleted file mode 100644 index 6b97824..0000000 --- a/man/plotCombineCellCellCommunication.Rd +++ /dev/null @@ -1,64 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/vis_spatial_interaction.R -\name{plotCombineCellCellCommunication} -\alias{plotCombineCellCellCommunication} -\title{plotCombineCellCellCommunication} -\usage{ -plotCombineCellCellCommunication( - gobject, - combCCcom, - selected_LR = NULL, - selected_cell_LR = NULL, - detail_plot = T, - simple_plot = F, - simple_plot_facet = c("interaction", "genes"), - facet_scales = "fixed", - facet_ncol = length(selected_LR), - facet_nrow = length(selected_cell_LR), - colors = c("#9932CC", "#FF8C00"), - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = "plotCombineCellCellCommunication" -) -} -\arguments{ -\item{gobject}{giotto object} - -\item{combCCcom}{combined communcation scores, output from combCCcom()} - -\item{selected_LR}{selected ligand-receptor pair} - -\item{selected_cell_LR}{selected cell-cell interaction pair for ligand-receptor pair} - -\item{detail_plot}{show detailed info in both interacting cell types} - -\item{simple_plot}{show a simplified plot} - -\item{simple_plot_facet}{facet on interactions or genes with simple plot} - -\item{facet_scales}{ggplot facet scales paramter} - -\item{facet_ncol}{ggplot facet ncol parameter} - -\item{facet_nrow}{ggplot facet nrow parameter} - -\item{colors}{vector with two colors to use} - -\item{show_plot}{logical. show plot} - -\item{return_plot}{logical. return ggplot object} - -\item{save_plot}{logical. save the plot} - -\item{save_param}{list of saving parameters, see \code{\link{showSaveParameters}}} - -\item{default_save_name}{default save name for saving, don't change, change save_name in save_param} -} -\value{ -ggplot -} -\description{ -Create visualization for combined (pairwise) cell proximity gene scores -} diff --git a/man/plotCombineICF.Rd b/man/plotCombineICF.Rd deleted file mode 100644 index 8f550a2..0000000 --- a/man/plotCombineICF.Rd +++ /dev/null @@ -1,64 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/vis_spatial_interaction.R -\name{plotCombineICF} -\alias{plotCombineICF} -\title{plotCombineICF} -\usage{ -plotCombineICF( - gobject, - combIcfObject, - selected_interactions = NULL, - selected_feat_to_feat = NULL, - detail_plot = T, - simple_plot = F, - simple_plot_facet = c("interaction", "feats"), - facet_scales = "fixed", - facet_ncol = length(selected_feat_to_feat), - facet_nrow = length(selected_interactions), - colors = c("#9932CC", "#FF8C00"), - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = "plotCombineICF" -) -} -\arguments{ -\item{gobject}{giotto object} - -\item{combIcfObject}{ICFscores, output from combineInteractionChangedFeats()} - -\item{selected_interactions}{interactions to show} - -\item{selected_feat_to_feat}{pairwise feature combinations to show} - -\item{detail_plot}{show detailed info in both interacting cell types} - -\item{simple_plot}{show a simplified plot} - -\item{simple_plot_facet}{facet on interactions or feats with simple plot} - -\item{facet_scales}{ggplot facet scales paramter} - -\item{facet_ncol}{ggplot facet ncol parameter} - -\item{facet_nrow}{ggplot facet nrow parameter} - -\item{colors}{vector with two colors to use} - -\item{show_plot}{logical. show plot} - -\item{return_plot}{logical. return ggplot object} - -\item{save_plot}{logical. save the plot} - -\item{save_param}{list of saving parameters, see \code{\link{showSaveParameters}}} - -\item{default_save_name}{default save name for saving, don't change, change save_name in save_param} -} -\value{ -ggplot -} -\description{ -Create visualization for combined (pairwise) ICF scores -} diff --git a/man/plotCombineInteractionChangedFeats.Rd b/man/plotCombineInteractionChangedFeats.Rd deleted file mode 100644 index c3561d1..0000000 --- a/man/plotCombineInteractionChangedFeats.Rd +++ /dev/null @@ -1,64 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/vis_spatial_interaction.R -\name{plotCombineInteractionChangedFeats} -\alias{plotCombineInteractionChangedFeats} -\title{plotCombineInteractionChangedFeats} -\usage{ -plotCombineInteractionChangedFeats( - gobject, - combIcfObject, - selected_interactions = NULL, - selected_feat_to_feat = NULL, - detail_plot = T, - simple_plot = F, - simple_plot_facet = c("interaction", "feats"), - facet_scales = "fixed", - facet_ncol = length(selected_feat_to_feat), - facet_nrow = length(selected_interactions), - colors = c("#9932CC", "#FF8C00"), - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = "plotCombineICF" -) -} -\arguments{ -\item{gobject}{giotto object} - -\item{combIcfObject}{ICFscores, output from combineInteractionChangedFeats()} - -\item{selected_interactions}{interactions to show} - -\item{selected_feat_to_feat}{pairwise feature combinations to show} - -\item{detail_plot}{show detailed info in both interacting cell types} - -\item{simple_plot}{show a simplified plot} - -\item{simple_plot_facet}{facet on interactions or feats with simple plot} - -\item{facet_scales}{ggplot facet scales paramter} - -\item{facet_ncol}{ggplot facet ncol parameter} - -\item{facet_nrow}{ggplot facet nrow parameter} - -\item{colors}{vector with two colors to use} - -\item{show_plot}{logical. show plot} - -\item{return_plot}{logical. return ggplot object} - -\item{save_plot}{logical. save the plot} - -\item{save_param}{list of saving parameters, see \code{\link{showSaveParameters}}} - -\item{default_save_name}{default save name for saving, don't change, change save_name in save_param} -} -\value{ -ggplot -} -\description{ -Create visualization for combined (pairwise) ICF scores -} diff --git a/man/plotICF.Rd b/man/plotICF.Rd deleted file mode 100644 index 8c8d79b..0000000 --- a/man/plotICF.Rd +++ /dev/null @@ -1,50 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/vis_spatial_interaction.R -\name{plotICF} -\alias{plotICF} -\title{Plot interaction changed features} -\usage{ -plotICF( - gobject, - icfObject, - source_type, - source_markers, - ICF_feats, - cell_color_code = NULL, - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = "plotICF" -) -} -\arguments{ -\item{gobject}{giotto object} - -\item{icfObject}{ICF (interaction changed feature) score object} - -\item{source_type}{cell type of the source cell} - -\item{source_markers}{markers for the source cell type} - -\item{ICF_feats}{named character vector of ICF features} - -\item{cell_color_code}{character. discrete colors to use. palette to use or -named vector of colors} - -\item{show_plot}{logical. show plot} - -\item{return_plot}{logical. return ggplot object} - -\item{save_plot}{logical. save the plot} - -\item{save_param}{list of saving parameters, see \code{\link{showSaveParameters}}} - -\item{default_save_name}{default save name for saving, don't change, change save_name in save_param} -} -\value{ -plot -} -\description{ -Create barplot to visualize interaction changed features -} diff --git a/man/plotInteractionChangedFeats.Rd b/man/plotInteractionChangedFeats.Rd deleted file mode 100644 index 2f7dbfe..0000000 --- a/man/plotInteractionChangedFeats.Rd +++ /dev/null @@ -1,50 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/vis_spatial_interaction.R -\name{plotInteractionChangedFeats} -\alias{plotInteractionChangedFeats} -\title{Plot interaction changed features} -\usage{ -plotInteractionChangedFeats( - gobject, - icfObject, - source_type, - source_markers, - ICF_feats, - cell_color_code = NULL, - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = "plotInteractionChangedFeats" -) -} -\arguments{ -\item{gobject}{giotto object} - -\item{icfObject}{ICF (interaction changed feature) score object} - -\item{source_type}{cell type of the source cell} - -\item{source_markers}{markers for the source cell type} - -\item{ICF_feats}{named character vector of ICF features} - -\item{cell_color_code}{character. discrete colors to use. palette to use or -named vector of colors} - -\item{show_plot}{logical. show plot} - -\item{return_plot}{logical. return ggplot object} - -\item{save_plot}{logical. save the plot} - -\item{save_param}{list of saving parameters, see \code{\link{showSaveParameters}}} - -\item{default_save_name}{default save name for saving, don't change, change save_name in save_param} -} -\value{ -plot -} -\description{ -Create barplot to visualize interaction changed features -} diff --git a/man/plotRankSpatvsExpr.Rd b/man/plotRankSpatvsExpr.Rd deleted file mode 100644 index 55dd56b..0000000 --- a/man/plotRankSpatvsExpr.Rd +++ /dev/null @@ -1,69 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/vis_spatial_interaction.R -\name{plotRankSpatvsExpr} -\alias{plotRankSpatvsExpr} -\title{plotRankSpatvsExpr} -\usage{ -plotRankSpatvsExpr( - gobject, - combCC, - expr_rnk_column = "LR_expr_rnk", - spat_rnk_column = "LR_spat_rnk", - dot_color_gradient = NULL, - midpoint = deprecated(), - gradient_midpoint = 10, - gradient_style = c("divergent", "sequential"), - size_range = c(0.01, 1.5), - xlims = NULL, - ylims = NULL, - selected_ranks = c(1, 10, 20), - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = "plotRankSpatvsExpr" -) -} -\arguments{ -\item{gobject}{giotto object} - -\item{combCC}{combined communication scores from \code{\link{combCCcom}}} - -\item{expr_rnk_column}{column with expression rank information to use} - -\item{spat_rnk_column}{column with spatial rank information to use} - -\item{dot_color_gradient}{character. continuous colors to use. palette to -use or vector of colors to use (minimum of 2).} - -\item{midpoint}{deprecated} - -\item{gradient_midpoint}{numeric. default = 10. midpoint of colors} - -\item{gradient_style}{either 'divergent' (midpoint is used in color scaling) -or 'sequential' (scaled based on data range)} - -\item{size_range}{size ranges of dotplot} - -\item{xlims}{x-limits, numerical vector of 2} - -\item{ylims}{y-limits, numerical vector of 2} - -\item{selected_ranks}{numerical vector, will be used to print out the percentage of top spatial ranks are recovered} - -\item{show_plot}{logical. show plot} - -\item{return_plot}{logical. return ggplot object} - -\item{save_plot}{logical. save the plot} - -\item{save_param}{list of saving parameters, see \code{\link{showSaveParameters}}} - -\item{default_save_name}{default save name for saving, don't change, change save_name in save_param} -} -\value{ -ggplot -} -\description{ -Plots dotplot to compare ligand-receptor rankings from spatial and expression information -} diff --git a/man/plotRecovery.Rd b/man/plotRecovery.Rd deleted file mode 100644 index b77090a..0000000 --- a/man/plotRecovery.Rd +++ /dev/null @@ -1,46 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/vis_spatial_interaction.R -\name{plotRecovery} -\alias{plotRecovery} -\title{plotRecovery} -\usage{ -plotRecovery( - gobject, - combCC, - expr_rnk_column = "exprPI_rnk", - spat_rnk_column = "spatPI_rnk", - ground_truth = c("spatial", "expression"), - show_plot = NA, - return_plot = NA, - save_plot = NA, - save_param = list(), - default_save_name = "plotRecovery" -) -} -\arguments{ -\item{gobject}{giotto object} - -\item{combCC}{combined communication scores from \code{\link{combCCcom}}} - -\item{expr_rnk_column}{column with expression rank information to use} - -\item{spat_rnk_column}{column with spatial rank information to use} - -\item{ground_truth}{what to consider as ground truth (default: spatial)} - -\item{show_plot}{logical. show plot} - -\item{return_plot}{logical. return ggplot object} - -\item{save_plot}{logical. save the plot} - -\item{save_param}{list of saving parameters, see \code{\link{showSaveParameters}}} - -\item{default_save_name}{default save name for saving, don't change, change save_name in save_param} -} -\value{ -ggplot -} -\description{ -Plots recovery plot to compare ligand-receptor rankings from spatial and expression information -} diff --git a/man/plotRecovery_sub.Rd b/man/plotRecovery_sub.Rd deleted file mode 100644 index 6b1688e..0000000 --- a/man/plotRecovery_sub.Rd +++ /dev/null @@ -1,19 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/vis_spatial_interaction.R -\name{plotRecovery_sub} -\alias{plotRecovery_sub} -\title{plotRecovery_sub} -\usage{ -plotRecovery_sub(combCC, first_col = "LR_expr_rnk", second_col = "LR_spat_rnk") -} -\arguments{ -\item{combCC}{combined communinication scores from \code{\link{combCCcom}}} - -\item{first_col}{first column to use} - -\item{second_col}{second column to use} -} -\description{ -Plots recovery plot to compare ligand-receptor rankings from spatial and expression information -} -\keyword{internal} diff --git a/man/reexports.Rd b/man/reexports.Rd new file mode 100644 index 0000000..3524c95 --- /dev/null +++ b/man/reexports.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/colorRamp2.R +\docType{import} +\name{reexports} +\alias{reexports} +\alias{colorRamp2} +\title{Objects exported from other packages} +\keyword{internal} +\description{ +These objects are imported from other packages. Follow the links +below to see their documentation. + +\describe{ + \item{colorRamp2}{\code{\link[colorRamp2]{colorRamp2}}} +}} + diff --git a/man/set_default_color_continuous.Rd b/man/set_default_color_continuous.Rd index 09c6e1d..4ef47c8 100644 --- a/man/set_default_color_continuous.Rd +++ b/man/set_default_color_continuous.Rd @@ -2,6 +2,11 @@ % Please edit documentation in R/aux_defaults.R \name{set_default_color_continuous} \alias{set_default_color_continuous} +\alias{set_default_color_continuous_cell} +\alias{set_default_color_continuous_poly} +\alias{set_default_color_continuous_heatmap} +\alias{set_default_color_continuous_CCcom_heatmap} +\alias{set_default_color_continuous_CCcom_dotplot} \title{Set a default color for continuous values} \usage{ set_default_color_continuous( @@ -14,30 +19,96 @@ set_default_color_continuous( type = c("fill", "color"), ... ) + +set_default_color_continuous_cell( + colors = NULL, + instrs, + midpoint = NULL, + style = "divergent", + type_default = NULL, + ... +) + +set_default_color_continuous_poly( + colors = NULL, + instrs, + midpoint = NULL, + style = "divergent", + ... +) + +set_default_color_continuous_heatmap( + colors = NULL, + instrs, + midpoint = NULL, + style = "divergent", + ... +) + +set_default_color_continuous_CCcom_heatmap( + colors = NULL, + instrs, + midpoint = NULL, + style = "divergent", + ... +) + +set_default_color_continuous_CCcom_dotplot( + colors = NULL, + instrs, + midpoint = NULL, + style = "divergent", + type = c("fill", "color"), + type_default = list(pal = c("darkblue", "blue", "white", "red", "darkred")), + ... +) } \arguments{ -\item{colors}{character or NULL. 2 to n number of hex color codes or 1 single +\item{colors}{character or \code{NULL}. 2 to n number of hex color codes or 1 single name of a palette to use can be passed} -\item{instr_pal}{instructions default: palette} - -\item{instr_rev}{instructions default: reverse palette} +\item{instr_pal, instr_rev}{used by upstream function to pass specific \code{giottoInstructions} params} -\item{midpoint}{midpoint value of color gradient} +\item{midpoint}{numeric. midpoint value of color gradient} -\item{style}{scale color scale around midpoint (divergent) or starting from +\item{style}{scale color scale around \code{midpoint} (divergent) or starting from minimum value (sequential)} -\item{type_default}{data type specific defaults} +\item{type_default}{data type specific default to use} \item{type}{whether setting is for ggplot2 'fill' or 'color' type function} \item{\dots}{additional params to pass to respective ggplot fill_gradient functions} + +\item{instrs}{\code{giottoInstructions} object (output of \code{instructions(gobject)})} } \description{ -Framework function. Should not be used directly. Specific wrapper functions -should be used for each item that needs defaults setting. -midpoint param only supplied when using color scale with 3 colors.\cr -This function sets a default color continuous color gradient to use. It takes +Generates a gradient color palette based on input to \code{colors} param. Sets a +default gradient if \code{NULL} is passed. +\code{midpoint} param only supplied when using color scale with 3 colors.\cr\cr + +Supports colors setting at four levels: +\itemize{ +\item \strong{type specific defaults} - defaults for a sepecific feature or type of +plot can be passed through \code{type_default} param +\item \strong{global options} (general session setting with blanket color palette type effects) +\itemize{ +\item options('giotto.color_c_pal) - palette to use. Default for 'divergent' +data is blue, white, red, for sequential, it is 'viridis' +\item options('giotto.color_c_rev) - whether colors should be reversed } -\keyword{internal} +\item \strong{giotto instructions} (gobject specific and effects specific types of plots) +\itemize{ +\item run \code{showColorInstructions()} for details on options/params to set in the \code{giottoInstructions} object +} +\item \strong{function specific} (directly pass desired colors to plotting function) +\cr\cr +} +} +\section{Functions}{ +\itemize{ +\item \code{set_default_color_continuous()}: Framework function. Direct use should +be minimal. Specific wrapper functions should be used for each item that needs +defaults setting (plots or types of features). + +}} diff --git a/man/set_default_color_discrete.Rd b/man/set_default_color_discrete.Rd new file mode 100644 index 0000000..284f071 --- /dev/null +++ b/man/set_default_color_discrete.Rd @@ -0,0 +1,71 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/aux_defaults.R +\name{set_default_color_discrete} +\alias{set_default_color_discrete} +\alias{set_default_color_discrete_cell} +\alias{set_default_color_discrete_poly} +\alias{set_default_color_discrete_feat} +\alias{set_default_color_discrete_heatmap_clus} +\title{Set a discrete coloring scheme} +\usage{ +set_default_color_discrete( + colors = NULL, + instr_pal, + instr_rev, + instr_strategy, + ... +) + +set_default_color_discrete_cell(colors = NULL, instrs, ...) + +set_default_color_discrete_poly(colors = NULL, instrs, ...) + +set_default_color_discrete_feat(colors = NULL, instrs, ...) + +set_default_color_discrete_heatmap_clus(colors = NULL, instrs, ...) +} +\arguments{ +\item{colors}{accepts color inputs} + +\item{instr_pal, instr_rev, instr_strategy}{used by upstream function to pass specific \code{giottoInstructions} params} + +\item{\dots}{additional params to pass} + +\item{instrs}{\code{giottoInstructions} object (output of \code{instructions(gobject)})} +} +\description{ +Provides a palette function that will generate 'n' hexadecimal color codes for +discrete colors. Sets a default coloring palette if \code{NULL} is passed to \code{colors} +param.\cr\cr + +Supports colors setting at three levels: +\itemize{ +\item \strong{global options} (general session setting with blanket color palette type effects) +\itemize{ +\item options('giotto.color_d_pal) - palette to use +\item options('giotto.color_d_rev) - whether colors should be reversed +\item options('giotto.color_d_strategy) - strategy to use when making colors continuous. See \code{\link[=get_continuous_colors]{get_continuous_colors()}} +} +\item \strong{giotto instructions} (gobject specific and effects specific types of plots) +\itemize{ +\item run \code{showColorInstructions()} for details on options/params to set in the \code{giottoInstructions} object +} +\item \strong{function specific} (directly pass desired colors to plotting function) +\cr\cr +} + +If a character vector of length 1 input is provided then it will be assumed +that a known color palette is being requested from \code{\link[=pal_names]{pal_names()}}.\cr +If a longer character input is provided then they will be expected to be +a vector of colors to use. These values will be passed to \link{simple_palette_factory} +which will generate a palette function that interpolates between the colors +provided by default and has a \code{n} param for number of requested colors.\cr +Custom function inputs to \code{colors} is also supported but these custom functions +should have a \code{n} param for number of requested colors. +} +\section{Functions}{ +\itemize{ +\item \code{set_default_color_discrete()}: Framework function. Direct use should be minimal. +Wrap this for specific things (plots or types of features) that need defaults setting. + +}} diff --git a/man/set_default_cow_n_col.Rd b/man/set_default_cow_n_col.Rd new file mode 100644 index 0000000..bbe2766 --- /dev/null +++ b/man/set_default_cow_n_col.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/aux_defaults.R +\name{set_default_cow_n_col} +\alias{set_default_cow_n_col} +\title{Set default ncols in plotting grid} +\usage{ +set_default_cow_n_col(cow_n_col = NULL, nr_plots) +} +\arguments{ +\item{cow_n_col}{number of columns for cowplot to use. A default number is +calculated if \code{NULL} is passed.} + +\item{nr_plots}{number of plots to use with cowplot} +} +\description{ +Determine a default cow_n_col param value for cowplot based on the number of +items to plot. +} diff --git a/man/simple_palette_factory.Rd b/man/simple_palette_factory.Rd new file mode 100644 index 0000000..26f513e --- /dev/null +++ b/man/simple_palette_factory.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/color_palettes.R +\name{simple_palette_factory} +\alias{simple_palette_factory} +\title{Generate a simple palette function} +\usage{ +simple_palette_factory(col, rev = FALSE, strategy = "interpolate") +} +\arguments{ +\item{col}{character vector. Hexadecimal color codes} + +\item{rev}{whether to reverse order of vector} + +\item{strategy}{policy when insufficient colors are available} +} +\description{ +Simple palette function generator. Creates a function with param n that +dictates how many colors to return from the provided vector of hexadecimal +color values. Generated functions send warning if there are not enough colors +to use and it needs to recycle values. +} +\seealso{ +\code{\link[=set_default_color_discrete]{set_default_color_discrete()}} +}