diff --git a/.gitignore b/.gitignore index 457525e..8a6f2db 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ .DS_Store .quarto docs +inst/doc diff --git a/CITATION.cff b/CITATION.cff index 6609958..8811f15 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -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:' @@ -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 @@ -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" @@ -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: xie@yihui.name + orcid: https://orcid.org/0000-0003-0645-5666 + year: "2024" - type: software title: readr abstract: "readr: Read Rectangular Text Data" @@ -142,6 +152,49 @@ references: email: jenny@posit.co 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: jj@posit.co + - family-names: Xie + given-names: Yihui + email: xie@yihui.name + orcid: https://orcid.org/0000-0003-0645-5666 + - family-names: Dervieux + given-names: Christophe + email: cderv@posit.co + orcid: https://orcid.org/0000-0003-4474-2498 + - family-names: McPherson + given-names: Jonathan + email: jonathan@posit.co + - family-names: Luraschi + given-names: Javier + - family-names: Ushey + given-names: Kevin + email: kevin@posit.co + - family-names: Atkins + given-names: Aron + email: aron@posit.co + - family-names: Wickham + given-names: Hadley + email: hadley@posit.co + - family-names: Cheng + given-names: Joe + email: joe@posit.co + - family-names: Chang + given-names: Winston + email: winston@posit.co + - family-names: Iannone + given-names: Richard + email: rich@posit.co + orcid: https://orcid.org/0000-0003-3925-190X + year: "2024" - type: software title: styler abstract: "styler: Non-Invasive Pretty Printing of R Code" diff --git a/DESCRIPTION b/DESCRIPTION index f3896e3..0aab490 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 diff --git a/NAMESPACE b/NAMESPACE index fedbab0..c6031cb 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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,"%>%") diff --git a/NEWS.md b/NEWS.md index 4b57317..5870ad3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# reneeTools development version +# reneeTools development version 0.0.0.9000 This is the first release of reneeTools 🎉 @@ -6,8 +6,8 @@ This is the first release of reneeTools 🎉 ## 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) diff --git a/R/renee-class.R b/R/0_renee-class.R similarity index 62% rename from R/renee-class.R rename to R/0_renee-class.R index f908a68..2d2dedd 100644 --- a/R/renee-class.R +++ b/R/0_renee-class.R @@ -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() ) @@ -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 @@ -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)) } diff --git a/R/deseq2.R b/R/deseq2.R index 4c4654c..2600f15 100644 --- a/R/deseq2.R +++ b/R/deseq2.R @@ -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" @@ -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) } diff --git a/R/filter_low_counts.R b/R/filter_low_counts.R index 6d32e54..7a90855 100644 --- a/R/filter_low_counts.R +++ b/R/filter_low_counts.R @@ -1,17 +1,17 @@ #' 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"), @@ -19,7 +19,7 @@ filter_low_counts <- function( ) %>% 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 %>% diff --git a/R/zzz.R b/R/zzz.R index 3a6f2a2..d01a195 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -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 diff --git a/man/reneeDataSetFromDataFrames.Rd b/man/create_reneeDataSet_from_dataframes.Rd similarity index 65% rename from man/reneeDataSetFromDataFrames.Rd rename to man/create_reneeDataSet_from_dataframes.Rd index f2f959d..e38d248 100644 --- a/man/reneeDataSetFromDataFrames.Rd +++ b/man/create_reneeDataSet_from_dataframes.Rd @@ -1,13 +1,13 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/renee-class.R -\name{reneeDataSetFromDataFrames} -\alias{reneeDataSetFromDataFrames} +% Please edit documentation in R/0_renee-class.R +\name{create_reneeDataSet_from_dataframes} +\alias{create_reneeDataSet_from_dataframes} \title{Construct a reneeDataSet object from data frames} \usage{ -reneeDataSetFromDataFrames(gene_counts_dat, sample_meta_dat) +create_reneeDataSet_from_dataframes(count_dat, sample_meta_dat) } \arguments{ -\item{gene_counts_dat}{expected gene counts from RSEM as a data frame or tibble. +\item{count_dat}{expected gene counts from RSEM as a data frame or tibble. Must contain a \code{gene_id} column and a column for each sample ID in the metadata.} \item{sample_meta_dat}{sample metadata as a data frame or tibble. @@ -27,5 +27,5 @@ sample_meta <- data.frame( levels = c("wildtype", "knockout") ) ) -reneeDataSetFromDataFrames(gene_counts, sample_meta) +create_reneeDataSet_from_dataframes(gene_counts, sample_meta) } diff --git a/man/reneeDataSetFromFiles.Rd b/man/create_reneeDataSet_from_files.Rd similarity index 71% rename from man/reneeDataSetFromFiles.Rd rename to man/create_reneeDataSet_from_files.Rd index 5ecffe1..c5d3595 100644 --- a/man/reneeDataSetFromFiles.Rd +++ b/man/create_reneeDataSet_from_files.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/renee-class.R -\name{reneeDataSetFromFiles} -\alias{reneeDataSetFromFiles} +% Please edit documentation in R/0_renee-class.R +\name{create_reneeDataSet_from_files} +\alias{create_reneeDataSet_from_files} \title{Construct a reneeDataSet object from tsv files.} \usage{ -reneeDataSetFromFiles(gene_counts_filepath, sample_meta_filepath) +create_reneeDataSet_from_files(gene_counts_filepath, sample_meta_filepath) } \arguments{ \item{gene_counts_filepath}{path to tsv file of expected gene counts from RSEM.} @@ -18,7 +18,7 @@ reneeDataSet object Construct a reneeDataSet object from tsv files. } \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") ) diff --git a/man/filter_low_counts.Rd b/man/filter_low_counts.Rd index d83cdc4..c4bd1cd 100644 --- a/man/filter_low_counts.Rd +++ b/man/filter_low_counts.Rd @@ -4,12 +4,12 @@ \alias{filter_low_counts} \title{filter_low_counts} \usage{ -filter_low_counts(counts_dat, min_counts = 0) +filter_low_counts(counts_dat, min_count = 0) } \arguments{ \item{counts_dat}{expected gene counts from RSEM as a data frame or tibble} -\item{min_counts}{integer number of minimum counts across all samples (default: 0)} +\item{min_count}{integer number of minimum counts across all samples (default: 0)} } \value{ filtered counts dataframe @@ -19,5 +19,5 @@ filter_low_counts } \examples{ filter_low_counts(gene_counts) \%>\% head() -filter_low_counts(gene_counts, min_counts = 100) +filter_low_counts(gene_counts, min_count = 100) } diff --git a/man/reneeDataSet.Rd b/man/reneeDataSet.Rd new file mode 100644 index 0000000..f319ab0 --- /dev/null +++ b/man/reneeDataSet.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/0_renee-class.R +\name{reneeDataSet} +\alias{reneeDataSet} +\title{reneeDataSet class} +\usage{ +reneeDataSet(count_dat, sample_meta_dat) +} +\arguments{ +\item{count_dat}{expected gene counts from RSEM as a data frame or tibble. +Must contain a \code{gene_id} column and a column for each sample ID in the metadata.} + +\item{sample_meta_dat}{sample metadata as a data frame or tibble. +Must contain a \code{sample_ID} column.} +} +\description{ +reneeDataSet class +} diff --git a/man/run_deseq2.Rd b/man/run_deseq2.Rd index 39732a4..8752bfe 100644 --- a/man/run_deseq2.Rd +++ b/man/run_deseq2.Rd @@ -20,7 +20,7 @@ reneeDataSet object with DESeq2 slot filled Run DESeq2 on a reneeDataSet } \examples{ -renee_ds <- reneeDataSetFromFiles( +renee_ds <- create_reneeDataSet_from_files( system.file("extdata", "RSEM.genes.expected_count.all_samples.txt", package = "reneeTools" diff --git a/tests/testthat/test-0_renee-class.R b/tests/testthat/test-0_renee-class.R new file mode 100644 index 0000000..6454aa9 --- /dev/null +++ b/tests/testthat/test-0_renee-class.R @@ -0,0 +1,52 @@ +test_that("reneeDataSet from files works", { + rds <- create_reneeDataSet_from_files( + system.file("extdata", "RSEM.genes.expected_count.all_samples.txt", package = "reneeTools"), + system.file("extdata", "sample_metadata.tsv", package = "reneeTools") + ) + expect_equal( + rds@counts %>% head(), + structure( + list( + gene_id = c( + "ENSG00000121410.11", + "ENSG00000268895.5", + "ENSG00000148584.15", + "ENSG00000175899.14", + "ENSG00000245105.3", + "ENSG00000166535.20" + ), + GeneName = c( + "A1BG", "A1BG-AS1", "A1CF", + "A2M", "A2M-AS1", "A2ML1" + ), + KO_S3 = c(0, 0, 0, 0, 0, 0), + KO_S4 = c(0, 0, 0, 0, 0, 0), + WT_S1 = c(0, 0, 0, 0, 0, 0), + WT_S2 = c(0, 0, 0, 0, 0, 0) + ), + row.names = c(NA, -6L), + class = c("tbl_df", "tbl", "data.frame") + ) + ) + expect_equal( + rds@sample_meta, + structure(list(condition = c( + "knockout", "knockout", "wildtype", + "wildtype" + )), row.names = c("KO_S3", "KO_S4", "WT_S1", "WT_S2"), class = "data.frame") + ) +}) + +test_that("reneeDataSet from data frames detect problems", { + sample_meta <- data.frame( + sample_id = c("KO_S3", "KO_S4", "WT_S1", "WT_S2"), + condition = factor( + c("knockout", "knockout", "wildtype", "wildtype"), + levels = c("wildtype", "knockout") + ) + ) + expect_error( + create_reneeDataSet_from_dataframes(gene_counts[, 1:4], sample_meta), + "Not all columns" + ) +}) diff --git a/tests/testthat/test-deseq2.R b/tests/testthat/test-deseq2.R index c62e2cb..c61c4cc 100644 --- a/tests/testthat/test-deseq2.R +++ b/tests/testthat/test-deseq2.R @@ -1,6 +1,6 @@ set.seed(20231228) test_that("run_deseq2 works", { - renee_ds <- reneeDataSetFromFiles( + renee_ds <- create_reneeDataSet_from_files( system.file( "extdata", "RSEM.genes.expected_count.all_samples.txt", @@ -14,7 +14,8 @@ test_that("run_deseq2 works", { dplyr::mutate(condition = factor(condition, levels = c("wildtype", "knockout") )) - renee_ds <- run_deseq2(renee_ds, design = ~condition, fitType = "local") + renee_ds <- + run_deseq2(renee_ds, design = ~condition, fitType = "local") dds <- renee_ds@analyses$deseq2_ds expect_equal( dds@colData %>% as.data.frame(), @@ -29,10 +30,10 @@ test_that("run_deseq2 works", { class = "factor" ), sizeFactor = c( - 0.759835685651593, - 0.718608223926169, - 1.24466595457696, - 1.68179283050743 + 0.739974960000608, + 0.717118872451827, + 1.34164078649987, + 1.69303431346171 ) ), class = "data.frame", @@ -56,22 +57,18 @@ test_that("run_deseq2 works", { 104L, 0L, 8L ), - mu.1 = c(24.1516682192168, 13.3092987017581, 23.1890203839711), - mu.2 = c(22.8412375617529, 12.5871575689046, 21.9308214491443), - mu.3 = c(75.6181929866826, 0.158242295472865, 7.74702804399805), - mu.4 = c(102.175314069834, 0.213817014139956, 10.4677854923446), - H.1 = c(0.511844332569779, 0.504138999697003, 0.50668916671393), - H.2 = c(0.48815561528062, 0.495860729372594, 0.493310737076545), - H.3 = c(0.454896663393873, 0.499997728127273, 0.447711231007698), - H.4 = c(0.545103297274594, 0.499997728127273, 0.552288438770429), - cooks.1 = c( - 0.00787282712563543, - 0.0262422886768066, - 0.0478403297046226 - ), - cooks.2 = c(0.00740399240405431, 0.025741204681852, 0.0464156166543046), - cooks.3 = c(0.00250160501520332, 0.127533456822227, 0.0779681548830785), - cooks.4 = c(0.00307311736197857, 0.161328557073165, 0.100411826759898) + mu.1 = c(23.8682703018296, 13.1709993621292, 22.8847421174049), + mu.2 = c(23.131035523431, 12.7641781441173, 22.1778862132993), + mu.3 = c(78.660598086526, 0.163744933328453, 8.02129153499216), + mu.4 = c(99.2628526338571, 0.20663190443383, 10.1221742389411), + H.1 = c(0.507689382133648, 0.502052019764842, 0.503779946658291), + H.2 = c(0.492310572696009, 0.497947673454118, 0.496219957488281), + H.3 = c(0.446124908477968, 0.499997692127505, 0.459429993613616), + H.4 = c(0.553875066333655, 0.499997692127505, 0.540569676700414), + cooks.1 = c(0.0157542703049353, 0.0289351707384892, 0.0400561954057841), + cooks.2 = c(0.0151418002975461, 0.0286548510838955, 0.0393806789741918), + cooks.3 = c(0.0212216674791077, 0.130797161405866, 0.058560061396526), + cooks.4 = c(0.026938300726748, 0.156792088506772, 0.0711568961752663) ), class = "data.frame", row.names = c( diff --git a/tests/testthat/test-filter_low_counts.R b/tests/testthat/test-filter_low_counts.R index 441d338..f744c95 100644 --- a/tests/testthat/test-filter_low_counts.R +++ b/tests/testthat/test-filter_low_counts.R @@ -8,7 +8,7 @@ test_that("filter_low_counts works", { ) expect_equal(filter_low_counts(test_dat), test_dat) expect_equal( - filter_low_counts(test_dat, min_counts = 1), + filter_low_counts(test_dat, min_count = 1), data.frame( gene_id = c("B", "C"), GeneName = c("geneB", "geneC"), @@ -16,14 +16,14 @@ test_that("filter_low_counts works", { ) ) expect_equal( - filter_low_counts(test_dat, min_counts = 2), + filter_low_counts(test_dat, min_count = 2), data.frame( gene_id = "C", GeneName = "geneC", s1 = 0, s2 = 0, s3 = 3 ) ) expect_equal( - filter_low_counts(test_dat, min_counts = 5), + filter_low_counts(test_dat, min_count = 5), data.frame( gene_id = character(0), GeneName = character(0), diff --git a/tests/testthat/test-read_raw_counts.R b/tests/testthat/test-read_raw_counts.R deleted file mode 100644 index 4e547c4..0000000 --- a/tests/testthat/test-read_raw_counts.R +++ /dev/null @@ -1,3 +0,0 @@ -test_that("multiplication works", { - expect_equal(2 * 2, 4) # TODO write real tests -}) diff --git a/tests/testthat/test-renee-class.R b/tests/testthat/test-renee-class.R deleted file mode 100644 index 9193620..0000000 --- a/tests/testthat/test-renee-class.R +++ /dev/null @@ -1,39 +0,0 @@ -test_that("reneeDataSetFromFiles works", { - rds <- reneeDataSetFromFiles( - system.file("extdata", "RSEM.genes.expected_count.all_samples.txt", package = "reneeTools"), - system.file("extdata", "sample_metadata.tsv", package = "reneeTools") - ) - expect_equal( - rds@counts %>% head(), - structure(c( - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, - 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L - ), dim = c(6L, 4L), dimnames = list( - c( - "ENSG00000121410.11", "ENSG00000268895.5", "ENSG00000148584.15", - "ENSG00000175899.14", "ENSG00000245105.3", "ENSG00000166535.20" - ), c("KO_S3", "KO_S4", "WT_S1", "WT_S2") - )) - ) - expect_equal( - rds@sample_meta, - structure(list(condition = c( - "knockout", "knockout", "wildtype", - "wildtype" - )), row.names = c("KO_S3", "KO_S4", "WT_S1", "WT_S2"), class = "data.frame") - ) -}) - -test_that("reneeDataSetFromDataFrames detect problems", { - sample_meta <- data.frame( - sample_id = c("KO_S3", "KO_S4", "WT_S1", "WT_S2"), - condition = factor( - c("knockout", "knockout", "wildtype", "wildtype"), - levels = c("wildtype", "knockout") - ) - ) - expect_error( - reneeDataSetFromDataFrames(gene_counts[, 1:4], sample_meta), - "Not all columns" - ) -}) diff --git a/vignettes/.gitignore b/vignettes/.gitignore new file mode 100644 index 0000000..097b241 --- /dev/null +++ b/vignettes/.gitignore @@ -0,0 +1,2 @@ +*.html +*.R diff --git a/vignettes/intro.Rmd b/vignettes/intro.Rmd new file mode 100644 index 0000000..b146553 --- /dev/null +++ b/vignettes/intro.Rmd @@ -0,0 +1,29 @@ +--- +title: "intro" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{intro} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +```{r setup} +library(reneeTools) +library(dplyr) +# replace this line with actual path to your gene counts +gene_counts_tsv <- system.file("extdata", "RSEM.genes.expected_count.all_samples.txt", package = "reneeTools") +metadata_tsv <- system.file("extdata", "sample_metadata.tsv", package = "reneeTools") + +# create reneeDataSet object +renee_ds <- create_reneeDataSet_from_files(gene_counts_tsv, metadata_tsv) %>% + run_deseq2(design = ~condition) + +renee_ds@analyses$deseq2_results %>% head() +```