作者Evil Genius多样本整合就是要在同一水平下比较多个样本。visium HD可以依据细胞分割的结果直接整合么有时候可以。可以的条件是大家visium HD的数据质量相当可以。那如果数据量不怎么样该怎么办那就需要数据增强banksy harmony的整合策略详细的内容我们在2026空间转录组系列课程会仔细讨论,包括项目运用的细节代码和生物学解读。那我们来看看bansky harmony的示例代码library(Banksy) library(SummarizedExperiment) library(SpatialExperiment) library(Seurat) library(scran) library(data.table) library(harmony) library(scater) library(cowplot) library(ggplot2) library(spatialLIBD) library(ExperimentHub) ehub - ExperimentHub::ExperimentHub() spe - spatialLIBD::fetch_data(type spe, eh ehub) # Remove NA spots na_id - which(is.na(spe$layer_guess_reordered_short)) spe - spe[, -na_id] # Trim imgData(spe) - NULL assay(spe, logcounts) - NULL reducedDims(spe) - NULL rowData(spe) - NULL colData(spe) - DataFrame( sample_id spe$sample_id, subject_id factor(spe$sample_id, labels rep(paste0(Subject, 1:3), each 4)), clust_annotation factor(as.numeric(spe$layer_guess_reordered_short)), in_tissue spe$in_tissue, row.names colnames(spe) ) colnames(spe) - paste0(colnames(spe), _, spe$sample_id) invisible(gc()) spe - spe[, spe$sample_id %in% c(151507, 151669, 151673)] sample_names - unique(spe$sample_id) # Stagger spatial coordinates locs - spatialCoords(spe) locs - cbind(locs, sample_id factor(spe$sample_id)) locs_dt - data.table(locs) colnames(locs_dt) - c(sdimx, sdimy, group) locs_dt[, sdimx : sdimx - min(sdimx), by group] global_max - max(locs_dt$sdimx) * 1.5 locs_dt[, sdimx : sdimx group * global_max] locs - as.matrix(locs_dt[, 1:2]) rownames(locs) - colnames(spe) spatialCoords(spe) - locs # Get HVGs seu - as.Seurat(spe, data NULL) seu - FindVariableFeatures(seu, nfeatures 2000) # Normalize data scale_factor - median(colSums(assay(spe, counts))) seu - NormalizeData(seu, scale.factor scale_factor, normalization.method RC) # Add data to SpatialExperiment and subset to HVGs aname - normcounts assay(spe, aname) - GetAssayData(seu) spe - spe[VariableFeatures(seu),] ##Running BANKSY compute_agf - TRUE k_geom - 18 spe - computeBanksy(spe, assay_name aname, compute_agf compute_agf, k_geom k_geom) ###Run PCA on the BANKSY matrix lambda - 0.2 npcs - 20 use_agf - TRUE spe - runBanksyPCA(spe, use_agf use_agf, lambda lambda, npcs npcs, seed SEED) ###Run Harmony on BANKSY’s embedding set.seed(SEED) harmony_embedding - HarmonyMatrix( data_mat reducedDim(spe, PCA_M1_lam0.2), meta_data colData(spe), vars_use c(sample_id, subject_id), do_pca FALSE, max.iter.harmony 20, verbose FALSE ) reducedDim(spe, Harmony_BANKSY) - harmony_embedding spe - runBanksyUMAP(spe, use_agf TRUE, lambda lambda, npcs npcs) spe - runBanksyUMAP(spe, dimred Harmony_BANKSY) plot_grid( plotReducedDim(spe, UMAP_M1_lam0.2, point_size 0.1, point_alpha 0.5, color_by subject_id) theme(legend.position none), plotReducedDim(spe, UMAP_Harmony_BANKSY, point_size 0.1, point_alpha 0.5, color_by subject_id) theme(legend.title element_blank()) guides(colour guide_legend(override.aes list(size 5, alpha 1))), nrow 1, rel_widths c(1, 1.2) ) spe - clusterBanksy(spe, dimred Harmony_BANKSY, resolution 0.55, seed SEED) spe - connectClusters(spe, map_to clust_annotation) cnm - clusterNames(spe)[2] spatial_plots - lapply(sample_names, function(snm) { x - spe[, spe$sample_id snm] ari - aricode::ARI(x$clust_annotation, colData(x)[, cnm]) df - cbind.data.frame(clustcolData(x)[[cnm]], spatialCoords(x)) ggplot(df, aes(xsdimy, ysdimx, colclust)) geom_point(size 0.5) scale_color_manual(values pals::kelly()[-1]) theme_classic() theme( legend.position none, axis.text.xelement_blank(), axis.text.yelement_blank(), axis.tickselement_blank(), axis.title.xelement_blank(), axis.title.yelement_blank()) labs(title sprintf(Sample %s - ARI: %s, snm, round(ari, 3))) coord_equal() }) plot_grid(plotlist spatial_plots, ncol 3, byrow FALSE)生活很好有你更好。