Skip to content

Commit

Permalink
fix: most R CMD Check errors/warnings/notes
Browse files Browse the repository at this point in the history
except documentation problems (in progress)
  • Loading branch information
kelly-sovacool committed Jul 31, 2024
1 parent 1662643 commit 3a0120e
Show file tree
Hide file tree
Showing 27 changed files with 411 additions and 79 deletions.
18 changes: 8 additions & 10 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,17 @@ Imports:
edgeR,
ggplot2,
ggrepel,
gplots,
gridExtra,
gridGraphics,
lattice,
limma,
methods,
plotly,
RColorBrewer,
RCurl,
reshape2,
rlang,
S7,
stringr,
tidyr
stats,
tibble,
tidyr,
tidyselect
Suggests:
glue,
knitr,
readr,
rmarkdown,
Expand All @@ -51,4 +49,4 @@ Config/testthat/edition: 3
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export("%>%")
export(counts_dat_to_matrix)
export(create_reneeDataSet_from_dataframes)
export(create_reneeDataSet_from_files)
export(filter_low_counts)
export(filter_counts)
export(meta_tbl_to_dat)
export(run_deseq2)
if (getRversion() < "4.3.0") importFrom("S7", "@")
Expand Down
22 changes: 16 additions & 6 deletions R/0_renee-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,35 @@ reneeDataSet <- S7::new_class("renee",

#' Construct a reneeDataSet object from tsv files.
#'
#' @param gene_counts_filepath path to tsv file of expected gene counts from RSEM.
#' @param sample_meta_filepath path to tsv file with sample IDs and metadata for differential analysis.
#' @param gene_counts_filepath path to tsv file of expected gene counts from RSEM.
#'
#' @return reneeDataSet object
#' @export
#'
#' @examples
#' create_reneeDataSet_from_files(
#' sample_meta_filepath = system.file("extdata", "sample_metadata.tsv", package = "reneeTools"),
#' gene_counts_filepath = system.file("extdata", "RSEM.genes.expected_count.all_samples.txt", package = "reneeTools")
#' renee_ds <- create_reneeDataSet_from_files(
#' sample_meta_filepath = system.file("extdata",
#' "sample_metadata.tsv",
#' package = "reneeTools"
#' ),
#' gene_counts_filepath = system.file("extdata",
#' "RSEM.genes.expected_count.all_samples.txt",
#' package = "reneeTools"
#' )
#' )
#' renee_ds@counts$raw %>% head()
#' renee_ds@sample_meta
create_reneeDataSet_from_files <- function(sample_meta_filepath, gene_counts_filepath,
count_type = "raw") {
count_type = "raw",
sample_id_colname = "sample_id") {
count_dat <- readr::read_tsv(gene_counts_filepath)
sample_meta_dat <- readr::read_tsv(sample_meta_filepath)
return(create_reneeDataSet_from_dataframes(
sample_meta_dat = sample_meta_dat,
count_dat = count_dat,
count_type = "raw"
count_type = "raw",
sample_id_colname = sample_id_colname
))
}

Expand Down
10 changes: 8 additions & 2 deletions R/colors.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@
#' @keywords internal
#'
#' @examples
#' \dontrun{
#' set.seed(10)
#' get_random_colors(5)
#' }
get_random_colors <- function(num_colors, n = 2e3) {
if (num_colors < 1) {
stop("num_colors must be at least 1")
}
n <- 2e3
ourColorSpace <- colorspace::RGB(runif(n), runif(n), runif(n))
ourColorSpace <- as(ourColorSpace, "LAB")
ourColorSpace <- colorspace::RGB(
stats::runif(n),
stats::runif(n),
stats::runif(n)
)
ourColorSpace <- methods::as(ourColorSpace, "LAB")
currentColorSpace <- ourColorSpace@coords
# Set iter.max to 20 to avoid convergence warnings.
km <- stats::kmeans(currentColorSpace, num_colors, iter.max = 20)
Expand Down
11 changes: 11 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,14 @@
#' @source Generated by running RENEE v2.5.8 on the
#' [test dataset](https://github.com/CCBR/RENEE/tree/e08f7db6c6e638cfd330caa182f64665d2ef37fa/.tests)
"gene_counts"

#' Sample metadata for the NIDAP test dataset
"nidap_sample_metadata"

#' Clean raw counts for the NIDAP test dataset.
#' Pairs with `nidap_sample_metadata`.
"nidap_clean_raw_counts"

#' Filtered counts for the NIDAP test dataset.
#' The result of running `filter_counts()` on `nidap_clean_raw_counts`.
"nidap_filtered_counts"
18 changes: 12 additions & 6 deletions R/filter.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#' renee_ds <- create_reneeDataSet_from_dataframes(
#' as.data.frame(nidap_sample_metadata),
#' as.data.frame(nidap_clean_raw_counts),
#' sample_id_colname = Sample
#' sample_id_colname = "Sample"
#' )
#' set.seed(10)
#' renee_ds2 <- filter_counts(renee_ds)
Expand Down Expand Up @@ -154,7 +154,9 @@ filter_counts <- function(renee_ds,
########################
histPlot <- plot_histogram(log_counts, sample_metadata,
gene_names_column = gene_names_column,
groups_column = groups_column,
labels_column = labels_column,
color_values = colorval,
color_histogram_by_group = color_histogram_by_group,
set_min_max_for_x_axis_for_histogram = set_min_max_for_x_axis_for_histogram,
minimum_for_x_axis_for_histogram = minimum_for_x_axis_for_histogram,
Expand All @@ -171,8 +173,9 @@ filter_counts <- function(renee_ds,

if (plot_correlation_matrix_heatmap == TRUE) {
if (interactive_plots == TRUE) {
pcaPlot1 <- (pcaPlot) %>% ggplotly(tooltip = c("sample", "group"))
histPlot2 <- (histPlot + theme(legend.position = "none")) %>% ggplotly(tooltip = c("sample"))
pcaPlot1 <- (pcaPlot) %>% plotly::ggplotly(tooltip = c("sample", "group"))
histPlot2 <- (histPlot + ggplot2::theme(legend.position = "none")) %>%
plotly::ggplotly(tooltip = c("sample"))

grid::grid.newpage()
# print(pcaPlot1)
Expand All @@ -197,8 +200,9 @@ filter_counts <- function(renee_ds,
}
} else {
if (interactive_plots == TRUE) {
pcaPlot1 <- (pcaPlot) %>% ggplotly(tooltip = c("sample", "group"))
histPlot2 <- (histPlot + theme(legend.position = "none")) %>% ggplotly(tooltip = "sample")
pcaPlot1 <- (pcaPlot) %>% plotly::ggplotly(tooltip = c("sample", "group"))
histPlot2 <- (histPlot + ggplot2::theme(legend.position = "none")) %>%
plotly::ggplotly(tooltip = "sample")

grid::grid.newpage()
# print(pcaPlot1)
Expand Down Expand Up @@ -248,6 +252,7 @@ remove_low_count_genes <- function(counts_matrix, sample_metadata,
Minimum_Count_Value_to_be_Considered_Nonzero = 8,
Minimum_Number_of_Samples_with_Nonzero_Counts_in_Total = 7,
Minimum_Number_of_Samples_with_Nonzero_Counts_in_a_Group = 3) {
value <- NULL
df <- counts_matrix

df <- df[stats::complete.cases(df), ]
Expand Down Expand Up @@ -278,7 +283,8 @@ remove_low_count_genes <- function(counts_matrix, sample_metadata,
tcounts$Row.names <- NULL
melted <- reshape2::melt(tcounts, id.vars = groups_column)
tcounts.tot <- dplyr::summarise(dplyr::group_by_at(melted, c(groups_column, "variable")), sum = sum(value))
tcounts.tot %>% tidyr::spread(variable, sum) -> tcounts.group
tcounts.group <- tcounts.tot %>%
tidyr::pivot_wider(names_from = "variable", values_from = "sum")
colSums(tcounts.group[(1:colnum + 1)] >= Minimum_Number_of_Samples_with_Nonzero_Counts_in_a_Group) >= 1 -> tcounts.keep
df.filt <- trans.df[tcounts.keep, ]
df.filt %>% tibble::rownames_to_column(gene_names_column) -> df.filt
Expand Down
9 changes: 6 additions & 3 deletions R/histogram.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
plot_histogram <- function(log_counts,
sample_metadata,
gene_names_column,
groups_column,
labels_column,
color_values,
color_histogram_by_group = FALSE,
set_min_max_for_x_axis_for_histogram = FALSE,
minimum_for_x_axis_for_histogram = -1,
maximum_for_x_axis_for_histogram = 1,
legend_position_for_histogram = "top",
legend_font_size_for_histogram = 10,
number_of_histogram_legend_columns = 6) {
Var2 <- colgroup <- value <- NULL
df.m <- reshape2::melt(log_counts, id.vars = c(gene_names_column))
df.m <- dplyr::rename(df.m, sample = Var2)

Expand All @@ -21,13 +24,13 @@ plot_histogram <- function(log_counts,
}

if (color_histogram_by_group == TRUE) {
df.m %>% dplyr::mutate(colgroup = sample_metadata[sample, groups_column]) -> df.m
df.m <- df.m[complete.cases(df.m[, "colgroup"]), ]
df.m <- df.m %>% dplyr::mutate(colgroup = sample_metadata[sample, groups_column])
df.m <- df.m[stats::complete.cases(df.m[, "colgroup"]), ]
df.m$colgroup <- gsub("\\s", "_", df.m$colgroup)
df.m$colgroup <- factor(df.m$colgroup, levels = unique(df.m$colgroup))
## print(unique(df.m$sample))
n <- length(levels(df.m$colgroup))
cols <- colorval[1:n]
cols <- color_values[1:n]

# plot Density
histPlot <- df.m %>%
Expand Down
3 changes: 2 additions & 1 deletion R/pca.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ plot_pca <- function(log_counts,
label_offset_y_ = 2,
label_offset_x_ = 2) {
# calculate PCA
var <- xdata <- ydata <- group <- NULL
tedf <- t(log_counts)
tedf <- tedf[, colSums(is.na(tedf)) != nrow(tedf)]
tedf <- tedf[, apply(tedf, 2, var) != 0]
pca <- prcomp(tedf, scale. = T)
pca <- stats::prcomp(tedf, scale. = T)

pcx <- paste0("PC", principal_component_on_x_axis)
pcy <- paste0("PC", principal_component_on_y_axis)
Expand Down
2 changes: 1 addition & 1 deletion man/counts_dat_to_matrix.Rd

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

15 changes: 10 additions & 5 deletions man/create_reneeDataSet_from_dataframes.Rd

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

22 changes: 16 additions & 6 deletions man/create_reneeDataSet_from_files.Rd

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

64 changes: 64 additions & 0 deletions man/filter_counts.Rd

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

23 changes: 0 additions & 23 deletions man/filter_low_counts.Rd

This file was deleted.

Loading

0 comments on commit 3a0120e

Please sign in to comment.