-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Hi, is it a desired behavior? Size of resulting data.table is very similar if you keep names as factor.
library(ORFik)
attach(loadNamespace(ORFik)
##only change is the if statement for keep.names within as.data.table if statement.
cpt_nm <- function (grl, reads, is.sorted = FALSE, keep.names = TRUE, as.data.table = FALSE,
withFrames = FALSE, weight = "score")
{
if (!is.sorted)
grl <- sortPerGroup(grl)
if (is.numeric(weight) | (weight[1] %in% colnames(mcols(reads)))) {
coverage <- coverageByTranscriptW(reads, grl, weight = weight)
}
else coverage <- coverageByTranscript(reads, grl)
if (!keep.names)
names(coverage) <- NULL
if (as.data.table) {
window_size <- unique(widthPerGroup(grl, FALSE))
count <- data.table(count = unlist(IntegerList(coverage),
use.names = FALSE))
if (keep.names){
count[, :=(genes,factor(rep(names(grl), widthPerGroup(grl))))]
} else count[, :=(genes, groupings(coverage))]
if (length(window_size) != 1) {
count[, :=(ones, rep.int(1L, length(genes)))]
count[, :=(position, cumsum(ones)), by = genes]
count$ones <- NULL
}
else {
count[, :=(position, rep.int(seq.int(window_size),
length(coverage)))]
}
if (withFrames) {
count[, :=(frame, (position - 1)%%3)]
}
count[]
return(count)
}
return(coverage)
}
bam_file <- system.file("extdata", "ribo-seq.bam", package = "ORFik")
footprints <- readBam(bam_file)
gtf_file <- system.file("extdata", "annotations.gtf", package = "ORFik")
txdb <- loadTxdb(gtf_file)
tx <- exonsBy(txdb, by = "tx", use.names = TRUE)
result1 <- coveragePerTiling(tx, footprints, as.data.table = TRUE)
result2 <- cpt_nm(tx, footprints, as.data.table = TRUE, keep.names = FALSE)
result3 <- cpt_nm(tx, footprints, as.data.table = TRUE, keep.names = TRUE)
identical(result1,result2)
object.size(result1)
object.size(result3)