This function initializes a file that will be used to store trees in binary format.

begin_writing_binary_trees(file)

Arguments

file

A file name.

Value

A vector of mode integer, which should be used to keep track of the addresses of trees that will be added to the file.

Details

This function will create an empty header for the binary format file (without writing any trees). Trees should written after the header using the keep_writing_binary_trees function. The file should be finalised using the finish_writing_binary_trees function.

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.

The vector that is returned by this function contains the position at which the first tree will be appended in the file. This vector should be provided to subsequent calls to keep_writing_binary_trees.

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)