ecotyper.rcompat.collate

String collation as used by R’s sort/order/factor/merge.

In a non-C locale R (built with ICU, as the conda-forge and CRAN macOS builds are) compares strings with an ICU collator for the current locale; in the C locale it compares bytes. EcoTyper’s output ordering (e.g. rows of heatmap_top_ann.txt after merge) depends on this, so every ordering of character keys in this package goes through sort_key().

The collation is a process-wide setting: set_collation("en_US") (default, matching LANG=en_US.UTF-8) or set_collation("C").

PyICU is optional. Without it, strings made of printable ASCII (all gene, cell type, state and sample names in practice) are ordered with a built-in copy of ICU’s en_US collation weights for those 95 characters: every ASCII character maps to one collation element (no contractions), so comparing primary, then secondary, then tertiary weights reproduces ICU exactly (checked against PyICU/ICU 78 on 200,000 random string pairs, see tests/test_collate.py). Other strings need PyICU (pip install "ecotyper-py[icu]").

Functions

get_collation()

set_collation(locale)

Select "C" (byte order) or an ICU locale name such as "en_US".

sort_key(s)

sorted_strings(values)

ecotyper.rcompat.collate.set_collation(locale)[source]

Select "C" (byte order) or an ICU locale name such as "en_US".

Parameters:

locale (str)

Return type:

None

ecotyper.rcompat.collate.get_collation()[source]
Return type:

str

ecotyper.rcompat.collate.sort_key(s)[source]
Parameters:

s (str)

ecotyper.rcompat.collate.sorted_strings(values)[source]
Return type:

list[str]