Skip to content

Commit

Permalink
feat: clonal prop per group plot
Browse files Browse the repository at this point in the history
  • Loading branch information
nahid18 committed Jun 16, 2024
1 parent 75a0459 commit a367526
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 8 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

export("%>%")
export(get_study)
export(plot_clonal_prop_per_group)
export(plot_clonal_prop_per_sample)
export(plot_motif_counts)
exportClasses(Basic)
Expand Down
47 changes: 47 additions & 0 deletions R/plot_clonal_prop_per_group.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#' Plot clonal proportion per group
#'
#' This function plots the clonal proportion per group.
#'
#' @param data A data frame of clonal proportion per group.
#' @param attr_col Character. Attribute column name.
#'
#' @return A ggplot2 plot of clonal proportion per group plot.
#' @export
#'
#' @examples
#' \dontrun{
#' proj <- reTCR::get_study(id = "PRJNA473147", attr_col = "cmv_status")
#' clonal_prop <- proj@clonality@clonal_prop
#' reTCR::plot_clonal_prop_per_group(clonal_prop, "cmv_status")
#' }
plot_clonal_prop_per_group <- function(data, attr_col) {
data[[attr_col]] <- as.factor(data[[attr_col]])
ggplot2::ggplot(
data,
ggplot2::aes_string(
x = attr_col,
y = "clonality_portion"
)
) +
ggplot2::geom_violin(trim = FALSE, fill = "skyblue", alpha = 0.5) +
ggplot2::geom_boxplot(outlier.shape = NA, width = 0.1, alpha = 0.7) +
ggplot2::geom_jitter(width = 0, height = 0.1, size = 1.5, alpha = 0.6) +
ggplot2::theme_classic() +
ggplot2::labs(x = attr_col, y = "number of clonotypes") +
ggplot2::theme(
axis.text.x = ggplot2::element_text(
angle = 90, vjust = 0.5, hjust = 1, size = 10
),
axis.text.y = ggplot2::element_text(
size = 12,
margin = ggplot2::margin(l = 10)
),
axis.title.x = ggplot2::element_text(
size = 14,
margin = ggplot2::margin(t = 10)
),
axis.title.y = ggplot2::element_text(size = 14),
legend.title = ggplot2::element_text(size = 14),
legend.text = ggplot2::element_text(size = 12)
)
}
6 changes: 3 additions & 3 deletions R/plot_clonal_prop_per_sample.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#' Plot Clonal Proportion per Sample
#' Plot clonal proportion per sample
#'
#' This function plots the clonal proportion per sample.
#'
#' @param data A data frame containing the clonal proportion per sample.
#' @param data A data frame of clonal proportion per sample.
#' @param attr_col Character. Attribute column name.
#'
#' @return A ggplot2 object representing the clonal proportion per sample plot.
#' @return A ggplot2 plot of clonal proportion per sample plot.
#' @export
#'
#' @examples
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,15 @@ print(proj@clonality@least_clonotype)
print(proj@clonality@pielou)

# clonal proportion
print(proj@clonality@clonal_prop)
clonal_prop <- proj@clonality@clonal_prop
print(clonal_prop)

# plot clonal proportion per sample
clonal_prop <- proj@clonality@clonal_prop
reTCR::plot_clonal_prop_per_sample(clonal_prop, "cmv_status")

# plot clonal proportion per group
reTCR::plot_clonal_prop_per_group(clonal_prop, "cmv_status")

# relative abundance (in all clonotypes)
print(proj@clonality@abundance)

Expand Down
26 changes: 26 additions & 0 deletions man/plot_clonal_prop_per_group.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/plot_clonal_prop_per_sample.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a367526

Please sign in to comment.