Regions module

Helper functions for working with genomic regions.

genomic_regions.helpers.apply_sliding_func(a, window, func=<numpy.ma.core._frommethod object>)

Apply function on a sliding window over an array, ignoring Numpy NaN values.

Parameters
  • a – Numpy array on which function is applied

  • window – The sliding window is i - window:i + window + 1 so total window is twice this parameter.

  • func – Function to apply

genomic_regions.helpers.human_format(num, precision=0)

Format a number as a string, suffixing letter for 1000 (K), 100000 (M), …

Parameters
  • num – any number larger than zero

  • precision – number of positions after decimal point

Returns

string representing the number

genomic_regions.helpers.intervals_weighted_mean(intervals)

Weighted mean for merging multiple interval scores into one.

Takes into account the size of each interval as score weight.

Parameters

intervals – list of tuple (start, end, score)

Returns

float score

genomic_regions.helpers.natural_sort(l)

Sort list of chromosome names “naturally”

Parameters

llist of strings

Returns

naturally sorted list of strings

genomic_regions.helpers.str_to_int(num_string, decimal_separator='.', thousand_separator=', ')

Convert a string denoting a genomic location to int (base pairs).

Parameters
  • num_string – input str

  • decimal_separator – Decimal separator used for float conversion

  • thousand_separator – Thousand separator (to be ignored)

Returns

int (base pairs)