Skip to content

TimeTree functions - #21

Open
pribiller wants to merge 6 commits into
masterfrom
divergence_time
Open

pribiller wants to merge 6 commits into
masterfrom
divergence_time

Conversation

@pribiller

Copy link
Copy Markdown
Contributor

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 httr as a new dependency to the package.

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 charles-plessy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Priscila, here are a couple of nitpicks!

Comment thread R/timeTree.R
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) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also have if(length(header) <8) return(NA) and continue without indentation.

Comment thread R/timeTree.R
# Break the line into data.
data <- strsplit(lineData, ",", fixed = TRUE)[[1]]
# Check if the request returned something valid.
if(length(data) >= 8) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Comment thread R/timeTree.R
#'
#' @export
getDivergenceTime <- function(taxid1, taxid2) {
timetreeBasePairwise <- "http://timetree.temple.edu/api/pairwise/"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread R/timeTree.R
#'
#' @export
getTimeline <- function(taxid) {
timetreeBaseTimeline <- "http://timetree.temple.edu/api/timeline/"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment in the other function below.

Comment thread R/timeTree.R
# 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="")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

paste0(timetreeBaseTimeline, taxid) for the lazy people :)

Comment thread R/timeTree.R
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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude says that the following works too:

header <- scan(text = lines, what = "", sep = ",", nlines = 1, quiet = TRUE)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants