Last chance! 50% off unlimited learning
Sale ends in
Given a text string will return the positions of each matching pair of opening and closing brackets.
locate_bracket_positions(input_string, bracket_type = "()")
A two-column matrix indicating opening and closing bracket positions within input_string
.
An input string containing matching brackets, such as a Newick string or character state tree.
The type of bracket to use. Must be one of parentheses ()
, curly braces {}
, or square brackets []
.
Graeme T. Lloyd graemetlloyd@gmail.com
This function is designed to deal with Newick strings and character state trees - ways of encoding information using nested parentheses. Although it is intended for internal use it seems sufficiently general to share as part of the package.
The function works by traversing the string from left to right and noting the position of each opening parenthesis and then storing the corresponding position for its' matching closing parenthesis.
It currently only works for a single string, but coud be built into a for loop or apply function if multiple strings are desired.
convert_state_tree_to_adjacency_matrix
# Locate the positions of a set of parentheses in a character state tree:
locate_bracket_positions(
input_string = "(((5)4)3,(2)1)0",
bracket_type = "()"
)
Run the code above in your browser using DataLab