{ "cells": [ { "metadata": { "collapsed": true }, "cell_type": "markdown", "source": "## Exercises 5 - answers\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": "library(httr)\nlibrary(jsonlite)\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\n# define the gene name\ngene_name <- \"ESPN\"\n\n# define the general URL parameters\nserver <- \"http://rest.ensembl.org/\"\ncon <- \"application/json\"\n\n# define REST query to get the gene ID from the gene name\next_get_lookup <- paste(\"lookup/symbol/homo_sapiens/\", gene_name, \"?\", sep =\"\")\n\nget_lookup <- fetch_endpoint(server, ext_get_lookup, con)\n\nstable_id <- get_lookup$id\n\n# define the REST query to get the sequence from the gene\next_get_seq <- paste(\"sequence/id/\", get_lookup$id, \"?\", sep = \"\")\nget_seq <- fetch_endpoint(server, ext_get_seq, 'text/x-fasta')\n\n# print the gene name, ID and sequence\ncat(\">\", gene_name, \"\\n\", get_seq, sep = \"\")", "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: get the gene ID first, then check the strand of the gene to see which way is upstream.)" }, { "metadata": { "trusted": true }, "cell_type": "code", "source": "library(httr)\nlibrary(jsonlite)\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/\"\ncon <- \"application/json\"\n\ngene_name <- \"ESPN\"\next_get_lookup <- paste(\"lookup/symbol/homo_sapiens/\", gene_name, \"?\", sep = \"\")\nget_lookup <- fetch_endpoint(server, ext_get_lookup, con)\n\nif (get_lookup$strand == 1){\n locus <- paste (get_lookup$seq_region_name, \":\", get_lookup$start - 1000, \"-\", get_lookup$start, sep = \"\")\n\n} else {\n locus <- paste (get_lookup$seq_region_name, \":\", get_lookup$end, \"-\", get_lookup$end + 1000, sep = \"\")\n}\n\noverlap_ext <- paste (\"overlap/region/human/\", locus, \"?feature=regulatory;\", sep = \"\")\n\nget_overlap <- fetch_endpoint(server, overlap_ext, con)\n\ncat(get_overlap$id)", "execution_count": null, "outputs": [] }, { "metadata": {}, "cell_type": "markdown", "source": "[Next page: Using POST](6_Using_POST.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 }