tracts.driver_utils._reorder_ancestry_proportions#

_reorder_ancestry_proportions(old_ancestor_labels, new_ancestor_labels, autosome_proportions, allosome_proportions)#

Permutes observed ancestry proportions computed under old_ancestor_labels so that they line up with new_ancestor_labels instead. Used when the implicit population changes during boundary re-optimization: this reorders demographic_model.population_indices (the implicit population is always placed last; see ParametrizedDemography(SexBiased).load_from_YAML), so any previously-computed proportions must be realigned to match wherever they are reused afterwards, whether for display or to fix parameters by ancestry proportion.

Parameters:
  • old_ancestor_labels (list[str]) – The population order that autosome_proportions/allosome_proportions were computed in (i.e. the ancestor_labels originally passed to get_ancestry_proportions).

  • new_ancestor_labels (list[str]) – The population order to realign to.

  • autosome_proportions (ndarray) – Observed autosomal ancestry proportions, in old_ancestor_labels order.

  • allosome_proportions (ndarray | list) – Observed allosomal ancestry proportions, in old_ancestor_labels order, or [] if allosomes are not modelled.

Returns:

(autosome_proportions, allosome_proportions) reordered to match new_ancestor_labels. Returned unchanged if the two label orders are already identical.

Return type:

tuple[np.ndarray, np.ndarray | list]