Home Pattern

Collection: split identifier via rules

Use Apply Rules regex columns to split one collection identifier into nested list identifiers.

Revised
2026-09-15
Rev
3

Pattern health

ok
  • IWC exemplar anchors

    1 abstract workflow anchor declared.

  • Foundry verification fixture

    1 verification path declared.

  • Pattern map coverage

    1 pattern map link here.

  • Metadata contract

    Pattern frontmatter matches the site contract.

Collection: split identifier via rules

Tool

Use __APPLY_RULES__ to turn a flat list into a nested list:list by splitting each element identifier into two parts.

When to reach for it

Use this when identifiers encode two nesting axes in one string, such as sampleA_rep1, and downstream tools need sampleA -> rep1 nesting.

Do not use this for swapping two existing nesting levels; use collection-swap-nesting-with-apply-rules. Do not use this to make forward/reverse pairs; use collection-build-list-paired-with-apply-rules when one parsed axis is a paired-end role.

This page is about deriving list nesting from one identifier. Use regex-relabel-via-tabular when the collection shape is already right and only labels need cleanup.

Parameters

rules is one parameter holding two lists: the rules: that build columns and the mapping: that says which columns become identifiers. Each mapping entry is an object with columns, not a bare array.

The corpus shape uses two parallel add_column_regex rules, each with one capture result:

tool_id: __APPLY_RULES__
tool_state:
  input: { __class__: ConnectedValue }
  rules:
    rules:
      - type: add_column_metadata
        value: identifier0
      - type: add_column_regex
        target_column: 0
        expression: "^(.*)_([^_]*)$"
        replacement: "\\1"
      - type: add_column_regex
        target_column: 0
        expression: "^(.*)_([^_]*)$"
        replacement: "\\2"
    mapping:
      - type: list_identifiers
        columns: [1, 2]

Column 0 is the original identifier; the two regex rules append columns 1 and 2, which the mapping turns into the outer and inner list identifiers.

Pitfalls

  • Flattening the rules parameter. rules nests its own rules: and mapping:; a top-level rules: list with a sibling mapping: is not the serialized shape and will not run.
  • Two regex rules and one group_count: 2 rule are equivalent. Both append the same two columns, and the verified workflow asserts identical output for each. Prefer two rules for corpus parity, not for correctness.
  • Target the original identifier column both times.
  • ^(.*)_([^_]*)$ splits on the last underscore; use a stricter regex if identifiers can contain multiple separators.
  • Unmatched identifiers fail the job, they do not create empty keys. apply_regex raises when the expression does not match. The empty nesting key only appears if you set allow_unmatched: true, which no corpus instance does.

See also

IWC exemplars 1 anchor

IWC Exemplars

epigenetics/average-bigwig-between-replicates/average-bigwig-between-replicates high

Splits flat bigWig identifiers into sample-prefix and replicate-suffix nesting with two regex-derived columns.

Incoming References (7)