Skip to content

Commit

Permalink
Adjusted Vignettes and removed unnecessary dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Piechotta committed Feb 12, 2022
1 parent 1757de2 commit 9fbe3d2
Show file tree
Hide file tree
Showing 12 changed files with 383 additions and 237 deletions.
14 changes: 6 additions & 8 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Package: JACUSA2helper
Type: Package
Title: Post-processing for JACUSA2 output
Version: 1.9.9.9100
Version: 1.9.9.9200
Depends: R (>= 3.5)
Date: 2022-01-26
Date: 2022-02-11
Authors@R: c(person("Michael", "Piechotta", email = "[email protected]", role = c("aut", "cre")),
person("Qi", "Wang", role = c("ctb")),
person("Christoph", "Dieterich", role = c("ctb")),
person("Dieterich Lab", role = c("fnd")))
Description: This package enables post-processing of JACUSA2 output: read, filter, plot, write.
Description: This package enables post-processing of JACUSA2 output: read, filter, and plot.
URL: https://github.com/dieterich-lab/JACUSA2helper, https://dieterich-lab.github.io/JACUSA2helper/
BugReports: https://github.com/dieterich-lab/JACUSA2helper/issues
License: GPL-3 + file LICENSE
Expand All @@ -18,27 +18,25 @@ LazyData: true
LazyDataCompression: bzip2
biocViews:
Imports:
curl,
data.table,
tibble,
tidyr,
dplyr,
rlang,
magrittr,
stringr,
Rcpp,
GenomicRanges,
IRanges,
plyranges,
methods
plyranges
Suggests:
ggplot2,
scales,
Rsamtools,
testthat (>= 2.1.0),
knitr,
VennDiagram,
reshape2,
rmarkdown,
markdown,
NMF,
BSgenome,
BSgenome.Hsapiens.NCBI.GRCh38
Expand Down
3 changes: 0 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ export(clean_tag)
export(coverage)
export(expand_tag)
export(extend)
export(extract_info)
export(extract_score)
export(fast_unpack_info)
export(filter_artefact)
export(gather_repl)
Expand All @@ -38,5 +36,4 @@ export(variant_bc)
export(write_bedGraph)
importFrom(Rcpp,sourceCpp)
importFrom(magrittr,"%>%")
importFrom(methods,as)
useDynLib(JACUSA2helper, .registration = TRUE)
33 changes: 0 additions & 33 deletions R/indel-ratio.R

This file was deleted.

