Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
initial commit
  • Loading branch information
lcy1364 authored Oct 18, 2024
0 parents commit bf44899
Show file tree
Hide file tree
Showing 94 changed files with 13,776 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/STEREO/1_cellbin/1_gemToH5ad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import read_io as gem
import sys
import os
gemfile = sys.argv[1]

#gemfile = "./B02111D1.gem"
import os
os.environ['JOBLIB_TEMP_FOLDER'] = '/tmp'
adata = gem.read_gem(gemfile,label_column="CellID")
ha5ad_file=gemfile.replace(".gem",".cellbin.h5ad")
adata.write_h5ad(ha5ad_file)
76 changes: 76 additions & 0 deletions src/STEREO/1_cellbin/2_h5adToRDS.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
library(Seurat)
library(parallel)
library(stringr)
library(tidyverse)
library(magrittr)
library(hdf5r)
library(dplyr)
library(rjson)
library(Seurat)
library(ggplot2)
library(argparser)
library(SeuratDisk)


setwd("~/cortex/STEREO/1_cellbin/")
h5adFiles <- list.files("./batch_gem/", ".h5ad$", full.names = T)

mclapply(h5adFiles, mc.cores = min(length(h5adFiles), 50), function (file) {
infile <- file
chipID <- str_extract(basename(file), "[A-Z0-9]*")
outfile <- str_c(chipID, ".qs")

# convert h5ad as h5seurat, which means a seurat-object format stored in h5
Convert(infile,
dest = "h5seurat",
assay = "Spatial",
overwrite = TRUE)

h5file <- paste(paste(unlist(strsplit(
infile, "h5ad", fixed = TRUE
)), collapse = 'h5ad'), "h5seurat", sep = "")
print(paste(
c("Finished! Converting h5ad to h5seurat file at:", h5file),
sep = " ",
collapse = NULL
))

object <- LoadH5Seurat(h5file, assays = "Spatial")
print(paste(
c("Successfully load h5seurat:", h5file),
sep = " ",
collapse = NULL
))

# spatial already transform to `Spatial`` in assays
if (!is.null(object@reductions$spatial)) {
object@reductions$spatial <- NULL
}

assay.used <- 'Spatial'


# TODO follow with old code, don't touch
print("Start add image...This may take some minutes...(~.~)")
# add image
cell_coords <- unique(object@meta.data[, c('x', 'y')])
cell_coords['cells'] <- row.names(cell_coords)

# generate object @images$slice1
generate_BGI_spatial <- function(cell_coords) {
return(new(Class = 'SlideSeq', coordinates = cell_coords))
}

BGI_spatial <- generate_BGI_spatial(cell_coords = cell_coords)

# can be thought of as a background of spatial
# import image into seurat object
object@images[['image']] <- BGI_spatial
object@images$image@key <- "image_"
object@images$image@assay <- "Spatial"

# conversion done, save
print("Finished add image...Start to saveRDS...")

qsave(object, outfile)
})
Loading

0 comments on commit bf44899

Please sign in to comment.