Learn R Programming

Claddis (version 0.7.0)

locate_bracket_positions: Locates matching positions for sets of brackets in a text string

Description

Given a text string will return the positions of each matching pair of opening and closing brackets.

Usage

locate_bracket_positions(input_string, bracket_type = "()")

Value

A two-column matrix indicating opening and closing bracket positions within input_string.

Arguments

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 (), curly braces {}, or square brackets [].

Author

Graeme T. Lloyd graemetlloyd@gmail.com

Details

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.

See Also

convert_state_tree_to_adjacency_matrix

Examples

Run this code

# 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