This function finalises a tree file in binary format.

finish_writing_binary_trees(
  file,
  addresses,
  additional_data = vector("raw", 0)
)

Arguments

file

A file name.

addresses

A vector of mode integer containing the addresses of previous trees that have been added to the file.

additional_data

A vector of mode raw containg additional binary data that will be included within the tree file.

Details

This function will finalise a tree file in binary format, by writing the file trailer containing the addresses of the trees stored in the file.

Note that, since node names are not stored in the header, files produced with this workflow may be much larger than files produced using the write_binary_trees function (e.g. if the file contains many trees which all have the same tip labels). The advantage of this approach is that the trees do not need to be all available/stored in memory at the same time.

Finalising the file is not strictly necessary, in the sense that a file with a missing or incomplete trailer can still be parsed. However, parsing such a file requires scanning through the whole file to determine tree addresses (which is not necessary if they are stored in a proper trailer).

The additional binary data (if any) will be written in the file after the trees and before the trailer.

References

https://github.com/arklumpus/TreeNode/blob/master/BinaryTree.md

See also

Examples

#A simple tree tree1 <- ape::read.tree(text = "((A,B),(C,D));") # Initialise the output file addresses <- begin_writing_binary_trees("outputFile.tbi") # Append a tree to the output file addresses <- keep_writing_binary_trees(tree1, "outputFile.tbi", addresses) # Some more trees (note that we are overwriting tree1) tree1 <- ape::read.tree(text = "(((A,B),C),D);") tree2 <- ape::read.tree(text = "((D,(A,B)),C);") # Append them to the file addresses <- keep_writing_binary_trees(tree1, "outputFile.tbi", addresses) addresses <- keep_writing_binary_trees(tree2, "outputFile.tbi", addresses) #Some raw data raw_data <- as.raw(seq(1, 5)) # Finalise the output file finish_writing_binary_trees("outputFile.tbi", addresses, raw_data)