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

View source: R/locate_bracket_positions.r

locate_bracket_positionsR Documentation

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 = "()")

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 [].

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.

Value

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

Author(s)

Graeme T. Lloyd graemetlloyd@gmail.com

See Also

convert_state_tree_to_adjacency_matrix

Examples


# 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 = "()"
)


Claddis documentation built on Sept. 11, 2024, 9:18 p.m.