Skip to content

Commit

Permalink
v0.16.15
Browse files Browse the repository at this point in the history
update vignettes
  • Loading branch information
jeffkimbrel committed Oct 2, 2024
1 parent 410fe3b commit 952e5ad
Show file tree
Hide file tree
Showing 12 changed files with 320 additions and 18 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: qSIP2
Title: qSIP Analysis
Version: 0.16.14
Version: 0.16.15
Authors@R:
person("Jeff", "Kimbrel", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-7213-9392"))
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ export(pivot_kbase_amplicon_matrix)
export(plot_EAF_values)
export(plot_density_outliers)
export(plot_feature_curves)
export(plot_feature_occurrence)
export(plot_feature_resamplings)
export(plot_filter_gradient_position)
export(plot_growth_values)
export(plot_resampling_convergence)
export(plot_sample_curves)
export(plot_source_wads)
export(plot_successful_resamples)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* `vignette("growth")`
* `vignette("multiple_objects")`
* `vignette("filtering")`
* `vignette("EAF")`
* The previous vignettes were hastily written, but now they have been hastily re-written to capture the modern workflow of `qSIP2`
* `vignette("qSIP_workflow")`
* `vignette("source_data")`
Expand Down
105 changes: 105 additions & 0 deletions R/plot_feature_occurrence.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#' Plot occurrence of features in samples
#'
#' This is a plotting function to visualize the occurrence of features in samples.
#' The function takes a qsip_data object and a vector of feature_ids, and can scale
#' the results by total abundance or source abundance, and the WAD value can also be shown.
#'
#' @param qsip_data_object (*qsip_data*) A qsip_data object
#' @param feature_ids (*character*) A vector of feature_ids
#' @param scale (*character*) A character string
#' @param show_wad (*logical*) A logical value
#' @param title (*character*) A character string
#' @param legend.position (*character* or *numeric vector*) Values passed to ggplot2::theme(legend.position = ...)
#'
#' @export
#'
#' @returns Returns a ggplot object

plot_feature_occurrence = function(qsip_data_object,
feature_ids,
scale = "none",
show_wad = FALSE,
title = NULL,
legend.position = "right") {

# stop if qsip_data_object !is_qsip()
if (!is_qsip_data(qsip_data_object)) {
stop("Input must be a <qsip_data> object", call. = F)
}

# features must be a vector, and not too big
if (!is.vector(feature_ids)) {
stop("feature_ids must be a vector", call. = F)
} else if (length(feature_ids) > 64) {
stop("The length of feature_ids is capped at 64", call. = F)
}

# scale must be "none", "total", or "source"
if (!scale %in% c("none", "total", "source")) {
stop("scale must be 'none', 'total', or 'source'", call. = F)
}

# show_wad must be boolean
if (!is.logical(show_wad)) {
stop("show_wad must be a boolean", call. = F)
}

# title must be a character or NULL
if (!is.character(title) & !is.null(title)) {
stop("title must be a character or NULL", call. = F)
}



# make dataframe with joined metadata
df = qsip_data_object@tube_rel_abundance |>
dplyr::filter(feature_id %in% feature_ids) |>
dplyr::left_join(qsip_data_object@sample_data@data,
by = join_by(sample_id, source_mat_id, gradient_pos_density, gradient_pos_rel_amt)) |>
dplyr::left_join(qsip_data_object@source_data@data,
by = join_by(source_mat_id)) |>
dplyr::left_join(qsip_data_object@wads,
by = join_by(feature_id, source_mat_id))

# if scale = "source"
if (scale == "source") {
df = df |>
dplyr::mutate(tube_rel_abundance_source = tube_rel_abundance / sum(tube_rel_abundance),
.by = c("feature_id", "source_mat_id"))
}

# base plot
p = df |>
ggplot2::ggplot(ggplot2::aes(y = source_mat_id))

# if show_wad is true
if (isTRUE(show_wad)) {
p = p +
ggplot2::geom_point(pch = "|", size = 6,
ggplot2::aes(x = WAD, color = isotope)) +
ggplot2::scale_color_manual(values = isotope_palette)
}

# choose which size to plot based on scale argument
if (scale == "total") {
p = p +
ggplot2::geom_point(pch = 21, alpha = 0.9,
ggplot2::aes(x = gradient_pos_density, size = tube_rel_abundance, fill = isotope))
} else if (scale == "source") {
p = p +
ggplot2::geom_point(pch = 21, alpha = 0.9,
ggplot2::aes(x = gradient_pos_density, size = tube_rel_abundance_source, fill = isotope))
} else {
p = p +
ggplot2::geom_point(pch = 21, alpha = 0.9, size = 2,
ggplot2::aes(x = gradient_pos_density, fill = isotope))
}


# finish and return plot
p +
ggplot2::facet_wrap(~feature_id) +
ggplot2::scale_fill_manual(values = isotope_palette) +
ggplot2::labs(title = title) +
ggplot2::theme(legend.position = legend.position)
}
3 changes: 2 additions & 1 deletion R/plot_feature_resamplings.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ plot_feature_resamplings <- function(qsip_data_object,
ggplot2::ggplot(ggplot2::aes(x = mean_resampled_WAD, y = type)) +
ggplot2::facet_wrap(~feature_id, scales = "free_x") +
ggplot2::scale_color_manual(values = c("labeled" = "#ff0000", "unlabeled" = "#037bcf")) +
ggplot2::scale_fill_manual(values = c("labeled" = "#FF000055", "unlabeled" = "#037bcf55"))
ggplot2::scale_fill_manual(values = c("labeled" = "#FF000055", "unlabeled" = "#037bcf55")) +
ggplot2::labs(x = "Resampled WAD Values")

if (isTRUE(area)) {
p <- p +
Expand Down
16 changes: 8 additions & 8 deletions R/plot_resampling_convergence.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#' Plot resampling convergence (under construction!)
#'
#' @param qsip_data_object (*qsip_data*) A qsip data object that has been resampled
#'
#' @export

plot_resampling_convergence = function(qsip_data_object) {

Expand All @@ -27,12 +25,14 @@ plot_resampling_convergence = function(qsip_data_object) {
)

dplyr::bind_rows(k) |>
dplyr:: mutate(L = (mean_resampled_EAF - lower) / mean_resampled_EAF,
U = (mean_resampled_EAF - upper) / mean_resampled_EAF) |>
tidyr::pivot_longer(cols = c(L, U)) |>
ggplot2:: ggplot(ggplot2::aes(x = n, y = value, color = name)) +
dplyr:: mutate(Lower = (mean_resampled_EAF - lower) / mean_resampled_EAF,
Upper = (mean_resampled_EAF - upper) / mean_resampled_EAF) |>
tidyr::pivot_longer(cols = c(Lower, Upper)) |>
ggplot2::ggplot(ggplot2::aes(x = n, y = value, color = name)) +
ggplot2::geom_point(alpha = 0.3, pch = 21) +
ggplot2::geom_smooth(formula = "y ~ x", method = "loess") +
ggplot2::scale_fill_manual(values = c("L" = "red", "U" = "#037bcf")) +
ggplot2::scale_color_manual(values = c("L" = "red", "U" = "#037bcf"))
ggplot2::scale_fill_manual(values = c("Lower" = "red", "Upper" = "#037bcf")) +
ggplot2::scale_color_manual(values = c("Lower" = "red", "Upper" = "#037bcf")) +
ggplot2::scale_y_log10() +
ggplot2::scale_x_log10()
}
6 changes: 1 addition & 5 deletions R/plot_source_wads.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ plot_source_wads <- function(qsip_data,
WAD <- isotope <- NULL

if (is.null(colors)) {
colors <- c(
"12C" = "cornflowerblue", "13C" = "firebrick",
"14N" = "cornflowerblue", "15N" = "firebrick",
"16O" = "cornflowerblue", "18O" = "firebrick"
)
colors <- isotope_palette
}

p = qsip_data@source_wads |>
Expand Down
Binary file added R/sysdata.rda
Binary file not shown.
3 changes: 2 additions & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ reference:
- plot_feature_resamplings
- plot_EAF_values
- plot_growth_values
- plot_resampling_convergence

- title: Datasets
contents:
Expand Down Expand Up @@ -110,6 +109,7 @@ reference:
- calculate_N_light_it
- calculate_di
- calculate_bi
- plot_resampling_convergence

articles:
- title: Learn qSIP
Expand All @@ -118,6 +118,7 @@ articles:
- qSIP_workflow
- filtering
- resampling
- EAF
- growth

- title: Working with...
Expand Down
9 changes: 8 additions & 1 deletion data-raw/example_qsip_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ example_qsip_growth_t0 <- get_N_total_it(example_qsip_growth_object, t = 0)
example_group_dataframe = readxl::read_excel("/Users/kimbrel1/Library/CloudStorage/Dropbox/working/qSIP/multiple_objects_test.xlsx")



# palettes
isotope_palette = c(
"12C" = "#037bcf", "13C" = "#ff0000",
"14N" = "#037bcf", "15N" = "#ff0000",
"16O" = "#037bcf", "18O" = "#ff0000"
)

# save
usethis::use_data(example_source_df, overwrite = TRUE)
Expand All @@ -128,3 +133,5 @@ usethis::use_data(example_qsip_growth_object, overwrite = TRUE)
usethis::use_data(example_qsip_growth_t0, overwrite = TRUE)

usethis::use_data(example_group_dataframe, overwrite = TRUE)

usethis::use_data(isotope_palette, overwrite = TRUE, internal = TRUE)
36 changes: 36 additions & 0 deletions man/plot_feature_occurrence.Rd

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

Loading

0 comments on commit 952e5ad

Please sign in to comment.