Entering edit mode

8 weeks ago

akansha.gitanjali
▴
30

I am performing WGCNA analysis on my RNAseq dataset and getting this error message:

```
>net = blockwiseModules(expression, power = 6,
+ TOMType = "unsigned", minModuleSize = 30,
+ reassignThreshold = 0, mergeCutHeight = 0.25,
+ numericLabels = TRUE, pamRespectsDendro = FALSE,
+ saveTOMs = TRUE,
+ saveTOMFileBase = "SW_TOM",
+ verbose = 3)
Calculating module eigengenes block-wise from all genes
Flagging genes and samples with too many missing values...
..step 1
..Excluding 722 genes from the calculation due to too many missing samples or zero variance.
..step 2
....pre-clustering genes to determine blocks..
Projective K-means:
..k-means clustering..
..merging smaller clusters...
Block sizes:
gBlocks
1 2 3 4 5
4999 4998 4945 4424 4306
..Working on block 1 .
Error in blockwiseModules(expression, power = 6, TOMType = "unsigned", :
REAL() can only be applied to a 'numeric', not a 'integer'
```

How do I solve this error? The code I used is given below.

```
library(WGCNA)
#Setting string not as factor
options(stringsAsFactors = FALSE)
#Enable multithread
enableWGCNAThreads()
#Reading the raw data (rows are the sample and columns the genes)
SWexpressiondata = read.csv("edgeR_normalized.csv")
#Create a new format expression data - remove gene name column
expression = as.data.frame(expressiondata[, -c(1)])
expression = t(expression)
#Column 1 - gene names
colnames(expression) = expressiondata$genes
rownames(expression) = names(expressiondata)[-c(1)]
#Group data in a dendogram to check outliers
sampleTree = hclust(dist(expression), method = "average")
dev.off()
sizeGrWindow(12,9)
par(cex = 0.6)
par(mar = c(0,4,2,0))
plot(sampleTree, main = "Sample clustering to detect outliers", sub="", xlab="", cex.lab = 1.5,
cex.axis = 1.5, cex.main = 2)
# Choose a set of soft-thresholding powers
powers = c(c(1:10), seq(from = 12, to = 20, by = 2))
# Call the network topology analysis function
sft = pickSoftThreshold(expression, # <= Input data
#blockSize = 30,
powerVector = powers,
verbose = 5)
# Plot the results:
sizeGrWindow(9, 5)
par(mfrow = c(1,2));
cex1 = 0.9;
# Scale-free topology fit index as a function of the soft-thresholding power
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],
labels = powers, cex = cex1, col = "red")
# this line corresponds to using an R^2 cut-off of h
abline(h = 0.90, col = "red")
# Mean connectivity as a function of the soft-thresholding power
plot(sft$fitIndices[, 1],
sft$fitIndices[, 5],
xlab = "Soft Threshold (power)",
ylab = "Mean Connectivity",
type = "n",
main = paste("Mean connectivity"))
text(sft$fitIndices[, 1],
sft$fitIndices[, 5],
labels = powers,
cex = cex1, col = "red")
```

possible solution: link

Using the above solution I get another error: "non-numeric argument to mathematical function"

check the expression matrix (

`expression`

) because you clearly have non-numeric values.Also, the expression matrix is uploaded as

`SWexpressiondata = read.csv("edgeR_normalized.csv")`

but along the code you use a different matrix`expression = as.data.frame(expressiondata[, -c(1)])`

I guess I was making some mistake. This code worked for me: