The first direction:
> go2gn <- sapply(mapIds(org.Pf.plasmo.db, keys(org.Pf.plasmo.db, "GO"), "ORF", "GO", multivals = "list"), paste, collapse = ",")
'select()' returned 1:many mapping between keys and columns
> go2gn.df <- data.frame(GOIDS = names(go2gn), ORF = go2gn)
> head(go2gn.df)
GOIDS ORF
GO:0004872 GO:0004872 PF3D7_0100100
GO:0009405 GO:0009405 PF3D7_0100100
GO:0016021 GO:0016021 PF3D7_0100100
GO:0016337 GO:0016337 PF3D7_0100100
GO:0020002 GO:0020002 PF3D7_0100100
GO:0020013 GO:0020013 PF3D7_0100100
## and the reverse
> gn2go <- sapply(mapIds(org.Pf.plasmo.db, keys(org.Pf.plasmo.db), "GO", "ORF", multiVals = "list"), paste, collapse = ",")
'select()' returned 1:many mapping between keys and columns
> gn2go.df <- data.frame(ORF = names(gn2go), GOIDS = gn2go)
> head(gn2go.df)
ORF
PF3D7_0100100 PF3D7_0100100
PF3D7_0100200 PF3D7_0100200
PF3D7_0100300 PF3D7_0100300
PF3D7_0100400 PF3D7_0100400
PF3D7_0100500 PF3D7_0100500
PF3D7_0100600 PF3D7_0100600
GOIDS
PF3D7_0100100 GO:0004872,GO:0009405,GO:0016021,GO:0016337,GO:0020002,GO:0020013,GO:0020030,GO:0020033,GO:0020035,GO:0050839
PF3D7_0100200 GO:0020002,GO:0020003,GO:0020013,GO:0020033,GO:0020035,GO:0020036
PF3D7_0100300 GO:0004872,GO:0009405,GO:0016021
PF3D7_0100400 GO:0020002,GO:0020003,GO:0020013,GO:0020033,GO:0020035,GO:0020036
PF3D7_0100500 NA
PF3D7_0100600 GO:0016020,GO:0020002,GO:0020033
You can then use e.g., write.xlsx
in the openxlsx
package to write to an Excel workbook.