Skip to content

Commit

Permalink
Updated load10XCoords to be able to read tissue positions from Visium…
Browse files Browse the repository at this point in the history
…HD which are stored in .parquet files. Added the nanoparquet function to depends in DESCRIPTION as well as updated package version. Added spatialDir to an argument in load10XCoords since VisiumHD typically has a separate folders for each of the resolutions each with their own spatial folder.
  • Loading branch information
orian116 committed Oct 11, 2024
1 parent e1864ad commit aeb75c5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: SpaceMarkers
Title: Spatial Interaction Markers
Version: 1.1.6
Version: 1.1.7
Authors@R: c(
person(given = "Atul", family = "Deshpande", email = "[email protected]", role = c("aut", "cre"), comment = c(ORCID="0000-0001-5144-6924")),
person(given = "Ludmila", family = "Danilova", email = "[email protected]", role = "ctb"),
Expand All @@ -27,6 +27,7 @@ Imports:
ape,
hdf5r,
jsonlite,
nanoparquet,
Matrix,
qvalue,
stats,
Expand Down
24 changes: 16 additions & 8 deletions R/preprocessing.R
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ load10XExpr<- function(visiumDir=NULL,
#' unlink("Visium_Human_Breast_Cancer_spatial.tar.gz")
#'

load10XCoords <- function(visiumDir, resolution = "lowres", version = NULL){
load10XCoords <- function(visiumDir, resolution = "lowres", version = NULL,
spatialDir = "spatial"){
#determine spacerager version
if(is.null(version)){
message("Version not provided. Trying to infer.")
Expand All @@ -116,15 +117,22 @@ load10XCoords <- function(visiumDir, resolution = "lowres", version = NULL){
has_header <- TRUE
tissue_pos_name <- "tissue_positions.csv"
}
spatial_dir <- paste0(visiumDir,'/spatial')
scale_json <- dir(spatial_dir,
pattern = "scalefactors_json.json",full.names = TRUE)
scale_values <- jsonlite::read_json(scale_json)
scale_factor <- scale_values[grepl(resolution, names(scale_values))][[1]]
spatial_dir <- file.path(visiumDir,spatialDir)
scale_json <- dir(spatial_dir,
pattern = "scalefactors_json.json",full.names = TRUE)
scale_values <- jsonlite::read_json(scale_json)
scale_factor <- scale_values[grepl(resolution, names(scale_values))][[1]]
# account for visiumHD
if (version == "1.0" | version == "2.0"){
coord_file <- dir(spatial_dir,
pattern = tissue_pos_name, full.names = TRUE)

pattern = tissue_pos_name, full.names = TRUE)
coord_values <- read.csv(coord_file, header = has_header)
} else if (version == "3.0") {
tissue_pos_name <- "tissue_positions.parquet"
coord_file <- dir(spatial_dir,
pattern = tissue_pos_name, full.names = TRUE)
coord_values <- nanoparquet::read_parquet(coord_file)
}
coord_values <- coord_values[,c(1,5,6)]
coord_values[,2:3] <- coord_values[,2:3]*scale_factor
names(coord_values) <- c("barcode","y","x")
Expand Down

0 comments on commit aeb75c5

Please sign in to comment.