Skip to content

Commit

Permalink
Merge pull request #28 from CCBR/vignette
Browse files Browse the repository at this point in the history
Create beginnings of introductory vignette
  • Loading branch information
kelly-sovacool authored Apr 24, 2024
2 parents 18d7148 + 8d6a16a commit f9c5894
Show file tree
Hide file tree
Showing 21 changed files with 255 additions and 123 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
.DS_Store
.quarto
docs
inst/doc
67 changes: 60 additions & 7 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -----------------------------------------------------------
# CITATION file created with {cffr} R package, v0.5.0
# --------------------------------------------
# CITATION file created with {cffr} R package
# See also: https://docs.ropensci.org/cffr/
# -----------------------------------------------------------
# --------------------------------------------

cff-version: 1.2.0
message: 'To cite package "reneeTools" in publications use:'
Expand Down Expand Up @@ -33,11 +33,10 @@ references:
url: https://www.R-project.org/
authors:
- name: R Core Team
location:
name: Vienna, Austria
year: "2024"
institution:
name: R Foundation for Statistical Computing
address: Vienna, Austria
year: "2024"
version: ">= 2.10"
- type: software
title: DESeq2
Expand All @@ -56,7 +55,6 @@ references:
- family-names: Huber
given-names: Wolfgang
year: "2024"
doi: 10.18129/B9.bioc.DESeq2
- type: software
title: dplyr
abstract: "dplyr: A Grammar of Data Manipulation"
Expand Down Expand Up @@ -125,6 +123,18 @@ references:
- family-names: Girlich
given-names: Maximilian
year: "2024"
- type: software
title: knitr
abstract: "knitr: A General-Purpose Package for Dynamic Report Generation in R"
notes: Suggests
url: https://yihui.org/knitr/
repository: https://CRAN.R-project.org/package=knitr
authors:
- family-names: Xie
given-names: Yihui
email: [email protected]
orcid: https://orcid.org/0000-0003-0645-5666
year: "2024"
- type: software
title: readr
abstract: "readr: Read Rectangular Text Data"
Expand All @@ -142,6 +152,49 @@ references:
email: [email protected]
orcid: https://orcid.org/0000-0002-6983-2759
year: "2024"
- type: software
title: rmarkdown
abstract: "rmarkdown: Dynamic Documents for R"
notes: Suggests
url: https://pkgs.rstudio.com/rmarkdown/
repository: https://CRAN.R-project.org/package=rmarkdown
authors:
- family-names: Allaire
given-names: JJ
email: [email protected]
- family-names: Xie
given-names: Yihui
email: [email protected]
orcid: https://orcid.org/0000-0003-0645-5666
- family-names: Dervieux
given-names: Christophe
email: [email protected]
orcid: https://orcid.org/0000-0003-4474-2498
- family-names: McPherson
given-names: Jonathan
email: [email protected]
- family-names: Luraschi
given-names: Javier
- family-names: Ushey
given-names: Kevin
email: [email protected]
- family-names: Atkins
given-names: Aron
email: [email protected]
- family-names: Wickham
given-names: Hadley
email: [email protected]
- family-names: Cheng
given-names: Joe
email: [email protected]
- family-names: Chang
given-names: Winston
email: [email protected]
- family-names: Iannone
given-names: Richard
email: [email protected]
orcid: https://orcid.org/0000-0003-3925-190X
year: "2024"
- type: software
title: styler
abstract: "styler: Non-Invasive Pretty Printing of R Code"
Expand Down
6 changes: 5 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ Imports:
S7,
tidyr
Suggests:
knitr,
readr,
rmarkdown,
styler,
testthat (>= 3.0.0),
usethis
VignetteBuilder:
knitr
biocViews:
Config/testthat/edition: 3
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.0
RoxygenNote: 7.3.1
5 changes: 3 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

