Commit 16d72c0e authored by smorabit's avatar smorabit
Browse files

error check for selectnetworkgenes

parent cd665bdf
Loading
Loading
Loading
Loading
+25 −2
Original line number Diff line number Diff line
@@ -15,7 +15,8 @@ SelectNetworkGenes <- function(
  seurat_obj,
  gene_select="variable", fraction=0.05,
  group.by=NULL, # should be a column in the Seurat object, eg clusters
  gene_list=NULL, wgcna_name=NULL
  gene_list=NULL,
  wgcna_name=NULL
 ){

  # validate inputs:
@@ -23,6 +24,14 @@ SelectNetworkGenes <- function(
    stop(paste0("Invalid selection gene_select: ", gene_select, '. Valid gene_selects are variable, fraction, all, or custom.'))
  }

  # get assay
  assay <- DefaultAssay(seurat_obj)
  tryCatch(
   tmp <- dim(seurat_obj[[assay]]@counts),
   error = function(e){
     print("Assay must contain counts slot.")
   })

  # handle different selection strategies
  if(gene_select == "fraction"){

@@ -456,12 +465,24 @@ ComputeModuleEigengene <- function(

  # set as active assay if wgcna_name is not given
  if(is.null(wgcna_name)){wgcna_name <- seurat_obj@misc$active_wgcna}
  ass <- DefaultAssay(seurat_obj)

  # get genes in this module:
  cur_genes <- modules %>% subset(module == cur_mod) %>% .$gene_name

  # subset seurat object by these genes only:
  cur_seurat <- seurat_obj[cur_genes,]
  X <- GetAssayData(seurat_obj, slot='counts')[cur_genes,]
  X_dat <- GetAssayData(seurat_obj, slot='data')[cur_genes,]
  X_scaled <- GetAssayData(seurat_obj, slot='scale.data')[cur_genes,]
  cur_seurat <- CreateSeuratObject(X, assay = ass, meta.data = seurat_obj@meta.data)
  cur_seurat <- SetAssayData(cur_seurat, slot='data', new.data=X_dat, assay=ass)
  cur_seurat <- SetAssayData(cur_seurat, slot='scale.data', new.data=X_scaled, assay=ass)

  print(ass)
  print(head(cur_genes))
  # cur_seurat <- seurat_obj
  # cur_seurat[[ass]] <- cur_seurat[[ass]][cur_genes,]
  print('subset success')

  # scale the subsetted expression dataset:
  if(is.null(vars.to.regress)){
@@ -472,6 +493,7 @@ ComputeModuleEigengene <- function(
    stop(paste0("Some variables specified in vars.to.regress are not found in seurat_obj@meta.data"))
  }


  # compute average expression of each gene
  cur_expr <- GetAssayData(cur_seurat, slot='data')
  expr <- t(as.matrix(cur_expr))
@@ -619,6 +641,7 @@ ModuleEigengenes <- function(
  for(cur_mod in mods){

    print(cur_mod)
    print('here')

    # compute module eigengenes for this module
    seurat_obj <- ComputeModuleEigengene(
+1 −1
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ articles:
  network_visualizations: network_visualizations.html
  projecting_modules: projecting_modules.html
  projecting_modules_cross: projecting_modules_cross.html
last_built: 2022-05-24T23:24Z
last_built: 2022-06-03T00:21Z
urls:
  reference: https://smorabit.github.io/scWGCNA/reference
  article: https://smorabit.github.io/scWGCNA/articles
+1 −1
Original line number Diff line number Diff line
@@ -234,7 +234,7 @@
<span class="r-out co"><span class="r-pr">#&gt;</span>     }</span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     out</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> }</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> &lt;bytecode: 0x7faaeb538c38&gt;</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> &lt;bytecode: 0x7fc3084faf60&gt;</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> &lt;environment: namespace:hdWGCNA&gt;</span>
</code></pre></div>
    </div>
+1 −1
Original line number Diff line number Diff line
@@ -221,7 +221,7 @@ using Seurat's DoHeatmap, and then assembles them all into one big heatmap.</p>
<span class="r-out co"><span class="r-pr">#&gt;</span>     }</span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     out</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> }</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> &lt;bytecode: 0x7faaeb216c38&gt;</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> &lt;bytecode: 0x7fc30aa4cd80&gt;</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> &lt;environment: namespace:hdWGCNA&gt;</span>
</code></pre></div>
    </div>
+1 −1
Original line number Diff line number Diff line
@@ -195,7 +195,7 @@
<span class="r-out co"><span class="r-pr">#&gt;</span>         dev.off()</span>
<span class="r-out co"><span class="r-pr">#&gt;</span>     }</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> }</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> &lt;bytecode: 0x7faaec252890&gt;</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> &lt;bytecode: 0x7fc305eab288&gt;</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> &lt;environment: namespace:hdWGCNA&gt;</span>
</code></pre></div>
    </div>
Loading