{ "cells": [ { "metadata": { "collapsed": true }, "cell_type": "markdown", "source": "# Using results\n\nThe 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.\n\n```\n{\nobject_type: \"Gene\",\nend: 140924928,\nversion: 13,\nseq_region_name: \"7\",\nstrand: -1,\nlogic_name: \"ensembl_havana_gene\",\nbiotype: \"protein_coding\",\nid: \"ENSG00000157764\",\ndb_type: \"core\",\ndisplay_name: \"BRAF\",\nspecies: \"homo_sapiens\",\nstart: 140719327,\nassembly_name: \"GRCh38\",\nsource: \"ensembl_havana\",\ndescription: \"B-Raf proto-oncogene, serine/threonine kinase [Source:HGNC Symbol;Acc:HGNC:1097]\"\n}\n```\n\n\nWe can add this to our previous script:" }, { "metadata": { "trusted": true }, "cell_type": "code", "source": "library(httr)\nlibrary(jsonlite)\n\n\nfetch_endpoint <- function(server, request, content_type){\n\n r <- GET(paste(server, request, sep = \"\"), accept(content_type))\n\n stop_for_status(r)\n\n if (content_type == 'application/json'){\n return (fromJSON(content(r, \"text\", encoding = \"UTF-8\")))\n } else {\n return (content(r, \"text\", encoding = \"UTF-8\"))\n }\n}\n\nserver <- \"http://rest.ensembl.org/\"\next <- \"lookup/id/ENSG00000157764?\"\ncon <- \"application/json\"\nget_gene <- fetch_endpoint(server, ext, con)\n\nsymbol <- get_gene$display_name\n\ncat(symbol)", "execution_count": null, "outputs": [] }, { "metadata": {}, "cell_type": "markdown", "source": "## Exercises 3\n\n1\\. Write a script to lookup the gene called *ESPN* in human and print the stable ID of this gene." }, { "metadata": { "trusted": true }, "cell_type": "code", "source": "# Exercise 3.1", "execution_count": null, "outputs": [] }, { "metadata": {}, "cell_type": "markdown", "source": "2\\. Get all variants that are associated with the phenotype 'Coffee consumption'. For each variant print\n\n a. the p-value for the association\n \n b. the PMID for the publication which describes the association between that variant and ‘Coffee consumption’\n \n c. the risk allele and the associated gene.\n\nNote that R cannot cope with spaces in your URL extension, so you will need to write the phenotype as 'coffee%20consumption'." }, { "metadata": { "trusted": true }, "cell_type": "code", "source": "# Exercise 3.2", "execution_count": null, "outputs": [] }, { "metadata": {}, "cell_type": "markdown", "source": "3\\. Get the mouse homologue of the human BRCA2 and print the ID and sequence of both.\n\nNote 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." }, { "metadata": { "trusted": true }, "cell_type": "code", "source": "# Exercise 3.3", "execution_count": null, "outputs": [] }, { "metadata": {}, "cell_type": "markdown", "source": "[Next page: Exercises 3 – answers](3_Using_results_answers.ipynb)" } ], "metadata": { "kernelspec": { "name": "r", "display_name": "R", "language": "R" }, "language_info": { "mimetype": "text/x-r-source", "name": "R", "pygments_lexer": "r", "version": "3.5.3", "file_extension": ".r", "codemirror_mode": "r" } }, "nbformat": 4, "nbformat_minor": 2 }