Skip to content

Commit

Permalink
Initialize objects with colnames and add check to binAcrossPixels
Browse files Browse the repository at this point in the history
  • Loading branch information
nilseling committed Dec 12, 2023
1 parent 1dc534e commit 1bd8483
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,6 @@ Changes in version 1.7.8 (2023-10-19)
Changes in version 1.9.1 (2023-11-20)

+ Switched from aes_ to .data
+ Initialise SPE and SCE objects with colnames
+ Additional test within binAcrossPixels

8 changes: 6 additions & 2 deletions R/binAcrossPixels.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ binAcrossPixels <- function(object,
stop("'statistic' must be 'sum', 'mean' or 'median'.")
}

cur_split <- split(object[[spot_id]], f = object[[spot_id]])
cur_split <- lapply(cur_split, function(x){ceiling(seq_along(x)/bin_size)})
cur_split_tmp <- split(object[[spot_id]], f = object[[spot_id]])
cur_split <- lapply(cur_split_tmp, function(x){ceiling(seq_along(x)/bin_size)})

if (!isTRUE(all.equal(unlist(cur_split_tmp), object[[spot_id]]))) {
stop("Spot IDs of pixels within 'object' are not ordered alphabetically.")
}

cur_df <- DataFrame(spot_id = object[[spot_id]],
bin = unlist(cur_split))
Expand Down
3 changes: 3 additions & 0 deletions R/read_cpout.R
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,8 @@ read_cpout <- function(path,

object <- .add_panel(object, path, panel_file, extract_metal_from)

# Add colnames
colnames(object) <- paste0(object$sample_id, "_", object$ObjectNumber)

return(object)
}
3 changes: 3 additions & 0 deletions R/read_steinbock.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,8 @@ read_steinbock <- function(path,
# Add panel data
object <- .add_panel(object, path, panel_file, extract_names_from)

# Add colnames
colnames(object) <- paste0(object$sample_id, "_", object$ObjectNumber)

return(object)
}

0 comments on commit 1bd8483

Please sign in to comment.