Home Pattern

Collection: swap nesting with Apply Rules

Use Apply Rules to regroup a list:list collection by swapping outer and inner identifier columns.

draft pattern
Revised
2026-05-03
Rev
2

Pattern health

warn
  • IWC exemplar anchors

    1 abstract workflow anchor declared.

  • Foundry verification fixture

    No structural verification fixture yet.

  • Pattern map coverage

    1 pattern map link here.

  • Metadata contract

    Pattern frontmatter matches the site contract.

Collection: swap nesting with Apply Rules

Tool

Use __APPLY_RULES__ to turn a list:list keyed as sample -> segment into a list:list keyed as segment -> sample.

When to reach for it

Use this when the upstream collection has the right leaf datasets but the wrong nesting axis for downstream map-over.

Do not use this for simple flattening; use collection-flatten-after-fanout when one axis should disappear. Do not use this to parse one identifier into multiple axes; use collection-split-identifier-via-rules.

This page is about pure axis swap. Use relabel-via-rules-and-find-replace when noisy identifiers must be cleaned during the reshape.

Parameters

The rule shape is intentionally small:

  1. Add the outer identifier as a column.
  2. Add the inner identifier as a column.
  3. Map list identifiers in reversed order.

Conceptual Apply Rules shape:

tool_id: __APPLY_RULES__
tool_state:
  rules:
    - type: add_column_metadata
      value: identifier0
    - type: add_column_metadata
      value: identifier1
  mapping:
    list_identifiers: [1, 0]

Treat this as the logical shape, not a complete serialized workflow API blob.

Pitfalls

  • Reverse the mapping, not the rules. The corpus shape adds identifier0, then identifier1, then maps [1, 0].
  • Check that the input is actually list:list; identifier1 exists only when there is an inner list level.
  • Keep pure regrouping separate from relabeling unless noisy identifiers force the heavier recipe.
  • Downstream map-over behavior changes after the swap; tools now iterate by the former inner axis.

Footnote: the same workflow uses __DUPLICATE_FILE_TO_COLLECTION__ before one Apply Rules step as a broadcast setup. That broadcast is barely attested and should not be treated as the main pattern.

See also

IWC exemplars1 anchor

IWC Exemplars

virology/influenza-isolates-consensus-and-subtyping/influenza-consensus-and-subtypinghigh

Shows repeated pure regrouping of list:list collections by swapping outer and inner identifier columns.

  • Regroup influenza BAM collections between sample and segment axes

Incoming References (9)