Description
After the search finishes, the user needs to be able to save trees to an output file (which the user can name). The output is a .tre file, which is basically just a different kind of nexus file.
Examples:
File's 'header'
#NEXUS
[ */ Put the same stuff in these square brackets as gets printed to screen
after the search terminates, plus a log of: the type of search used
(exhaustive, heuristic, branch-and-bound). It must be in square
brackets though. */]
Then there are two ways of following this, either by having a TRANSLATE statement and a list of taxon names, or inlining the taxon names into the Newick strings. For example:
Translate type:
BEGIN TREES;
TRANSLATE
1 'Tyrannosaurus rex',
2 'Boa constrictor',
3 'Gorilla gorilla',
4 'E. coli'; [<- Note the terminal semicolon and no comma]
tree Morphy_1 = [&U] (4,(3,(2,1))));
tree Morphy_2 = [&U] ((4,3),(2,1))));
tree Morphy_3 = [&U] (1,(4,(3,2))));
END;
Alternatively, inlining the taxon names:
BEGIN TREES;
tree Morphy_1 = [&U] ('E. coli',('Gorilla gorilla',('Boa constrictor', 'Tyrannosaurus rex'))));
tree Morphy_2 = [&U] (('E. coli','Gorilla gorilla'),('Boa constrictor','Tyrannosaurus rex'))));
tree Morphy_3 = [&U] ('Tyrannosaurus rex',('E. coli',('Gorilla gorilla','Boa constrictor'))));
END;
The former way is probably easier. This is the format which Morphy returns the trees in. All we need is the taxon list, either from the TAXA block or the DATA block. The taxa represented numerically. Also, I will make Morphy return the leading part of the tree string (i.e. the "tree Morphy_1 = [&U]" or "...[&R]" part and the terminal semicolon. That will all be part of the string. They just have to be inserted into the file one string per line.
In the case of the DATA block, that may be tricky, because the taxon names are inline with the rows of the matrix they correspond to. So, a taxon list has to be extracted from there. Not sure if the appropriate NCL classes have functions for doing that.
The programs that generate the nexus files will include single quotes around names that are composed of multiple parts (e.g. 'Tyrannosaurus rex'). So we have to include those single quotes wherever we use those names.