suppressMessages(library(MERINGUE))
data_path<-"/home/fgao/Data_vizgen/"
mtx_BC<-read.csv(paste(data_path, "datasets_mouse_brain_map_BrainReceptorShowcase_Slice1_Replicate1_cell_by_gene_S1R1.csv", sep=""), header=T, row.names=1)
rownames(mtx_BC)<-as.factor(rownames(mtx_BC))
mtx_BC[is.na(mtx_BC)] <- 0
meta_BC<-read.csv(paste(data_path, "datasets_mouse_brain_map_BrainReceptorShowcase_Slice1_Replicate1_cell_metadata_S1R1.csv", sep=""), header=T, row.names=1)
rownames(meta_BC)<-rownames(mtx_BC)
counts_BC<-t(mtx_BC[, 1:483])
#filter out genes with less than 1000 counts across all cells and cells with less than 100 total counts
cc <- cleanCounts(counts_BC, min.reads = 1000, min.lib.size = 100, plot=TRUE)
#CPM normalization
mat <- normalizeCounts(cc, log=FALSE, verbose=TRUE)
#Normalized matrix has 67576 cells and 382 genes.
pos_BC<-meta_BC[,c("center_x", "center_y")]
colnames(pos_BC)<-c("x", "y")
pos_BC$slice<-1
pos_mat_BC <- pos_BC[intersect(rownames(pos_BC), colnames(mat)),]
#Get neighbor-relationship
w <- getSpatialNeighbors(pos_mat_BC, filterDist = 2.5)