phylotastic / datelife

R package containing datelife's core functionality
http://phylotastic.org/datelife/
13 stars 11 forks source link

Run bladj from calibrations #95

Open snacktavish opened 4 months ago

snacktavish commented 4 months ago

http://phylotastic.org/datelife/reference/use_calibrations_bladj.matchedCalibrations.html

I am having issues running this -


> honeycreepers<-c("Akialoa obscura",
                 "Akialoa stejnegeri",
                 "Chloridops kona",
                 "Chlorodrepanis flava",
                 "Chlorodrepanis stejnegeri",
                 "Chlorodrepanis virens",
                 "Hemignathus affinis",
                 "Hemignathus hanapepe",
                 "Hemignathus wilsoni",
                 "Himatione fraithii",
                 "Himatione sanguinea",
                 "Loxioides bailleui")
> bird_query = datelife::make_datelife_query(input = honeycreepers)
> use_calibrations_bladj.matchedCalibrations(
     calibrations,
     type = "mean",
     root_age = NULL
 )
Using secondary calibrations with BLADJ.
Error in UseMethod("Ntip") : 
  no applicable method for 'Ntip' applied to an object of class "NULL"
LunaSare commented 4 months ago

Nice example! I do not see how you obtained the calibrations, but this is how I would do it:

# create the species query
bird_query = datelife::make_datelife_query(input = honeycreepers)
# Key step: search the chronogram database:
bird_res <- datelife::get_datelife_result(input = bird_query)
# summarize results (this will get you the opentree topology)
bird_summ <- summary(object = bird_res, datelife_query = bird_query)
# get calibrations congruified to a topology, we will use the opentree one, but we cold use any from the list of chronograms in bird_summ$phylo_all
cc <- datelife::congruify_and_mrca_multiPhylo(phy = bird_summ$phylo_median,
                              source_chronograms = bird_summ$phylo_all)

nrow(cc) # 12 calibrations
# now date with bladj
bird_bladj_mean <- datelife::use_calibrations_bladj(calibrations = cc,
                                                    type = "mean")
bird_bladj_median <- datelife::use_calibrations_bladj(calibrations = cc,
                                                    type = "median")
# you can compare the node ages from mean and median
data.frame(branching.times(bird_bladj_mean), branching.times(bird_bladj_median))
snacktavish commented 4 months ago

Sorry - I should have included a complete example! My query is a tree, and the summary step fails on bladj, because there is no root age. I wanted to run the bladj step on it's own, so I could put in a root age, but I can't figure out how to do it directly!

queryTree <- "((Psittirostra_psittacea:16.17084019,(((((((((Hemignathus_affinis:0.205878784,Viridonia_sagittirostris:0.2058788809)NA:0.6176362992,Hemignathus_hanapepe:0.82351501)NA:0.82351501,Hemignathus_wilsoni:1.64703)NA:1.64703,(Chlorodrepanis_virens:1.64703,Chlorodrepanis_stejnegeri:1.64703)mrcaott324560ott667189:1.64703)mrcaott324560ott324561:1.64703,((Akialoa_stejnegeri:1.2352725,Akialoa_obscura:1.235272524)NA:1.2352725,Chlorodrepanis_flava:2.470545)mrcaott324558ott706153:2.470545)mrcaott324558ott324560:1.64703,(((Drepanis_coccinea:1.64703,(Himatione_sanguinea:0.823515,Himatione_fraithii:0.8235151401)NA:0.823515)mrcaott298780ott823302:1.64703,Palmeria_dolei:3.29406)mrcaott298765ott298780:1.64703,(Loxops_mana:2.470545,Loxops_ochraceus:2.47054503)NA:2.470545)mrcaott298765ott298768:1.64703)mrcaott298765ott324558:1.647029,(((Loxops_caeruleirostris:2.058787,Loxops_coccineus:2.058787)mrcaott1016648ott1089641:2.058787,Pseudonestor_xanthophrys:4.117574)mrcaott823300ott1016648:2.058787,Magumma_parva:6.176361)mrcaott823300ott1089642:2.058788)mrcaott298765ott823300:1.64703,(Telespiza_cantans:6.58812,Loxioides_bailleui:6.58812)mrcaott213516ott221897:3.294059)mrcaott157614ott298765:1.64703,((((Paroreomyza_maculata:1.441151027,Rhodacanthis_palmeri:1.441151164)NA:1.441151027,Paroreomyza_montana:2.882302)NA:1.441151,Paroreomyza_flammea:4.32345312)NA:1.441151,Oreomystis_bairdi:5.764604)mrcaott298769ott823298:5.764605)mrcaott157614ott298769:4.641631)mrcaott6366ott157599:1.540082,Chloridops_kona:17.71092218)mrcaott6366ott88283:1;"
> bird_query = datelife::make_datelife_query(input = queryTree)
> bird_res <- datelife::get_datelife_result(input = queryTree)
# summarize results (this will get you the opentree topology)
> bird_summ <- summary(object = bird_res, datelife_query = bird_query)

Trying with overlap = 2

