Skip to content

Commit

Permalink
Fix regression due to natsorted (thanks @cutykaka, #588) (#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanghaibao authored Aug 30, 2023
1 parent a604135 commit 695bd2e
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions jcvi/graphics/chromosome.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,10 @@ def draw_chromosomes(
ratio = r / max_chr_len # canvas / base

# first the chromosomes
chr_locations = {}
for a, (chr, clen) in enumerate(natsorted(chr_lens.items())):
xx = xstart + a * xinterval + 0.5 * xwidth
chr_locations[chr] = xx
root.text(xx, ystart + 0.01, str(get_number(chr)), ha="center")
if centromeres:
yy = ystart - centromeres[chr] * ratio
Expand All @@ -598,24 +600,21 @@ def draw_chromosomes(
else:
Chromosome(root, xx, ystart, ystart - clen * ratio, width=xwidth)

chr_idxs = dict((a, i) for i, a in enumerate(sorted(chr_lens.keys())))

alpha = 1
# color the regions
for chr in sorted(chr_lens.keys()):
segment_size, excess = 0, 0
excess = 0
bac_list = []
prev_end, prev_klass = 0, None
xx = chr_locations[chr] - 0.5 * xwidth
for b in bed.sub_bed(chr):
idx = chr_idxs[chr]
klass = b.accn
if klass == "centromere":
continue
start = b.start
end = b.end
if start < prev_end + mergedist and klass == prev_klass:
start = prev_end
xx = xstart + idx * xinterval
yystart = ystart - end * ratio
yyend = ystart - start * ratio
root.add_patch(
Expand Down

0 comments on commit 695bd2e

Please sign in to comment.