45 changes: 33 additions & 12 deletions R/io.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,32 @@
#'
#' \code{read_result()} reads data that was generated by JACUSA2 and creates a JACUSA2 result object.
#'
#' @param file String that represents the file name of the JACUSA2 output.
#' @param file String that represents the file name of the JACUSA2 output or an URL.
#' @param cond_desc Vector of strings that represent names/descriptions for conditions.
#' @param unpack Boolean indicates if info column should be processed.
#' @param ... parameters forwarded to `data.table::fread`
#' @param tmpdir String @see `data.table::fread`.
#' @param showProgress Boolean @see `data.table::fread`.
#' @param ... parameters forwarded to `data.table::fread`.
#'
#' @importFrom magrittr %>%
#'
#' @export
read_result <- function(file, cond_desc = c(), unpack = FALSE, ...) {
read_result <- function(file, cond_desc = c(), unpack = FALSE, tmpdir = tempdir(), showProgress = FALSE, ...) {
# if url download first
if (grepl("ftp://|http://", file)) {
# partly adopted from data.table::fread
tmpFile <- tempfile(tmpdir = tmpdir)
if (! requireNamespace("curl", quietly = TRUE))
stop("Input URL requires https:// connection for which fread() requires 'curl' package which cannot be found. Please install 'curl' using 'install.packages('curl')'.")

tmpFile = tempfile(fileext = paste0(".", tools::file_ext(file)), tmpdir = tmpdir)
curl::curl_download(file, tmpFile, mode = "wb", quiet = ! showProgress)
file = tmpFile
on.exit(unlink(file), add = TRUE)
}

# pre process file
# parse comments ^(#|##) to determine result/method type and number of conditions
# parse comments ^(#|##) to determine result/method type and number of conditions
fun <- ifelse(grepl('\\.gz$', file), base::gzfile, base::file)
con <- fun(file, "r")
cond_count <- 0
Expand Down Expand Up @@ -196,15 +211,21 @@ base_call <-function(bases) {
.matches <- function(df, prefixes, cond_count) {
# regex parts:
prefix_regex = paste0("^(", paste0(prefixes, collapse = "|"), ")")
cond_regex = paste0("([:digit:]{", nchar(cond_count), "})")
repl_regex = "([:digit:]+)"
cond_regex = paste0("([0-9]{", nchar(cond_count), "})")
repl_regex = "([0-9]+)"

# get relevant cols and disect to m(atch):
# match, base_type, condition, replicate
cols <- stringr::str_subset(names(df), paste0(prefix_regex, cond_regex, repl_regex))
m <- stringr::str_match(
cols,
paste0(prefix_regex, cond_regex, repl_regex)
cols <- grep(paste0(prefix_regex, cond_regex, repl_regex), names(df), value = TRUE)
m <- do.call(
rbind,
regmatches(names(df), regexec(paste0(prefix_regex, cond_regex, repl_regex), names(df)))
)

col_names <- c("col", "prefix", "cond", "repl")
if (ncol(m) != length(col_names)) {
m <- matrix(character(), 0, length(col_names))
}
colnames(m) <- c("col", "prefix", "cond", "repl")
matches <- as.data.frame(m, stringsAsFactors = FALSE)

Expand Down Expand Up @@ -381,7 +402,6 @@ unpack_info <- function(info, cond_count, keys=get_info_keys(info)) {
#' @param meta_conds Vector of string vectors that explain files.
#' @param cond_descs Vector of strings that represent names/descriptions for conditions.
#' @param unpack Boolean indicates if info column should be processed.
#' @importFrom methods as
#' @export
read_results <- function(files, meta_conds, cond_descs = replicate(length(files), c()), unpack = FALSE) {
stopifnot(length(files) == length(meta_conds))
Expand All @@ -401,7 +421,8 @@ read_results <- function(files, meta_conds, cond_descs = replicate(length(files)
types <- lapply(l, "[[", 2) %>% unlist(use.names = FALSE)

# combine read files
results <- unlist(as(lapply(l, "[[", 1), "GRangesList"))
#results <- unlist(as(lapply(l, "[[", 1), "GRangesList"))
results <- unlist(GenomicRanges::GRangesList(lapply(l, "[[", 1)))
results$meta_cond <- as.factor(results$meta_cond)

attr(results, .ATTR_TYPE) <- types
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ Check vignettes:
* `vignette("Introduction to JACUSA2helper")`
* `vignette("Analysis of DART-seq with JACUSA2helper")`
* `vignette("Analysis of m6A mapping by MazF with JACUSA2helper")`
* `vignette("Analysis of Nanopore HEK293 with JACUSA2helper")`
* `vignette("Introduction to meta conditions with JACUSA2helper")`
# * `vignette("Introduction to meta conditions with JACUSA2helper")`
19 changes: 0 additions & 19 deletions man/extract_info.Rd

This file was deleted.

19 changes: 0 additions & 19 deletions man/extract_score.Rd

This file was deleted.

17 changes: 14 additions & 3 deletions man/read_result.Rd

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

2 changes: 1 addition & 1 deletion vignettes/JACUSA2helper-dart-seq.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ We observe a lot more C-to-U transitions in the active YTH binding domain as com

```{r}
tidyr::tibble(
base_sub = c(ref2YTH,ref2YTHmut),
base_sub = c(ref2YTH, ref2YTHmut),
Source = c(
rep("YTH",length(ref2YTH)),
rep("YTHmut",length(ref2YTHmut)))
Expand Down
Loading

0 comments on commit 9fbe3d2

Please sign in to comment.