Commit a034f322 authored by smorabit's avatar smorabit
Browse files

Bug fix for ModuleTraitCorrelation

parent 501c4a29
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
Package: hdWGCNA
Title: hdWGCNA
Version: 0.1.1.9003
Version: 0.1.1.9004
Authors@R: c(
    person("Sam", "Morabito", , "smorabit@uci.edu", role = c("aut", "cre"),
           comment = c(ORCID = "0000-0002-7768-4856")),
+7 −0
Original line number Diff line number Diff line
# hdWGCNA 0.1.1.9004 (2022-6-13)
## Added
- None

## Changes
- Bug fix so `ModuleTraitCorrelation` can be run with a single trait.

# hdWGCNA 0.1.1.9003 (2022-6-11)
## Added
- `GetHubGenes` function to extract the top hub genes from the module assignment table.
+39 −4
Original line number Diff line number Diff line
@@ -1776,6 +1776,12 @@ ModuleTraitCorrelation <- function(
  # get trait table:
  trait_df <- seurat_obj@meta.data[,traits]

  # cast vector to data frame if there's only one trait
  if(length(traits == 1)){
    trait_df <- data.frame(x = trait_df)
    colnames(trait_df) <- traits
  }

  # convert factors to numeric
  if(any(data_types == 'factor')){
    factor_traits <- traits[data_types == 'factor']
@@ -1796,7 +1802,21 @@ ModuleTraitCorrelation <- function(

  # compute FDR:
  p_df <- cur_p %>%
    reshape2::melt() %>%
    reshape2::melt()

    if(length(traits) == 1){

      tmp <- rep(mods, length(traits))
      tmp <- factor(tmp, levels = mods)
      tmp <- tmp[order(tmp)]

      p_df$Var1 <- traits
      p_df$Var2 <- tmp
      rownames(p_df) <- 1:nrow(p_df)
      p_df <- dplyr::select(p_df, c(Var1, Var2, value))
    }

  p_df <- p_df %>%
  dplyr::mutate(fdr=p.adjust(value, method='fdr')) %>%
  dplyr::select(c(Var1, Var2, fdr))

@@ -1839,7 +1859,22 @@ ModuleTraitCorrelation <- function(

    # compute FDR:
    p_df <- cur_p %>%
      reshape2::melt() %>%
      reshape2::melt()


    if(length(traits) == 1){

      tmp <- rep(mods, length(traits))
      tmp <- factor(tmp, levels = mods)
      tmp <- tmp[order(tmp)]

      p_df$Var1 <- traits
      p_df$Var2 <- tmp
      rownames(p_df) <- 1:nrow(p_df)
      p_df <- dplyr::select(p_df, c(Var1, Var2, value))
    }

    p_df <- p_df %>%
      dplyr::mutate(fdr=p.adjust(value, method='fdr')) %>%
      dplyr::select(c(Var1, Var2, fdr))

+2 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ ConstructMetacells <- function(
    seurat_obj <- seurat_obj[,cells.use]
  }


  reduced_coordinates <- as.data.frame(seurat_obj@reductions[[reduction]]@cell.embeddings)
  nn_map <- FNN::knn.index(reduced_coordinates, k = (k - 1))
  row.names(nn_map) <- row.names(reduced_coordinates)
@@ -132,6 +133,7 @@ ConstructMetacells <- function(
    max_shared = max_shared,
    mean_shared = mean_shared,
    median_shared = median_shared,
    density = density,
    n = ncol(new_exprs)
  )

+5 −2
Original line number Diff line number Diff line
@@ -1903,13 +1903,16 @@ PlotModuleTraitCorrelation <- function(

  if(is.null(wgcna_name)){wgcna_name <- seurat_obj@misc$active_wgcna}


  # get the module trait correlation results:
  temp <- GetModuleTraitCorrelation(seurat_obj)
  temp <- GetModuleTraitCorrelation(seurat_obj, wgcna_name)
  cor_list <- temp$cor
  pval_list <- temp$pval
  fdr_list <- temp$fdr

  if(is.null(dim(cor_list[[1]]))){
    stop('ModuleTraitCorrelation was run only for one trait. Heatmaps are not suggested for visualizing only one variable!')
  }

  # get module colors:
  modules <- GetModules(seurat_obj, wgcna_name)
  module_colors <- modules %>%
Loading