Skip to content

Commit

Permalink
remove data.table and R.utils
Browse files Browse the repository at this point in the history
  • Loading branch information
kriemo committed Jan 23, 2024
1 parent 13ce89c commit c1498d6
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
6 changes: 2 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: raer
Type: Package
Title: RNA editing tools in R
Version: 1.1.3
Version: 1.1.2
Authors@R: c(
person("Kent", "Riemondy", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-0750-1273")),
Expand All @@ -22,7 +22,6 @@ License: MIT + file LICENSE
Imports:
stats,
methods,
data.table,
GenomicRanges,
IRanges,
Rsamtools,
Expand All @@ -38,7 +37,6 @@ Imports:
BiocParallel,
rtracklayer,
Matrix,
R.utils,
cli
Suggests:
testthat (>= 3.0.0),
Expand All @@ -65,7 +63,7 @@ SystemRequirements:
VignetteBuilder: knitr
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.0
URL: https://rnabioco.github.io/raer, https://github.com/rnabioco/raer
BugReports: https://github.com/rnabioco/raer/issues
biocViews:
Expand Down
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ importFrom(IRanges,extractList)
importFrom(IRanges,subsetByOverlaps)
importFrom(Matrix,colSums)
importFrom(Matrix,sparseMatrix)
importFrom(R.utils,gzip)
importFrom(Rsamtools,BamFile)
importFrom(Rsamtools,BamFileList)
importFrom(Rsamtools,FaFile)
Expand All @@ -71,7 +70,6 @@ importFrom(Rsamtools,seqinfo)
importFrom(S4Vectors,aggregate)
importFrom(S4Vectors,unstrsplit)
importFrom(SingleCellExperiment,SingleCellExperiment)
importFrom(data.table,fread)
importFrom(methods,"slot<-")
importFrom(methods,as)
importFrom(methods,is)
Expand Down
13 changes: 6 additions & 7 deletions R/sc-pileup.R
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ get_sc_pileup <- function(bamfn, index, id, sites, barcodes,
#' intervals, whereas `index`` will only add row indices to the rownames.
#' @returns a `SingleCellExperiment` object populated with `nRef` and `nAlt`
#' assays.
#'
#'
#' @importFrom utils read.table
#' @examples
#' library(Rsamtools)
#' library(GenomicRanges)
Expand All @@ -359,18 +360,16 @@ get_sc_pileup <- function(bamfn, index, id, sites, barcodes,
#'
#' unlink(bai)
#'
#' @importFrom data.table fread
#' @importFrom Matrix sparseMatrix
#' @importFrom SingleCellExperiment SingleCellExperiment
#' @importFrom R.utils gzip
#' @export
read_sparray <- function(mtx_fn, sites_fn, bc_fn,
site_format = c("coordinate", "index")) {
if (!file.size(sites_fn) > 0) {
return(SingleCellExperiment::SingleCellExperiment())
}

rnames <- data.table::fread(sites_fn,
rnames <- read.table(sites_fn,
sep = "\t",
col.names = c(
"index", "seqnames", "start",
Expand All @@ -380,7 +379,7 @@ read_sparray <- function(mtx_fn, sites_fn, bc_fn,
"integer", "character", "integer",
"integer", "character", "character"
),
data.table = FALSE
row.names = NULL
)
site_format <- match.arg(site_format)

Expand All @@ -404,7 +403,7 @@ read_sparray <- function(mtx_fn, sites_fn, bc_fn,
n_sp_cols <- 2 + length(sp_mtx_names)

if (file.size(mtx_fn) > 0) {
dt <- data.table::fread(mtx_fn,
dt <- read.table(mtx_fn,
sep = " ",
colClasses = "integer",
skip = n_skip,
Expand Down Expand Up @@ -443,6 +442,7 @@ read_sparray <- function(mtx_fn, sites_fn, bc_fn,
res
}

#' @importFrom utils write.table
write_sparray <- function(sce, mtx_fn, sites_fn, bc_fn) {
if (!all(c("nRef", "nAlt") %in% assayNames(sce))) {
cli::cli_abort("missing required asssays nRef or nAlt")
Expand Down Expand Up @@ -474,7 +474,6 @@ write_sparray <- function(sce, mtx_fn, sites_fn, bc_fn) {
mtx_fn
)

mtx <- matrix(0L, nrow = dim(nref_trpl)[1], ncol = 4L)
mtx <- cbind(nref_trpl, nalt = nalt_trpl$x)

write.table(mtx,
Expand Down
7 changes: 4 additions & 3 deletions man/find_de_sites.Rd

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

2 changes: 1 addition & 1 deletion man/raer.Rd

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

20 changes: 12 additions & 8 deletions tests/testthat/test_aei.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pkgs <- c("Rsamtools", "data.table", "Biostrings")
pkgs <- c("Rsamtools", "Biostrings")
msg <- lapply(pkgs, function(x) {
suppressPackageStartupMessages(library(x, character.only = TRUE))
})
Expand Down Expand Up @@ -29,13 +29,17 @@ test_that("calc_aei basic options work", {
expect_true(ag_aei["wt"] > ag_aei["ko"])

x <- aei$AEI_per_chrom
setDT(x)
pc_aei <- x[, 100 * (sum(alt) / sum(alt + ref)), by = .(allele, bam_file)]
pc_aei <- dcast(pc_aei, bam_file ~ allele, value.var = "V1")
pc_aei <- as.data.frame(pc_aei)
rownames(pc_aei) <- pc_aei$bam_file
pc_aei$bam_file <- NULL
expect_true(identical(pc_aei, as.data.frame(aei$AEI)))
xx <- lapply(split(x, ~ allele + bam_file), function(x) {
xx <- 100 * (sum(x$alt) / sum(x$alt + x$ref))
data.frame(allele = unique(x$allele),
bam_file = unique(x$bam_file),
total = xx)
}) |> do.call(rbind, args = _)
xx <- reshape(xx, idvar = c("bam_file"), v.names = "total", timevar = "allele", direction = "wide")
rownames(xx) <- xx$bam_file
xx$bam_file <- NULL
colnames(xx) <- sub("total.", "", colnames(xx))
expect_true(identical(data.frame(xx), as.data.frame(aei$AEI)))

aei <- calc_AEI(unname(bams), fafn, mock_alu_ranges)
expect_true(all(rownames(aei$AEI) == unname(bams)))
Expand Down

0 comments on commit c1498d6

Please sign in to comment.