Hi,
I try to do differential expression analysis by "EdgeR", I have the "counts.csv " which achieved by "HTSeq". i want to add the "symbol" column with the gene symbol corresponding to the Gene ID to a data frame in EdgeR to have also the symbols in up and down-regulated genes table. Here is my code which i used for differential expression analysis:
library(edgeR)
library(org.Hs.eg.db)
x<-read.csv("counts.csv")
y<-DGEList(counts=x[,2:51], genes = x[,1])
y <- calcNormFactors(y)
group <- factor(c(rep("high",30),rep("low",20)))
time<-factor(c("pre","post","pre","post","pre","post","pre","post","pre","post",
"pre","post","pre","post","pre","post","pre","post","pre","post",
"pre","post","pre","post","pre","post","pre","post","pre","post",
"pre","post","pre","post","pre","post","pre","post","pre","post",
"pre","post","pre","post","pre","post","pre","post","pre","post"))
data.frame(sample=colnames(y),group,time) #data frame
design<-model.matrix(~group+time)
y<-estimateDisp(y,design)
fit<-glmFit(y,design)
lrt<-glmLRT(fit,coef = 2)
deg <-topTags(lrt, n = Inf , p= 0.05)$table
up <-deg[deg$logFC > 0,]
down <-deg[deg$logFC < 0,]
write.csv(up, file="up.csv")
write.csv(down, file="down.csv")
i try to use this code to insert symbols to my data frame but it doesn't work! can anyone help me to go through it?
mp=gsub("\\..*","",row.names(y))
y$symbol<- mapIds(org.Hs.eg.db, keys= row.names(mp),
keytype="ENSEMBL", column="SYMBOL")
This is also the results table that i got:
head(up)
genes logFC logCPM LR PValue FDR
5659 ENSG00000125207 4.383522 0.5658056 1139.1891 1.003436e-249 5.797650e-245
25588 ENSG00000222057 4.589772 -0.2246701 980.9821 2.444029e-215 7.060555e-211
50136 ENSG00000261177 5.207807 -0.1559902 810.7058 2.537797e-178 4.887627e-174
35996 ENSG00000236941 2.595311 2.0293394 790.5476 6.126318e-174 8.849161e-170
29288 ENSG00000227615 5.668960 0.4194818 767.6254 5.902889e-169 6.821142e-165
17466 ENSG00000196564 4.778656 -0.8531067 715.6777 1.165581e-157 1.122415e-153
the error phrase that i received is:
Error in mapIds_base(x, keys, column, keytype, ..., multiVals = multiVals) : mapIds must have at least one key to match against.
Thanks
Thank you so much! i appreciate your description, and i got it. It was a comprehensive one. But i get a new error now, unfortunately.
So the error message is supposed to be self-explanatory. It is telling you that the
keys
have to be a character vector. Which almost surely means the keys are afactor
. So you need to coerce to character first. If you don't understand what I am telling you, then you need to read An Intro to R.i reckon i will need that since i am not into R. thanks again, James. i appreciate that.