{"id":37320004,"url":"https://github.com/csiro/nrca-phylodist","last_synced_at":"2026-01-16T03:16:57.976Z","repository":{"id":294617138,"uuid":"966484777","full_name":"csiro/nrca-phylodist","owner":"csiro","description":"Calculating phylogenetic distances for weed biological control","archived":false,"fork":false,"pushed_at":"2025-06-04T04:13:10.000Z","size":594,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-09-10T06:42:16.648Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/csiro.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-04-15T02:01:38.000Z","updated_at":"2025-06-04T04:13:12.000Z","dependencies_parsed_at":"2025-09-10T05:20:01.166Z","dependency_job_id":null,"html_url":"https://github.com/csiro/nrca-phylodist","commit_stats":null,"previous_names":["csiro/nrca-phylodist"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/csiro/nrca-phylodist","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csiro%2Fnrca-phylodist","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csiro%2Fnrca-phylodist/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csiro%2Fnrca-phylodist/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csiro%2Fnrca-phylodist/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/csiro","download_url":"https://codeload.github.com/csiro/nrca-phylodist/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csiro%2Fnrca-phylodist/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28477087,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T03:13:13.607Z","status":"ssl_error","status_checked_at":"2026-01-16T03:11:47.863Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-16T03:16:57.896Z","updated_at":"2026-01-16T03:16:57.959Z","avatar_url":"https://github.com/csiro.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Calculating phylogenetic distances for weed biological control\n\nAuthors of code: Nunzio Knerr, Stephanie Chen, Alexander Schmidt-Lebuhn\n\n## What does this script do and what is it useful for?\n\nThis code was introduced in a submitted paper titled 'Phylogenomics-driven host test list selection for weed biological control'. It contains functions for calculating phylogenetic distance measures useful for creating host tests list in classical weed biological control.\n\nThe degree of relatedness between two taxa on a phylogeny is indicated by the number of nodes separating them. Here, we provide functions that calculate two distance measures, degree of separation i.e. node count and patristic distance, given an input phylogenetic tree.\n\n## Descendant List Function\n\nFirst define a function to recursively collect descendants of a node. This is used by the 'degreeofsep' function later on.\n\n``` {.r .cell-code}\ndescendantlist \u003c- function(thistree, thisnode)\n{\n  if (thisnode \u003c= length(thistree$tip.label))\n  {\n    return (thisnode)\n  }\n  else\n  {\n    wherenext \u003c- which(thistree$edge[,1]==thisnode)  # get immediate descendants\n    thislist \u003c- NULL\n    for (x in 1:length(wherenext))\n    {\n      thislist \u003c- c(thislist, descendantlist(thistree, thistree$edge[wherenext[x],2]))\n    }\n    return(thislist)\n  }\n}\n```\n\n## Degree Of Separation Function\n\nFunction for calculating degrees of separation i.e. node count from a specified target weed.\n\n``` {.r .cell-code}\ndegreesofsep \u003c- function(thistree)\n{\n  dosmatrix \u003c- matrix(0, nrow=length(thistree$tip.label), ncol=length(thistree$tip.label))\n  colnames(dosmatrix) \u003c- thistree$tip.label\n  rownames(dosmatrix) \u003c- thistree$tip.label\n  for (x in 1:length(thistree$tip.label))\n  {\n    prior_y \u003c- x         # start at present terminal\n    y \u003c- thistree$edge[which(thistree$edge[,2]==x),1]   # get immediately ancestral node\n    currentdist \u003c- 0\n    while (y != (length(thistree$tip.label)+1)) # move downtree until root node is found\n    {\n      currentdesc \u003c- which(thistree$edge[,1]==y)\n      for (z in 1:length(currentdesc))\n      {\n        if (thistree$edge[currentdesc[z],2]!=prior_y)\n        {\n          dosmatrix[x,descendantlist(thistree,thistree$edge[currentdesc[z],2])] \u003c- currentdist\n        }\n      }\n      prior_y \u003c- y\n      y \u003c- thistree$edge[which(thistree$edge[,2]==y),1]   # get immediately ancestral node\n      currentdist \u003c- currentdist + 1\n    }\n    currentdesc \u003c- which(thistree$edge[,1]==y)\n    for (z in 1:length(currentdesc))\n    {\n      if (thistree$edge[currentdesc[z],2]!=prior_y)\n      {\n        dosmatrix[x,descendantlist(thistree,thistree$edge[currentdesc[z],2])] \u003c- currentdist\n      }\n    }\n  }\n  return(dosmatrix)\n}\n```\n\n## User Input Variables\n\nSpecify the inputs and outputs for use in the script. A tree file in newick format is required. The outgroup(s) may be specified. The target taxon i.e. target weed for biological control is also specified here so that the distance measures can be calculated in relation to the target.\n\n``` {.r .cell-code}\n# phylogenetic tree as newick file\ntreeFileName \u003c- \"astereae_concatenated.tre\"\n# specify outgroup(s)\ntaxonListForOutgroup \u003c- c(\"Dimorphotheca_pluvialis\", \"Ewartia_nubigena\", \"Abrotanella_nivigena\",\"Cotula_coronopifolia\") \n# the target taxon to calculate distances from\nmyTargetTaxon \u003c- \"Erigeron_bonariensis\"\n# the output file name\noutputFileName \u003c- paste0(\"phylodists_\", myTargetTaxon, \".tsv\")\n```\n\n## Example Usage\n\n``` {.r .cell-code}\n# load libraries\n# load libraries\nlibrary(ape)\nlibrary(adephylo)\n\n# read phylogenetic tree\nmytree \u003c- ape::read.tree(treeFileName)\n\n# call the get Most Recent Common Ancesstors (MRCA)\nmyOG \u003c- getMRCA(mytree, taxonListForOutgroup)\n#root the tree based on the MRCA results\nmytree \u003c- root(mytree, node = myOG)\n\n# infer matrix of pairwise patristic distances between all terminals\n# this takes quite some time for larger trees\n\nmyPatristic \u003c- distTips(mytree)\nmyPatristicM \u003c- as.matrix(myPatristic)\nmyPatristicMordered \u003c- myPatristicM[order(rownames(myPatristicM)), order(rownames(myPatristicM))]\n#write.matrix(myPatristicMordered, file=\"patristicdists.tsv\", sep=\"\\t\")\n\n# now calculate degrees of separation, i.e. counting nodes between any terminal and its ancestral lineage splits\n# this will take quite some time for larger trees\n\nmyDegsep \u003c- degreesofsep(mytree)\nmyDegsep \u003c- myDegsep[order(rownames(myDegsep)),order(rownames(myDegsep))]\n#write.matrix(myDegsep, file=\"degsep.tsv\", sep=\"\\t\")\n\n# make data frame for one target species with both its degrees of separation and patristic distances\ntargetTaxon \u003c- myTargetTaxon\nTerminal \u003c- row.names(myDegsep)\nDegsep \u003c- myDegsep[which(row.names(myDegsep)==targetTaxon), ]\nPatristicDist \u003c- myPatristicMordered[which(row.names(myPatristicMordered) ==\n                                            targetTaxon), ]\n\nPhyloDists \u003c- data.frame(Species = Terminal[order(PatristicDist)], \n                         DegSep = Degsep[order(PatristicDist)], \n                         PatristicDist = PatristicDist[order(PatristicDist)],\n                         row.names = NULL)\n\nwrite.table(PhyloDists, file = outputFileName, sep = \"\\t\", row.names = FALSE)\n\nknitr::kable(PhyloDists)\n```\n\nThe output is a tab separated file with columns for the scientific name, degree of separation and patristic distance. See the file phylodists_Erigeron_bonariensis.tsv for an example that was used as a case study in the paper.\n\n## Copyright and license information\nCopyright (C) 2024  CSIRO\n\nThis program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program.  If not, see \u003chttp://www.gnu.org/licenses/\u003e.\n\n## Citation and contact information\n\nPlease cite the following paper if you use these scripts:\n\nStephanie H. Chen, Ben Gooden, Michelle A. Rafter, Gavin C. Hunter, Alicia Grealy, Nunzio Knerr, Alexander N. Schmidt-Lebuhn. *Phylogenomics-driven host test list selection for weed biological control*. Biological Control, Volume 193, 2024, 105529, \u003chttps://doi.org/10.1016/j.biocontrol.2024.105529\u003e[\\\n\\\n](#0)Contact the corresponding author of the paper, [Alexander Schmidt-Lebuhn](mailto:alexander.s-l@csiro.au), if you have any questions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcsiro%2Fnrca-phylodist","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcsiro%2Fnrca-phylodist","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcsiro%2Fnrca-phylodist/lists"}