WGCNA R Dataframe using
1
0
Entering edit mode
2.3 years ago
Recep • 0

Hej guys,

I want to use WGCNA to cluster genes. I have a dataframe like this:

Dataframe

I get this data because that is not a matrix afterall.

  datExpr must contain numeric data.

How can use this dataframe as a matrix by using R?

Thanks.

R Bioconductor WGCNA Dataframe • 1.5k views
ADD COMMENT
0
Entering edit mode

Show us your code and tell us what you've tried. Googling the error message should be enough to solve this problem.

ADD REPLY
0
Entering edit mode
DatExpr=read.csv("filtered_reduced_rc.csv")
gsg = goodSamplesGenes(datExpr, verbose = 3)

Error in goodGenes(datExpr, weights, goodSamples, goodGenes, minFraction = minFraction,  : 
datExpr must contain numeric data.
ADD REPLY
0
Entering edit mode

What does str(head(datExpr[,1:5]) show? Also, you're reading into DatExpr and using datExpr in the next line. Is that a typo or are they 2 different objects?

ADD REPLY
0
Entering edit mode
> str(head(datExpr[,1:5]))
'data.frame':   6 obs. of  5 variables:
 $ Genes             : chr  "ENSG00000182199" "ENSG00000157870" "ENSG00000077092" "ENSG00000047936" ...
 $ F02283_L1_S49_L006: int  1517 3712 29 104 0 460
 $ F02284_L1_S50_L006: int  1932 2859 17 51 3 813
 $ F02320_L1_S14_L002: int  2246 2574 65 8 0 454
 $ F02357_L1_S50_L006: int  2860 1964 125 3 0 1321
> 

it is a typo.

ADD REPLY
1
Entering edit mode

From your screenshot, I thought the gene IDs were rownames but you have them as a non-numeric column, which makes the error kinda obvious, don't you think?

Use as.matrix on the dataframe after excluding the first column.

ADD REPLY
0
Entering edit mode
2.3 years ago
LChart 4.6k

as.matrix

This is count data; so I would strongly recommend filtering it for low counts and normalizing it with limma

expr <- matrix(as.integer(your.df), nrow=nrow(your.df))
rownames(expr) <- rownames(your.df)
colnames(expr) <- colnames(your.df)
med.cnt <- apply(expr, 1, median)
expr.vm <- limma::voom(expr)$E
expr.vm <- expr.vm[med.cnt > 5,]  # or so -- see how many genes there are and how stable your results are

expr.for.wgcna <- t(expr.vm)  # WGCNA expects genes to be columns
ADD COMMENT
0
Entering edit mode

thank but i got this error.

> expr <- matrix(as.integer(DatExpr), nrow=nrow(DatExpr))
Error in matrix(as.integer(DatExpr), nrow = nrow(DatExpr)) : 

 'list' object cannot be coerced to type 'integer'
ADD REPLY

Login before adding your answer.

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