Segmenting Chromosome

When computing statistics on each base across a chromosome, it is often not feasible to put the whole chromosome into memory.

Here is a python generator function to create segments on a chromosome and iterate through them.

def make_regions(chromosome_length, how_many_bases_to_look_at):
    start = 0
    end = start + how_many_bases_to_look_at
    while end < chromosome_length:
        yield (start, end)
        start = end
        end = end + how_man_bases_to_look_at
    yield (start, chromosome_length)



Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License. If you liked this post, you can share it with your followers or follow me on Twitter!