Commit 4c06c719 authored by smorabit's avatar smorabit
Browse files

MetaspotsByGroups bugfix

parent d32e467d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
Package: hdWGCNA
Title: hdWGCNA
Version: 0.2.00
Version: 0.2.01
Authors@R: c(
    person("Sam", "Morabito", , "smorabit@uci.edu", role = c("aut", "cre"),
           comment = c(ORCID = "0000-0002-7768-4856")),
+8 −0
Original line number Diff line number Diff line
# hdWGCNA 0.2.01 (2022-10-06)
## Added
- None

## Changes
- Bugfix in `MetaspotsByGroups`.


# hdWGCNA 0.2.00 (2022-09-23)
## Added
- `MetaspotsByGroups` to aggregate neighboring ST spots prior to network analysis.
+12 −0
Original line number Diff line number Diff line
@@ -96,6 +96,11 @@ ConstructMetaspots <- function(

    })

    if(length(tmp) <= 1){
      print('here')
      next
    }

    # get bc-neighbor results
    bcs <- unlist(lapply(1:length(tmp), function(k){tmp[[k]][[1]]}))
    cur_neighbors <- lapply(1:length(tmp), function(k){tmp[[k]][[2]]})
@@ -119,8 +124,15 @@ ConstructMetaspots <- function(
  names(cur_neighbors) <- bcs

  # combine expression results
  if(length(tmp) <= 1){
    return(NULL)
  }
  agg_X <- do.call(rbind, lapply(1:length(tmp), function(k){tmp[[k]][[3]]}))


  # print(length(tmp))
  # print(dim(agg_X))

  # transpose expression matrix:
  agg_X <- t(agg_X)
  colnames(agg_X) <- bcs
+13 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
#' @param assay Assay to extract data for aggregation. Default = 'Spatial'
#' @param slot Slot to extract data for aggregation. Default = 'counts'
#' @param mode determines how to make gene expression profiles for metacells from their constituent single cells. Options are "average" or "sum".
#' @param min_spots the minimum number of spots in a particular grouping to construct metaspots
#' @param wgcna_name name of the WGCNA experiment
#' @keywords ST
#' @export
@@ -20,6 +21,7 @@ MetaspotsByGroups <- function(
  assay = 'Spatial',
  slot = 'counts',
  mode = 'sum',
  min_spots = 50,
  wgcna_name = NULL
){

@@ -76,6 +78,17 @@ MetaspotsByGroups <- function(
  groupings <- unique(seurat_obj$metacell_grouping)
  groupings <- groupings[order(groupings)]

  # remove groups that are too small:
  group_counts <- table(seurat_obj$metacell_grouping) < min_spots
  if(any(group_counts)){
    warning(paste0("Removing the following groups that did not meet min_spots: ", paste(names(group_counts)[group_counts], collapse=', ')))
  }
  groupings <- groupings[table(seurat_obj$metacell_grouping) >= min_spots]

  if(length(groupings) == 0 ){
    stop("No groups met the min_spots requirement.")
  }

  # split seurat obj by groupings
  seurat_list <- lapply(groupings, function(x){seurat_obj[,seurat_obj$metacell_grouping == x]})
  names(seurat_list) <- groupings
+3 −3
Original line number Diff line number Diff line
@@ -312,7 +312,7 @@ GetDatExpr <- function(seurat_obj, wgcna_name=NULL){
#' @keywords scRNA-seq
#' @export
#' @examples
#' SetDatExpr
#' SetMultiExpr
SetMultiExpr <- function(
  seurat_obj,
  group_name,
@@ -348,9 +348,9 @@ SetMultiExpr <- function(

  # get the different groups present if not specified by the user:
  if(is.null(multi_groups)){
    multi_groups <- unique(seurat_obj@meta.data[[multi.group.by]])
    multi_groups <- unique(s_obj@meta.data[[multi.group.by]])
  } else{
    seurat_groups <- unique(seurat_obj@meta.data[[multi.group.by]])
    seurat_groups <- unique(s_obj@meta.data[[multi.group.by]])
    if(sum(multi_groups %in% seurat_groups) != length(multi_groups)){
      stop('Some or all groups specified in multi_groups not found in seurat_obj@meta.data[,multi.group.by]')
    }
Loading