Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review of code and minor updates. #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ License: What license is it under?
LazyData: true
Suggests: testthat, BSgenome.Scerevisiae.UCSC.sacCer2, intSiteRetriever
Imports: Biostrings, BSgenome, GenomicRanges, GenomeInfoDb, S4Vectors
RoxygenNote: 6.0.1.9000
3 changes: 1 addition & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Generated by roxygen2 (4.1.1): do not edit by hand
import(BSgenome, Biostrings, S4Vectors)
# Generated by roxygen2: do not edit by hand

export(getGCpercentage)
24 changes: 13 additions & 11 deletions R/GCcontent.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@
getGCpercentage <- function(
sites, column_prefix, window_size, reference_genome_sequence
){
stopifnot(class(sites) == "GRanges")
stopifnot(length(window_size) == length(names(window_size)))
metadata <- mcols(sites)
metadata <- GenomicRanges::mcols(sites)

rangesToCalc <- .expand_trim_GRanges(sites, window_size)

#seqs will take a lot of memory
#could split at severe cpu time penelty
seqs <- getSeq(reference_genome_sequence, rangesToCalc, as.character=F)
seqs <- BSgenome::getSeq(
reference_genome_sequence, rangesToCalc, as.character = FALSE)

letterFreqs <- letterFrequency(seqs, c("G", "C", "A", "T"))
letterFreqs <- Biostrings::letterFrequency(seqs, c("G", "C", "A", "T"))
rm(seqs)

GC <- letterFreqs[, c("G", "C")]
Expand All @@ -49,11 +51,11 @@ getGCpercentage <- function(

gcContent[!is.finite(gcContent)] <- NA #handled gracefully by pipeUtils

gcContent <- DataFrame(matrix(gcContent, nrow=length(sites)))
gcContent <- S4Vectors::DataFrame(matrix(gcContent, nrow = length(sites)))

names(gcContent) <- paste(column_prefix, names(window_size), sep=".")

mcols(sites) <- cbind(metadata, gcContent)
GenomicRanges::mcols(sites) <- cbind(metadata, gcContent)

sites
}
Expand All @@ -62,14 +64,14 @@ getGCpercentage <- function(
nsites <- length(sites)
strand(sites) = "+" #unimportant for GC and speeds up later calculations

sites.seqinfo.original <- seqinfo(sites)
isCircular(seqinfo(sites)) <- rep(FALSE, length(seqinfo(sites)))
sites.seqinfo.original <- GenomicRanges::seqinfo(sites)
isCircular(GenomicRanges::seqinfo(sites)) <- rep(
FALSE, length(GenomicRanges::seqinfo(sites)))

sites <- rep(sites, length(window_size))
sites <- trim(suppressWarnings(flank(sites,
rep(window_size/2, each=nsites),
both=T)))
sites <- GenomicRanges::trim(suppressWarnings(GenomicRanges::flank(
sites, rep(window_size/2, each = nsites), both = TRUE)))

seqinfo(sites) = sites.seqinfo.original
GenomicRanges::seqinfo(sites) <- sites.seqinfo.original
sites
}
9 changes: 4 additions & 5 deletions man/getGCpercentage.Rd

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

13 changes: 6 additions & 7 deletions tests/testthat/test_GContent.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
context("Testing GC perecntage calculation and edge cases")

reference <- intSiteRetriever::get_reference_genome("sacCer2")
sac_seqinfo <- seqinfo(reference)
sac_seqinfo <- BSgenome::seqinfo(reference)

sites <- GRanges(
seqnames=Rle(c("chrI", "chrII", "chrV")),
ranges=IRanges(start=c(100, 200, 50000), width=rep(1, 3)),
strand=Rle(c("+", "-", "+")),
seqinfo=sac_seqinfo
)
sites <- GenomicRanges::GRanges(
seqnames = S4Vectors::Rle(c("chrI", "chrII", "chrV")),
ranges = IRanges::IRanges(start=c(100, 200, 50000), width=rep(1, 3)),
strand = S4Vectors::Rle(c("+", "-", "+")),
seqinfo = sac_seqinfo)

window_size <- c(small=10, large=1000)
sites_GC <- getGCpercentage(sites, "GC", window_size, reference)
Expand Down