{ "cells": [ { "metadata": { "collapsed": true }, "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 genomic locus of a gene then looks up repeats overlapping it:" }, { "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/\"\ngene_ext <- \"lookup/id/TraesCS3D02G007500?\"\njson <- \"application/json\"\nget_gene <- fetch_endpoint(server, gene_ext, json)\n\nlocus = paste(get_gene$species, \"/\", get_gene$seq_region_name, \":\",get_gene$start, \"..\", get_gene$end, sep=\"\")\n\next_get_bed <- paste(\"overlap/region/\", locus, \"?feature=repeat\", sep = \"\")\n\nget_bed <- fetch_endpoint(server, ext_get_bed, \"text/x-bed\")\n\n# print the bed file\ncat(get_bed)", "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 BCH1 in FASTA format." }, { "metadata": { "trusted": true }, "cell_type": "code", "source": "# Exercise 5.1", "execution_count": null, "outputs": [] }, { "metadata": {}, "cell_type": "markdown", "source": "2\\. Print the ID of any variants that overlap the region 5000 bp upstream of the Brachypodium BRADI_5g16840v3 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": "# 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": "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 }