{ "cells": [ { "metadata": {}, "cell_type": "markdown", "source": "# Linking endpoints together\n\nIf you can pull a datapoint from the json, you can use it as input for another endpoint.\n\nFor example, this script gets the symbol of a gene then looks up xrefs associated with it:" }, { "metadata": { "trusted": true }, "cell_type": "code", "source": "import requests, json\nfrom pprint import pprint\n\ndef fetch_endpoint(server, request, content_type):\n\n r = requests.get(server+request, headers={ \"Accept\" : content_type})\n\n if not r.ok:\n r.raise_for_status()\n sys.exit()\n\n if content_type == 'application/json':\n return r.json()\n else:\n return r.text\n\n\nserver = \"http://rest.ensembl.org/\"\ngene_ext = \"lookup/id/ENSG00000157764?\"\ncon = \"application/json\"\nget_gene = fetch_endpoint(server, gene_ext, con)\n\nsymbol = get_gene['display_name']\n\nxrefs_ext = \"xrefs/symbol/human/\" + symbol + \"?\"\nget_xrefs = fetch_endpoint(server, xrefs_ext, con)\n\npprint (get_xrefs)", "execution_count": null, "outputs": [] }, { "metadata": {}, "cell_type": "markdown", "source": "## Exercises 5\n\n1\\. Using the script from 3.1, add a call to fetch and print the sequence for the gene *ESPN* in FASTA." }, { "metadata": { "trusted": true }, "cell_type": "code", "source": "# Exercise 5.1", "execution_count": null, "outputs": [] }, { "metadata": {}, "cell_type": "markdown", "source": "2\\. Print the stable ID of any regulatory features that overlap the region 1000 bp upstream of the ESPN gene. (Hints: lookup the gene first to get the coordinates, then check the strand of the gene to see which way is upstream, and use this to create coordinates to query.)" }, { "metadata": { "trusted": true }, "cell_type": "code", "source": "# Exercise 5.2", "execution_count": null, "outputs": [] }, { "metadata": {}, "cell_type": "markdown", "source": "[Next page: Exercises 5 - answers](5_Linking_endpoints_together_answers.ipynb)" } ], "metadata": { "kernelspec": { "name": "python3", "display_name": "Python 3", "language": "python" }, "language_info": { "mimetype": "text/x-python", "nbconvert_exporter": "python", "name": "python", "pygments_lexer": "ipython3", "version": "3.5.4", "file_extension": ".py", "codemirror_mode": { "version": 3, "name": "ipython" } } }, "nbformat": 4, "nbformat_minor": 2 }