Open AnjaliS1 opened 1 year ago
Can you please provide the code that you ran?
Yes of course! This is the entirety of my code up until the plot:
library(Seurat)
library(tidyverse) library(cowplot) library(patchwork)
library(WGCNA) library(hdWGCNA)
theme_set(theme_cowplot())
set.seed(12345)
Smith_microglia <- readRDS("~/WGCNA_Smith/microglia_cluster.rds")
library(readr)
background <- read_tsv("~/scFlow_Workshop/refs/ensembl_mappings.tsv") background_genes <- background$external_gene_name[which(background$gene_biotype=='protein_coding')]
Smith_microglia <- Smith_microglia[which(rownames(Smith_microglia) %in% background_genes),]
######################################################################################### Smith_microglia <- NormalizeData(Smith_microglia)
Smith_microglia[["percent.mt"]] <- PercentageFeatureSet(Smith_microglia, pattern = "^MT-")
Idents(Smith_microglia) <- Smith_microglia$cluster_celltype
Smith_microglia <- FindVariableFeatures(Smith_microglia, selection.method = "vst", nfeatures = 2000) genes.keep <- VariableFeatures(Smith_microglia)
microglia <- SetupForWGCNA( Smith_microglia, gene_select = "variable", # the gene selection approach wgcna_name = "microglia" # the name of the hdWGCNA experiment )
microglia <- MetacellsByGroups( seurat_obj = microglia, group.by = c("individual", "cluster_celltype"), # specify the columns in seurat_obj@meta.data to group by k = 40, # nearest-neighbors parameter max_shared = 10, # maximum number of shared cells between two metacells ident.group = 'cluster_celltype', reduction = "tSNE_Liger"# set the Idents of the metacell seurat object )
microglia <- NormalizeMetacells(microglia)
microglia <- SetDatExpr( microglia, group_name = "Micro", # the name of the group of interest in the group.by column group.by='cluster_celltype', # the metadata column containing the cell type info. This same column should have also been used in MetacellsByGroups assay = 'originalexp', # using RNA assay slot = 'data' # using normalized data )
microglia<- TestSoftPowers( microglia, networkType = 'signed' # you can also use "unsigned" or "signed hybrid" )
plot_list <- PlotSoftPowers(microglia)
wrap_plots(plot_list, ncol=2)
power_table <- GetPowerTable(microglia) head(power_table)
microglia <- ConstructNetwork( microglia, soft_power=6, setDatExpr=FALSE, tom_name = 'Micro', randomSeed = 12345, corType = "pearson", deepSplit=2, TOMType = "signed", minModuleSize = 10, reassignThreshold = 0, mergeCutHeight = 0.4, detectCutHeight = 0.995, numericLabels = TRUE, pamRespectsDendro = FALSE, saveTOMs = FALSE, verbose = 3, networkType="signed")# name of the topoligical overlap matrix written to disk
PlotDendrogram(microglia, main='Microglia hdWGCNA Dendrogram')
microglia <- ScaleData(microglia, features=VariableFeatures(microglia))
microglia <- ModuleEigengenes( microglia, group.by.vars="individual" )
hMEs <- GetMEs(microglia)
MEs <- GetMEs(microglia, harmonized=FALSE)
microglia <- ModuleConnectivity( microglia, group.by = 'cluster_celltype', group_name = 'Micro' )
microglia <- ResetModuleNames( microglia, new_name = "Micro-M" )
p <- PlotKMEs(microglia, ncol=5)
p
modules <- GetModules(microglia)
head(modules[,1:6])
hub_df <- GetHubGenes(microglia, n_hubs = 10)
head(hub_df)
hub <- hub_df %>% group_by(module) %>% filter(kME == max(kME)) %>% ungroup()
saveRDS(microglia, file='hdWGCNA_object.rds')
microglia <- ModuleExprScore( microglia, n_genes = 25, method='Seurat' )
library(UCell) microglia <- ModuleExprScore( microglia, n_genes = 25, method='UCell' )
plot_list1 <- ModuleFeaturePlot( microglia, features='hMEs', # plot the hMEs order=TRUE, reduction = "tSNE_Liger"# order so the points with highest hMEs are on top )
wrap_plots(plot_list1, ncol=6)
plot_list2 <- ModuleFeaturePlot( microglia, features='scores', # plot the hub gene scores order='shuffle', # order so cells are shuffled ucell = TRUE, reduction = "tSNE_Liger"# depending on Seurat vs UCell for gene scoring )
wrap_plots(plot_list2, ncol=6)
ModuleCorrelogram(microglia)
MEs <- GetMEs(microglia, harmonized=TRUE) mods <- colnames(MEs); mods <- mods[mods != 'grey']
microglia@meta.data <- cbind(microglia@meta.data, MEs)
dotp <- DotPlot(microglia, features=mods, group.by = 'cluster_celltype')
dotp <- dotp +
RotatedAxis() + scale_color_gradient2(high='red', mid='grey95', low='blue') +
dotp
p <- VlnPlot( microglia, features = '1', group.by = 'cluster_celltype', pt.size = 0 # don't show actual data points )
p <- p + geom_boxplot(width=.25, fill='white')
p <- p + xlab('') + ylab('hME') + NoLegend()
p
#########################################################################################
ModuleNetworkPlot(microglia)
Error in col2rgb(col, alpha = TRUE) : numerical color values must be positive
#################################################################################
microglia@meta.data <- microglia@meta.data %>% mutate_all(., as.character) %>% mutate(AD = diagnosis, Control = diagnosis, Male = sex, Female = sex) %>% mutate_at(vars("AD"), ~ ifelse(. == "AD", 1, 0)) %>% mutate_at(vars("Control"), ~ ifelse(. == "Control", 1, 0)) %>% mutate_at(vars("Male"), ~ ifelse(. == "M", 1, 0)) %>% mutate_at(vars("Female"), ~ ifelse(. == "F", 1, 0)) %>% dplyr::select(-c(diagnosis, sex, orig.ident, barcode, manifest, sequence_id, individual, brain_region, diagnosis_brain_region, individual_brain_region, is_empty_drop, is_singlet, cluster_celltype, Allan2019_ML1, Allan2019_ML2, Zeisel2018_ML4, Zeisel2018_ML5, allan_celltype, allan_layer, allan_cluster_gene_1, allan_cluster_2, cluster_celltype_pipeline, metacell_grouping)) %>% mutate_all(as.numeric)
group1 <- microglia@meta.data %>% subset(AD == 1) %>% rownames group2 <- microglia@meta.data %>% subset(Control == 1) %>% rownames
head(group1)
DMEs <- FindDMEs( microglia, barcodes1 = group1, barcodes2 = group2, test.use='wilcox', wgcna_name='microglia' )
head(DMEs)
PlotDMEsVolcano( microglia, DMEs, wgcna_name = 'microglia' )
Error: colours encodes as numbers must be positive
I am new to computational work. I keep running into this specific error when trying to use any of the plot functions, such as PlotDMEsVolcano: Error: colours encodes as numbers must be positive. However, each of my modules are named after positive numbers and therefore their assigned color numbers are also positive. I have followed the vignettes exactly with the only changes being that I used my own dataset. I had a look online and found an answer that said "The issue is that you did not map on aesthetics but instead pass vectors to arguments. When doing so you have to pass color names or codes or a positive number to the color argument". Not sure if this is what the actual issue is and if so, then the function would need to be altered? Is there any advice that you would suggest as mapping to aesthetics didn't solve the error?