gl.tree.nj: Outputs a tree to summarize genetic similarity among...

View source: R/gl.tree.nj.r

gl.tree.njR Documentation

Outputs a tree to summarize genetic similarity among populations (e.g. phenogram)

Description

This function is a wrapper for the nj function in package ape (and, for method='upgma', the hclust function in stats) applied to Euclidean distances calculated from the genlight object.

Usage

gl.tree.nj(
  x,
  dist.matrix = NULL,
  method = "nj",
  by.pop = TRUE,
  as.pop = NULL,
  type = "phylogram",
  outgroup = NULL,
  labelsize = 0.7,
  treefile = NULL,
  plot.display = TRUE,
  verbose = NULL
)

Arguments

x

Name of the genlight object containing the SNP data [required].

dist.matrix

Distance matrix [default NULL].

method

Clustering method – nj, neighbour-joining tree; upgma, UPGMA tree [default 'nj'].

by.pop

If TRUE, populations are the terminal taxa; if FALSE, individuals are the terminal taxa [default TRUE].

as.pop

Assign another ind.metric as the population for the purposes of displaying more informative tip labels [default NULL].

type

Type of dendrogram "phylogram"|"cladogram"|"fan"|"unrooted"|"radial"|"tidy" [default "phylogram"].

outgroup

Vector containing the population names that are the outgroups [default NULL].

labelsize

Size of the labels as a proportion of the graphics default [default 0.7].

treefile

Name of the file for the tree topology using Newick format [default NULL].

plot.display

If TRUE, the tree is plotted in the plot window [default TRUE].

verbose

Verbosity: 0, silent or fatal errors; 1, begin and end; 2, progress log; 3, progress and results summary; 5, full report [default NULL, adopting the global verbosity set by gl.set.verbosity(), or 2 if no global is set].

Details

A Euclidean distance matrix is calculated by default [dist.matrix = NULL] from allele frequencies computed for each population at each locus, excluding missing genotypes. Frequencies are scaled by ploidy, so SNP (0/1/2) and Tag P/A (0/1) data both yield frequencies in the range 0 to 1. Optionally the user can use as input for the tree any other distance matrix using this parameter, see for example the function gl.dist.pop.

The tree is built with the neighbour-joining algorithm [method='nj'] or by UPGMA clustering [method='upgma']; the legacy spelling 'ugpma' is accepted as a synonym of 'upgma'. If an outgroup is specified, the tree is rooted on that outgroup with the root resolved.

The tree is computed and returned whether or not it is plotted; a failure in plotting does not affect the returned tree.

Value

A tree of class phylo. If treefile is specified, the tree is also written to that file in Newick format.

Author(s)

Author(s): Arthur Georges. Custodian: Arthur Georges – Post to https://groups.google.com/d/forum/dartr

See Also

Other graphics: gl.colors(), gl.map.interactive(), gl.plot.heatmap(), gl.plot.snp.density(), gl.select.colors(), gl.select.shapes(), gl.smearplot()

Examples

# SNP data
if (isTRUE(getOption("dartR_fbm"))) testset.gl <- gl.gen2fbm(testset.gl)
  gl.tree.nj(testset.gl,type='fan')
# Tag P/A data
  gl.tree.nj(testset.gs,type='fan')
  res <- gl.tree.nj(platypus.gl)


dartR.base documentation built on Nov. 18, 2026, 9:06 a.m.