Success!

... Calculating a median summary chronogram.
Warning in check_root_node(phylo, ages) :
  bladj may fail; the root node 'n1' is not in the ages nodes
Error: Program '/home/ejmctavish/R/x86_64-pc-linux-gnu-library/4.3/phylocomr/bin//phylocom' terminated by SIGNAL (Segmentation fault)

I have had a few queries fail on the summary step due to bladj errors - but I am having trouble finding where in the code bladj is getting called in the summary! e.g.

> phylo_sdm <- datelife::datelife_search(input = bird_query,
                                          summary_format = "phylo_sdm")
... Running a DateLife search.
... Searching DateLife's OpenTree chronogram database version v2023.12.30
Search done!

Input taxon names were found in 8 chronograms.
Trying with overlap = 2

Success!

1 out of 8 chronograms tried:  Failed.
2 out of 8 chronograms tried:  Ok.
3 out of 8 chronograms tried:  Ok.
4 out of 8 chronograms tried:  Ok.
5 out of 8 chronograms tried:  Failed.
6 out of 8 chronograms tried:  Failed.
7 out of 8 chronograms tried:  Ok.
8 out of 8 chronograms tried:  Failed.

 Synthesizing 4 chronograms with SDM
Warning in check_root_node(phylo, ages) :
  bladj may fail; the root node 'n1' is not in the ages nodes
Error: Program '/home/ejmctavish/R/x86_64-pc-linux-gnu-library/4.3/phylocomr/bin//phylocom' terminated by SIGNAL (Segmentation fault)
snacktavish commented 4 months ago

Yay! :confetti_ball: In person solution from @LunaSare

> queryTree <- "((Psittirostra_psittacea:16.17084019,(((((((((Hemignathus_affinis:0.205878784,Viridonia_sagittirostris:0.2058788809)NA:0.6176362992,Hemignathus_hanapepe:0.82351501)NA:0.82351501,Hemignathus_wilsoni:1.64703)NA:1.64703,(Chlorodrepanis_virens:1.64703,Chlorodrepanis_stejnegeri:1.64703)mrcaott324560ott667189:1.64703)mrcaott324560ott324561:1.64703,((Akialoa_stejnegeri:1.2352725,Akialoa_obscura:1.235272524)NA:1.2352725,Chlorodrepanis_flava:2.470545)mrcaott324558ott706153:2.470545)mrcaott324558ott324560:1.64703,(((Drepanis_coccinea:1.64703,(Himatione_sanguinea:0.823515,Himatione_fraithii:0.8235151401)NA:0.823515)mrcaott298780ott823302:1.64703,Palmeria_dolei:3.29406)mrcaott298765ott298780:1.64703,(Loxops_mana:2.470545,Loxops_ochraceus:2.47054503)NA:2.470545)mrcaott298765ott298768:1.64703)mrcaott298765ott324558:1.647029,(((Loxops_caeruleirostris:2.058787,Loxops_coccineus:2.058787)mrcaott1016648ott1089641:2.058787,Pseudonestor_xanthophrys:4.117574)mrcaott823300ott1016648:2.058787,Magumma_parva:6.176361)mrcaott823300ott1089642:2.058788)mrcaott298765ott823300:1.64703,(Telespiza_cantans:6.58812,Loxioides_bailleui:6.58812)mrcaott213516ott221897:3.294059)mrcaott157614ott298765:1.64703,((((Paroreomyza_maculata:1.441151027,Rhodacanthis_palmeri:1.441151164)NA:1.441151027,Paroreomyza_montana:2.882302)NA:1.441151,Paroreomyza_flammea:4.32345312)NA:1.441151,Oreomystis_bairdi:5.764604)mrcaott298769ott823298:5.764605)mrcaott157614ott298769:4.641631)mrcaott6366ott157599:1.540082,Chloridops_kona:17.71092218)mrcaott6366ott88283:1;"
> bird_query = datelife::make_datelife_query(input = queryTree)
> queryphylo<-ape::read.tree(text=queryTree)
>cc <- datelife::congruify_and_mrca_multiPhylo(phy = queryphylo,
                                              source_chronograms = attributes(calibrations)$chronograms
                                               )
> bird_bladj_mean <- datelife::use_calibrations_bladj(calibrations = cc,
                                                    type = "mean")
snacktavish commented 4 months ago

note <- update docs here http://phylotastic.org/datelife/reference/use_calibrations_bladj.matchedCalibrations.html because it appears that it needs to be congruified calibrations, not get_all_calibrations. (updated example where I actually show where the calibrations come from :P)

