Skip to content

Commit

Permalink
Redefine generics from VariantAnnotation and SummarizedExperiment
Browse files Browse the repository at this point in the history
To avoid long loading times from importing VariantAnnotation and
SummarizedExperiment, redefine generic methods from those packages.
  • Loading branch information
smgogarten committed May 17, 2017
1 parent 1e197e3 commit 7d9c700
Show file tree
Hide file tree
Showing 9 changed files with 394 additions and 463 deletions.
5 changes: 2 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ Title: Big Data Management of Whole-genome Sequence Variant Calls
Version: 1.17.1
Date: 2017-05-07
Depends: R (>= 3.3.0), gdsfmt (>= 1.10.1)
Imports: methods, parallel, IRanges, GenomicRanges, GenomeInfoDb
Imports: methods, parallel, IRanges, GenomicRanges, GenomeInfoDb, Biostrings, S4Vectors
LinkingTo: gdsfmt
Suggests: digest, crayon, RUnit, knitr, Rcpp, SNPRelate, Biobase, BiocParallel,
BiocGenerics, Biostrings, S4Vectors, VariantAnnotation,
SummarizedExperiment
BiocGenerics, VariantAnnotation
Authors@R: c(person("Xiuwen", "Zheng", role=c("aut", "cre"),
email="[email protected]"),
person("Stephanie", "Gogarten", role="aut",
Expand Down
12 changes: 8 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,22 @@ importFrom(parallel, clusterApply, clusterApplyLB, clusterCall, detectCores,
makeCluster, makeForkCluster, mclapply, stopCluster)
importFrom(utils, read.table, flush.console)

importFrom(S4Vectors, DataFrame, SimpleList)
importClassesFrom(IRanges, IRanges)
importFrom(IRanges, IRanges, IntegerList, NumericList, CharacterList)
importFrom(IRanges, IRanges, IntegerList, NumericList, CharacterList, DataFrameList)
importClassesFrom(GenomicRanges, GRanges, GRangesList)
importFrom(GenomicRanges, GRanges)
importMethodsFrom(GenomicRanges, granges)
importMethodsFrom(GenomeInfoDb, seqnames)
importMethodsFrom(GenomeInfoDb, seqnames, seqlevels)
importFrom(GenomeInfoDb, renameSeqlevels)
importFrom(Biostrings, DNAStringSet, DNAStringSetList)


# Export all names
exportPattern("^seq*")
export(.onAttach, .Last.lib)

exportClasses(SeqVarGDSClass)
exportMethods(granges)
exportMethods(seqClose, seqSetFilter)
exportMethods(granges, ref, alt, qual, filt, header, fixed,
info, geno, colData, rowRanges)
exportMethods(seqClose, seqSetFilter, seqAsVCF)
14 changes: 14 additions & 0 deletions R/AllGenerics.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,17 @@ setGeneric("seqSetFilter", function(object, variant.sel, ...)
standardGeneric("seqSetFilter"))

# setGeneric("seqAppend", function(object, ...) standardGeneric("seqAppend"))

setGeneric("seqAsVCF", function(x, ...) standardGeneric("seqAsVCF"))

# redefine generics from VariantAnnotation and SummarizedExperiment to reduce package load time
setGeneric("ref", function(x, ...) standardGeneric("ref"))
setGeneric("alt", function(x, ...) standardGeneric("alt"))
setGeneric("qual", function(x, ...) standardGeneric("qual"))
setGeneric("filt", function(x, ...) standardGeneric("filt"))
setGeneric("fixed", function(x, ...) standardGeneric("fixed"))
setGeneric("header", function(x, ...) standardGeneric("header"))
setGeneric("info", function(x, ...) standardGeneric("info"))
setGeneric("geno", function(x, ...) standardGeneric("geno"))
setGeneric("rowRanges", function(x, ...) standardGeneric("rowRanges"))
setGeneric("colData", function(x, ...) standardGeneric("colData"))
67 changes: 46 additions & 21 deletions R/Internal.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,6 @@
#


#######################################################################
# Internal variable(s)
#

# package-wide variable
.packageEnv <- new.env()

# asVCF exported functions
.asVCF_Export <- function()
{
isTRUE(.packageEnv$vcf_export)
}

# set asVCF export flag
.asVCF_SetTRUE <- function()
{
.packageEnv$vcf_export <- TRUE
}



#######################################################################
# Get the numbers of selected samples and variants
#
Expand Down Expand Up @@ -727,3 +706,49 @@

invisible()
}

#######################################################################
# Convert to a VariantAnnotation object
#

.variableLengthToList <- function(x)
{
xl <- list()
j <- 1L
for (i in 1:length(x$length))
{
len <- x$length[i]
if (len > 0L)
{
xl[[i]] <- x$data[j:(j+len-1)]
j <- j+len
} else {
xl[[i]] <- NA
}
}
xl
}

.toAtomicList <- function(x, type)
{
switch(type,
Character=CharacterList(x),
String=CharacterList(x),
Integer=IntegerList(x),
Float=NumericList(x))
}

.variableLengthToMatrix <- function(x)
{
xl <- list()
i <- 1L
for (j in seq_along(x))
{
for (k in seq_len(NROW(x[[j]])))
{
xl[[i]] <- x[[j]][k,]
i <- i + 1L
}
}
matrix(xl, nrow=NROW(x[[1L]]), ncol=length(x))
}
Loading

0 comments on commit 7d9c700

Please sign in to comment.