bx.intervals.random_intervals module

Classes for generating random sets of intervals over larger regions.

exception bx.intervals.random_intervals.MaxtriesException

Bases: Exception

bx.intervals.random_intervals.overwrite_start_end(s, e, rgn)
bx.intervals.random_intervals.throw_random_bits(lengths, mask, allow_overlap=False)
bx.intervals.random_intervals.throw_random_gap_list(lengths, mask, save_interval_func, allow_overlap=False)

Generates a set of non-overlapping random intervals from a length distribution.

lengths: list containing the length of each interval to be generated.

We expect this to be sorted by decreasing length to minimize the chance of failure (MaxtriesException) and for some performance gains when allow_overlap==True and there are duplicate lengths

mask: a BitSet in which set bits represent regions not to place

intervals. The size of the region is also determined from the mask.

bx.intervals.random_intervals.throw_random_intervals(lengths, regions, save_interval_func=None, allow_overlap=False)

Generates a set of non-overlapping random intervals from a length distribution.

lengths: list containing the length of each interval to be generated.

We expect this to be sorted by decreasing length to minimize the chance of failure (MaxtriesException) and for some performance gains when allow_overlap==True and there are duplicate lengths.

regions: A list of regions in which intervals can be placed. Elements

are tuples or lists of the form (start, end, …), where … indicates any number of items (including zero).

save_interval_func: A function accepting three arguments which will be

passed the (start,stop,region) for each generated interval, where region is an entry in the regions list. If this is None, the generated intervals will be returned as a list of elements copied from the region with start and end modified.

bx.intervals.random_intervals.throw_random_list(lengths, mask, allow_overlap=False)
bx.intervals.random_intervals.throw_random_private(lengths, regions, save_interval_func, allow_overlap=False, three_args=True)

(Internal function; we expect calls only through the interface functions above)

lengths: A list containing the length of each interval to be generated. regions: A list of regions in which intervals can be placed, sorted by

decreasing length. Elements are triples of the form (length, start, extra), This list CAN BE MODIFIED by this function.

save_interval_func: A function accepting three arguments which will be

passed the (start,stop,extra) for each generated interval.