SpatiallyVariableFeatures_workaround <-function(object, assay="SCT", selection.method ="moransi"){ #' This is work around function to replace SeuratObject::SpatiallyVariableFeatures function. #' return ranked list of Spatially Variable Features # Check if object is a Seurat object if(!inherits(object,"Seurat")){ stop("object must be a Seurat object") } # Check if assay is a valid assay if(!assay %in%names(object@assays)){ stop("assay must be a valid assay") } # Extract meta.features from the specified object and assay data <- object@assays[[assay]]@meta.features # Select columns starting with the provided col_prefix moransi_cols <- grep(paste0("^", selection.method), colnames(data), value =TRUE) # Filter rows where "moransi.spatially.variable" is TRUE filtered_data <- data[data[[paste0(selection.method,".spatially.variable")]], moransi_cols] # Sort filtered data by "moransi.spatially.variable.rank" column in ascending order sorted_data <- filtered_data[order(filtered_data[[paste0(selection.method,".spatially.variable.rank")]]),] # Return row names of the sorted data frame rownames(sorted_data) }