<jupyter_start><jupyter_text>Using resultsThe fromJSON module we used to pull out the data converts it to a dataframe, so you can pull out a single datapoint using the key.```{object_type: "Gene",end: 140924928,version: 13,seq_region_name: "7",strand: -1,logic_name: "ensembl_havana_gene",biotype: "protein_coding",id: "ENSG00000157764",db_type: "core",display_name: "BRAF",species: "homo_sapiens",start: 140719327,assembly_name: "GRCh38",source: "ensembl_havana",description: "B-Raf proto-oncogene, serine/threonine kinase [Source:HGNC Symbol;Acc:HGNC:1097]"}```We can add this to our previous script:<jupyter_code>library(httr)
library(jsonlite)


fetch_endpoint <- function(server, request, content_type){

    r <- GET(paste(server, request, sep = ""), accept(content_type))

    stop_for_status(r)

    if (content_type == 'application/json'){
        return (fromJSON(content(r, "text", encoding = "UTF-8")))
    } else {
        return (content(r, "text", encoding = "UTF-8"))
    }
}

server <- "http://rest.ensembl.org/"
ext <- "lookup/id/ENSG00000157764?"
con <- "application/json"
get_gene <- fetch_endpoint(server, ext, con)

symbol <- get_gene$display_name

cat(symbol)<jupyter_output><empty_output><jupyter_text>Exercises 31\. Write a script to lookup the gene called *ESPN* in human and print the stable ID of this gene.<jupyter_code># Exercise 3.1<jupyter_output><empty_output><jupyter_text>2\. Get all variants that are associated with the phenotype 'Coffee consumption'. For each variant print   a. the p-value for the association      b. the PMID for the publication which describes the association between that variant and ‘Coffee consumption’      c. the risk allele and the associated gene.Note that R cannot cope with spaces in your URL extension, so you will need to write the phenotype as 'coffee%20consumption'.<jupyter_code># Exercise 3.2<jupyter_output><empty_output><jupyter_text>3\. Get the mouse homologue of the human BRCA2 and print the ID and sequence of both.Note that the JSON for the endpoint you need is several layers deep, containing nested lists (appear as square brackets [ ] in the JSON) and key value sets (appear as curly brackets { } in the JSON). Prettify comes in very useful here for the intermediate stage when you're trying to work out the json.<jupyter_code># Exercise 3.3<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10535259133389975, 'fraction_numerical': 0.027612574341546302, 'mean_word_length': 5.382113821138211, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '167338', 'license': 'Apache-2.0', 'n_tokens_mistral': 816, 'n_tokens_neox': 725, 'n_words': 251, 'path': 'R/3_Using_results.ipynb', 'repo_name': 'fabiolib/rest-api-jupyter-course', 'size': '2354'}