Skip to content

Commit

Permalink
Merge branch 'main' into devel
Browse files Browse the repository at this point in the history
  • Loading branch information
lambdamoses committed Jan 2, 2025
2 parents 0803d83 + 21d4666 commit 761c859
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
11 changes: 7 additions & 4 deletions R/aggregate.R
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,20 @@ aggregateTxTech <- function(data_dir, df = NULL, by = NULL,

# Probably faster than directly calling st_intersection, since I don't need
# the actual geometries of the intersections, maybe not
tx_coords <- st_coordinates(rg) # Might write another function similar to formatTxTech to skip this
tx_point <- df2sf(tx_coords, spatialCoordsNames = c("X", "Y", "Z"))
tx_coords <- st_coordinates(rg)
if (ncol(tx_coords) > 3L) scn <- c("X", "Y", "Z") else scn <- c("X", "Y")
tx_point <- df2sf(tx_coords, spatialCoordsNames = scn)
tx_ind <- as.data.table(st_drop_geometry(tx_point))
tx_info <- txSpots(x) |> st_drop_geometry()
tx_info$L1 <- seq_along(tx_info$gene) # it has to be "gene" if it's from formatTxSpots
tx_point <- merge(tx_point, tx_info, by = "L1") # takes a while
tx_point <- st_as_sf(tx_point) |> st_join(grid_sf) # takes a few minutes
tx_counts <- tx_point |> st_drop_geometry() |> as.data.table()
tx_counts <- tx_counts[, .N, by = .(gene, L1, grid_id)]

new_mat <- sparseMatrix(i = tx_counts$L1, j = tx_counts$grid_id, x = tx_counts$N)
# When some spots are outside the grids
tx_counts <- tx_counts[!is.na(grid_id),]
new_mat <- sparseMatrix(i = tx_counts$L1, j = tx_counts$grid_id, x = tx_counts$N,
dims = c(nrow(x), max(tx_counts$grid_id)))
cgs <- list(bins = grid_sf)
names(cgs) <- new_geometry_name
out <- SpatialFeatureExperiment(assays = list(counts = new_mat),
Expand Down
8 changes: 4 additions & 4 deletions R/read.R
Original file line number Diff line number Diff line change
Expand Up @@ -986,10 +986,10 @@ readCosMX <- function(data_dir,
z_option = c("3d", "split")) {
check_installed("sfarrow")
data_dir <- normalizePath(data_dir, mustWork = TRUE)
fns <- list.files(data_dir, pattern = "\\.csv$", full.names = TRUE)
fn_metadata <- grep("metadata", fns, value = TRUE)
fn_mat <- grep("exprMat", fns, value = TRUE)
fn_polys <- grep("polygons", fns, value = TRUE)
fns <- list.files(data_dir, pattern = "\\.csv.*$", full.names = TRUE)
fn_metadata <- grep("metadata", fns, value = TRUE)[1]
fn_mat <- grep("exprMat", fns, value = TRUE)[1]
fn_polys <- grep("polygons", fns, value = TRUE)[1]

meta <- fread(fn_metadata)
mat <- fread(fn_mat) # TODO: write to h5 or mtx. Consult alabaster.sce
Expand Down

0 comments on commit 761c859

Please sign in to comment.