> honeycreepers<-c("Akialoa obscura",
                 "Akialoa stejnegeri",
                  "Chloridops kona",
                  "Chlorodrepanis flava",
                  "Chlorodrepanis stejnegeri",
                  "Chlorodrepanis virens",
                  "Hemignathus affinis",
                  "Hemignathus hanapepe",
                  "Hemignathus wilsoni",
                  "Himatione fraithii",
                  "Himatione sanguinea",
                  "Loxioides bailleui",
                  "Loxops caeruleirostris",
                  "Loxops coccineus",
                  "Loxops mana",
                  "Loxops ochraceus",
                  "Magumma parva",
                  "Oreomystis bairdi",
                  "Palmeria dolei",
                  "Paroreomyza flammea",
                  "Paroreomyza maculata",
                  "Paroreomyza montana",
                  "Pseudonestor xanthophrys",
                  "Psittirostra psittacea",
                  "Rhodacanthis palmeri",
                  "Telespiza cantans",
                  "Viridonia sagittirostris",
                  "Drepanis coccinea")
> bird_query = datelife::make_datelife_query(input = honeycreepers)
---> Phylo-processing 'input'.
* 'input' is not a phylogeny.
---> Making a DateLife query.
---> Runnning TNRS to match input names to reference taxonomy (OTT).
  |=============================================================================================================================| 100%
---> Working with the following 28 taxa: Akialoa obscura | Hemignathus stejnegeri | Chloridops kona | Hemignathus flavus | Hemignathus kauaiensis | Hemignathus virens | Hemignathus affinis | Hemignathus hanapepe | Hemignathus wilsoni | Himatione fraithii... omitted  18 taxon names.
DateLife query made!

> calibrations<-get_all_calibrations(input = bird_query)
... Running a DateLife search.
... Searching DateLife's OpenTree chronogram database version v2023.12.30
Search done!

Input taxon names were found in 8 chronograms.
Source chronograms from:

1: Uyeda, J. C., Pennell, M. W., Miller, E. T., Maia, R., & McClain, C. R. (2017). The Evolution of Energetic Scaling across the Vertebrate Tree of Life. The American Naturalist, 190(2), 185–199. doi:10.1086/692326

2: Jetz, W., G. H. Thomas, J. B. Joy, K. Hartmann, A. O. Mooers. 2012. The global diversity of birds in space and time. Nature 491 (7424): 444-448

3: Jetz, W., G. H. Thomas, J. B. Joy, K. Hartmann, A. O. Mooers. 2012. The global diversity of birds in space and time. Nature 491 (7424): 444-448

4: Barker, F. Keith, Kevin J. Burns, John Klicka, Scott M. Lanyon, Irby J. Lovette. 2015. New insights into New World biogeography: An integrated view from the phylogeny of blackbirds, cardinals, sparrows, tanagers, warblers, and allies. The Auk 132 (2): 333-348.

5: Barker, F. Keith, Kevin J. Burns, John Klicka, Scott M. Lanyon, Irby J. Lovette. 2015. New insights into New World biogeography: An integrated view from the phylogeny of blackbirds, cardinals, sparrows, tanagers, warblers, and allies. The Auk 132 (2): 333-348.

6: Selvatti, Alexandre Pedro, Luiz Pedreira Gonzaga, Claudia Augusta de Moraes Russo. 2015. A Paleogene origin for crown passerines and the diversification of the Oscines in the New World. Molecular Phylogenetics and Evolution 88: 1-15.

7: Barker, F. K., K. J. Burns, J. Klicka, S. M. Lanyon, I. J. Lovette. 2013. Going to extremes: contrasting rates of diversification in a recent radiation of New World passerine birds. Systematic Biology 62 (2): 298-320.

8: Hedges, S. Blair, Julie Marin, Michael Suleski, Madeline Paymer, Sudhir Kumar. 2015. Tree of life reveals clock-like speciation and diversification. Molecular Biology and Evolution 32 (4): 835-845

Input taxa presence across source chronograms:
                      taxon chronograms
1       Himatione_sanguinea         4/8
2        Loxioides_bailleui         4/8
3         Telespiza_cantans         3/8
4        Vestiaria_coccinea         4/8
5            Palmeria_dolei         3/8
6    Hemignathus_kauaiensis         3/8
7        Hemignathus_virens         3/8
8    Loxops_caeruleirostris         3/8
9          Loxops_coccineus         4/8
10              Loxops_mana         2/8
11      Hemignathus_wilsoni         2/8
12 Pseudonestor_xanthophrys         3/8
13       Hemignathus_parvus         3/8
14        Oreomystis_bairdi         6/8
15      Paroreomyza_montana         7/8
16   Hemignathus_stejnegeri         1/8
17       Hemignathus_flavus         1/8
18      Paroreomyza_flammea         1/8
19     Paroreomyza_maculata         1/8

Input taxa completely absent from source chronograms:
                     taxon
1          Akialoa_obscura
2          Chloridops_kona
3      Hemignathus_affinis
4     Hemignathus_hanapepe
5       Himatione_fraithii
6         Loxops_ochraceus
7   Psittirostra_psittacea
8     Rhodacanthis_palmeri
9 Viridonia_sagittirostris

DateLife search done!
> use_calibrations_bladj.matchedCalibrations(
+     calibrations,
+     type = "mean",
+     root_age = NULL
+ )
... Using secondary calibrations with BLADJ.
Error in UseMethod("Ntip") : 
  no applicable method for 'Ntip' applied to an object of class "NULL"
>