lib5c.util.primers module

Module containing utilities for manipulating 5C primer information.

lib5c.util.primers.aggregate_primermap(primermap, region_order=None)[source]

Aggregates a primermap into a single list.

Parameters
  • primermap (Dict[str, List[Dict[str, Any]]]) – Primermap to aggregate. See lib5c.parsers.primers.get_primermap().

  • region_order (Optional[List[str]]) – Order in which regions should be concatenated. If None, the regions will be concatenated in order of increasing genomic coordinate. See lib5c.util.primers.determine_region_order().

Returns

The dicts represent primers in the same format as the inner dicts of the passed primermap; however, they exist as a single flat list instead of within an outer dict structure. The regions are arranged within this list in contiguous blocks, arranged in the order specified by the region_order kwarg.

Return type

List[Dict[str, Any]]

Notes

This function returns a list of references to the original primermap, under the assumption that primer dicts are rarely modified. To avoid this, pass a copy of the primermap instead of the original primermap.

lib5c.util.primers.determine_region_order(primermap)[source]

Orders regions in a primermap by genomic coordinate.

Parameters

primermap (Dict[str, List[Dict[str, Any]]]) – Primermap containing information about the regions to be ordered. See lib5c.parsers.primers.get_primermap().

Returns

List of ordered region names.

Return type

List[str]

lib5c.util.primers.guess_bin_step(regional_pixelmap)[source]

Guesses the bin step from a regional pixelmap.

Parameters

regional_pixelmap (List[Dict[str, Any]]) – Ordered list of bins for a single region.

Returns

The guessed bin step for this pixelmap.

Return type

int

lib5c.util.primers.natural_sort_key(s)[source]

Function to enable natural sorting of alphanumeric strings.

Parameters

s (str) – String being sorted.

Returns

This list is an alternative represenation of the input string that will sort in natural order.

Return type

List[Union[int, str]]

Notes

Function written by SO user http://stackoverflow.com/users/15055/claudiu and provided in answer http://stackoverflow.com/a/16090640.