WGCNA, module trait relationship
0
0
Entering edit mode
4.3 years ago

Hi all I'm currently analyzing a microarray dataset using the WGCNA package. but am running into difficulty when relating the clinical traits to the eigenmodules.i have 3 group as patient and one group as control so in binary i used 0 for control and 1-3 for 3 patient group and it gave me this error:

-Error in labeledHeatmap(Matrix = moduleTraitCor, xLabels = names(datTraits),  : 
  Length of 'xLabels' must equal the number of columns in 'Matrix.'
 my codes are `# Define numbers of genes and samples
nGenes = ncol(datExpr);
nSamples = nrow(datExpr);
# Recalculate MEs with color labels
MEs0 = moduleEigengenes(datExpr, moduleColors)$eigengenes
MEs = orderMEs(MEs0)

moduleTraitCor = cor(MEs, datTraits, use = "p");
moduleTraitPvalue = corPvalueStudent(moduleTraitCor, nSamples);
sizeGrWindow(10,6)
# load data
data(agaricus.train, package='xgboost')
data(agaricus.test, package='xgboost')
train <- agaricus.train
test <- agaricus.test
# fit model
bst <- xgboost(data = train$data, label = train$label, max.depth = 2, eta = 1, nrounds = 2,
               nthread = 2, objective = "binary:logistic")
# predict
pred <- predict(bst, test$data)
vec_y <- mtcars$vs
mat_y <- as.matrix(mtcars$vs)
df_y  <- mtcars[,8,drop=FALSE] #column vs is the 8th column

x <- as.matrix(mtcars[,-8])    #column vs is the 8th column

#vector labels: works
xgboost::xgb.DMatrix(data=x, label=vec_y)
#matrix labels: works
xgboost::xgb.DMatrix(data=x, label=mat_y)
#df labels: doesnt work
xgboost::xgb.DMatrix(data=x, label=df_y)

# Will display correlations and their p-values
textMatrix = paste(signif(moduleTraitCor, 2), "\n(",
                   signif(moduleTraitPvalue, 1), ")", sep = "");
dim(textMatrix) = dim(moduleTraitCor)
par(mar = c(1, 15, 3, 3));
colnames(moduleTraitCor)=levels(as.factor(datTraits["ClinicalTraits"]))
# Display the correlation values within a heatmap plot
labeledHeatmap(Matrix = moduleTraitCor,
               xLabels = names(datTraits),
               yLabels = names(MEs),
               ySymbols = names(MEs),
               colorLabels = FALSE,
               colors = greenWhiteRed(50),
               textMatrix = textMatrix,
               setStdMargins = FALSE,
               cex.text = 0.5,
               zlim = c(-1,1),
               main = paste("Module-trait relationships"))`
R • 3.3k views
ADD COMMENT
0
Entering edit mode

Hi. What is the output of:

str(moduleTraitCor)
str(datTraits)
str(MEs)
str(textMatrix)

?

ADD REPLY
0
Entering edit mode
> str(moduleTraitCor)
 num [1:6, 1] -0.5976 -0.0352 0.8752 0.2891 0.4359 ...
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:6] "MEblue" "MEgreen" "MEyellow" "MEbrown" ...
  ..$ : NULL
> str(datTraits)
 int [1:13] 0 0 0 1 1 1 2 2 2 3 ...

> str(MEs)

'data.frame':   13 obs. of  6 variables:
 $ MEblue     : num  0.0955 0.1848 0.1843 0.1433 0.0767 ...
 $ MEgreen    : num  0.0977 0.1181 0.0548 0.174 -0.1234 ...
 $ MEyellow   : num  -0.4514 -0.457 -0.4773 0.0836 -0.0531 ...
 $ MEbrown    : num  -0.0321 -0.0383 0.0428 -0.9257 0.1233 ...
 $ MEturquoise: num  -0.53034 0.05494 0.00686 -0.41319 0.20651 ...
 $ MEgrey     : num  0.0195 -0.2932 0.0201 -0.0818 -0.2981 ...
> str(textMatrix)
 chr [1:6, 1] "-0.6\n(0.03)" "-0.035\n(0.9)" "0.88\n(9e-05)" "0.29\n(0.3)" ...
>
ADD REPLY
0
Entering edit mode

Well, there is the disparity. The error reads:

