extract_sequence_subsequences: Extract bounded non-contiguous sequence subsequences

View source: R/sequence-subsequences.R

extract_sequence_subsequencesR Documentation

Extract bounded non-contiguous sequence subsequences

Description

Enumerates ordered non-contiguous subsequences under explicit length, gap, span, and safety limits. The implementation is transparent and intended for modest sequence collections; specialist mining packages remain preferable for very large search spaces.

Usage

extract_sequence_subsequences(
  data,
  sequence_id_col = "sequence_id",
  order_col = "sequence_order",
  state_col = "state",
  metadata_cols = NULL,
  min_length = 2L,
  max_length = 5L,
  max_gap = Inf,
  max_span = Inf,
  repeated_state_policy = c("preserve", "collapse"),
  separator = " > ",
  max_combinations_per_sequence = 100000L
)

Arguments

data

Long-format sequence data or a prepared result.

sequence_id_col, order_col, state_col

Core sequence columns.

metadata_cols

Optional sequence-constant metadata retained as attributes.

min_length, max_length

Minimum and maximum subsequence lengths.

max_gap

Maximum number of skipped positions between adjacent selected states. Use Inf for no restriction.

max_span

Maximum difference between the first and last selected sequence positions. Use Inf for no restriction.

repeated_state_policy

Preserve or collapse consecutive repeated states before mining.

separator

Separator used in stable motif labels.

max_combinations_per_sequence

Safety limit for the number of index combinations considered for any one sequence.

Value

A data frame of class gp3_sequence_subsequences, with one row per qualifying occurrence.

Examples

sequences <- data.frame(
  sequence_id = rep(c("s1", "s2"), each = 5L),
  sequence_order = rep(1:5, times = 2L),
  state = c("A", "B", "C", "D", "E", "A", "C", "B", "D", "E")
)
extract_sequence_subsequences(sequences, min_length = 2L, max_length = 3L,
                              max_gap = 2L)

gp3sequences documentation built on Aug. 23, 2026, 5:10 p.m.