Commit 93fd73d5 authored by smorabit's avatar smorabit
Browse files

working on pkgdown

parent a44f5729
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -13,4 +13,5 @@ License: `use_mit_license()`, `use_gpl3_license()` or friends to
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.1
RoxygenNote: 7.1.2
URL: https://smorabit.github.io/scWGCNA/
+36 −0
Original line number Diff line number Diff line
# Generated by roxygen2: do not edit by hand

export(AvgModuleExpr)
export(ComputeModuleEigengene)
export(ComputeROC)
export(ConstructMetacells)
export(ConstructNetwork)
export(DimPlotMetacells)
export(EnrichrBarPlot)
export(EnrichrDotPlot)
export(GetDatExpr)
export(GetMEs)
export(HubGeneNetworkPlot)
export(MetacellsByGroups)
export(ModuleConnectivity)
export(ModuleCorrNetwork)
export(ModuleCorrelogram)
export(ModuleEigengenes)
export(ModuleExprScore)
export(ModuleFeaturePlot)
export(ModuleNetworkPlot)
export(NormalizeMetacells)
export(OverlapBarPlot)
export(OverlapDotPlot)
export(OverlapModulesDEGs)
export(PlotDendrogram)
export(ProjectModules)
export(ROCCurves)
export(RunEnrichr)
export(RunHarmonyMetacells)
export(RunPCAMetacells)
export(RunUMAPMetacells)
export(ScaleMetacells)
export(SelectNetworkGenes)
export(SetDatExpr)
export(SetupForWGCNA)
export(TestSoftPowers)
export(TransferModuleGenome)
export(construct_metacells)
export(metacells_by_groups)
+11 −9
Original line number Diff line number Diff line
@@ -918,6 +918,7 @@ ComputeROC <- function(
  scale_genes=TRUE,
  verbose=FALSE,
  exp_thresh = 0.75,
  return_seurat=TRUE,
  wgcna_name=NULL, wgcna_name_test=NULL
){

@@ -975,7 +976,6 @@ ComputeROC <- function(

  }

  print('here')

  # get names of different cell groupings in test
  groups_test <- as.character(unique(Idents(seurat_test)))
@@ -1010,13 +1010,6 @@ ComputeROC <- function(
    stop('Invalid feature selection. Valid choices: hMEs, MEs, scores.')
  )

  print('train')
  print(dim(MEs))
  print(dim(seurat_train))
  print('test')
  print(dim(MEs_p))
  print(dim(seurat_test))

  # add group column to MEs:
  MEs <- as.data.frame(MEs) %>% mutate(group = seurat_train@meta.data[[group.by]])
  MEs_p <- as.data.frame(MEs_p) %>% mutate(group = seurat_test@meta.data[[group.by]])
@@ -1072,10 +1065,19 @@ ComputeROC <- function(
  colnames(conf_df)[1:3] <- c('lo', 'mid', 'hi')

  # return ROC tables & objects:
  list(
  roc_info = list(
    roc = plot_df,
    conf = conf_df,
    objects = roc_list
  )

  if(return_seurat){
    # add roc info to seurat object:
    seurat_obj <- SetROCData(seurat_obj, roc_info, wgcna_name)
    out <- seurat_obj
  } else{
    out <- roc_info
  }

  out
}
+36 −0
Original line number Diff line number Diff line
@@ -381,6 +381,27 @@ GetTOM <- function(seurat_obj, wgcna_name=NULL){

}

############################
# ROC Curve
###########################

SetROCData <- function(seurat_obj, roc_info, wgcna_name=NULL){

  # get data from active assay if wgcna_name is not given
  if(is.null(wgcna_name)){wgcna_name <- seurat_obj@misc$active_wgcna}
  seurat_obj@misc[[wgcna_name]]$roc_data <- roc_info
  seurat_obj
}


GetROCData <- function(seurat_obj,  wgcna_name=NULL){

  # get data from active assay if wgcna_name is not given
  if(is.null(wgcna_name)){wgcna_name <- seurat_obj@misc$active_wgcna}
  seurat_obj@misc[[wgcna_name]]$roc_data
}


############################
# Reset module names:
###########################
@@ -479,6 +500,21 @@ ResetModuleNames <- function(
    seurat_obj <- SetEnrichrTable(seurat_obj, enrich_table, wgcna_name)
  }

  # update ROC info:
  # THIS DOES NOT UPDATE THE ROC OBJECTS THEMSELVES!!!
  roc_data <- GetROCData(seurat_obj, wgcna_name)
  if(!is.na(roc_data)){
    roc_data$roc$module <- factor(
      new_mod_df[match(roc_data$roc$module, new_mod_df$old),'new'],
      levels = as.character(new_mod_df$new)
    )
    roc_data$conf$module <- factor(
      new_mod_df[match(roc_data$conf$module, new_mod_df$old),'new'],
      levels = as.character(new_mod_df$new)
    )
    seurat_obj <- SetROCData(seurat_obj, roc_data, wgcna_name)
  }

  seurat_obj

}
+11 −7
Original line number Diff line number Diff line
@@ -908,9 +908,7 @@ OverlapDotPlot <- function(
  p
}

#' OverlapBarPlot
#'
#' Makes barplots from Enrichr data
#' Plots the results from OverlapModulesDEGs as a bar plot
#'
#' @param seurat_obj A Seurat object
#' @param dbs List of EnrichR databases
@@ -991,7 +989,7 @@ OverlapBarPlot <- function(
#' ROCCurves
ROCCurves <- function(
  seurat_obj,
  roc_df, conf_df, wgcna_name=NULL
  roc_df=NULL, conf_df=NULL, wgcna_name=NULL
){

  if(is.null(wgcna_name)){wgcna_name <- seurat_obj@misc$active_wgcna}
@@ -1007,15 +1005,21 @@ ROCCurves <- function(
    distinct %>%
    arrange(module) %>% .$color

  # get the ROC info from seurat obj:
  if(is.null(roc_df) | is.null(conf_df)){
    roc_df <- GetROCData(seurat_obj, wgcna_name)$roc
    conf_df <- GetROCData(seurat_obj, wgcna_name)$conf
  }

  # plot the ROC curve
  roc_df <- roc_df %>% group_by(module) %>% arrange(sensitivity)
  conf_df <- conf_df %>% group_by(module) %>% arrange(sensitivity)
  auc_df <- distinct(roc_df[,c('module', 'auc')])

  # set factor levels for modules:
  roc_df$module <- factor(roc_df$module, levels=mods)
  conf_df$module <- factor(conf_df$module, levels=mods)
  auc_df$module <- factor(auc_df$module, levels=mods)
  roc_df$module <- factor(as.character(roc_df$module), levels=mods)
  conf_df$module <- factor(as.character(conf_df$module), levels=mods)
  auc_df$module <- factor(as.character(auc_df$module), levels=mods)

  p <- roc_df %>% ggplot(
    aes(x=specificity, y=sensitivity, color=module, fill=module),
Loading