Sort the children of each node without changing the topology.
Input:
- A Newick tree file.
Notes:
- Visits every internal node and sorts its children according to the selected criterion; different modes use post-order or level-order traversals internally.
- When no sort criterion is specified, defaults to forward alphanumeric order (equivalent to
--alphanumeric). - Multiple sort options can be given in one command; they are applied in this order:
--name-list--alphanumeric/--alphanumeric-rev--num-descendants/--num-descendants-rev--deladderizeEach step fully reorders the children of every internal node, so later steps override earlier ones.
--olocannot be combined with other sort options because it computes a global optimal order from a distance matrix.- To combine criteria as tie-breakers instead of sequential overrides, pipe multiple
nwk ordercalls:necom nwk order tree.nwk --num-descendants | necom nwk order stdin --alphanumeric - Sort orders:
--name-list: by a list of names in the file, one per line.--alphanumeric(--an) /--alphanumeric-rev(--anr): by alphanumeric order of labels, or in reverse order.--num-descendants(--nd) /--num-descendants-rev(--ndr): by number of descendants (ladderize), or in reverse order.--deladderize(alias--dl): alternate sort direction at each level.--olo <MATRIX>: optimal leaf ordering using a distance matrix.
--olo-formatcontrols the format of the--olomatrix:phylip(default) orpair.--oloexpects the original data-space distance matrix, not the tree’s own path distances. Optimizing against tree-derived distances would mostly reproduce the current topology, defeating the purpose of leaf reordering.- Entries in
--name-listthat are not found among the leaf names cause the command to fail with an error listing the missing names. - The
--olomatrix must cover every leaf in the tree; missing leaves cause an error. Non-finite distances are also rejected.
Examples:
-
Sort by number of descendants (ladderize)
necom nwk order tree.nwk --num-descendants -
Sort by alphanumeric order
necom nwk order tree.nwk --alphanumeric -
Sort by a list of names
necom nwk order tree.nwk --name-list names.txt -
Sort by alphanumeric order, then by number of descendants (reverse)
necom nwk order tree.nwk --alphanumeric --num-descendants-rev -
De-ladderize
necom nwk order tree.nwk --deladderize -
Optimal leaf ordering with a PHYLIP distance matrix
necom nwk order tree.nwk --olo distances.phy -
Optimal leaf ordering with a pairwise TSV matrix
necom nwk order tree.nwk --olo pairs.tsv --olo-format pair