{ "cells": [ { "metadata": { "collapsed": true }, "cell_type": "markdown", "source": "## Exercises 4 – answers \n\n1\\. Get the gene tree predicted for the gene ENSG00000189221 in full nh format. " }, { "metadata": { "trusted": true }, "cell_type": "code", "source": "library(httr)\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\ngene_id <- \"ENSG00000189221\"\n\n# define the general URL parameters\nserver <- \"http://rest.ensembl.org/\"\next_gt <- paste(\"genetree/member/id/\", gene_id, \"?nh_format=full;\", sep = \"\")\ngt_content_type <- \"text/x-nh\"\nget_gt <- fetch_endpoint(server, ext_gt, gt_content_type)\n\ncat(get_gt)", "execution_count": null, "outputs": [] }, { "metadata": {}, "cell_type": "markdown", "source": "2\\. Get the sequence of the gene ENSG00000157764 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\ngene <- \"ENSG00000157764\"\nserver <- \"http://rest.ensembl.org/\"\next_get_seq <- paste(\"/sequence/id/\", gene, \"?\", sep = \"\")\ncon <- \"text/x-fasta\"\n\nget_seq <- fetch_endpoint(server, ext_get_seq, con)\n\n# print the gene name, ID and sequence\ncat(get_seq)", "execution_count": null, "outputs": [] }, { "metadata": {}, "cell_type": "markdown", "source": "[Next page: Linking endpoints together](5_Linking_endpoints_together.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 }