The error you see comes from AnnotationDbi::select
and indicates that the items in your genes
object aren't character. Here's an example
> library(clusterProfiler)
> data(gcSample)
> sapply(gcSample, class)
X1 X2 X3 X4 X5 X6
"character" "character" "character" "character" "character" "character"
X7 X8
"character" "character"
## convert to numeric
> gcSample <- lapply(gcSample, as.numeric)
> sapply(gcSample, class)
X1 X2 X3 X4 X5 X6 X7 X8
"numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric" "numeric"
## Note that I am messing things up as an example. The gene IDs should be character!!!
> xx <- compareCluster(gcSample, fun="enrichKEGG",
organism="hsa", pvalueCutoff=0.05)
> z <- setReadable(xx, "org.Hs.eg.db", "ENTREZID")
Error in .testForValidKeys(x, keys, keytype, fks) :
'keys' must be a character vector
## Let's fix it
> gcSample <- lapply(gcSample, as.character)
> xx <- compareCluster(gcSample, fun="enrichKEGG",
organism="hsa", pvalueCutoff=0.05)
> z <- setReadable(xx, "org.Hs.eg.db", "ENTREZID")
>
## Works now
Ideally you would have read the help page and that would have like, you know, helped. Unfortunately, here's what it says
Arguments:
geneClusters: a list of entrez gene id. Alternatively, a formula of
type 'Entrez~group' or a formula of type 'Entrez | logFC ~
group' for "gseGO", "gseKEGG" and "GSEA".
Which is not particularly helpful. Entrez Gene IDs are conventionally numeric, but when using the OrgDb
packages they have to be character. However! There is an example that you can look at (which I used for the example above), and you could see what is in gcSample
and compare to what you have and then figured out what you needed because they differ.
R help tends to be pretty terse, and it's a learned skill to be able to read and interpret. Hopefully this example provides one indication of how that's done.