View source: R/locate_bracket_positions.r
locate_bracket_positions | R Documentation |
Given a text string will return the positions of each matching pair of opening and closing brackets.
locate_bracket_positions(input_string, bracket_type = "()")
input_string |
An input string containing matching brackets, such as a Newick string or character state tree. |
bracket_type |
The type of bracket to use. Must be one of parentheses |
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.
A two-column matrix indicating opening and closing bracket positions within input_string
.
Graeme T. Lloyd graemetlloyd@gmail.com
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 = "()"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.