Skip to content

Commit

Permalink
Merge branch 'devel' of github.com:SydneyBioX/scFeatures into devel
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-robo committed Oct 4, 2023
2 parents 4bb16e9 + 7d04749 commit ac6f5b4
Showing 1 changed file with 61 additions and 101 deletions.
162 changes: 61 additions & 101 deletions R/wrapper_run_scfeatures.R
Original file line number Diff line number Diff line change
Expand Up @@ -247,114 +247,74 @@ scFeatures <- function(data, feature_types = NULL, type = "scrna", ncores = 1,
#'
#' @export
makeSeurat <- function(data,
sample = NULL ,
celltype = NULL,
assay = NULL,
spatialCoords = NULL,
spotProbability = NULL) {
sample = NULL ,
celltype = NULL,
select_assay = NULL,
spatialCoords = NULL,
spotProbability = NULL) {


if (!is.null(spotProbability)){
spotProbability <- t(spotProbability )
predictions <- data.frame(
prediction.score = as.matrix(spotProbability ),
row.names = colnames(data), stringsAsFactors = FALSE )

predictions <- Seurat::CreateAssayObject( data = t(x = as.matrix(x = predictions)),
check.matrix = FALSE )
if (!is.null(spotProbability)){
spotProbability <- t(spotProbability )
predictions <- data.frame(
prediction.score = as.matrix(spotProbability ),
row.names = colnames(data), stringsAsFactors = FALSE )

predictions <- Seurat::CreateAssayObject( data = t(x = as.matrix(x = predictions)),
check.matrix = FALSE )
}


if (is(data, "Seurat")) {
if (!is.null(celltype)){
data$celltype <- celltype
}
if (!is.null(sample)){
data$sample <- sample
}


if (is(data, "Seurat")) {
if (!is.null(celltype)){
data$celltype <- celltype
}
if (!is.null(sample)){
data$sample <- sample
}

if (!is.null(spatialCoords)) {
data$x_cord <- spatialCoords[1]
data$y_cord <- spatialCoords[2]
}
if (!is.null(spotProbability)) {
data[["predictions"]] <- predictions
}
return(data)
if (!is.null(spatialCoords)) {
data$x_cord <- spatialCoords[1]
data$y_cord <- spatialCoords[2]
}

if (is(data, "SingleCellExperiment")) {
df <- data

if(!is.null(celltype)){
df$celltype <- celltype
}else{
df$celltype <- SummarizedExperiment::colData(df)[, "celltype"]
}

if(!is.null(sample)){
df$sample <- sample
}else{
df$sample <- SummarizedExperiment::colData(df)[, "sample"]
}
if (!is.null(spatialCoords)) {
df$x_cord <- spatialCoords[1]
df$y_cord <- spatialCoords[2]
}else{
df$x_cord <- SummarizedExperiment::colData(df)[, "x_cord"]
df$y_cord <- SummarizedExperiment::colData(df)[, "y_cord"]
}


if (!is.null(assay)){
data <- Seurat::as.Seurat(df, data = assay)
}else{
data <- Seurat::as.Seurat(df)
}


if (!is.null(spotProbability)) {
data[["predictions"]] <- predictions
}
return(data)
if (!is.null(spotProbability)) {
data[["predictions"]] <- predictions
}
return(data)
}

if (is(data, "SingleCellExperiment")) {
df <- data

if(!is.null(celltype)){
df$celltype <- celltype
}

if(!is.null(sample)){
df$sample <- sample
}

if (!is.null(spatialCoords)) {
df$x_cord <- spatialCoords[[1]]
df$y_cord <- spatialCoords[[2]]
}



if (!is.null(select_assay)){
data_seurat <- CreateSeuratObject( counts = assay(df, select_assay))
}else{
data_seurat <- CreateSeuratObject( counts = assay(df, "logcounts"))
}


data_seurat@meta.data <- data.frame( colData(df) )


if (is(data, "SpatialExperiment")) {
df <- data

if(!is.null(celltype)){
df$celltype <- celltype
}else{
df$celltype <- SummarizedExperiment::colData(df)[, "celltype"]
}

if(!is.null(sample)){
df$sample <- sample
}else{
df$sample <- SummarizedExperiment::colData(df)[, "sample"]
}

if(!is.null(spatialCoords)){
df$x_cord <- spatialCoords[1]
df$y_cord <- spatialCoords[2]
}else{
df$x_cord <- SpatialExperiment::spatialCoords(df)[, 1]
df$y_cord <- SpatialExperiment::spatialCoords(df)[, 2]
}

if (!is.null(assay)){
data <- Seurat::as.Seurat(df, data = assay)
}else{
data <- Seurat::as.Seurat(df)
}

if (!is.null(spotProbability)) {
data[["predictions"]] <- predictions
}

return(data)
if (!is.null(spotProbability)) {
data_seurat[["predictions"]] <- predictions
}
return(data_seurat)
}

data

}

0 comments on commit ac6f5b4

Please sign in to comment.