Skip to content
Merged
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: projectR
Type: Package
Title: Functions for the projection of weights from PCA, CoGAPS, NMF,
correlation, and clustering
Version: 1.23.1
Version: 1.23.2
Author: Gaurav Sharma, Charles Shin, Jared Slosberg, Loyal Goff, Genevieve Stein-O'Brien
Authors@R: c(
person("Gaurav", "Sharma", role = c("aut")),
Expand Down
17 changes: 11 additions & 6 deletions R/projectR.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ setMethod("projectR",signature(data="matrix",loadings="matrix"),function(
#' @param NP vector of integers indicating which columns of loadings object to use. The default of NP=NA will use entire matrix.
#' @param full logical indicating whether to return the full model solution. By default only the new pattern object is returned.
#' @param model Optional arguements to choose method for projection
#' @param chopBy number of columns to chop the data into (chopping helps runnning large datasets)
#' @rdname projectR-methods
#' @aliases projectR
setMethod("projectR",signature(data="dgCMatrix",loadings="matrix"),function(
Expand All @@ -79,7 +80,8 @@ setMethod("projectR",signature(data="dgCMatrix",loadings="matrix"),function(
dataNames = NULL, # a vector with names of data rows
loadingsNames = NULL, # a vector with names of loadings rows
NP=NULL, # vector of integers indicating which columns of loadings object to use. The default of NP=NA will use entire matrix.
full=FALSE # logical indicating whether to return the full model solution. By default only the new pattern object is returned.
full=FALSE, # logical indicating whether to return the full model solution. By default only the new pattern object is returned.
chopBy=1000 # number of columns to chop the data into
){

if(!is.null(NP)) {
Expand All @@ -93,7 +95,7 @@ setMethod("projectR",signature(data="dgCMatrix",loadings="matrix"),function(

chop <- function(sparsematrix) {
coln <- ncol(sparsematrix)
bins <- seq(1, coln, by = 1000)
bins <- seq(1, coln, by = chopBy)
lapply(seq_along(bins), function(i) {
start <- bins[i]
end <- ifelse(i < length(bins), bins[i + 1] - 1, coln)
Expand All @@ -110,11 +112,14 @@ setMethod("projectR",signature(data="dgCMatrix",loadings="matrix"),function(
print(w[1])

if(full==TRUE) {
if(length(projectionList)==1) {#if only one chunk
if(length(projectionList)==1) {#if only one chunk all OK
res <- projectionList[[1]]
} else {
projectionFit <- lapply(projectionList, function(x) do.call(cbind, x))
res <- projectionFit
} else {#if multiple chunks - gather pvalues and projections
pvalues <- do.call(cbind,
lapply(projectionList, function(x) x[["pval"]]))
projections <- do.call(cbind,
lapply(projectionList, function(x) x[["projection"]]))
res <- list(projection=projections, pval=pvalues)
}
} else {
res <- do.call(cbind, projectionList)
Expand Down
5 changes: 4 additions & 1 deletion man/projectR-methods.Rd

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

5 changes: 5 additions & 0 deletions tests/testthat/test_projectR.R
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ test_that("projection works on sparse data matrix with full=TRUE", {
expect_no_error(projectR(sparse, loadings))

pdense <- projectR(dense, loadings, full=TRUE)
#case with default number of chopBy, when it's > ncol
psparse <- projectR(sparse, loadings, full=TRUE)
expect_identical(pdense, psparse)

#case with chopBy < ncol
psparse_chunked <- projectR(sparse, loadings, full=TRUE, chopBy=10)
expect_identical(pdense, psparse_chunked)
})
Loading