Hello,
I am trying to run this on visiumHD data, and am having issues with the visualization. No tissue appears and the in and out dots are just layered on top of each other. Here is my code:
read spatial metadata
spatial_dir <- "/original_square_008um"
list.files(spatial_dir)
#read in raw data
raw <- read10xRaw("/original_square_008um/raw_feature_bc_matrix")
pos <- read_parquet("/cellranger_output/ELWA02_FL3_0_v1/binned_outputs/square_008um/spatial/tissue_positions.parquet") |>
rename(barcode = 1, in_tissue = 2, array_row = 3, array_col = 4,
pxl_row_in_fullres = 5, pxl_col_in_fullres = 6) |>
mutate(in_tissue = as.integer(in_tissue))
pos_use <- pos[ match(colnames(raw), pos$barcode), ]
2) Keep only in-tissue rows
pos_in <- pos_use |> filter(in_tissue == 1)
slide_df <- pos_use %>%
transmute(
barcode,
tissue = as.integer(in_tissue), # rename in_tissue -> tissue
imagerow = as.numeric(pxl_row_in_fullres), # rename -> imagerow
imagecol = as.numeric(pxl_col_in_fullres), # rename -> imagecol
# keep anything else you want as extra metadata:
array_row, array_col
)
stopifnot(identical(slide_df$barcode, colnames(raw)))
csv_path <- file.path(spatial_dir, "tissue_positions_list_from_parquet.csv")
write.table(slide_df, csv_path, sep = ",", row.names = FALSE, col.names = FALSE, quote = FALSE)
slide_info <- read10xSlide(
tissue_csv_file = file.path(spatial_dir, "tissue_positions_list_from_parquet.csv"),
tissue_img_file = file.path(spatial_dir, "tissue_lowres_image.png"),
scale_factor_file = file.path(spatial_dir, "scalefactors_json.json")
)
library(jsonlite)
sf <- fromJSON("/cellranger_output/ELWA02_FL3_0_v1/binned_outputs/original_square_008um/spatial/scalefactors_json.json")
low <- sf$tissue_lowres_scalef # e.g., ~0.05
slide_df$imagerow <- as.numeric(slide_df$imagerow) * low
slide_df$imagecol <- as.numeric(slide_df$imagecol) * low
#create slide object
slide_obj <- createSlide(raw, slide_info)
slide_obj
p <- visualizeLabel(slide_obj,"tissue")
Hello,
I am trying to run this on visiumHD data, and am having issues with the visualization. No tissue appears and the in and out dots are just layered on top of each other. Here is my code:
read spatial metadata
spatial_dir <- "/original_square_008um"
list.files(spatial_dir)
#read in raw data
raw <- read10xRaw("/original_square_008um/raw_feature_bc_matrix")
pos <- read_parquet("/cellranger_output/ELWA02_FL3_0_v1/binned_outputs/square_008um/spatial/tissue_positions.parquet") |>
rename(barcode = 1, in_tissue = 2, array_row = 3, array_col = 4,
pxl_row_in_fullres = 5, pxl_col_in_fullres = 6) |>
mutate(in_tissue = as.integer(in_tissue))
pos_use <- pos[ match(colnames(raw), pos$barcode), ]
2) Keep only in-tissue rows
pos_in <- pos_use |> filter(in_tissue == 1)
slide_df <- pos_use %>%
transmute(
barcode,
tissue = as.integer(in_tissue), # rename in_tissue -> tissue
imagerow = as.numeric(pxl_row_in_fullres), # rename -> imagerow
imagecol = as.numeric(pxl_col_in_fullres), # rename -> imagecol
# keep anything else you want as extra metadata:
array_row, array_col
)
stopifnot(identical(slide_df$barcode, colnames(raw)))
csv_path <- file.path(spatial_dir, "tissue_positions_list_from_parquet.csv")
write.table(slide_df, csv_path, sep = ",", row.names = FALSE, col.names = FALSE, quote = FALSE)
slide_info <- read10xSlide(
tissue_csv_file = file.path(spatial_dir, "tissue_positions_list_from_parquet.csv"),
tissue_img_file = file.path(spatial_dir, "tissue_lowres_image.png"),
scale_factor_file = file.path(spatial_dir, "scalefactors_json.json")
)
library(jsonlite)
sf <- fromJSON("/cellranger_output/ELWA02_FL3_0_v1/binned_outputs/original_square_008um/spatial/scalefactors_json.json")
low <- sf$tissue_lowres_scalef # e.g., ~0.05
slide_df$imagerow <- as.numeric(slide_df$imagerow) * low
slide_df$imagecol <- as.numeric(slide_df$imagecol) * low
#create slide object
slide_obj <- createSlide(raw, slide_info)
slide_obj
p <- visualizeLabel(slide_obj,"tissue")