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
rulesparameter.rulesnests its ownrules:andmapping:; a top-levelrules:list with a siblingmapping:is not the serialized shape and will not run. - Two regex rules and one
group_count: 2rule 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_regexraises when the expression does not match. The empty nesting key only appears if you setallow_unmatched: true, which no corpus instance does.
See also
- iwc-transformations-survey — Apply Rules Shape B and candidate boundary.
- galaxy-apply-rules-dsl —
add_column_regexandlist_identifiersdetails. - collection-swap-nesting-with-apply-rules — regroup existing
list:listaxes. - collection-build-list-paired-with-apply-rules — paired-end variant.