export("%>%")
export(counts_dat_to_matrix)
export(create_reneeDataSet_from_dataframes)
export(create_reneeDataSet_from_files)
export(filter_low_counts)
export(meta_tbl_to_dat)
export(reneeDataSetFromDataFrames)
export(reneeDataSetFromFiles)
export(run_deseq2)
if (getRversion() < "4.3.0") importFrom("S7", "@")
importFrom(DESeq2,DESeq)
importFrom(dplyr,"%>%")
12 changes: 6 additions & 6 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# reneeTools development version
# reneeTools development version 0.0.0.9000

This is the first release of reneeTools 🎉

- Create a `NEWS.md` file to track changes to the package.

## Main functions & classes

- `reneeDataSet` (#16)
- `reneeDataSetFromFiles()` (#16)
- `reneeDataSetFromDataFrames()` (#16)
- `run_deseq2()` (#16)
- `filter_low_counts()` (#10)
- `reneeDataSet` (#16, #28, @kelly-sovacool)
- `create_reneeDataSet_from_files()`
- `create_reneeDataSet_from_dataframes()`
- `run_deseq2()`
- `filter_low_counts()` (#10, @kelly-sovacool)
38 changes: 22 additions & 16 deletions R/renee-class.R → R/0_renee-class.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
#' reneeDataSet class
#'
#' @param count_dat expected gene counts from RSEM as a data frame or tibble.
#' Must contain a `gene_id` column and a column for each sample ID in the metadata.
#' @param sample_meta_dat sample metadata as a data frame or tibble.
#' Must contain a `sample_ID` column.
#'
#'
reneeDataSet <- S7::new_class("renee",
properties = list(
counts = S7::new_S3_class("matrix"),
counts = S7::class_data.frame,
sample_meta = S7::class_data.frame,
analyses = S7::class_list
),
constructor = function(count_matrix, sample_meta_dat) {
constructor = function(count_dat, sample_meta_dat) {
S7::new_object(S7::S7_object(),
counts = count_matrix,
counts = count_dat,
sample_meta = sample_meta_dat,
analyses = list()
)
Expand All @@ -22,22 +30,19 @@ reneeDataSet <- S7::new_class("renee",
#' @export
#'
#' @examples
#' reneeDataSetFromFiles(
#' create_reneeDataSet_from_files(
#' system.file("extdata", "RSEM.genes.expected_count.all_samples.txt", package = "reneeTools"),
#' system.file("extdata", "sample_metadata.tsv", package = "reneeTools")
#' )
reneeDataSetFromFiles <- function(gene_counts_filepath, sample_meta_filepath) {
create_reneeDataSet_from_files <- function(gene_counts_filepath, sample_meta_filepath) {
count_dat <- readr::read_tsv(gene_counts_filepath)
sample_meta_dat <- readr::read_tsv(sample_meta_filepath)
return(reneeDataSetFromDataFrames(count_dat, sample_meta_dat))
return(create_reneeDataSet_from_dataframes(count_dat, sample_meta_dat))
}

#' Construct a reneeDataSet object from data frames
#'
#' @param gene_counts_dat expected gene counts from RSEM as a data frame or tibble.
#' Must contain a `gene_id` column and a column for each sample ID in the metadata.
#' @param sample_meta_dat sample metadata as a data frame or tibble.
#' Must contain a `sample_ID` column.
#' @inheritParams reneeDataSet
#'
#' @return reneeDataSet object
#' @export
Expand All @@ -50,15 +55,16 @@ reneeDataSetFromFiles <- function(gene_counts_filepath, sample_meta_filepath) {
#' levels = c("wildtype", "knockout")
#' )
#' )
#' reneeDataSetFromDataFrames(gene_counts, sample_meta)
reneeDataSetFromDataFrames <- function(gene_counts_dat, sample_meta_dat) {
count_mat <- gene_counts_dat %>% counts_dat_to_matrix()
#' create_reneeDataSet_from_dataframes(gene_counts, sample_meta)
create_reneeDataSet_from_dataframes <- function(count_dat, sample_meta_dat) {
gene_id <- GeneName <- NULL

sample_meta_dat <- sample_meta_dat %>% meta_tbl_to_dat()

# sample IDs must be in the same order
if (!all(colnames(count_mat) == rownames(sample_meta_dat))) {
stop("Not all columns in the count matrix equal the rows in the sample metadata. Sample IDs must be in the same order.")
if (!all(colnames(count_dat %>% dplyr::select(-gene_id, -GeneName)) == rownames(sample_meta_dat))) {
stop("Not all columns in the count data equal the rows in the sample metadata. Sample IDs must be in the same order.")
}

return(reneeDataSet(count_mat, sample_meta_dat))
return(reneeDataSet(count_dat, sample_meta_dat))
}
15 changes: 10 additions & 5 deletions R/deseq2.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @export
#'
#' @examples
#' renee_ds <- reneeDataSetFromFiles(
#' renee_ds <- create_reneeDataSet_from_files(
#' system.file("extdata",
#' "RSEM.genes.expected_count.all_samples.txt",
#' package = "reneeTools"
Expand All @@ -18,12 +18,17 @@
#' )
#' )
#' renee_ds <- run_deseq2(renee_ds, ~condition)
run_deseq2 <- function(renee_ds, design, ...) {
run_deseq2 <- S7::new_generic("run_deseq2", "renee_ds", function(renee_ds, design, ...) {
S7::S7_dispatch()
})

S7::method(run_deseq2, reneeDataSet) <- function(renee_ds, design, min_count = 10, ...) {
dds <- DESeq2::DESeqDataSetFromMatrix(
renee_ds@counts,
renee_ds@sample_meta,
design
countData = renee_ds@counts %>% filter_low_counts(min_count = min_count) %>% counts_dat_to_matrix(),
colData = renee_ds@sample_meta,
design = design
)
renee_ds@analyses$deseq2_ds <- DESeq2::DESeq(dds, ...)
renee_ds@analyses$deseq2_results <- DESeq2::results(renee_ds@analyses$deseq2_ds)
return(renee_ds)
}
8 changes: 4 additions & 4 deletions R/filter_low_counts.R
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#' filter_low_counts
#'
#' @param counts_dat expected gene counts from RSEM as a data frame or tibble
#' @param min_counts integer number of minimum counts across all samples (default: 0)
#' @param min_count integer number of minimum counts across all samples (default: 0)
#'
#' @return filtered counts dataframe
#' @export
#'
#' @examples
#' filter_low_counts(gene_counts) %>% head()
#' filter_low_counts(gene_counts, min_counts = 100)
#' filter_low_counts(gene_counts, min_count = 100)
filter_low_counts <- function(
counts_dat,
min_counts = 0) {
min_count = 0) {
gene_id <- count <- count_sum <- NULL
genes_above_threshold <- counts_dat %>%
tidyr::pivot_longer(!c("gene_id", "GeneName"),
names_to = "sample_id", values_to = "count"
) %>%
dplyr::group_by(gene_id) %>%
dplyr::summarize(count_sum = sum(count)) %>%
dplyr::filter(count_sum >= min_counts) %>%
dplyr::filter(count_sum >= min_count) %>%
dplyr::pull(gene_id)
return(
counts_dat %>%
Expand Down
6 changes: 6 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@
# source: https://rconsortium.github.io/S7/articles/packages.html#backward-compatibility
#' @rawNamespace if (getRversion() < "4.3.0") importFrom("S7", "@")
NULL


# Suppress R CMD check note 'All declared Imports should be used'.
# These packages are used within S7 methods.
#' @importFrom DESeq2 DESeq
NULL

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

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

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

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

18 changes: 18 additions & 0 deletions man/reneeDataSet.Rd

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

Loading

0 comments on commit f9c5894

Please sign in to comment.