Question: WGCNA, module trait relationship
0
gravatar for sadeghi.reyhane
8 weeks ago by
sadeghi.reyhane0 wrote:

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 • 234 views
ADD COMMENTlink modified 8 weeks ago by Kevin Blighe66k • written 8 weeks ago by sadeghi.reyhane0

Hi. What is the output of:

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

?

ADD REPLYlink written 8 weeks ago by Kevin Blighe66k
> 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 REPLYlink modified 7 weeks ago by Kevin Blighe66k • written 7 weeks ago by sadeghi.reyhane0

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 REPLYlink written 7 weeks ago by Kevin Blighe66k

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 REPLYlink modified 7 weeks ago • written 7 weeks ago by sadeghi.reyhane0

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 REPLYlink written 7 weeks ago by Kevin Blighe66k

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 REPLYlink written 7 weeks ago by Sandip Darji10

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

ADD REPLYlink written 7 weeks ago by sadeghi.reyhane0

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 REPLYlink written 7 weeks ago by Sandip Darji10

can i have your mail?

ADD REPLYlink written 6 weeks ago by sadeghi.reyhane0
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 842 users visited in the last hour