WGCNA error during network construction
0
0
Entering edit mode
2.6 years ago

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")
WGCNA R • 2.0k views
ADD COMMENT
0
Entering edit mode

possible solution: link

ADD REPLY
0
Entering edit mode

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

> bwnet = blockwiseModules(expression, maxBlockSize = 5000,
+                         power = 10, TOMType = "unsigned", minModuleSize = 100,
+                         reassignThreshold = 0, mergeCutHeight = 0.25,
+                         numericLabels = TRUE,
+                         saveTOMs = TRUE,
+                         saveTOMFileBase = "SpodopteraTOM-blockwise",
+                         verbose = 3)
 Calculating module eigengenes block-wise from all genes
   Flagging genes and samples with too many missing values...
    ..step 1
Error in abs(datExpr) : non-numeric argument to mathematical function
ADD REPLY
0
Entering edit mode

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)])

ADD REPLY
1
Entering edit mode

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

expression[1:20, 1:19323] <- as.numeric(as.character(expression[1:20, 1:19323]))
ADD REPLY

Login before adding your answer.

Traffic: 2481 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6