Length of 'xLabels' must equal the number of columns in 'Matrix.'

Your xLabels is:

int [1:13] 0 0 0 1 1 1 2 2 2 3 ...

Your Matrix is:

num [1:6, 1] -0.5976 -0.0352 0.8752 0.2891 0.4359 ...
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:6] "MEblue" "MEgreen" "MEyellow" "MEbrown" ...
  ..$ : NULL

There is an apparent lack of sync between these. You should trace back through your code to understand why.

ADD REPLY
0
Entering edit mode

I've used this code for about 30 GSEs but only this time i stocked with this error i will check it again thank you so much

ADD REPLY
0
Entering edit mode

In that case, compare the output from str() between a GSE that works and the GSE to which you are referring in this thread. This would be a good debugging exercise.

ADD REPLY
0
Entering edit mode

This is where your problem originated:

colnames(moduleTraitCor)=levels(as.factor(datTraits["ClinicalTraits"]))

Your colnames() for moduleTraitCor should be the colnames() for datTraits you are interested in. You have mentioned in the beginning that you have 4 levels of condition or group. I would expect therefore to have 4 different columns for each variable, considering you are looking for "level vs all" or even "level1 vs level2" etc. effects. However, Looking at your str(datTraits), you only have rows representing moduleEigenLabels and not columns, which should be the names or colnames of your datTraits (COntrol, Treatment1, Treatment2, Treatment3). Getting this corrected, you would have Length of 'xLabels' i.e. colnames of datTraits equal to the number of columns in Matrix of moduleTraitCor.

ADD REPLY
0
Entering edit mode

thanks it was so useful but i'm amateur in R and i don't know how i can define column for datTraits

ADD REPLY
0
Entering edit mode

Could you show the output for levels(as.factor(datTraits["ClinicalTraits"]))? Also, if you can, please show your datTraits file, If your datTraits file is either a matrix or a dataframe and that "ClinicalTraits" is the name of one of the columns you are interested in, you should use following before running labeledHeatmap function.

 `levels(as.factor(datTraits[,"ClinicalTraits"]))`

Probably you forgot putting , to properly subset your column in datTraits file.

ADD REPLY
0
Entering edit mode

can i have your mail?

ADD REPLY
0
Entering edit mode

I too have the same issue. Were you able to resolve this issue? I checked the datTraits files, dimnames(datTraits) was returned as NULL

datTraits
                                     8 pcw_occipital neocortex                   8 pcw_primary motor-sensory cortex (samples) 
                                                             1                                                              1 
                                      8 pcw_amygdaloid complex                               8 pcw_medial ganglionic eminence 
                                                             1                                                              1 
  8 pcw_posterior (caudal) superior temporal cortex (area 22c)                              8 pcw_upper (rostral) rhombic lip 
                                                             1                                                              1 
                              8 pcw_caudal ganglionic eminence                                          8 pcw_dorsal thalamus 
                                                             1                                                              1 
 8 pcw_anterior (rostral) cingulate (medial prefrontal) cortex                           8 pcw_dorsolateral prefrontal cortex 
                                                             1                                                              1 
                                  8 pcw_orbital frontal cortex                              8 pcw_lateral ganglionic eminence 
                                                             1                                                              1 
       8 pcw_inferolateral temporal cortex (area TEv, area 20)                      8 pcw_hippocampus (hippocampal formation) 
                                                             1                                                              1 
                         8 pcw_ventrolateral prefrontal cortex                                       8 pcw_parietal neocortex 
                                                             1                                                              1 
                          9 pcw_dorsolateral prefrontal cortex  9 pcw_anterior (rostral) cingulate (medial prefrontal) cortex 
                                                             1                                                              1 
                                      9 pcw_amygdaloid complex                                          9 pcw_dorsal thalamus 
                                                             1                                                              1 
                             9 pcw_upper (rostral) rhombic lip                              9 pcw_lateral ganglionic eminence 
                                                             1                                                              1 
                  9 pcw_primary motor-sensory cortex (samples)                               9 pcw_medial ganglionic eminence 
                                                             1                                                              1 
                                      9 pcw_temporal neocortex                      9 pcw_hippocampus (hippocampal formation) 

Thanks

ADD REPLY

Login before adding your answer.

Traffic: 1960 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