Answers.Body: <p>I guess the following code will help,</p>
  
  <pre><code>source("https://bioconductor.org/biocLite.R")
  biocLite("biomaRt")
  library("biomaRt")
  ensembl = useMart("ensembl", dataset = "hsapiens_gene_ensembl")
  #listAttributes(ensembl)
  mapping &lt;- getBM(attributes = c("ensembl_gene_id", "hgnc_symbol", "go_id"), mart = ensembl)
  head(mapping)
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-18T19:22:43.573Z
Answers.LastActivityDate: 2017-09-18T19:40:03.890Z
Answers.LastEditDate: 2017-09-18T19:40:03.890Z
Answers.UserDisplayName: arup
Answers.Body: <p>Here's an example for the mouse genome:</p>
  
  <pre class="lang-r prettyprint-override"><code>library(org.Mm.eg.db)
  select(org.Mm.eg.db, c("GO:0048406"), c("GENENAME","SYMBOL"), c("GO"))
  </code></pre>
  
  <p>You get output like:</p>
  
  <pre><code>                                                    GENENAME SYMBOL
  1                                     pregnancy zone protein    Pzp
  2 nerve growth factor receptor (TNFR superfamily, member 16)   Ngfr
  3 nerve growth factor receptor (TNFR superfamily, member 16)   Ngfr
  4                                             neurotrophin 3   Ntf3
  5             neurotrophic tyrosine kinase, receptor, type 1  Ntrk1
  6            furin (paired basic amino acid cleaving enzyme)  Furin
  7              proprotein convertase subtilisin/kexin type 6  Pcsk6
  8                                                 sortilin 1  Sort1
  9                                      alpha-2-macroglobulin    A2m
  </code></pre>
  
  <p><strong>Edit</strong>: Given your comment that you want instead a list of all genes with a GO term associated with them (for human):</p>
  
  <pre><code>library(org.Hs.eg.db) # Install it from bioconductor yourself
  unlist(as.list(org.Hs.egSYMBOL)[mappedkeys(org.Hs.egGO)])
  </code></pre>
  
  <p>The <code>mappedkey()</code> part gets the index into the bimap of all entries with a valid GO mapping. That's then used to subset the symbol bimap (after converting to a list).</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-18T17:05:28.830Z
Answers.LastActivityDate: 2017-09-18T20:38:20.467Z
Answers.LastEditDate: 2017-09-18T20:38:20.467Z
Answers.UserDisplayName: Devon Ryan
Body: <p>I need a command in R to retrieve all human genes associated with a Gene Ontology entry. I tried to look for it online but did not find it.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-09-20T07:06:33.550Z
Comments.Text: @DanielStandage I am not sure this question is about the human genome.
Comments.UserDisplayName: llrs
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-09-20T16:15:46.077Z
Comments.Text: @Llopis When he says "retrieve all human genes" it definitely makes *me* think of the human genome. :-)
Comments.UserDisplayName: Daniel Standage
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-09-20T16:18:40.570Z
Comments.Text: @Daniel yes, but the question is not about the human genome. Or should we also use gene as tag here ? Maybe we use different definitions of the tag
Comments.UserDisplayName: llrs
Tags: <r><human-genome><gene-ontology>
Title: Retrieving a list of human genes having GO associations
ThreadText: # Retrieving a list of human genes having GO associations
  
  (Asked by: username_0 on 2017-09-18)
  
  I need a command in R to retrieve all human genes associated with a Gene Ontology entry. I tried to look for it online but did not find it.
  
  **Tags:** r, human-genome, gene-ontology
  
  > **Comments:**
  > **username_1**: @username_2 I am not sure this question is about the human genome.  
  > **username_2**: @Llopis When he says "retrieve all human genes" it definitely makes *me* think of the human genome. :-)  
  > **username_1**: @username_2 yes, but the question is not about the human genome. Or should we also use gene as tag here ? Maybe we use different definitions of the tag  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_3 on 2017-09-18. Score: 6
  
  I guess the following code will help,
  
  ```
  source("https://bioconductor.org/biocLite.R")
  biocLite("biomaRt")
  library("biomaRt")
  ensembl = useMart("ensembl", dataset = "hsapiens_gene_ensembl")
  #listAttributes(ensembl)
  mapping <- getBM(attributes = c("ensembl_gene_id", "hgnc_symbol", "go_id"), mart = ensembl)
  head(mapping)
  
  ```
  
  
  ---
  
  ### Answer by username_4 on 2017-09-18. Score: 6
  
  Here's an example for the mouse genome:
  
  ```r
  library(org.Mm.eg.db)
  select(org.Mm.eg.db, c("GO:0048406"), c("GENENAME","SYMBOL"), c("GO"))
  
  ```
  
  You get output like:
  
  ```
                                                      GENENAME SYMBOL
  1                                     pregnancy zone protein    Pzp
  2 nerve growth factor receptor (TNFR superfamily, member 16)   Ngfr
  3 nerve growth factor receptor (TNFR superfamily, member 16)   Ngfr
  4                                             neurotrophin 3   Ntf3
  5             neurotrophic tyrosine kinase, receptor, type 1  Ntrk1
  6            furin (paired basic amino acid cleaving enzyme)  Furin
  7              proprotein convertase subtilisin/kexin type 6  Pcsk6
  8                                                 sortilin 1  Sort1
  9                                      alpha-2-macroglobulin    A2m
  
  ```
  
  **Edit**: Given your comment that you want instead a list of all genes with a GO term associated with them (for human):
  
  ```
  library(org.Hs.eg.db) # Install it from bioconductor yourself
  unlist(as.list(org.Hs.egSYMBOL)[mappedkeys(org.Hs.egGO)])
  
  ```
  
  The `mappedkey()` part gets the index into the bimap of all entries with a valid GO mapping. That's then used to subset the symbol bimap (after converting to a list).
  
  
  ---
  
  