Skip to content

Commit

Permalink
feat: clonal prop and plot
Browse files Browse the repository at this point in the history
  • Loading branch information
nahid18 committed Jun 16, 2024
1 parent b69b2f0 commit 75a0459
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 3 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_sample)
export(plot_motif_counts)
exportClasses(Basic)
exportClasses(Clonality)
Expand Down
47 changes: 47 additions & 0 deletions R/plot_clonal_prop_per_sample.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#' 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 attr_col Character. Attribute column name.
#'
#' @return A ggplot2 object representing the clonal proportion per sample 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_sample(clonal_prop, "cmv_status")
#' }
plot_clonal_prop_per_sample <- function(data, attr_col) {
ggplot2::ggplot(
data,
ggplot2::aes(
x = sample,
y = clonality_portion,
fill = !!rlang::sym(attr_col)
)
) +
ggplot2::geom_bar(stat = "identity", position = ggplot2::position_dodge()) +
ggplot2::labs(x = "sample", y = "number of clonotypes") +
ggplot2::theme_classic() +
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)
) +
ggplot2::scale_y_continuous(expand = c(0, 0)) +
ggplot2::scale_fill_brewer(palette = "Set1", name = attr_col)
}
8 changes: 6 additions & 2 deletions R/plot_motif_counts.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#'
#' @examples
#' \dontrun{
#' proj <- reTCR::get_study(id = "PRJNA473147")
#' proj <- reTCR::get_study(id="PRJNA473147", attr_col="cmv_status")
#' reTCR::plot_motif_counts(proj@motif@aa_motif_count, 20)
#' }
plot_motif_counts <- function(data, threshold = 60) {
Expand All @@ -29,7 +29,11 @@ plot_motif_counts <- function(data, threshold = 60) {
)
) +
ggplot2::geom_jitter(width = 0.2, size = 3) +
ggplot2::labs(x = "Amino acid motif", y = "Count", color = "CMV Status") +
ggplot2::labs(
x = "Amino acid motif",
y = "Count",
color = "CMV Status"
) +
ggplot2::theme_bw() +
ggplot2::theme(
axis.text.x = ggplot2::element_text(
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ print(proj@clonality@pielou)
# clonal proportion
print(proj@clonality@clonal_prop)

# plot clonal proportion per sample
clonal_prop <- proj@clonality@clonal_prop
reTCR::plot_clonal_prop_per_sample(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_sample.Rd

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

2 changes: 1 addition & 1 deletion man/plot_motif_counts.Rd

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

0 comments on commit 75a0459

Please sign in to comment.