Skip to content

Commit

Permalink
Merge pull request #10 from CCBR/iss-2
Browse files Browse the repository at this point in the history
Create filter_low_counts()
  • Loading branch information
kelly-sovacool authored Dec 23, 2023
2 parents 23b7d5e + 85f4703 commit a996d49
Show file tree
Hide file tree
Showing 19 changed files with 59,124 additions and 28 deletions.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
^\.github$
^README\.Rmd$
^\.pre-commit-config\.yaml$
^\.prettierignore$
^\.prettierrc$
^data-raw$
5 changes: 4 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ default_stages: [pre-commit]
exclude: |
(?x)(
^assets/|
^docs/.*.html
^docs/.*.html|
^data-raw/*.txt|
^man/
)
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v1.2.3
hooks:
- id: check-added-large-files
args: ["--maxkb=12000"]
- id: end-of-file-fixer
- id: trailing-whitespace
# spell check
Expand Down
10 changes: 10 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# gitignore
.nextflow*
work/
data/
results/
.DS_Store
*.code-workspace
assets/*.html
data-raw/*.txt
man/*
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
overrides:
- files: "*.md"
options:
tabWidth: 2
7 changes: 7 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@ License: MIT + file LICENSE
URL: https://github.com/CCBR/reneeTools,
https://ccbr.github.io/reneeTools/
BugReports: https://github.com/CCBR/reneeTools/issues
Depends:
R (>= 2.10)
Imports:
dplyr,
tidyr
Suggests:
readr,
testthat (>= 3.0.0)
Config/testthat/edition: 3
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export(filter_low_counts)
export(read_raw_counts)
importFrom(dplyr,"%>%")
6 changes: 4 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# reneeTools development version
# reneeTools 0.1.0

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

# reneeTools 0.1.0
## New functions

- `filter_low_counts()` (#10)
8 changes: 8 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#' RSEM gene counts
#'
#' @format ## `gene_counts`
#' A data frame with columns 'gene_id', 'GeneName', and a column for each sample's count.
#'
#' @source Generated by running RENEE v2.5.8 on the
#' [test dataset](https://github.com/CCBR/RENEE/tree/e08f7db6c6e638cfd330caa182f64665d2ef37fa/.tests)
"gene_counts"
30 changes: 20 additions & 10 deletions R/filter_low_counts.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
#' filter_low_counts
#'
#' @param raw_counts_matrix raw_counts_matrix object
#' @param min_counts integer number of min_counts across all samples, default 0
#' @param min_cpm float minimum cpm value, default 0
#' @param min_cpm_fraction float fraction of samples that need to satisfy min_cpm filter, default 1.0
#' @param counts_dat dataframe of expected gene counts from RSEM
#' @param min_counts integer number of minimum counts across all samples (default: 0)
#'
#' @return filtered_raw_count_matrix
#' @return filtered counts dataframe
#' @export
#'
#' @examples
#' filter_low_counts(gene_counts) %>% head()
#' filter_low_counts(gene_counts, min_counts = 100)
filter_low_counts <- function(
raw_counts_matrix,
min_counts = 0,
min_cpm = 0,
min_cpm_fraction = 1.0) {

counts_dat,
min_counts = 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::pull(gene_id)
return(
counts_dat %>%
dplyr::filter(gene_id %in% (genes_above_threshold))
)
}
4 changes: 4 additions & 0 deletions R/reexports.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#' dplyr pipe
#' @importFrom dplyr %>%
#' @export
dplyr::`%>%`
11 changes: 11 additions & 0 deletions R/reneeTools-package.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#' reneeTools: R helper functions for RENEE
#'
#' `reneeTools` implements helper functions for RENEE, a comprehensive
#' quality-control and quantification RNA-seq pipeline
#'
#' @keywords internal
"_PACKAGE"

## usethis namespace: start
## usethis namespace: end
NULL
Loading

0 comments on commit a996d49

Please sign in to comment.