I think this is on the right track but I can't quite get it to work. I used the biomaRt package to retrieve the GO terms:
results <- getBM(
attributes = c("ensembl_gene_id", "go_accession", "go_name_1006", "go_linkage_type"),
filters="ensembl_gene_id",
values=geneID[1],
mart=mart)
This worked fine and it resulted in this format:
head(results)
ensembl_gene_id go_accession go_name_1006 go_linkage_type
1 AGAP004677 GO:0016491 oxidoreductase activity
2 AGAP004677 GO:0044281 small molecule metabolic process
3 AGAP004677 GO:0009058 biosynthetic process
4 AGAP004677 GO:0003674 molecular_function
5 AGAP004677 GO:0055114 oxidation-reduction process IEA
6 AGAP004677 GO:0003824 catalytic activity IEA
Since there are multiple GO terms for each gene ID, I'd like to group gene IDs together and so there's only one row for each gene ID with the corresponding GO terms place in a single cell. So the above result would then be:
ensembl_gene_id go_accession go_name_1006
GO:0016491, oxidoreductase activity,
GO:0044281, small molecule metabolic process,
AGAP004677 GO:0009058, biosynthetic process,
GO:0003674, molecular_function,
GO:0055114, oxidation-reduction process, catalytic activity
GO:0003824
How should I go about doing this?