keep_writing_binary_trees.Rd
This function adds trees to a file in binary format.
keep_writing_binary_trees(trees, file, addresses)
trees | An object of class |
---|---|
file | A file name. |
addresses | A vector of mode integer containing the addresses of previous trees that have been added to the file. |
A vector of mode integer containing the addresses of the trees that have been added to the file, which should be used to keep track of the addresses of subsequent trees.
This function will append trees in binary format to a file. The file should have been already
initialised by the begin_writing_binary_trees
function and may already
contain some trees. It 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 trees have been appendend
to the file, as well as the position at which the next tree will be appended. This vector should be provided
to subsequent calls to keep_writing_binary_trees
and to finish_writing_binary_trees
.
https://github.com/arklumpus/TreeNode/blob/master/BinaryTree.md
write_binary_trees
, begin_writing_binary_trees
, finish_writing_binary_trees
, ape
, write.tree
Other functions to write trees:
write_binary_trees()
,
write_nwka_nexus()
,
write_nwka_tree()
#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)