WGCNA Package in R

Here is my code. I am new to R and i need help. I dont know what to do because i keep getting the same messages over and over again. someone please help me. I am desperate.

Code:

Install required packages

install.packages('WGCNA')
install.packages('edgeR')
install.packages('matrixStats')

Load the required packages

library(WGCNA)
library(edgeR)
library(matrixStats)

Display the current working directory

getwd()

Set the working directory

workingDir = "/Users/ayanpatel/LumiereProject"
setwd(workingDir)

The following setting is important, do not omit.

options(stringsAsFactors = FALSE)

Read in the dataset

Data = read.csv("GSE194313_FPKM.matrix.csv", head = TRUE, sep="")

Preprocessing steps

rownames(Data) = Data[,"GeneID"]
Data = Data[,-c(1:3)]
Data = Data[!rowSums(as.matrix(Data)) == 0,]

Take a quick look at the data set

dim(Data)
names(Data)

Additional preprocessing steps

Data <- DGEList(Data)
Data <- calcNormFactors(Data, method = "TMM")
Data <- cpm(Data)

Continue with the rest of your code

powers <- c(c(1:10), seq(from = 12, to = 20, by = 2))
sft <- pickSoftThreshold(Data, powerVector = powers, verbose = 5)
sizeGrWindow(9, 5)
par(mfrow = c(1, 2))
cex1 <- 0.9

plot(sft$fitIndices[, 1], -sign(sft$fitIndices[, 3]) * sft$fitIndices[, 2],
xlab = "Soft Threshold (power)", ylab = "Scale Free Topology Model Fit, signed R^2", type = "n",
main = paste("Scale independence"))
text(sft$fitIndices[, 1], -sign(sft$fitIndices[, 3]) * sft$fitIndices[, 2],)

net = blockwiseModules(datExpr, power = 6,
TOMType = "unsigned", minModuleSize = 30,
reassignThreshold = 0, mergeCutHeight = 0.25,
numericLabels = TRUE, pamRespectsDendro = FALSE,
saveTOMs = TRUE,
saveTOMFileBase = "lunghemorrhageTOM",
verbose = 3)

open a graphics window

sizeGrWindow(12, 9)

Convert labels to colors for plotting

mergedColors = labels2colors(net$colors)

Plot the dendrogram and the module colors underneath

plotDendroAndColors(net$dendrograms[[1]], mergedColors[net$blockGenes[[1]]],
"Module colors",
dendroLabels = FALSE, hang = 0.03,
addGuide = TRUE, guideHang = 0.05)

moduleLabels = net$colors
moduleColors = labels2colors(net$colors)
MEs = net$MEs;
geneTree = net$dendrograms[[1]];
save(MEs, moduleLabels, moduleColors, geneTree,
file = "Lunghemorrhage.RData")

Without a reprex (see the FAQ). It's hard to see what's going on. If the error arises early on it may be due to

which specifies no separator. Try omitting sep=""

this is the error im getting: Error: package or namespace load failed for ‘WGCNA’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
there is no package called ‘impute’

I used the sep="" to create columns. My mentor did that.

This is asking for

install.packages(“impute”)

yes i did that but it still gives me the same error

Did you also

library(“impute”)

(Otherwise, we need to talk about whether the installation was successful.)

does it need " ". because i havent put any of my things in ""

nvm it does the same thing. There isnt any package call impute to install there is imputeR and all these other imputes but no plain old impute. idk if it is because of the type of Rstudio that i have or something

I'll install later and get back to you late PDT.

You see this commonly on life sciences packages—dependencies on packages that are only available through the specialized life sciences repository, Bioconductor.org. Here's the fix

if (!require("BiocManager", quietly = TRUE))
  install.packages("BiocManager")

BiocManager::install("impute")

thanks, it fixed that issue but created another issue some how. now it says: Error in DGEList(Data) : could not find function "DGEList".

Is from the edgeR package, also on the bioconductor repo

so would i just do the same thing

thanks so much for your help. do you know what to do to get the trait heatmap. Chatgpt gave me this code but it says i need a thing for traitdata which i have no clue how to do.

Code:

Calculate trait-sample correlation matrix

traitCor <- cor(t(traitData), MEs)

Set up heatmap parameters

heatmapColors <- colorRampPalette(c("blue", "white", "red"))(50) # Adjust colors as needed
heatmapRowLabels <- colnames(traitData)
heatmapColumnLabels <- moduleLabels
heatmapMain <- "Trait Heatmap"

Create trait heatmap

heatmap(traitCor, col = heatmapColors, Rowv = NA, Colv = NA,
main = heatmapMain, xlab = "Module", ylab = "Trait",
labRow = heatmapRowLabels, labCol = heatmapColumnLabels)

also i need to produce a scale independence graph, a mean connectivity graph, and a cluster dendrogram with the color at the bottom and i think its supposed to have more branches because the one that was just made only has like 4 branches while the one on the ucla tutorial is really clustered.

That's your data that you want to show in a heatmap

like what is the format that i am supposed to type it in

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.