I was also interested in using the mysql server for ensembl for this query. After doing some little reverse engineering with the SQL schema, I wrote the following SQL query:
query:
use homo_sapiens_core_48_36j;
select distinct
GENE_ID.stable_id as "ensembl.gene",
RNA_ID.stable_id as "ensembl.transcript",
PROT_ID.stable_id as "ensembl.translation",
GO.acc as "go.acc",
GO.name as "go.name",
GOXREF.linkage_type as "evidence"
from
ensembl_go_54.term as GO,
external_db as EXTDB0,
external_db as EXTDB1,
object_xref as OX0,
object_xref as OX1,
xref as XREF0,
xref as XREF1,
transcript as RNA,
transcript_stable_id as RNA_ID,
gene as GENE,
gene_stable_id as GENE_ID,
translation as PROT,
translation_stable_id as PROT_ID,
go_xref as GOXREF
where
XREF0.dbprimary_acc="NM_030621" and
XREF0.external_db_id=EXTDB0.external_db_id and
EXTDB0.db_name="RefSeq_dna" and
OX0.xref_id=XREF0.xref_id and
RNA.gene_id=GENE.gene_id and
GENE.gene_id= GENE_ID.gene_id and
RNA.transcript_id=OX0.ensembl_id and
RNA_ID.transcript_id=RNA.transcript_id and
PROT.transcript_id = RNA.transcript_id and
OX1.ensembl_id=PROT.translation_id and
PROT.translation_id=PROT_ID.translation_id and
OX1.ensembl_object_type='Translation' and
OX1.xref_id=XREF1.xref_id and
GOXREF.object_xref_id=OX1.object_xref_id and
XREF1.external_db_id=EXTDB1.external_db_id and
EXTDB1.db_name="GO" and
GO.acc=XREF1.dbprimary_acc
order by GO.acc;
Execute:
mysql -A -h ensembldb.ensembl.org -u anonymous -P 5306 < query.sql
Result:
ensembl.gene ensembl.transcript ensembl.translation go.acc go.name evidence
ENSG00000100697 ENST00000393063 ENSP00000376783 GO:0000166 nucleotide binding IEA
ENSG00000100697 ENST00000393063 ENSP00000376783 GO:0001525 angiogenesis IEA
ENSG00000100697 ENST00000393063 ENSP00000376783 GO:0003676 nucleic acid binding IEA
ENSG00000100697 ENST00000393063 ENSP00000376783 GO:0003677 DNA binding IEA
ENSG00000100697 ENST00000393063 ENSP00000376783 GO:0003723 RNA binding IEA
ENSG00000100697 ENST00000393063 ENSP00000376783 GO:0003725 double-stranded RNA binding IDA
ENSG00000100697 ENST00000393063 ENSP00000376783 GO:0004386 helicase activity IEA
ENSG00000100697 ENST00000393063 ENSP00000376783 GO:0004519 endonuclease activity IEA
ENSG00000100697 ENST00000393063 ENSP00000376783 GO:0004525 ribonuclease III activity IDA
ENSG00000100697 ENST00000393063 ENSP00000376783 GO:0005515 protein binding IPI
ENSG00000100697 ENST00000393063 ENSP00000376783 GO:0005524 ATP binding IEA
ENSG00000100697 ENST00000393063 ENSP00000376783 GO:0005622 intracellular NAS
ENSG00000100697 ENST00000393063 ENSP00000376783 GO:0006396 RNA processing IEA
ENSG00000100697 ENST00000393063 ENSP00000376783 GO:0008026 ATP-dependent helicase activity IEA
ENSG00000100697 ENST00000393063 ENSP00000376783 GO:0016787 hydrolase activity IEA
ENSG00000100697 ENST00000393063 ENSP00000376783 GO:0019827 stem cell maintenance IEA
ENSG00000100697 ENST00000393063 ENSP00000376783 GO:0030324 lung development IEA
ENSG00000100697 ENST00000393063 ENSP00000376783 GO:0030422 RNA interference, production of siRNA IEA
ENSG00000100697 ENST00000393063 ENSP00000376783 GO:0030423 RNA interference, targeting of mRNA for destruction IEP
ENSG00000100697 ENST00000393063 ENSP00000376783 GO:0031047 gene silencing by RNA IEA
ENSG00000100697 ENST00000393063 ENSP00000376783 GO:0035116 embryonic hindlimb morphogenesis IEA
ENSG00000100697 ENST00000393063 ENSP00000376783 GO:0035196 gene silencing by miRNA, production of miRNAs IEA
ENSG00000100697 ENST00000393063 ENSP00000376783 GO:0048754 branching morphogenesis of a tube IEA
Note: my previous solution as well as Neil's one don't list all the GO terms visible here. This SQL looks probably better even if the result is still different with the web page (e.g.: I can see GO:0016442 on the web page, but not in my result ). The ensembl schema is complex, and I might have missed some links (left join ?) between the tables.
Thanks for all the answers, everyone. I ended up using biomaRt in R.
Nice question, awesome answers, just added my suggestion using GOOSE.
Thank you for this post ! I can't believe that something so elemental would be so complicated.