diff --git a/R/RunCellToCell.R b/R/RunCellToCell.R index 91c6fe4..bfdf07e 100644 --- a/R/RunCellToCell.R +++ b/R/RunCellToCell.R @@ -5,8 +5,8 @@ #' The default assay of this object is called "CellToCell" to distinguish it from normal Seurat objects. #' Meta.data slots by default contain "SendingType" "ReceivingType" and "VectorType" information. #' -#' @param sys.small A filtered Seurat object. The active identity will be used to define populations for connectomic sampling and crossings. -#' @param ground.truth Ground truth signaling mechanisms present in sys.small. +#' @param filtered.obj A filtered Seurat object. The active identity will be used to define populations for connectomic sampling and crossings. +#' @param ground.truth Ground truth signaling mechanisms present in filtered.obj. #' @param assay The assay to run the SCC transformation on. Defaults to "RNA." #' @param meta.data.to.map A character vector of metadata names present in the original object which will be carried to the SCC objects #' @param output_format string. Choice of the output format. "seurat" will output a list of seurat objects, "raw" will output a list of lists with raw interaction matrix and compiled metadata @@ -16,7 +16,7 @@ #' @export -RunCellToCell <- function(sys.small, +RunCellToCell <- function(filtered.obj, ground.truth, assay, meta.data.to.map, @@ -25,13 +25,13 @@ RunCellToCell <- function(sys.small, ### CREATE MAPPING ### - # jc: Identify celltypes:names(table(Idents(sys.small))). Better to run check_celltypes, but harder to check - celltypes <- return_celltypes(sys.small) + # jc: Identify celltypes:names(table(Idents(filtered.obj))). Better to run check_celltypes, but harder to check + celltypes <- return_celltypes(filtered.obj) # Ligand dataset (listwise, for each celltype) lig.list <- list() for (i in 1:length(celltypes)){ - temp <- subset(sys.small,idents = celltypes[i]) + temp <- subset(filtered.obj,idents = celltypes[i]) subunit.list <- list() # Builds sending (ligand) data for any number of ligand subunits for (s in 1:ncol(ground.truth$source.subunits)){ #For each subunit column... subunit.list[[s]] <- matrix(data = 1,nrow = nrow(ground.truth$source.subunits),ncol = ncol(temp)) #initialize a mechanism x barcode matrix of all NAs @@ -47,7 +47,7 @@ RunCellToCell <- function(sys.small, # Receptor dataset (listwise, for each celltype) rec.list <- list() for (i in 1:length(celltypes)){ - temp <- subset(sys.small,idents = celltypes[i]) + temp <- subset(filtered.obj,idents = celltypes[i]) subunit.list <- list() # Builds receiving (receptor) data for any number of receptor subunits for (t in 1:ncol(ground.truth$target.subunits)){ subunit.list[[t]] <- matrix(data = 1,nrow = nrow(ground.truth$target.subunits),ncol = ncol(temp)) #initialize a mechanism x barcode matrix of all NAs @@ -72,7 +72,7 @@ RunCellToCell <- function(sys.small, for (i in 1:length(celltypes)){ # Define maximum number of comparisons for each pairing - num <- as.data.frame(table(Seurat::Idents(sys.small))) + num <- as.data.frame(table(Seurat::Idents(filtered.obj))) num$sender.freq <- ncol(lig.list[[i]]) rownames(num) <- num$Var1 num <- num[,-1] @@ -98,8 +98,8 @@ RunCellToCell <- function(sys.small, rownames(scc.data[[i]]) <- paste(rownames(lig.data[[i]]),rownames(rec.data[[i]]),sep = '—') colnames(scc.data[[i]]) <- paste(colnames(lig.data[[i]]),colnames(rec.data[[i]]),sep = '—') - sending.cell.idents[[i]] <- as.character(Seurat::Idents(sys.small)[colnames(lig.data[[i]])]) - receiving.cell.idents[[i]] <- as.character(Seurat::Idents(sys.small)[colnames(rec.data[[i]])]) + sending.cell.idents[[i]] <- as.character(Seurat::Idents(filtered.obj)[colnames(lig.data[[i]])]) + receiving.cell.idents[[i]] <- as.character(Seurat::Idents(filtered.obj)[colnames(rec.data[[i]])]) } @@ -110,7 +110,7 @@ RunCellToCell <- function(sys.small, demo <- Seurat::CreateSeuratObject(counts = as.matrix(scc),assay = 'CellToCell') # JC: Seurat V5 will not create data slot automatically, the following step is to manually add this slot if(SeuratObject::Version(demo) >= "5.0.0"){ - demo <- NormalizeData(demo,assay = "CellToCell") # Seura Object need to be >= 5.0.1 + demo <- Seurat::NormalizeData(demo,assay = "CellToCell") # Seura Object need to be >= 5.0.1 demo@assays$CellToCell@layers$data <- demo@assays$CellToCell@layers$counts # Seura Object need to be>= 5.0.1 } @@ -133,9 +133,9 @@ RunCellToCell <- function(sys.small, # Identify sending and receiving barcodes sending.barcodes <- colnames(do.call(cbind,lig.data)) #This can be simplified if the above SCC construction is simplified receiving.barcodes <- colnames(do.call(cbind,rec.data)) #This can be simplified if the above SCC construction is simplified - # Pull and format sending and receiving metadata jc: possible bug, change object to sys.small - sending.metadata <- as.matrix(sys.small@meta.data[,meta.data.to.map,drop=FALSE][sending.barcodes,]) - receiving.metadata <- as.matrix(sys.small@meta.data[,meta.data.to.map,drop=FALSE][receiving.barcodes,]) + # Pull and format sending and receiving metadata jc: possible bug, change object to filtered.obj + sending.metadata <- as.matrix(filtered.obj@meta.data[,meta.data.to.map,drop=FALSE][sending.barcodes,]) + receiving.metadata <- as.matrix(filtered.obj@meta.data[,meta.data.to.map,drop=FALSE][receiving.barcodes,]) # Make joint metadata datArray <- abind::abind(sending.metadata,receiving.metadata,along=3) joint.metadata <- as.matrix(apply(datArray,1:2,function(x)paste(x[1],"-",x[2]))) @@ -154,7 +154,7 @@ RunCellToCell <- function(sys.small, Seurat::Idents(demo) <- demo$VectorType # How many vectors were captured by this sampling? - message(paste("\n",ncol(demo),'Cell-To-Cell edges computed, sampling',length(unique(demo$VectorType)),'distinct VectorTypes, out of',length(table(Seurat::Idents(sys.small)))^2,'total possible')) + message(paste("\n",ncol(demo),'Cell-To-Cell edges computed, sampling',length(unique(demo$VectorType)),'distinct VectorTypes, out of',length(table(Seurat::Idents(filtered.obj)))^2,'total possible')) if(output_format == "seurat") return(demo) else{ diff --git a/R/RunCellToCellSpatial.R b/R/RunCellToCellSpatial.R index 88d7844..f61601b 100644 --- a/R/RunCellToCellSpatial.R +++ b/R/RunCellToCellSpatial.R @@ -1,7 +1,7 @@ #' RunCellToCellSpatial #' -#' @param sys.small A filtered Seurat object. The active identity will be used to define populations for connectomic sampling and crossings. -#' @param ground.truth Ground truth signaling mechanisms present in sys.small. +#' @param filtered.obj A filtered Seurat object. The active identity will be used to define populations for connectomic sampling and crossings. +#' @param ground.truth Ground truth signaling mechanisms present in filtered.obj. #' @param assay The assay to run the SCC transformation on. Defaults to "RNA." #' @param meta.data.to.map A character vector of metadata names present in the original object which will be carried to the NICHES objects #' @param edgelist data.frame. Each row is an directional edge between two spatially connected cells @@ -11,7 +11,7 @@ #' @importFrom dplyr %>% #' @export -RunCellToCellSpatial <- function(sys.small, +RunCellToCellSpatial <- function(filtered.obj, ground.truth, assay, meta.data.to.map, @@ -22,30 +22,30 @@ RunCellToCellSpatial <- function(sys.small, # Make ligand matrix - #lig.data <- sys.small@assays[[assay]]@data[ligands,edgelist$from] + #lig.data <- filtered.obj@assays[[assay]]@data[ligands,edgelist$from] subunit.list <- list() # Builds sending (ligand) data for any number of ligand subunits for (s in 1:ncol(ground.truth$source.subunits)){ #For each subunit column... - subunit.list[[s]] <- matrix(data = 1,nrow = nrow(ground.truth$source.subunits),ncol = ncol(getSeuratAssay(sys.small,assay,"data")[,edgelist$from])) #initialize a mechanism x barcode matrix of all NAs - colnames(subunit.list[[s]]) <- colnames(getSeuratAssay(sys.small,assay,"data")[,edgelist$from]) + subunit.list[[s]] <- matrix(data = 1,nrow = nrow(ground.truth$source.subunits),ncol = ncol(getSeuratAssay(filtered.obj,assay,"data")[,edgelist$from])) #initialize a mechanism x barcode matrix of all NAs + colnames(subunit.list[[s]]) <- colnames(getSeuratAssay(filtered.obj,assay,"data")[,edgelist$from]) rownames(subunit.list[[s]]) <- rownames(ground.truth$source.subunits) non.na.indices <- !is.na(ground.truth$source.subunits[,s]) #Identify rows in the s-th column of the ground truth which are not NA - subunit.list[[s]][non.na.indices,] <- as.matrix(getSeuratAssay(sys.small,assay,"data")[ground.truth$source.subunits[non.na.indices,s],edgelist$from]) #For every row in the initialized matrix corresponding to the indices of the ground.truth which are not NA, replace with the rows from the Seurat object corresponding to the genes in the ground.truth at those indices + subunit.list[[s]][non.na.indices,] <- as.matrix(getSeuratAssay(filtered.obj,assay,"data")[ground.truth$source.subunits[non.na.indices,s],edgelist$from]) #For every row in the initialized matrix corresponding to the indices of the ground.truth which are not NA, replace with the rows from the Seurat object corresponding to the genes in the ground.truth at those indices } lig.data <- Reduce('*',subunit.list) rm(subunit.list) # Make receptor matrix - #rec.data <- sys.small@assays[[assay]]@data[receptors,edgelist$to] + #rec.data <- filtered.obj@assays[[assay]]@data[receptors,edgelist$to] subunit.list <- list() # Builds receiving (receptor) data for any number of receptor subunits for (t in 1:ncol(ground.truth$target.subunits)){ - subunit.list[[t]] <- matrix(data = 1,nrow = nrow(ground.truth$target.subunits),ncol = ncol(getSeuratAssay(sys.small,assay,"data")[,edgelist$to])) #initialize a mechanism x barcode matrix of all NAs - colnames(subunit.list[[t]]) <- colnames(getSeuratAssay(sys.small,assay,"data")[,edgelist$to]) + subunit.list[[t]] <- matrix(data = 1,nrow = nrow(ground.truth$target.subunits),ncol = ncol(getSeuratAssay(filtered.obj,assay,"data")[,edgelist$to])) #initialize a mechanism x barcode matrix of all NAs + colnames(subunit.list[[t]]) <- colnames(getSeuratAssay(filtered.obj,assay,"data")[,edgelist$to]) rownames(subunit.list[[t]]) <- rownames(ground.truth$target.subunits) non.na.indices <- !is.na(ground.truth$target.subunits[,t]) #Identify rows in the t-th column of the ground truth which are not NA - subunit.list[[t]][non.na.indices,] <- as.matrix(getSeuratAssay(sys.small,assay,"data")[ground.truth$target.subunits[non.na.indices,t],edgelist$to]) #For every row in the initialized matrix corresponding to the indices of the ground.truth which are not NA, replace with the rows from the Seurat object corresponding to the genes in the ground.truth at those indices + subunit.list[[t]][non.na.indices,] <- as.matrix(getSeuratAssay(filtered.obj,assay,"data")[ground.truth$target.subunits[non.na.indices,t],edgelist$to]) #For every row in the initialized matrix corresponding to the indices of the ground.truth which are not NA, replace with the rows from the Seurat object corresponding to the genes in the ground.truth at those indices } rec.data <- Reduce('*',subunit.list) rm(subunit.list) @@ -54,8 +54,8 @@ RunCellToCellSpatial <- function(sys.small, scc <- lig.data*rec.data rownames(scc) <- paste(rownames(lig.data),rownames(rec.data),sep = '—') colnames(scc) <- paste(colnames(lig.data),colnames(rec.data),sep = '—') - sending.cell.idents <- as.character(Seurat::Idents(sys.small)[colnames(lig.data)]) - receiving.cell.idents <- as.character(Seurat::Idents(sys.small)[colnames(rec.data)]) + sending.cell.idents <- as.character(Seurat::Idents(filtered.obj)[colnames(lig.data)]) + receiving.cell.idents <- as.character(Seurat::Idents(filtered.obj)[colnames(rec.data)]) dim(scc) # Use this matrix to create a Seurat object: @@ -63,7 +63,7 @@ RunCellToCellSpatial <- function(sys.small, # JC: Seurat V5 will not create data slot automatically, the following step is to manually add this slot if(SeuratObject::Version(demo) >= "5.0.0"){ - demo <- NormalizeData(demo,assay = "CellToCellSpatial") # Seura Object need to be >= 5.0.1 + demo <- Seurat::NormalizeData(demo,assay = "CellToCellSpatial") # Seura Object need to be >= 5.0.1 demo@assays$CellToCellSpatial@layers$data <- demo@assays$CellToCellSpatial@layers$counts # Seura Object need to be >= 5.0.1 } @@ -87,9 +87,9 @@ RunCellToCellSpatial <- function(sys.small, sending.barcodes <- colnames(lig.data) receiving.barcodes <- colnames(rec.data) # Pull and format sending and receiving metadata - # jc: possible bug, change object to sys.small - sending.metadata <- as.matrix(sys.small@meta.data[,meta.data.to.map,drop=FALSE][sending.barcodes,]) - receiving.metadata <- as.matrix(sys.small@meta.data[,meta.data.to.map,drop=FALSE][receiving.barcodes,]) + # jc: possible bug, change object to filtered.obj + sending.metadata <- as.matrix(filtered.obj@meta.data[,meta.data.to.map,drop=FALSE][sending.barcodes,]) + receiving.metadata <- as.matrix(filtered.obj@meta.data[,meta.data.to.map,drop=FALSE][receiving.barcodes,]) # Make joint metadata datArray <- abind::abind(sending.metadata,receiving.metadata,along=3) joint.metadata <- as.matrix(apply(datArray,1:2,function(x)paste(x[1],"-",x[2]))) @@ -107,7 +107,7 @@ RunCellToCellSpatial <- function(sys.small, Seurat::Idents(demo) <- demo$VectorType # How many vectors were captured by this sampling? - message(paste("\n",length(unique(demo$VectorType)),'distinct VectorTypes were computed, out of',length(table(Seurat::Idents(sys.small)))^2,'total possible')) + message(paste("\n",length(unique(demo$VectorType)),'distinct VectorTypes were computed, out of',length(table(Seurat::Idents(filtered.obj)))^2,'total possible')) if(output_format == "seurat") return(demo) diff --git a/R/RunCellToNeighborhood.R b/R/RunCellToNeighborhood.R index b0930bb..fdb410f 100644 --- a/R/RunCellToNeighborhood.R +++ b/R/RunCellToNeighborhood.R @@ -1,7 +1,7 @@ #' RunCellToNeighborhood #' -#' @param sys.small A filtered Seurat object. The active identity will be used to define populations for connectomic sampling and crossings. -#' @param ground.truth Ground truth signaling mechanisms present in sys.small. +#' @param filtered.obj A filtered Seurat object. The active identity will be used to define populations for connectomic sampling and crossings. +#' @param ground.truth Ground truth signaling mechanisms present in filtered.obj. #' @param assay The assay to run the SCC transformation on. Defaults to "RNA." #' @param meta.data.to.map A character vector of metadata names present in the original object which will be carried to the NICHES objects #' @param blend Choice of linear operator to combine edges. Defaults to "mean", also accepts "sum" @@ -10,7 +10,7 @@ #' #' @export -RunCellToNeighborhood <- function(sys.small, +RunCellToNeighborhood <- function(filtered.obj, ground.truth, assay, meta.data.to.map, @@ -21,30 +21,30 @@ RunCellToNeighborhood <- function(sys.small, # Make ligand matrix - #lig.data <- sys.small@assays[[assay]]@data[ligands,edgelist$from] + #lig.data <- filtered.obj@assays[[assay]]@data[ligands,edgelist$from] subunit.list <- list() # Builds sending (ligand) data for any number of ligand subunits for (s in 1:ncol(ground.truth$source.subunits)){ #For each subunit column... - subunit.list[[s]] <- matrix(data = 1,nrow = nrow(ground.truth$source.subunits),ncol = ncol(getSeuratAssay(sys.small,assay,"data")[,edgelist$from])) #initialize a mechanism x barcode matrix of all NAs - colnames(subunit.list[[s]]) <- colnames(getSeuratAssay(sys.small,assay,"data")[,edgelist$from]) + subunit.list[[s]] <- matrix(data = 1,nrow = nrow(ground.truth$source.subunits),ncol = ncol(getSeuratAssay(filtered.obj,assay,"data")[,edgelist$from])) #initialize a mechanism x barcode matrix of all NAs + colnames(subunit.list[[s]]) <- colnames(getSeuratAssay(filtered.obj,assay,"data")[,edgelist$from]) rownames(subunit.list[[s]]) <- rownames(ground.truth$source.subunits) non.na.indices <- !is.na(ground.truth$source.subunits[,s]) #Identify rows in the s-th column of the ground truth which are not NA - subunit.list[[s]][non.na.indices,] <- as.matrix(getSeuratAssay(sys.small,assay,"data")[ground.truth$source.subunits[non.na.indices,s],edgelist$from]) #For every row in the initialized matrix corresponding to the indices of the ground.truth which are not NA, replace with the rows from the Seurat object corresponding to the genes in the ground.truth at those indices + subunit.list[[s]][non.na.indices,] <- as.matrix(getSeuratAssay(filtered.obj,assay,"data")[ground.truth$source.subunits[non.na.indices,s],edgelist$from]) #For every row in the initialized matrix corresponding to the indices of the ground.truth which are not NA, replace with the rows from the Seurat object corresponding to the genes in the ground.truth at those indices } lig.data <- Reduce('*',subunit.list) rm(subunit.list) # Make receptor matrix - #rec.data <- sys.small@assays[[assay]]@data[receptors,edgelist$to] + #rec.data <- filtered.obj@assays[[assay]]@data[receptors,edgelist$to] subunit.list <- list() # Builds receiving (receptor) data for any number of receptor subunits for (t in 1:ncol(ground.truth$target.subunits)){ - subunit.list[[t]] <- matrix(data = 1,nrow = nrow(ground.truth$target.subunits),ncol = ncol(getSeuratAssay(sys.small,assay,"data")[,edgelist$to])) #initialize a mechanism x barcode matrix of all NAs - colnames(subunit.list[[t]]) <- colnames(getSeuratAssay(sys.small,assay,"data")[,edgelist$to]) + subunit.list[[t]] <- matrix(data = 1,nrow = nrow(ground.truth$target.subunits),ncol = ncol(getSeuratAssay(filtered.obj,assay,"data")[,edgelist$to])) #initialize a mechanism x barcode matrix of all NAs + colnames(subunit.list[[t]]) <- colnames(getSeuratAssay(filtered.obj,assay,"data")[,edgelist$to]) rownames(subunit.list[[t]]) <- rownames(ground.truth$target.subunits) non.na.indices <- !is.na(ground.truth$target.subunits[,t]) #Identify rows in the t-th column of the ground truth which are not NA - subunit.list[[t]][non.na.indices,] <- as.matrix(getSeuratAssay(sys.small,assay,"data")[ground.truth$target.subunits[non.na.indices,t],edgelist$to]) #For every row in the initialized matrix corresponding to the indices of the ground.truth which are not NA, replace with the rows from the Seurat object corresponding to the genes in the ground.truth at those indices + subunit.list[[t]][non.na.indices,] <- as.matrix(getSeuratAssay(filtered.obj,assay,"data")[ground.truth$target.subunits[non.na.indices,t],edgelist$to]) #For every row in the initialized matrix corresponding to the indices of the ground.truth which are not NA, replace with the rows from the Seurat object corresponding to the genes in the ground.truth at those indices } rec.data <- Reduce('*',subunit.list) rm(subunit.list) @@ -69,7 +69,7 @@ RunCellToNeighborhood <- function(sys.small, demo <- Seurat::CreateSeuratObject(counts = as.matrix(scc),assay = 'CellToNeighborhood') # JC: Seurat V5 will not create data slot automatically, the following step is to manually add this slot if(SeuratObject::Version(demo) >= "5.0.0"){ - demo <- NormalizeData(demo,assay = "CellToNeighborhood") # Seura Object need to be >= 5.0.1 + demo <- Seurat::NormalizeData(demo,assay = "CellToNeighborhood") # Seura Object need to be >= 5.0.1 demo@assays$CellToNeighborhood@layers$data <- demo@assays$CellToNeighborhood@layers$counts # Seura Object need to be >= 5.0.1 } @@ -77,7 +77,7 @@ RunCellToNeighborhood <- function(sys.small, # Add metadata based on ident slot # bug fix: add the Neighborhood - prefix sending_type.meta <- data.frame(SendingCell = barcodes, - SendingType = Seurat::Idents(sys.small)[barcodes], + SendingType = Seurat::Idents(filtered.obj)[barcodes], row.names = paste(barcodes,"Neighborhood",sep = '—')) demo <- Seurat::AddMetaData(demo,metadata = sending_type.meta,col.name = c("SendingCell","SendingType")) @@ -88,8 +88,8 @@ RunCellToNeighborhood <- function(sys.small, sending.barcodes <- barcodes # Only sending cell metadata applies for this function #receiving.barcodes <- colnames(rec.map) # Pull and format sending and receiving metadata - # jc: possible bug, change object to sys.small - sending.metadata <- as.matrix(sys.small@meta.data[,meta.data.to.map,drop=FALSE][sending.barcodes,]) + # jc: possible bug, change object to filtered.obj + sending.metadata <- as.matrix(filtered.obj@meta.data[,meta.data.to.map,drop=FALSE][sending.barcodes,]) #receiving.metadata <- as.matrix(object@meta.data[,meta.data.to.map][receiving.barcodes,]) # Make joint metadata #datArray <- abind(sending.metadata,receiving.metadata,along=3) diff --git a/R/RunCellToSystem.R b/R/RunCellToSystem.R index 5b49ac7..93a195d 100644 --- a/R/RunCellToSystem.R +++ b/R/RunCellToSystem.R @@ -9,8 +9,8 @@ #' Meta.data slots by default contain "SendingType" information, which is the celltypes for each point, #' and "SendingCell" which is the exact cell barcode present in the original Seurat object. #' -#' @param sys.small A filtered Seurat object. The active identity will be used to define populations for connectomic sampling and crossings. -#' @param ground.truth Ground truth signaling mechanisms present in sys.small. +#' @param filtered.obj A filtered Seurat object. The active identity will be used to define populations for connectomic sampling and crossings. +#' @param ground.truth Ground truth signaling mechanisms present in filtered.obj. #' @param assay The assay to run the CellToSystem transformation on. Defaults to "RNA." #' @param blend Choice of linear operator to combine edges. Defaults to "mean", also accepts "sum","mean.adj" #' @param meta.data.to.map A character vector of metadata names present in the original object which will be carried to the NICHES objects @@ -19,7 +19,7 @@ #' @export -RunCellToSystem <- function(sys.small, +RunCellToSystem <- function(filtered.obj, ground.truth, assay, blend = 'mean', @@ -33,11 +33,11 @@ RunCellToSystem <- function(sys.small, # Receptor data subunit.list <- list() # Builds receiving (receptor) data for any number of receptor subunits for (t in 1:ncol(ground.truth$target.subunits)){ - subunit.list[[t]] <- matrix(data = 1,nrow = nrow(ground.truth$target.subunits),ncol = ncol(sys.small)) #initialize a mechanism x barcode matrix of all NAs - colnames(subunit.list[[t]]) <- colnames(sys.small) + subunit.list[[t]] <- matrix(data = 1,nrow = nrow(ground.truth$target.subunits),ncol = ncol(filtered.obj)) #initialize a mechanism x barcode matrix of all NAs + colnames(subunit.list[[t]]) <- colnames(filtered.obj) rownames(subunit.list[[t]]) <- rownames(ground.truth$target.subunits) non.na.indices <- !is.na(ground.truth$target.subunits[,t]) #Identify rows in the s-th column of the ground truth which are not NA - subunit.list[[t]][non.na.indices,] <- as.matrix(getSeuratAssay(sys.small,assay,"data")[ground.truth$target.subunits[non.na.indices,t],]) #For every row in the initialized matrix corresponding to the indices of the ground.truth which are not NA, replace with the rows from the Seurat object corresponding to the genes in the ground.truth at those indices + subunit.list[[t]][non.na.indices,] <- as.matrix(getSeuratAssay(filtered.obj,assay,"data")[ground.truth$target.subunits[non.na.indices,t],]) #For every row in the initialized matrix corresponding to the indices of the ground.truth which are not NA, replace with the rows from the Seurat object corresponding to the genes in the ground.truth at those indices } rec.map <- Reduce('*',subunit.list) rm(subunit.list) @@ -61,11 +61,11 @@ RunCellToSystem <- function(sys.small, # Ligand data subunit.list <- list() # Builds sending (ligand) data for any number of ligand subunits for (s in 1:ncol(ground.truth$source.subunits)){ #For each subunit column... - subunit.list[[s]] <- matrix(data = 1,nrow = nrow(ground.truth$source.subunits),ncol = ncol(sys.small)) #initialize a mechanism x barcode matrix of all NAs - colnames(subunit.list[[s]]) <- colnames(sys.small) + subunit.list[[s]] <- matrix(data = 1,nrow = nrow(ground.truth$source.subunits),ncol = ncol(filtered.obj)) #initialize a mechanism x barcode matrix of all NAs + colnames(subunit.list[[s]]) <- colnames(filtered.obj) rownames(subunit.list[[s]]) <- rownames(ground.truth$source.subunits) non.na.indices <- !is.na(ground.truth$source.subunits[,s]) #Identify rows in the s-th column of the ground truth which are not NA - subunit.list[[s]][non.na.indices,] <- as.matrix(getSeuratAssay(sys.small,assay,"data")[ground.truth$source.subunits[non.na.indices,s],]) #For every row in the initialized matrix corresponding to the indices of the ground.truth which are not NA, replace with the rows from the Seurat object corresponding to the genes in the ground.truth at those indices + subunit.list[[s]][non.na.indices,] <- as.matrix(getSeuratAssay(filtered.obj,assay,"data")[ground.truth$source.subunits[non.na.indices,s],]) #For every row in the initialized matrix corresponding to the indices of the ground.truth which are not NA, replace with the rows from the Seurat object corresponding to the genes in the ground.truth at those indices } lig.map <- Reduce('*',subunit.list) rm(subunit.list) @@ -84,7 +84,7 @@ RunCellToSystem <- function(sys.small, demo <- Seurat::CreateSeuratObject(counts = as.matrix(sc.connectome),assay = 'CellToSystem') # JC: Seurat V5 will not create data slot automatically, the following step is to manually add this slot if(SeuratObject::Version(demo) >= "5.0.0"){ - demo <- NormalizeData(demo,assay = "CellToSystem") # Seura Object need to be >= 5.0.1 + demo <- Seurat::NormalizeData(demo,assay = "CellToSystem") # Seura Object need to be >= 5.0.1 demo@assays$CellToSystem@layers$data <- demo@assays$CellToSystem@layers$counts # Seura Object need to be >= 5.0.1 } @@ -95,7 +95,7 @@ RunCellToSystem <- function(sys.small, demo <- Seurat::AddMetaData(demo,metadata = meta.data.to.add,col.name = 'SendingCell') # bug fix: add the system - prefix - sending_type.meta <- data.frame(Seurat::Idents(sys.small)) + sending_type.meta <- data.frame(Seurat::Idents(filtered.obj)) rownames(sending_type.meta) <- paste(rownames(sending_type.meta),"System",sep = '—') demo <- Seurat::AddMetaData(demo,metadata = sending_type.meta,col.name = 'SendingType') @@ -106,8 +106,8 @@ RunCellToSystem <- function(sys.small, sending.barcodes <- colnames(lig.map) # Only sending cell metadata applies for this function #receiving.barcodes <- colnames(rec.map) # Pull and format sending and receiving metadata - # jc: possible bug, change object to sys.small - sending.metadata <- as.matrix(sys.small@meta.data[,meta.data.to.map,drop=FALSE][sending.barcodes,]) + # jc: possible bug, change object to filtered.obj + sending.metadata <- as.matrix(filtered.obj@meta.data[,meta.data.to.map,drop=FALSE][sending.barcodes,]) #receiving.metadata <- as.matrix(object@meta.data[,meta.data.to.map][receiving.barcodes,]) # Make joint metadata #datArray <- abind(sending.metadata,receiving.metadata,along=3) diff --git a/R/RunNICHES.R b/R/RunNICHES.R index 3a324d2..3f3fcef 100644 --- a/R/RunNICHES.R +++ b/R/RunNICHES.R @@ -161,12 +161,12 @@ RunNICHES.default <- function(object, # jc: move the shared preprocessing steps here to avoid redundancy and reduce the number of parameters to be passed to other functions # NOTE: relies on Idents(object) to be cell types to subset - sys.small <- prepSeurat(object,assay,min.cells.per.ident,min.cells.per.gene) - ground.truth <- lr_load(LR.database,custom_LR_database,species,rownames(sys.small@assays[[assay]])) + filtered.obj <- prepSeurat(object,assay,min.cells.per.ident,min.cells.per.gene) + ground.truth <- lr_load(LR.database,custom_LR_database,species,rownames(filtered.obj@assays[[assay]])) if (org_names_indicator["CellToCellSpatial"] == T | org_names_indicator["CellToNeighborhood"] == T | org_names_indicator["NeighborhoodToCell"] == T){ ## 1. Move the neighbor graph construction here ## 2. Enable a k-nearest-neighbor parameter as an alternative - edgelist <- compute_edgelist(sys.small,position.x,position.y,k,rad.set) + edgelist <- compute_edgelist(filtered.obj,position.x,position.y,k,rad.set) } # check the output format @@ -179,20 +179,20 @@ RunNICHES.default <- function(object, # NOTE: RunCellToCell relies on Idents(object) to be cell types to subset # Also each RunXXX function needs Idents(object) to build VectorType meta data - if (CellToCell == T){output[[length(output)+1]] <- RunCellToCell(sys.small=sys.small, + if (CellToCell == T){output[[length(output)+1]] <- RunCellToCell(filtered.obj=filtered.obj, ground.truth=ground.truth, assay = assay, meta.data.to.map = meta.data.to.map, output_format = output_format )} - if (CellToSystem == T){output[[length(output)+1]] <- RunCellToSystem(sys.small=sys.small, + if (CellToSystem == T){output[[length(output)+1]] <- RunCellToSystem(filtered.obj=filtered.obj, ground.truth=ground.truth, assay = assay, meta.data.to.map = meta.data.to.map, blend = blend, output_format = output_format )} - if (SystemToCell == T){output[[length(output)+1]] <- RunSystemToCell(sys.small=sys.small, + if (SystemToCell == T){output[[length(output)+1]] <- RunSystemToCell(filtered.obj=filtered.obj, ground.truth=ground.truth, assay = assay, meta.data.to.map = meta.data.to.map, @@ -201,14 +201,14 @@ RunNICHES.default <- function(object, )} - if (CellToCellSpatial == T){output[[length(output)+1]] <- RunCellToCellSpatial(sys.small=sys.small, + if (CellToCellSpatial == T){output[[length(output)+1]] <- RunCellToCellSpatial(filtered.obj=filtered.obj, ground.truth=ground.truth, assay = assay, meta.data.to.map = meta.data.to.map, edgelist = edgelist, output_format = output_format )} #Spatially-limited Cell-Cell vectors - if (CellToNeighborhood == T){output[[length(output)+1]] <- RunCellToNeighborhood(sys.small=sys.small, + if (CellToNeighborhood == T){output[[length(output)+1]] <- RunCellToNeighborhood(filtered.obj=filtered.obj, ground.truth=ground.truth, assay = assay, meta.data.to.map = meta.data.to.map, @@ -216,7 +216,7 @@ RunNICHES.default <- function(object, edgelist = edgelist, output_format = output_format )} #Spatially-limited Cell-Neighborhood vectors - if (NeighborhoodToCell == T){output[[length(output)+1]] <- RunNeighborhoodToCell(sys.small=sys.small, + if (NeighborhoodToCell == T){output[[length(output)+1]] <- RunNeighborhoodToCell(filtered.obj=filtered.obj, ground.truth=ground.truth, assay = assay, meta.data.to.map = meta.data.to.map, diff --git a/R/RunNeighborhoodToCell.R b/R/RunNeighborhoodToCell.R index 2e70f1b..39895f8 100644 --- a/R/RunNeighborhoodToCell.R +++ b/R/RunNeighborhoodToCell.R @@ -1,7 +1,7 @@ #' RunNeighborhoodToCell #' -#' @param sys.small A filtered Seurat object. The active identity will be used to define populations for connectomic sampling and crossings. -#' @param ground.truth Ground truth signaling mechanisms present in sys.small. +#' @param filtered.obj A filtered Seurat object. The active identity will be used to define populations for connectomic sampling and crossings. +#' @param ground.truth Ground truth signaling mechanisms present in filtered.obj. #' @param assay The assay to run the SCC transformation on. Defaults to "RNA." #' @param meta.data.to.map A character vector of metadata names present in the original object which will be carried to the NICHES objects #' @param blend Choice of linear operator to combine edges. Defaults to "mean", also accepts "sum" @@ -10,7 +10,7 @@ #' #' @export -RunNeighborhoodToCell <- function(sys.small, +RunNeighborhoodToCell <- function(filtered.obj, ground.truth, assay, meta.data.to.map, @@ -21,30 +21,30 @@ RunNeighborhoodToCell <- function(sys.small, # Make ligand matrix - #lig.data <- sys.small@assays[[assay]]@data[ligands,edgelist$from] + #lig.data <- filtered.obj@assays[[assay]]@data[ligands,edgelist$from] subunit.list <- list() # Builds sending (ligand) data for any number of ligand subunits for (s in 1:ncol(ground.truth$source.subunits)){ #For each subunit column... - subunit.list[[s]] <- matrix(data = 1,nrow = nrow(ground.truth$source.subunits),ncol = ncol(getSeuratAssay(sys.small,assay,"data")[,edgelist$from])) #initialize a mechanism x barcode matrix of all NAs - colnames(subunit.list[[s]]) <- colnames(getSeuratAssay(sys.small,assay,"data")[,edgelist$from]) + subunit.list[[s]] <- matrix(data = 1,nrow = nrow(ground.truth$source.subunits),ncol = ncol(getSeuratAssay(filtered.obj,assay,"data")[,edgelist$from])) #initialize a mechanism x barcode matrix of all NAs + colnames(subunit.list[[s]]) <- colnames(getSeuratAssay(filtered.obj,assay,"data")[,edgelist$from]) rownames(subunit.list[[s]]) <- rownames(ground.truth$source.subunits) non.na.indices <- !is.na(ground.truth$source.subunits[,s]) #Identify rows in the s-th column of the ground truth which are not NA - subunit.list[[s]][non.na.indices,] <- as.matrix(getSeuratAssay(sys.small,assay,"data")[ground.truth$source.subunits[non.na.indices,s],edgelist$from]) #For every row in the initialized matrix corresponding to the indices of the ground.truth which are not NA, replace with the rows from the Seurat object corresponding to the genes in the ground.truth at those indices + subunit.list[[s]][non.na.indices,] <- as.matrix(getSeuratAssay(filtered.obj,assay,"data")[ground.truth$source.subunits[non.na.indices,s],edgelist$from]) #For every row in the initialized matrix corresponding to the indices of the ground.truth which are not NA, replace with the rows from the Seurat object corresponding to the genes in the ground.truth at those indices } lig.data <- Reduce('*',subunit.list) rm(subunit.list) # Make receptor matrix - #rec.data <- sys.small@assays[[assay]]@data[receptors,edgelist$to] + #rec.data <- filtered.obj@assays[[assay]]@data[receptors,edgelist$to] subunit.list <- list() # Builds receiving (receptor) data for any number of receptor subunits for (t in 1:ncol(ground.truth$target.subunits)){ - subunit.list[[t]] <- matrix(data = 1,nrow = nrow(ground.truth$target.subunits),ncol = ncol(getSeuratAssay(sys.small,assay,"data")[,edgelist$to])) #initialize a mechanism x barcode matrix of all NAs - colnames(subunit.list[[t]]) <- colnames(getSeuratAssay(sys.small,assay,"data")[,edgelist$to]) + subunit.list[[t]] <- matrix(data = 1,nrow = nrow(ground.truth$target.subunits),ncol = ncol(getSeuratAssay(filtered.obj,assay,"data")[,edgelist$to])) #initialize a mechanism x barcode matrix of all NAs + colnames(subunit.list[[t]]) <- colnames(getSeuratAssay(filtered.obj,assay,"data")[,edgelist$to]) rownames(subunit.list[[t]]) <- rownames(ground.truth$target.subunits) non.na.indices <- !is.na(ground.truth$target.subunits[,t]) #Identify rows in the t-th column of the ground truth which are not NA - subunit.list[[t]][non.na.indices,] <- as.matrix(getSeuratAssay(sys.small,assay,"data")[ground.truth$target.subunits[non.na.indices,t],edgelist$to]) #For every row in the initialized matrix corresponding to the indices of the ground.truth which are not NA, replace with the rows from the Seurat object corresponding to the genes in the ground.truth at those indices + subunit.list[[t]][non.na.indices,] <- as.matrix(getSeuratAssay(filtered.obj,assay,"data")[ground.truth$target.subunits[non.na.indices,t],edgelist$to]) #For every row in the initialized matrix corresponding to the indices of the ground.truth which are not NA, replace with the rows from the Seurat object corresponding to the genes in the ground.truth at those indices } rec.data <- Reduce('*',subunit.list) rm(subunit.list) @@ -69,7 +69,7 @@ RunNeighborhoodToCell <- function(sys.small, demo <- Seurat::CreateSeuratObject(counts = as.matrix(scc),assay = 'NeighborhoodToCell') # JC: Seurat V5 will not create data slot automatically, the following step is to manually add this slot if(SeuratObject::Version(demo) >= "5.0.0"){ - demo <- NormalizeData(demo,assay = "NeighborhoodToCell") # Seura Object need to be >= 5.0.1 + demo <- Seurat::NormalizeData(demo,assay = "NeighborhoodToCell") # Seura Object need to be >= 5.0.1 demo@assays$NeighborhoodToCell@layers$data <- demo@assays$NeighborhoodToCell@layers$counts # Seura Object need to be >= 5.0.1 } @@ -77,7 +77,7 @@ RunNeighborhoodToCell <- function(sys.small, # Add metadata based on ident slot # bug fix: add the Neighborhood - prefix receiving_type.meta <- data.frame(ReceivingCell = barcodes, - ReceivingType = Seurat::Idents(sys.small)[barcodes], + ReceivingType = Seurat::Idents(filtered.obj)[barcodes], row.names = paste("Neighborhood",barcodes,sep = '—')) demo <- Seurat::AddMetaData(demo,metadata = receiving_type.meta,col.name = c("ReceivingCell","ReceivingType")) @@ -89,8 +89,8 @@ RunNeighborhoodToCell <- function(sys.small, receiving.barcodes <- barcodes # Only receiving cell metadata applies for this function # Pull and format sending and receiving metadata #sending.metadata <- as.matrix(object@meta.data[,meta.data.to.map][sending.barcodes,]) - # jc: possible bug, change object to sys.small - receiving.metadata <- as.matrix(sys.small@meta.data[,meta.data.to.map,drop=FALSE][receiving.barcodes,]) + # jc: possible bug, change object to filtered.obj + receiving.metadata <- as.matrix(filtered.obj@meta.data[,meta.data.to.map,drop=FALSE][receiving.barcodes,]) # Make joint metadata #datArray <- abind(sending.metadata,receiving.metadata,along=3) #joint.metadata <- as.matrix(apply(datArray,1:2,function(x)paste(x[1],"-",x[2]))) diff --git a/R/RunSystemToCell.R b/R/RunSystemToCell.R index bdf347b..475234d 100644 --- a/R/RunSystemToCell.R +++ b/R/RunSystemToCell.R @@ -9,8 +9,8 @@ #' Meta.data slots by default contain "ReceivingType" information, which is the celltypes for each point, #' and "ReceivingCell" which is the exact cell barcode present in the original Seurat object. #' -#' @param sys.small A filtered Seurat object. The active identity will be used to define populations for connectomic sampling and crossings. -#' @param ground.truth Ground truth signaling mechanisms present in sys.small. +#' @param filtered.obj A filtered Seurat object. The active identity will be used to define populations for connectomic sampling and crossings. +#' @param ground.truth Ground truth signaling mechanisms present in filtered.obj. #' @param assay The assay to run the SystemToCell transformation on. Defaults to "RNA." #' @param blend Choice of linear operator to combine edges. Defaults to "mean", also accepts "sum", "mean.adj" #' @param meta.data.to.map A character vector of metadata names present in the original object which will be carried to the NICHES objects @@ -19,7 +19,7 @@ #' @export -RunSystemToCell <- function(sys.small, +RunSystemToCell <- function(filtered.obj, ground.truth, assay, blend = 'mean', @@ -33,11 +33,11 @@ RunSystemToCell <- function(sys.small, # Ligand data subunit.list <- list() # Builds sending (ligand) data for any number of ligand subunits for (s in 1:ncol(ground.truth$source.subunits)){ #For each subunit column... - subunit.list[[s]] <- matrix(data = 1,nrow = nrow(ground.truth$source.subunits),ncol = ncol(sys.small)) #initialize a mechanism x barcode matrix of all NAs - colnames(subunit.list[[s]]) <- colnames(sys.small) + subunit.list[[s]] <- matrix(data = 1,nrow = nrow(ground.truth$source.subunits),ncol = ncol(filtered.obj)) #initialize a mechanism x barcode matrix of all NAs + colnames(subunit.list[[s]]) <- colnames(filtered.obj) rownames(subunit.list[[s]]) <- rownames(ground.truth$source.subunits) non.na.indices <- !is.na(ground.truth$source.subunits[,s]) #Identify rows in the s-th column of the ground truth which are not NA - subunit.list[[s]][non.na.indices,] <- as.matrix(getSeuratAssay(sys.small,assay,"data")[ground.truth$source.subunits[non.na.indices,s],]) #For every row in the initialized matrix corresponding to the indices of the ground.truth which are not NA, replace with the rows from the Seurat object corresponding to the genes in the ground.truth at those indices + subunit.list[[s]][non.na.indices,] <- as.matrix(getSeuratAssay(filtered.obj,assay,"data")[ground.truth$source.subunits[non.na.indices,s],]) #For every row in the initialized matrix corresponding to the indices of the ground.truth which are not NA, replace with the rows from the Seurat object corresponding to the genes in the ground.truth at those indices } lig.map <- Reduce('*',subunit.list) rm(subunit.list) @@ -60,11 +60,11 @@ RunSystemToCell <- function(sys.small, # Receptor data subunit.list <- list() # Builds receiving (receptor) data for any number of receptor subunits for (t in 1:ncol(ground.truth$target.subunits)){ - subunit.list[[t]] <- matrix(data = 1,nrow = nrow(ground.truth$target.subunits),ncol = ncol(sys.small)) #initialize a mechanism x barcode matrix of all NAs - colnames(subunit.list[[t]]) <- colnames(sys.small) + subunit.list[[t]] <- matrix(data = 1,nrow = nrow(ground.truth$target.subunits),ncol = ncol(filtered.obj)) #initialize a mechanism x barcode matrix of all NAs + colnames(subunit.list[[t]]) <- colnames(filtered.obj) rownames(subunit.list[[t]]) <- rownames(ground.truth$target.subunits) non.na.indices <- !is.na(ground.truth$target.subunits[,t]) #Identify rows in the s-th column of the ground truth which are not NA - subunit.list[[t]][non.na.indices,] <- as.matrix(getSeuratAssay(sys.small,assay,"data")[ground.truth$target.subunits[non.na.indices,t],]) #For every row in the initialized matrix corresponding to the indices of the ground.truth which are not NA, replace with the rows from the Seurat object corresponding to the genes in the ground.truth at those indices + subunit.list[[t]][non.na.indices,] <- as.matrix(getSeuratAssay(filtered.obj,assay,"data")[ground.truth$target.subunits[non.na.indices,t],]) #For every row in the initialized matrix corresponding to the indices of the ground.truth which are not NA, replace with the rows from the Seurat object corresponding to the genes in the ground.truth at those indices } rec.map <- Reduce('*',subunit.list) rm(subunit.list) @@ -82,7 +82,7 @@ RunSystemToCell <- function(sys.small, demo <- Seurat::CreateSeuratObject(counts = as.matrix(sc.connectome),assay = 'SystemToCell') # JC: Seurat V5 will not create data slot automatically, the following step is to manually add this slot if(SeuratObject::Version(demo) >= "5.0.0"){ - demo <- NormalizeData(demo,assay = "SystemToCell") # Seurat Object need to be >= 5.0.1 + demo <- Seurat::NormalizeData(demo,assay = "SystemToCell") # Seurat Object need to be >= 5.0.1 demo@assays$SystemToCell@layers$data <- demo@assays$SystemToCell@layers$counts # Seurat Object need to be >= 5.0.1 } @@ -93,7 +93,7 @@ RunSystemToCell <- function(sys.small, demo <- Seurat::AddMetaData(demo,metadata = meta.data.to.add,col.name = 'ReceivingCell') # bug fix: add the system - prefix - receiving_type.meta <- data.frame(Seurat::Idents(sys.small)) + receiving_type.meta <- data.frame(Seurat::Idents(filtered.obj)) rownames(receiving_type.meta) <- paste("System",rownames(receiving_type.meta),sep = '—') demo <- Seurat::AddMetaData(demo,metadata = receiving_type.meta,col.name = 'ReceivingType') @@ -105,8 +105,8 @@ RunSystemToCell <- function(sys.small, receiving.barcodes <- colnames(rec.map) # Pull and format sending and receiving metadata #sending.metadata <- as.matrix(object@meta.data[,meta.data.to.map][sending.barcodes,]) - # jc: possible bug, change object to sys.small - receiving.metadata <- as.matrix(sys.small@meta.data[,meta.data.to.map,drop=FALSE][receiving.barcodes,]) + # jc: possible bug, change object to filtered.obj + receiving.metadata <- as.matrix(filtered.obj@meta.data[,meta.data.to.map,drop=FALSE][receiving.barcodes,]) # Make joint metadata #datArray <- abind(sending.metadata,receiving.metadata,along=3) #joint.metadata <- as.matrix(apply(datArray,1:2,function(x)paste(x[1],"-",x[2]))) diff --git a/R/utils.R b/R/utils.R index 63d9d78..a7af241 100644 --- a/R/utils.R +++ b/R/utils.R @@ -26,14 +26,14 @@ prepSeurat <- function(object,assay,min.cells.per.ident,min.cells.per.gene){ Seurat::DefaultAssay(object) <- assay # Stash object - sys.small <- object + filtered.obj <- object # Limit object to cell populations larger than requested minimum if (!is.null(min.cells.per.ident)){ message(paste("\n",'Subsetting to populations with greater than',min.cells.per.ident,'cells')) - idents.include <- names(table(Seurat::Idents(sys.small)))[table(Seurat::Idents(sys.small)) > min.cells.per.ident] - sys.small <- subset(sys.small,idents = idents.include) + idents.include <- names(table(Seurat::Idents(filtered.obj)))[table(Seurat::Idents(filtered.obj)) > min.cells.per.ident] + filtered.obj <- subset(filtered.obj,idents = idents.include) } # Limit analysis to interaction involving genes expressed above minimum threshold number of cells in the system @@ -41,18 +41,18 @@ prepSeurat <- function(object,assay,min.cells.per.ident,min.cells.per.gene){ message(paste("\n",'Subsetting to genes expressed in greater than',min.cells.per.gene,'cells')) # jc: return an error if the count matrix in the given assay is empty - if(!length(getSeuratAssay(sys.small,assay,"counts"))) stop("Unable to subset: the count matrix in the given assay is empty.") + if(!length(getSeuratAssay(filtered.obj,assay,"counts"))) stop("Unable to subset: the count matrix in the given assay is empty.") - cells.per.gene <- data.frame(non.zero.cells = Matrix::rowSums(getSeuratAssay(sys.small,assay,"counts")>0)) + cells.per.gene <- data.frame(non.zero.cells = Matrix::rowSums(getSeuratAssay(filtered.obj,assay,"counts")>0)) GOI <- subset(cells.per.gene,non.zero.cells > min.cells.per.gene) - sys.small <- sys.small[rownames(GOI),] + filtered.obj <- filtered.obj[rownames(GOI),] } - num.cells <- ncol(sys.small) + num.cells <- ncol(filtered.obj) message(paste("\n",num.cells,'distinct cells from', - length(names(table(Seurat::Idents(sys.small)))),'celltypes to be analyzed')) + length(names(table(Seurat::Idents(filtered.obj)))),'celltypes to be analyzed')) - return(sys.small) + return(filtered.obj) } @@ -100,7 +100,7 @@ return_celltypes <- function(seurat_object){ #' Compute an edgelist based on the spatial coordinates #' -#' @param sys.small A filtered Seurat object. The active identity will be used to define populations for connectomic sampling and crossings. +#' @param filtered.obj A filtered Seurat object. The active identity will be used to define populations for connectomic sampling and crossings. #' @param position.x string. Optional. Default: NULL. The name of the meta.data column specifying location on the spatial x-axis. Only required for spatial omics data. #' @param position.y string. Optional. Default: NULL. The name of the meta.data column specifying location on the spatial y-axis. Only required for spatial omics data. #' @param k integer. Optional. Default: 4. Number of neighbors in a knn graph. Used to compute a mutual nearest neighbor graph based on the spatial coordinates of the spatial transcriptomic datasets. @@ -108,7 +108,7 @@ return_celltypes <- function(seurat_object){ #' #' @export #' -compute_edgelist <- function(sys.small, +compute_edgelist <- function(filtered.obj, position.x, position.y, k=4, @@ -120,8 +120,8 @@ compute_edgelist <- function(sys.small, # Create adjacency matrix # Adapted from :: https://stackoverflow.com/questions/16075232/how-to-create-adjacency-matrix-from-grid-coordinates-in-r # Setup numbering and labeling - # jc: possible bug, change object to sys.small - df <- data.frame(x = sys.small[[position.x]], y = sys.small[[position.y]]) + # jc: possible bug, change object to filtered.obj + df <- data.frame(x = filtered.obj[[position.x]], y = filtered.obj[[position.y]]) df$barcode <- rownames(df) df$x <- as.character(df$x) df$y <- as.character(df$y)