1. Get the gene tree predicted for the gene Pp3c2_11370 in full nh format.
library(httr)
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"))
}
}
gene_id <- "Pp3c2_11370"
# define the general URL parameters
server <- "http://rest.ensembl.org/"
ext_gt <- paste("genetree/member/id/", gene_id, "?nh_format=full;", sep = "")
gt_content_type <- "text/x-nh"
get_gt <- fetch_endpoint(server, ext_gt, gt_content_type)
cat(get_gt)
2. Get the sequence of the gene TraesCS4A02G446800 in FASTA format.
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"))
}
}
gene <- "TraesCS4A02G446800"
server <- "http://rest.ensembl.org/"
ext_get_seq <- paste("/sequence/id/", gene, "?", sep = "")
con <- "text/x-fasta"
get_seq <- fetch_endpoint(server, ext_get_seq, con)
# print the gene name, ID and sequence
cat(get_seq)