| 1 | """ |
|---|
| 2 | Support for chopping a list of alignment blocks to only the portion that |
|---|
| 3 | intersects a particular interval. |
|---|
| 4 | """ |
|---|
| 5 | |
|---|
| 6 | def chop_list( blocks, src, start, end ): |
|---|
| 7 | """ |
|---|
| 8 | For each alignment block in the sequence `blocks`, chop out the portion |
|---|
| 9 | of the block that overlaps the interval [`start`,`end`) in the |
|---|
| 10 | component/species named `src`. |
|---|
| 11 | """ |
|---|
| 12 | new_blocks = [] |
|---|
| 13 | for block in blocks: |
|---|
| 14 | ref = block.get_component_by_src( src ) |
|---|
| 15 | # If the reference component is on the '-' strand we should complement the interval |
|---|
| 16 | if ref.strand == '-': |
|---|
| 17 | slice_start = max( ref.src_size - end, ref.start ) |
|---|
| 18 | slice_end = max( ref.src_size - start, ref.end ) |
|---|
| 19 | else: |
|---|
| 20 | slice_start = max( start, ref.start ) |
|---|
| 21 | slice_end = min( end, ref.end ) |
|---|
| 22 | sliced = block.slice_by_component( ref, slice_start, slice_end ) |
|---|
| 23 | good = True |
|---|
| 24 | for c in sliced.components: |
|---|
| 25 | if c.size < 1: |
|---|
| 26 | good = False |
|---|
| 27 | if good: |
|---|
| 28 | new_blocks.append( sliced ) |
|---|
| 29 | return new_blocks |
|---|