1. Using the script from 3.1, add a call to fetch and print the sequence for the gene ESPN in FASTA.
library(httr)
library(jsonlite)
fetch_endpoint <- function(server, request, content_type){
r <- GET(paste(server, request, sep = ""), accept(content_type))
stop_for_status(r)
if (content_type == 'application/json'){
return (fromJSON(content(r, "text", encoding = "UTF-8")))
} else {
return (content(r, "text", encoding = "UTF-8"))
}
}
# define the gene name
gene_name <- "ESPN"
# define the general URL parameters
server <- "http://rest.ensembl.org/"
con <- "application/json"
# define REST query to get the gene ID from the gene name
ext_get_lookup <- paste("lookup/symbol/homo_sapiens/", gene_name, "?", sep ="")
get_lookup <- fetch_endpoint(server, ext_get_lookup, con)
stable_id <- get_lookup$id
# define the REST query to get the sequence from the gene
ext_get_seq <- paste("sequence/id/", get_lookup$id, "?", sep = "")
get_seq <- fetch_endpoint(server, ext_get_seq, 'text/x-fasta')
# print the gene name, ID and sequence
cat(">", gene_name, "\n", get_seq, sep = "")
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.)
library(httr)
library(jsonlite)
fetch_endpoint <- function(server, request, content_type){
r <- GET(paste(server, request, sep = ""), accept(content_type))
stop_for_status(r)
if (content_type == 'application/json'){
return (fromJSON(content(r, "text", encoding = "UTF-8")))
} else {
return (content(r, "text", encoding = "UTF-8"))
}
}
server <- "http://rest.ensembl.org/"
con <- "application/json"
gene_name <- "ESPN"
ext_get_lookup <- paste("lookup/symbol/homo_sapiens/", gene_name, "?", sep = "")
get_lookup <- fetch_endpoint(server, ext_get_lookup, con)
if (get_lookup$strand == 1){
locus <- paste (get_lookup$seq_region_name, ":", get_lookup$start - 1000, "-", get_lookup$start, sep = "")
} else {
locus <- paste (get_lookup$seq_region_name, ":", get_lookup$end, "-", get_lookup$end + 1000, sep = "")
}
overlap_ext <- paste ("overlap/region/human/", locus, "?feature=regulatory;", sep = "")
get_overlap <- fetch_endpoint(server, overlap_ext, con)
cat(get_overlap$id)