diff --git a/DESCRIPTION b/DESCRIPTION index bd2b247..5d87247 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -38,7 +38,8 @@ Imports: tidytree, treeio, purrr, - yaml + yaml, + httr VignetteBuilder: knitr Collate: 'ConvenientTblTree.R' @@ -64,6 +65,7 @@ Collate: 'removeAssemblies.R' 'resultFiles.R' 'subMatrix.R' + 'timeTree.R' 'treeHeatMap.R' 'visualizeTree.R' 'zzz.R' diff --git a/NAMESPACE b/NAMESPACE index 9ac60ff..763a991 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -12,6 +12,8 @@ export(eog) export(extractValues) export(focalClade) export(formatStats) +export(getDivergenceTime) +export(getTimeline) export(makeMatrix) export(makeTidyTree) export(makeValueTibble) @@ -28,54 +30,73 @@ export(thinByMin) export(treeHeatMap) export(visualizeTree) import(S7) -importFrom(ape,as.phylo) -importFrom(ape,cophenetic.phylo) -importFrom(ape,prop.clades) -importFrom(ape,prop.part) -importFrom(dplyr,across) -importFrom(dplyr,arrange) -importFrom(dplyr,case_when) -importFrom(dplyr,desc) -importFrom(dplyr,filter) -importFrom(dplyr,group_by) -importFrom(dplyr,mutate) -importFrom(dplyr,n) -importFrom(dplyr,pull) -importFrom(dplyr,summarise) -importFrom(dplyr,summarize) -importFrom(dplyr,sym) -importFrom(dplyr,ungroup) -importFrom(dplyr,where) +importFrom(ape, + as.phylo, + cophenetic.phylo, + prop.clades, + prop.part +) +importFrom(dplyr, + across, + arrange, + case_when, + desc, + filter, + group_by, + mutate, + n, + pull, + summarise, + summarize, + sym, + ungroup, + where +) importFrom(ggforce,geom_mark_ellipse) -importFrom(ggplot2,aes) -importFrom(ggplot2,geom_errorbar) -importFrom(ggplot2,geom_errorbarh) -importFrom(ggplot2,geom_point) -importFrom(ggplot2,ggplot) -importFrom(ggplot2,labs) -importFrom(ggplot2,scale_color_manual) -importFrom(ggplot2,scale_fill_manual) -importFrom(ggplot2,scale_x_continuous) -importFrom(ggplot2,scale_y_continuous) -importFrom(ggplot2,theme_bw) -importFrom(ggplot2,theme_minimal) +importFrom(ggplot2, + aes, + geom_errorbar, + geom_errorbarh, + geom_point, + ggplot, + labs, + scale_color_manual, + scale_fill_manual, + scale_x_continuous, + scale_y_continuous, + theme_bw, + theme_minimal +) +importFrom(httr, + GET, + content +) importFrom(pheatmap,pheatmap) importFrom(rlang,.data) -importFrom(stats,as.dist) -importFrom(stats,complete.cases) -importFrom(stats,hclust) -importFrom(stats,loess) -importFrom(stats,mad) -importFrom(stats,na.omit) -importFrom(stats,predict) -importFrom(stats,quantile) -importFrom(stats,sd) -importFrom(tidytree,as.treedata) -importFrom(tidytree,as_tibble) -importFrom(tidytree,child) -importFrom(tidytree,offspring) -importFrom(tidytree,tree_subset) +importFrom(stats, + as.dist, + complete.cases, + hclust, + loess, + mad, + na.omit, + predict, + quantile, + sd +) +importFrom(tidytree, + as.treedata, + as_tibble, + child, + offspring, + tree_subset +) importFrom(treeio,MRCA) -importFrom(utils,read.delim) -importFrom(yaml,read_yaml) -importFrom(yaml,yaml.load) +importFrom(utils, + read.csv, + read.delim +) +importFrom(yaml, + read_yaml, + yaml.load +) diff --git a/R/timeTree.R b/R/timeTree.R new file mode 100644 index 0000000..be31c76 --- /dev/null +++ b/R/timeTree.R @@ -0,0 +1,93 @@ +#' Timeline - TimeTree +#' +#' Fetches a list of divergence times of nodes in TimeTree from the specified taxon to the common ancestor of all cellular organisms. +#' +#' @param taxid An integer: The NCBI id of a taxon +#' +#' @return A dataframe in which each row corresponds to an ancestor. +#' Each row contains the divergence time (`divtime`), its confidence interval +#' (`divtimeCI_low` and `divtimeCI_high`), and additional information, +#' including the scientific name (`name`) and taxonomic rank (`rank`). +#' If the divergence time is not found in the TimeTree database, it returns `NA`. +#' +#' @author Priscila Biller +#' +#' @examples +#' \dontrun{ +#' getTimeline(9555)} +#' +#' @importFrom httr GET content +#' @importFrom utils read.csv +#' +#' @export +getTimeline <- function(taxid) { + timetreeBaseTimeline <- "http://timetree.temple.edu/api/timeline/" + # Example of request to the TimeTree's API: + # - Request: http://timetree.temple.edu/api/timeline/9555 + # - Answer from TimeTree: + # ncbi-id,scientific_name,common_name,level,rank,summary_age,adjusted_age,ci_high,ci_low + # -1,unnamed,,46,unknown,1.1,1.1,1.48,0.72 + # -1,unnamed,,45,unknown,1.27,1.36,1.97,0.56 + # -1,unnamed,,44,unknown,1.27,1.58,1.97,0.56 + # 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="") + 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) { + df <- read.csv(text=lines) + # In TimeTree there are two possibilities for the divergence time (here we go with "adjusted age"): + # - "Summary age" is the median of all studies. + # - "Adjusted age" is the adjusted time, computed in cases where a node is older than its parent in the global timetree reconstructed from individual timetrees. + df <- df[ c("ncbi.id", "scientific_name", "rank", "adjusted_age", "ci_low", "ci_high")] + names(df) <- c("NCBIid", "name", "rank", "divtime", "divtimeCI_low", "divtimeCI_high") + df + } else { + NA + } +} + +#' Divergence time - TimeTree +#' +#' Retrieves the divergence time of two species via the TimeTree API. +#' +#' @param taxid1 An integer: The NCBI id of one taxon +#' @param taxid2 An integer: The NCBI id of the other taxon +#' +#' @return A list in which the first item is the divergence time (`divtime`), +#' and the last two items are the divergence time confidence interval +#' (`divtimeCI_low` and `divtimeCI_high`). +#' If the divergence time is not found in the TimeTree database, it returns `NA`. +#' +#' @author Priscila Biller +#' +#' @examples +#' \dontrun{ +#' getDivergenceTime(9555,9601)} +#' +#' @importFrom httr GET content +#' +#' @export +getDivergenceTime <- function(taxid1, taxid2) { + timetreeBasePairwise <- "http://timetree.temple.edu/api/pairwise/" + # Example of request to the TimeTree's API: + # - Request: http://timetree.temple.edu/api/pairwise/9555/9601 + # - Answer from TimeTree: + # taxon_a_id,taxon_b_id,scientific_name_a,scientific_name_b,all_total,precomputed_age,precomputed_ci_low,precomputed_ci_high,adjusted_age + # 9555,9601,Papio anubis,Pongo abelii,83,28.82,26.8,30.6,0 + timetreeRequest <- paste(timetreeBasePairwise, taxid1, "/", taxid2, sep="") + timetreeResponse <- GET(timetreeRequest) + lines <- content(timetreeResponse, as="text", encoding="UTF-8") + # Break the whole content into lines, and gets the second line (data). + lineData <- strsplit(lines, "\n", fixed = TRUE)[[1]][2] # First line: header; Second line: data. + # Break the line into data. + data <- strsplit(lineData, ",", fixed = TRUE)[[1]] + # Check if the request returned something valid. + if(length(data) >= 8) { + list(divtime=as.numeric(data[6]),divtimeCI_low=as.numeric(data[7]),divtimeCI_high=as.numeric(data[8])) + } else { + NA + } +} diff --git a/man/ConvenientTblTree.Rd b/man/ConvenientTblTree.Rd index c072dea..a7d2050 100644 --- a/man/ConvenientTblTree.Rd +++ b/man/ConvenientTblTree.Rd @@ -1,12 +1,8 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/ConvenientTblTree.R -\docType{data} \name{ConvenientTblTree} \alias{ConvenientTblTree} \title{Convenient tbl_trees} -\format{ -An object of class \code{S7_S3_class} of length 3. -} \usage{ ConvenientTblTree } @@ -23,4 +19,3 @@ order in which the nodes would be plotted. This is needed by the \author{ Charles Plessy } -\keyword{datasets} diff --git a/man/Haloarchaea.Rd b/man/Haloarchaea.Rd index 98c52df..157c87d 100644 --- a/man/Haloarchaea.Rd +++ b/man/Haloarchaea.Rd @@ -32,7 +32,7 @@ Halo_FocalClades } \seealso{ -Other Lazy-loaded data: +Other Lazy-loaded data: \code{\link{oikData}} } \author{ diff --git a/man/MRCA_2D_plot.Rd b/man/MRCA_2D_plot.Rd index 7249bb6..fbc358a 100644 --- a/man/MRCA_2D_plot.Rd +++ b/man/MRCA_2D_plot.Rd @@ -26,10 +26,10 @@ p + ggplot2::geom_point( color = focalClade)) } \seealso{ -Other Plotting functions: -\code{\link{ellipsePlot}()}, -\code{\link{treeHeatMap}()}, -\code{\link{visualizeTree}()} +Other Plotting functions: +\code{\link[=ellipsePlot]{ellipsePlot()}}, +\code{\link[=treeHeatMap]{treeHeatMap()}}, +\code{\link[=visualizeTree]{visualizeTree()}} } \author{ Charles Plessy diff --git a/man/childSpecies.Rd b/man/childSpecies.Rd index bb0da69..cbd5611 100644 --- a/man/childSpecies.Rd +++ b/man/childSpecies.Rd @@ -22,10 +22,10 @@ childSpecies(Halo_Tree, 7) } \seealso{ -Other Functions for trees: -\code{\link{extractValues}()}, -\code{\link{recordAncestor}()}, -\code{\link{subMatrix}()} +Other Functions for trees: +\code{\link[=extractValues]{extractValues()}}, +\code{\link[=recordAncestor]{recordAncestor()}}, +\code{\link[=subMatrix]{subMatrix()}} } \author{ Noa Brenner diff --git a/man/ellipsePlot.Rd b/man/ellipsePlot.Rd index 674378d..ae1bbb1 100644 --- a/man/ellipsePlot.Rd +++ b/man/ellipsePlot.Rd @@ -28,10 +28,10 @@ clade. ellipsePlot(Halo_DF |> averageResults()) } \seealso{ -Other Plotting functions: -\code{\link{MRCA_2D_plot}()}, -\code{\link{treeHeatMap}()}, -\code{\link{visualizeTree}()} +Other Plotting functions: +\code{\link[=MRCA_2D_plot]{MRCA_2D_plot()}}, +\code{\link[=treeHeatMap]{treeHeatMap()}}, +\code{\link[=visualizeTree]{visualizeTree()}} } \author{ Charles Plessy diff --git a/man/eog.Rd b/man/eog.Rd index 1a9ba14..245b41a 100644 --- a/man/eog.Rd +++ b/man/eog.Rd @@ -25,13 +25,13 @@ eog(Halo_Tree, Halo_FocalClades$Haloferax) } \seealso{ -Other Focal clade functions: -\code{\link{focalClade}()}, -\code{\link{recordAncestor}()}, -\code{\link{recordClades}()}, -\code{\link{subMatrix}()}, -\code{\link{subTree}()}, -\code{\link{visualizeTree}()} +Other Focal clade functions: +\code{\link[=focalClade]{focalClade()}}, +\code{\link[=recordAncestor]{recordAncestor()}}, +\code{\link[=recordClades]{recordClades()}}, +\code{\link[=subMatrix]{subMatrix()}}, +\code{\link[=subTree]{subTree()}}, +\code{\link[=visualizeTree]{visualizeTree()}} } \author{ Charles Plessy diff --git a/man/extractValues.Rd b/man/extractValues.Rd index ea2910d..2b3cb89 100644 --- a/man/extractValues.Rd +++ b/man/extractValues.Rd @@ -26,9 +26,9 @@ unique(Halo_Tree$parent) |> sort() |> purrr::set_names() |> sapply(extractValues, Halo_Tree, Halo_PercentDiff) } \seealso{ -Other Functions for trees: -\code{\link{childSpecies}()}, -\code{\link{recordAncestor}()}, -\code{\link{subMatrix}()} +Other Functions for trees: +\code{\link[=childSpecies]{childSpecies()}}, +\code{\link[=recordAncestor]{recordAncestor()}}, +\code{\link[=subMatrix]{subMatrix()}} } \concept{Functions for trees} diff --git a/man/focalClade.Rd b/man/focalClade.Rd index 70ecc32..f56394e 100644 --- a/man/focalClade.Rd +++ b/man/focalClade.Rd @@ -29,13 +29,13 @@ Clades of interest to be plotted in color visualizeTree(Halo_Tree) + clades } \seealso{ -Other Focal clade functions: -\code{\link{eog}()}, -\code{\link{recordAncestor}()}, -\code{\link{recordClades}()}, -\code{\link{subMatrix}()}, -\code{\link{subTree}()}, -\code{\link{visualizeTree}()} +Other Focal clade functions: +\code{\link[=eog]{eog()}}, +\code{\link[=recordAncestor]{recordAncestor()}}, +\code{\link[=recordClades]{recordClades()}}, +\code{\link[=subMatrix]{subMatrix()}}, +\code{\link[=subTree]{subTree()}}, +\code{\link[=visualizeTree]{visualizeTree()}} } \author{ Charles Plessy diff --git a/man/formatStats.Rd b/man/formatStats.Rd index b000707..2eb32d4 100644 --- a/man/formatStats.Rd +++ b/man/formatStats.Rd @@ -33,8 +33,8 @@ exDataFrame <- formatStats(yamlFileData) exDataFrame[1:10,1:6] } \seealso{ -Other Data load functions: -\code{\link{resultFiles}()} +Other Data load functions: +\code{\link[=resultFiles]{resultFiles()}} } \author{ Noah Brenner diff --git a/man/getDivergenceTime.Rd b/man/getDivergenceTime.Rd new file mode 100644 index 0000000..2aea125 --- /dev/null +++ b/man/getDivergenceTime.Rd @@ -0,0 +1,30 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/timeTree.R +\name{getDivergenceTime} +\alias{getDivergenceTime} +\title{Divergence time - TimeTree} +\usage{ +getDivergenceTime(taxid1, taxid2) +} +\arguments{ +\item{taxid1}{An integer: The NCBI id of one taxon} + +\item{taxid2}{An integer: The NCBI id of the other taxon} +} +\value{ +A list in which the first item is the divergence time (\code{divtime}), +and the last two items are the divergence time confidence interval +(\code{divtimeCI_low} and \code{divtimeCI_high}). +If the divergence time is not found in the TimeTree database, it returns \code{NA}. +} +\description{ +Retrieves the divergence time of two species via the TimeTree API. +} +\examples{ +\dontrun{ +getDivergenceTime(9555,9601)} + +} +\author{ +Priscila Biller +} diff --git a/man/getTimeline.Rd b/man/getTimeline.Rd new file mode 100644 index 0000000..b6a1af6 --- /dev/null +++ b/man/getTimeline.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/timeTree.R +\name{getTimeline} +\alias{getTimeline} +\title{Timeline - TimeTree} +\usage{ +getTimeline(taxid) +} +\arguments{ +\item{taxid}{An integer: The NCBI id of a taxon} +} +\value{ +A dataframe in which each row corresponds to an ancestor. +Each row contains the divergence time (\code{divtime}), its confidence interval +(\code{divtimeCI_low} and \code{divtimeCI_high}), and additional information, +including the scientific name (\code{name}) and taxonomic rank (\code{rank}). +If the divergence time is not found in the TimeTree database, it returns \code{NA}. +} +\description{ +Fetches a list of divergence times of nodes in TimeTree from the specified taxon to the common ancestor of all cellular organisms. +} +\examples{ +\dontrun{ +getTimeline(9555)} + +} +\author{ +Priscila Biller +} diff --git a/man/oikData.Rd b/man/oikData.Rd index 60fc056..5b47c94 100644 --- a/man/oikData.Rd +++ b/man/oikData.Rd @@ -28,7 +28,7 @@ by a beta version of the \url{https://nf-co.re/pairgenomealign} pipeline. oikData } \seealso{ -Other Lazy-loaded data: +Other Lazy-loaded data: \code{\link{Haloarchaea}} } \author{ diff --git a/man/recordAncestor.Rd b/man/recordAncestor.Rd index 7a66889..f062363 100644 --- a/man/recordAncestor.Rd +++ b/man/recordAncestor.Rd @@ -23,18 +23,18 @@ recordAncestor(Halo_DF, Halo_Tree)$MRCA } \seealso{ -Other Functions for trees: -\code{\link{childSpecies}()}, -\code{\link{extractValues}()}, -\code{\link{subMatrix}()} +Other Functions for trees: +\code{\link[=childSpecies]{childSpecies()}}, +\code{\link[=extractValues]{extractValues()}}, +\code{\link[=subMatrix]{subMatrix()}} -Other Focal clade functions: -\code{\link{eog}()}, -\code{\link{focalClade}()}, -\code{\link{recordClades}()}, -\code{\link{subMatrix}()}, -\code{\link{subTree}()}, -\code{\link{visualizeTree}()} +Other Focal clade functions: +\code{\link[=eog]{eog()}}, +\code{\link[=focalClade]{focalClade()}}, +\code{\link[=recordClades]{recordClades()}}, +\code{\link[=subMatrix]{subMatrix()}}, +\code{\link[=subTree]{subTree()}}, +\code{\link[=visualizeTree]{visualizeTree()}} } \author{ Noa Brenner diff --git a/man/recordClades.Rd b/man/recordClades.Rd index 9724c41..8d9857c 100644 --- a/man/recordClades.Rd +++ b/man/recordClades.Rd @@ -26,13 +26,13 @@ when it did not find it. recordClades(Halo_DF, Halo_FocalClades) } \seealso{ -Other Focal clade functions: -\code{\link{eog}()}, -\code{\link{focalClade}()}, -\code{\link{recordAncestor}()}, -\code{\link{subMatrix}()}, -\code{\link{subTree}()}, -\code{\link{visualizeTree}()} +Other Focal clade functions: +\code{\link[=eog]{eog()}}, +\code{\link[=focalClade]{focalClade()}}, +\code{\link[=recordAncestor]{recordAncestor()}}, +\code{\link[=subMatrix]{subMatrix()}}, +\code{\link[=subTree]{subTree()}}, +\code{\link[=visualizeTree]{visualizeTree()}} } \author{ Charles Plessy diff --git a/man/resultFiles.Rd b/man/resultFiles.Rd index 9483b17..f1fd465 100644 --- a/man/resultFiles.Rd +++ b/man/resultFiles.Rd @@ -30,8 +30,8 @@ system.file("extdata/yaml", package = "ScrambledTreeBuilder") |> resultFiles() } \seealso{ -Other Data load functions: -\code{\link{formatStats}()} +Other Data load functions: +\code{\link[=formatStats]{formatStats()}} } \author{ Charles Plessy diff --git a/man/subMatrix.Rd b/man/subMatrix.Rd index 6d34d0c..e649ffb 100644 --- a/man/subMatrix.Rd +++ b/man/subMatrix.Rd @@ -40,18 +40,18 @@ subTree(Halo_Tree, 9) |> subMatrix(Halo_PercentDiff) } \seealso{ -Other Functions for trees: -\code{\link{childSpecies}()}, -\code{\link{extractValues}()}, -\code{\link{recordAncestor}()} - -Other Focal clade functions: -\code{\link{eog}()}, -\code{\link{focalClade}()}, -\code{\link{recordAncestor}()}, -\code{\link{recordClades}()}, -\code{\link{subTree}()}, -\code{\link{visualizeTree}()} +Other Functions for trees: +\code{\link[=childSpecies]{childSpecies()}}, +\code{\link[=extractValues]{extractValues()}}, +\code{\link[=recordAncestor]{recordAncestor()}} + +Other Focal clade functions: +\code{\link[=eog]{eog()}}, +\code{\link[=focalClade]{focalClade()}}, +\code{\link[=recordAncestor]{recordAncestor()}}, +\code{\link[=recordClades]{recordClades()}}, +\code{\link[=subTree]{subTree()}}, +\code{\link[=visualizeTree]{visualizeTree()}} } \author{ Charles Plessy diff --git a/man/subTree.Rd b/man/subTree.Rd index 69ebffe..24dbe72 100644 --- a/man/subTree.Rd +++ b/man/subTree.Rd @@ -30,13 +30,13 @@ visualizeTree(subtree, subtree$node.orig) } \seealso{ -Other Focal clade functions: -\code{\link{eog}()}, -\code{\link{focalClade}()}, -\code{\link{recordAncestor}()}, -\code{\link{recordClades}()}, -\code{\link{subMatrix}()}, -\code{\link{visualizeTree}()} +Other Focal clade functions: +\code{\link[=eog]{eog()}}, +\code{\link[=focalClade]{focalClade()}}, +\code{\link[=recordAncestor]{recordAncestor()}}, +\code{\link[=recordClades]{recordClades()}}, +\code{\link[=subMatrix]{subMatrix()}}, +\code{\link[=visualizeTree]{visualizeTree()}} } \author{ Charles Plessy diff --git a/man/treeHeatMap.Rd b/man/treeHeatMap.Rd index 1d1e1a7..16ee2f1 100644 --- a/man/treeHeatMap.Rd +++ b/man/treeHeatMap.Rd @@ -30,10 +30,10 @@ treeHeatMap(Halo_PercentDiff, Halo_Tree, Halo_FocalClades) } \seealso{ -Other Plotting functions: -\code{\link{MRCA_2D_plot}()}, -\code{\link{ellipsePlot}()}, -\code{\link{visualizeTree}()} +Other Plotting functions: +\code{\link[=MRCA_2D_plot]{MRCA_2D_plot()}}, +\code{\link[=ellipsePlot]{ellipsePlot()}}, +\code{\link[=visualizeTree]{visualizeTree()}} } \author{ Charles Plessy diff --git a/man/visualizeTree.Rd b/man/visualizeTree.Rd index 29d4185..665e195 100644 --- a/man/visualizeTree.Rd +++ b/man/visualizeTree.Rd @@ -42,18 +42,18 @@ visualizeTree(Halo_Tree, value = Halo_Tree$Scrambling_index) visualizeTree(Halo_Tree, "Scrambling_index") # same } \seealso{ -Other Focal clade functions: -\code{\link{eog}()}, -\code{\link{focalClade}()}, -\code{\link{recordAncestor}()}, -\code{\link{recordClades}()}, -\code{\link{subMatrix}()}, -\code{\link{subTree}()} +Other Focal clade functions: +\code{\link[=eog]{eog()}}, +\code{\link[=focalClade]{focalClade()}}, +\code{\link[=recordAncestor]{recordAncestor()}}, +\code{\link[=recordClades]{recordClades()}}, +\code{\link[=subMatrix]{subMatrix()}}, +\code{\link[=subTree]{subTree()}} -Other Plotting functions: -\code{\link{MRCA_2D_plot}()}, -\code{\link{ellipsePlot}()}, -\code{\link{treeHeatMap}()} +Other Plotting functions: +\code{\link[=MRCA_2D_plot]{MRCA_2D_plot()}}, +\code{\link[=ellipsePlot]{ellipsePlot()}}, +\code{\link[=treeHeatMap]{treeHeatMap()}} } \author{ Noah Brenner