Conversation
Add a function to retrieve the divergence time of two species via the TimeTree API. Add 'httr' as a new dependency to the package.
Update documentation for existing functions. Add new documentation for new function 'getDivergenceTime'.
Add documentation of new function.
Add a function that uses the TimeTree API to retrieve the divergence time of all species from the specified taxon to the common ancestor of all cellular organisms.
Update the documentation for the two new functions, `getTimeline` and `getDivergenceTime`.
As the TimeTree API was updated, the names of some fields changed (e.g. "branch_length" is now "summary_age"), so the code had to be modified accordingly.
charles-plessy
left a comment
There was a problem hiding this comment.
Hi Priscila, here are a couple of nitpicks!
| timetreeResponse <- GET(timetreeRequest) | ||
| lines <- content(timetreeResponse, as="text", encoding="UTF-8") | ||
| header <- lines |> strsplit(split="\n", fixed=TRUE) |> (\(x) x[[1]][1])() |> strsplit(split = ",", fixed = TRUE) |> (\(x) x[[1]])() # First line: header; Other lines: data. | ||
| if(length(header) >= 8) { |
There was a problem hiding this comment.
You could also have if(length(header) <8) return(NA) and continue without indentation.
| # Break the line into data. | ||
| data <- strsplit(lineData, ",", fixed = TRUE)[[1]] | ||
| # Check if the request returned something valid. | ||
| if(length(data) >= 8) { |
| #' | ||
| #' @export | ||
| getDivergenceTime <- function(taxid1, taxid2) { | ||
| timetreeBasePairwise <- "http://timetree.temple.edu/api/pairwise/" |
There was a problem hiding this comment.
Maybe getDivergenceTime <- function(taxid1, taxid2, timetreeBasePairwise="http://timetree.temple.edu/api/pairwise/") { so that we can transiently fix scripts without fixing the package if the URL changes.
| #' | ||
| #' @export | ||
| getTimeline <- function(taxid) { | ||
| timetreeBaseTimeline <- "http://timetree.temple.edu/api/timeline/" |
There was a problem hiding this comment.
See my comment in the other function below.
| # 9554,Papio,,43,genus,1.9,1.9,2.31,1.48 | ||
| # -1,unnamed,,42,unknown,4.68,4.68,5.08,4.27 | ||
| # ... | ||
| timetreeRequest <- paste(timetreeBaseTimeline, taxid, sep="") |
There was a problem hiding this comment.
paste0(timetreeBaseTimeline, taxid) for the lazy people :)
| timetreeRequest <- paste(timetreeBaseTimeline, taxid, sep="") | ||
| timetreeResponse <- GET(timetreeRequest) | ||
| lines <- content(timetreeResponse, as="text", encoding="UTF-8") | ||
| header <- lines |> strsplit(split="\n", fixed=TRUE) |> (\(x) x[[1]][1])() |> strsplit(split = ",", fixed = TRUE) |> (\(x) x[[1]])() # First line: header; Other lines: data. |
There was a problem hiding this comment.
Claude says that the following works too:
header <- scan(text = lines, what = "", sep = ",", nlines = 1, quiet = TRUE)
This pull request adds two new functions that use the TimeTree API:
getDivergenceTime: retrieves the divergence time between two species given their NCBI IDs.getTimeline: retrieves a list of divergence times for the nodes in the TimeTree, from the specified taxon to the common ancestor of all cellular organisms.It also adds
httras a new dependency to the package.