Skip to content

Commit

Permalink
Fixes to loom and loom
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Hoffman committed Jun 28, 2018
1 parent 3aeef04 commit f52d0b7
Showing 1 changed file with 74 additions and 76 deletions.
150 changes: 74 additions & 76 deletions R/loom.R
Original file line number Diff line number Diff line change
Expand Up @@ -1106,59 +1106,58 @@ loom <- R6Class(
chunk.indices <- start:end
indices.use <- chunk.indices[chunk.indices %in% index.use]
indices.use <- indices.use - chunk.indices[1] + 1
if (length(x = indices.use) < 1) {
next
}
# Get the data and apply FUN
chunk.data <- if (dataset.matrix) {
switch(
EXPR = MARGIN,
'1' = {
# Chunk genes
x <- self[[dataset.use]][, chunk.indices]
x[, indices.use]
},
'2' = {
# Chunk cells
x <- self[[dataset.use]][chunk.indices, ]
x[indices.use, ]
}
)
} else {
x <- self[[private$iter.datset]][chunk.indices]
x[indices.use]
}
chunk.data <- FUN(chunk.data, ...)
if (results.matrix) {
# If we're writign to a matrix
# Figure out which way we're writing the data
switch(
EXPR = MARGIN,
'1' = {
chunk.full <- matrix(
nrow = nrow(x = chunk.data),
ncol = length(x = chunk.indices)
)
chunk.full[, indices.use] <- chunk.data
group[[results.basename]][, chunk.indices] <- chunk.full
# group[[results.use]][, chunk.indices] <- chunk.full
},
'2' = {
chunk.full <- matrix(
nrow = length(x = chunk.indices),
ncol = ncol(x = chunk.data)
)
chunk.full[indices.use, ] <- chunk.data
group[[results.basename]][chunk.indices, ] <- chunk.full
# group[[results.use]][chunk.indices, ] <- chunk.full
}
)
} else {
# Just write to the vector
chunk.full <- vector(length = length(x = chunk.indices))
chunk.full[indices.use] <- chunk.data
group[[results.basename]][chunk.indices] <- chunk.full
# group[[results.use]][chunk.indices] <- chunk.full
if (length(x = indices.use) >= 1) {
# Get the data and apply FUN
chunk.data <- if (dataset.matrix) {
switch(
EXPR = MARGIN,
'1' = {
# Chunk genes
x <- self[[dataset.use]][, chunk.indices]
x[, indices.use]
},
'2' = {
# Chunk cells
x <- self[[dataset.use]][chunk.indices, ]
x[indices.use, ]
}
)
} else {
x <- self[[private$iter.datset]][chunk.indices]
x[indices.use]
}
chunk.data <- FUN(chunk.data, ...)
if (results.matrix) {
# If we're writign to a matrix
# Figure out which way we're writing the data
switch(
EXPR = MARGIN,
'1' = {
chunk.full <- matrix(
nrow = nrow(x = chunk.data),
ncol = length(x = chunk.indices)
)
chunk.full[, indices.use] <- chunk.data
group[[results.basename]][, chunk.indices] <- chunk.full
# group[[results.use]][, chunk.indices] <- chunk.full
},
'2' = {
chunk.full <- matrix(
nrow = length(x = chunk.indices),
ncol = ncol(x = chunk.data)
)
chunk.full[indices.use, ] <- chunk.data
group[[results.basename]][chunk.indices, ] <- chunk.full
# group[[results.use]][chunk.indices, ] <- chunk.full
}
)
} else {
# Just write to the vector
chunk.full <- vector(length = length(x = chunk.indices))
chunk.full[indices.use] <- chunk.data
group[[results.basename]][chunk.indices] <- chunk.full
# group[[results.use]][chunk.indices] <- chunk.full
}
}
gc(verbose = FALSE)
return(NULL)
Expand Down Expand Up @@ -1228,29 +1227,28 @@ loom <- R6Class(
chunk.indices <- start:end
indices.use <- chunk.indices[chunk.indices %in% index.use]
indices.use <- indices.use - chunk.indices[1] + 1
if (length(x = indices.use) < 1) {
next
}
# Get the data and apply FUN
chunk.data <- if (dataset.matrix) {
switch(
EXPR = MARGIN,
'1' = {
# Chunk genes
x <- self[[dataset.use]][, chunk.indices]
x[, indices.use]
},
'2' = {
# Chunk cells
x <- self[[dataset.use]][chunk.indices, ]
x[indices.use, ]
}
)
} else {
x <- self[[dataset.use]][chunk.indices]
x[indices.use]
if (length(x = indices.use) >= 1) {
# Get the data and apply FUN
chunk.data <- if (dataset.matrix) {
switch(
EXPR = MARGIN,
'1' = {
# Chunk genes
x <- self[[dataset.use]][, chunk.indices]
x[, indices.use]
},
'2' = {
# Chunk cells
x <- self[[dataset.use]][chunk.indices, ]
x[indices.use, ]
}
)
} else {
x <- self[[dataset.use]][chunk.indices]
x[indices.use]
}
results[[i]] <<- FUN(chunk.data, ...)
}
results[[i]] <<- FUN(chunk.data, ...)
return(NULL)
},
...
Expand Down Expand Up @@ -2274,7 +2272,7 @@ combine <- function(
ncols[i] <- this[['matrix']]$dims[1]
matrix.type[[i]] <- class(x = this[['matrix']]$get_type())[1]
# loom.chunk.dims[[i]] <- as.numeric(strsplit(h5attr(this, 'chunks'), split = '[\\(, \\)]+')[[1]][2:3])
loom.chunk.dims[[i]] <- lfile[['matrix']]$chunk_dims
loom.chunk.dims[[i]] <- this[['matrix']]$chunk_dims
if (is.character(x = looms[[i]])) {
this$close_all()
}
Expand Down

0 comments on commit f52d0b7

Please sign in to comment.