Skip to content

Commit

Permalink
added detail=FALSE arg for visualization
Browse files Browse the repository at this point in the history
  • Loading branch information
Qile0317 committed Apr 10, 2024
1 parent 8fbedf7 commit 62ab687
Show file tree
Hide file tree
Showing 13 changed files with 249 additions and 137 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Additions

- Add argument `detail` in `APOTCPlot` and `vizAPOTC` to allow user to plot a version of the clonal expansion plot where each cluster is just one large circle. Correspondingly added a subsection in `vignette("APackOfTheClones-shared")`.

## Changes

# APackOfTheClones 1.1.0
Expand Down
18 changes: 15 additions & 3 deletions R/APOTCPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@
#' changed between the circle sizes on the left side of the legend and the
#' numbers on the right. Useful to set to around 0.5 (or more / less) when there
#' are particularly large clone sizes that may cover the numbers.
#' @param detail logical. If `FALSE`, will only plot entire clusters as one
#' large circle, which may be useful in cases where there are a high number
#' of clones resulting in a large number of circles on the resulting ggplot,
#' which has increased plotting times, and certain aspects of the plot needs
#' to be finely adjusted with [AdjustAPOTC] or simply inspected. This should
#' not be set to `FALSE` for the actual clonal expansion plot.
#'
#' @return A ggplot object of the APackOfTheClones clonal expansion plot of the
#' seurat object. There is an additional 10th element in the object named
Expand Down Expand Up @@ -139,6 +145,8 @@ APOTCPlot <- function(
add_legend_background = TRUE,
add_legend_centerspace = 0,

detail = TRUE,

verbose = TRUE
) {
# handle varargs, run_id, and typecheck
Expand All @@ -151,7 +159,9 @@ APOTCPlot <- function(
apotc_obj <- getApotcData(seurat_obj, args$run_id)

# initialize plot
result_plot <- create_initial_apotc_plot(apotc_obj, res, linetype, alpha)
result_plot <- create_initial_apotc_plot(
apotc_obj, res, linetype, alpha, detail
)
result_plot_dimensions <- get_apotc_plot_dims(apotc_obj)

#set theme
Expand Down Expand Up @@ -180,7 +190,7 @@ APOTCPlot <- function(
}

if (isnt_empty(show_shared)) {

# check only_link indexing
if (!is.null(only_link) &&
!is_valid_nonempty_cluster(apotc_obj, only_link)) {
Expand Down Expand Up @@ -234,7 +244,7 @@ APOTCPlot <- function(
}

APOTCPlot_error_handler <- function(args) {

check_apotc_identifiers(args)
check_filtering_conditions(args)

Expand Down Expand Up @@ -266,6 +276,8 @@ APOTCPlot_error_handler <- function(args) {
typecheck(args$add_size_legend, is_a_logical)
check_legend_params(args)

typecheck(args$detail, is_a_logical)

}

# helpers for getting plot dimensions quickly
Expand Down
2 changes: 1 addition & 1 deletion R/AdjustAPOTC.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ AdjustAPOTC <- function(
recolor_cluster = NULL,
new_color = NULL,

rename_label = NULL, # TODO add functionality to change all at once or modify all at once
rename_label = NULL,
new_label = NULL,
relocate_label = NULL,
label_relocation_coord = NULL,
Expand Down
1 change: 0 additions & 1 deletion R/ApotcClonalNetwork.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ getSharedClones_error_handler <- function() {
# output: a named list where each name is a clonotype, each element is a
# numeric indicating which seurat cluster(s) its in. If exclude_unique_clones,
# will filter out any clonotype with only length one. (not shared)
# TODO - allow filtering based on original clone size
get_shared_clones <- function(
apotc_obj,
zero_indexed = FALSE,
Expand Down
4 changes: 4 additions & 0 deletions R/Repulsion.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# cluster repulsion - the n body problem
# FIXME the repulsion is too aggressive when clusters are super close, put upper bound on force based on clone scale
# time complexity is O(mn^2) where m is the max number of iterations and n is the number of clusters(circles). n will never be that high so the timing isnt a problem

# Functions defined in src/repulsion.cpp
# - get_average_vector(vec_list)
# avg vector of a list of vectors
Expand Down
18 changes: 15 additions & 3 deletions R/clusters.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ get_x_coords <- function(l) l[[1]]
get_y_coords <- function(l) l[[2]]
get_radii <- function(l) l[[3]]
get_centroid <- function(l) l[[4]]
get_centroid_x <- function(l) get_centroid(l)[1]
get_centroid_y <- function(l) get_centroid(l)[2]
get_cluster_radius <- function(l) l[[5]]
get_clonotypes <- function(l) l$clonotype # not index due to legacy clusterlists

Expand All @@ -29,9 +31,19 @@ set_centroid <- function(l, v) {l$centroid <- v; l}
set_cluster_radius <- function(l, v) {l$clRad <- v; l}
set_clonotypes <- function(l, v) {l$clonotype <- v; l}

# convert clusterlist to dataframe, assuming its valid
# TODO allow get_abstract option to just get 1 large circle
convert_to_dataframe <- function(clstr_list, seurat_cluster_index) {
# convert clusterlist to dataframe, assuming its ***valid***
convert_to_dataframe <- function(
clstr_list, seurat_cluster_index, detail = TRUE
) {
if (!detail) {
return(data.frame(
"label" = paste("cluster", seurat_cluster_index),
"x" = get_centroid_x(clstr_list),
"y" = get_centroid_y(clstr_list),
"r" = get_cluster_radius(clstr_list)
))
}

data.frame(
"label" = rep(
paste("cluster", seurat_cluster_index),
Expand Down
Loading

0 comments on commit 62ab687

Please sign in to comment.