% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ReadTntTree.R
\name{ReadTntTree}
\alias{ReadTntTree}
\alias{TntText2Tree}
\alias{TNTText2Tree}
\title{Parse TNT Tree}
\usage{
ReadTntTree(filepath, relativePath = NULL, keepEnd = 1L, tipLabels = NULL)

TntText2Tree(treeText)

TNTText2Tree(treeText)
}
\arguments{
\item{filepath}{character string specifying path to TNT \code{.tre} file,
relative to the R working directory (visible with \code{getwd()}).}

\item{relativePath}{(discouraged) character string specifying location of the
matrix file used to generate the TNT results, relative to the current working
directory.  Taxon names will be read from this file if they are not specified
by \code{tipLabels}.}

\item{keepEnd}{(optional, default 1) integer specifying how many elements of
the file path to conserve when creating relative path (see examples).}

\item{tipLabels}{(optional) character vector specifying the names of the
taxa, in the sequence that they appear in the TNT file.  If not specified,
taxon names will be loaded from the data file linked in the first line of the
\code{.tre} file specified in \code{filepath}.}

\item{treeText}{Character string describing one or more trees,
in the parenthetical format output by TNT.}
}
\value{
\code{ReadTntTree()} returns a tree of class \code{phylo} in
\link[=TNTOrder]{TNT order},
corresponding to the tree in \code{filepath}, or NULL if no trees are found.
}
\description{
Read a tree from \href{https://www.lillo.org.ar/phylogeny/tnt/}{TNT}'s
parenthetical output.
}
\details{
\code{ReadTntTree()} imports trees generated by the parsimony analysis program
\href{https://www.lillo.org.ar/phylogeny/tnt/}{TNT} into R, including node labels
written with the \code{ttags} command.
Tree files must have been saved by TNT in parenthetical notation, using the
TNT command \verb{tsave *}.
Trees are easiest to load into R if taxa have been saved using their names
(TNT command \verb{taxname =}).  In this case, the TNT \code{.tre} file
contains tip labels and can be parsed directly.  The downside is that the
uncompressed \code{.tre} files will have a larger file size.

\code{ReadTntTree()} can also read \code{.tre} files in which taxa have been saved
using their numbers (\verb{taxname -}).  Such files contain a hard-coded link to
the matrix file that was used to generate the trees, in the first line of the
\code{.tre} file.  This poses problems for portability: if the matrix file is
moved, or the \code{.tre} file is accessed on another computer, the taxon names
may be lost.  As such, it is important to check that the matrix file
exists in the expected location -- if it does not,
either use the \code{relativePath} argument to point to its new location, or
specify \code{tipLabels} to manually specify the tip labels.

\code{TntText2Tree()} converts text representation of a tree in TNT to an
object of class \code{phylo}.
}
\examples{
# In the examples below, TNT has read a matrix from
# "c:/TreeTools/input/dataset.nex"
# The results of an analysis were written to
# "c:/TreeTools/output/results1.tnt"
#
# results1.tnt will contain a hard-coded reference to
# "c:/TreeTools/input/dataset.nex".

# On the original machine (but not elsewhere), it would be possible to read
# this hard-coded reference from results.tnt:
# ReadTntTree("output/results1.tnt")

# These datasets are provided with the "TreeTools" package, which will
# probably not be located at c:/TreeTools on your machine:

oldWD <- getwd() # Remember the current working directory
setwd(system.file(package = "TreeTools"))

# If taxon names were saved within the file (using `taxname=` in TNT),
# then our job is easy:
ReadTntTree("extdata/output/named.tre")

# But if taxa were compressed to numbers (using `taxname-`), we need to
# look up the original matrix in order to dereference the tip names.
#
# We need to extract the relevant file path from the end of the
# hard-coded path in the original file.
#
# We are interested in the last two elements of
# c:/TreeTools/input/dataset.nex
#                2      1
#
# "." means "relative to the current directory"
ReadTntTree("extdata/output/numbered.tre", "./extdata", 2)

# If working in a lower subdirectory
setwd("./extdata/otherfolder")

# then it will be necessary to navigate up the directory path with "..":
ReadTntTree("../output/numbered.tre", "..", 2)


setwd(oldWD) # Restore original working directory

TNTText2Tree("(A (B (C (D E ))));")

}
\seealso{
Other tree import functions: 
\code{\link{ReadMrBayesTrees}()}
}
\author{
\href{https://orcid.org/0000-0001-5660-1727}{Martin R. Smith}
(\href{mailto:martin.smith@durham.ac.uk}{martin.smith@durham.ac.uk})
}
\concept{tree import functions}
