last-dotplot: refactor
authorMartin C. Frith
Fri Jul 31 10:18:25 2020 +0900 (11 days ago)
changeset 1072e43ecf1c3fb6
parent 1071 c5d3cf8c1058
child 1073 8ec299b42e28
last-dotplot: refactor
scripts/last-dotplot
     1.1 --- a/scripts/last-dotplot	Thu Jul 30 22:02:15 2020 +0900
     1.2 +++ b/scripts/last-dotplot	Fri Jul 31 10:18:25 2020 +0900
     1.3 @@ -686,22 +686,22 @@
     1.4                  beg, end = -end, -beg
     1.5              if layer <= 1000:
     1.6                  # include partly-covered pixels
     1.7 -                b = (origin + beg) // bpPerPix
     1.8 -                e = div_ceil(origin + end, bpPerPix)
     1.9 +                pixBeg = (origin + beg) // bpPerPix
    1.10 +                pixEnd = div_ceil(origin + end, bpPerPix)
    1.11              else:
    1.12                  # exclude partly-covered pixels
    1.13 -                b = div_ceil(origin + beg, bpPerPix)
    1.14 -                e = (origin + end) // bpPerPix
    1.15 -                if e <= b: continue
    1.16 +                pixBeg = div_ceil(origin + beg, bpPerPix)
    1.17 +                pixEnd = (origin + end) // bpPerPix
    1.18 +                if pixEnd <= pixBeg: continue
    1.19                  if bedEnd >= rangeEnd:  # include partly-covered end pixels
    1.20                      if isReverseRange:
    1.21 -                        b = (origin + beg) // bpPerPix
    1.22 +                        pixBeg = (origin + beg) // bpPerPix
    1.23                      else:
    1.24 -                        e = div_ceil(origin + end, bpPerPix)
    1.25 +                        pixEnd = div_ceil(origin + end, bpPerPix)
    1.26              if isTop:
    1.27 -                box = b, margin, e, edge
    1.28 +                box = pixBeg, margin, pixEnd, edge
    1.29              else:
    1.30 -                box = margin, b, edge, e
    1.31 +                box = margin, pixBeg, edge, pixEnd
    1.32              yield layer, color, box
    1.33  
    1.34  def drawAnnotations(im, boxes):
    1.35 @@ -889,20 +889,24 @@
    1.36      i2 = dataFromRanges(sortedRanges2, font, textDraw, opts.labels2, textRot2)
    1.37      rangeSizes2, labelData2, lMargin = i2
    1.38  
    1.39 -    maxPixels1 = opts.width  - lMargin
    1.40 -    maxPixels2 = opts.height - tMargin
    1.41 +    bMargin = rMargin = 0  # xxx
    1.42 +
    1.43 +    maxPixels1 = opts.width  - lMargin - rMargin
    1.44 +    maxPixels2 = opts.height - tMargin - bMargin
    1.45      bpPerPix1 = get_bp_per_pix(rangeSizes1, opts.border_pixels, maxPixels1)
    1.46      bpPerPix2 = get_bp_per_pix(rangeSizes2, opts.border_pixels, maxPixels2)
    1.47      bpPerPix = max(bpPerPix1, bpPerPix2)
    1.48      logging.info("bp per pixel = " + str(bpPerPix))
    1.49  
    1.50      p1 = pixelData(rangeSizes1, bpPerPix, opts.border_pixels, lMargin)
    1.51 -    rangePixBegs1, rangePixLens1, width = p1
    1.52 +    rangePixBegs1, rangePixLens1, rMarginBeg = p1
    1.53 +    width = rMarginBeg + rMargin
    1.54      rangeDict1 = dict(rangesAndOriginsPerSeq(sortedRanges1, rangePixBegs1,
    1.55                                               rangePixLens1, bpPerPix))
    1.56  
    1.57      p2 = pixelData(rangeSizes2, bpPerPix, opts.border_pixels, tMargin)
    1.58 -    rangePixBegs2, rangePixLens2, height = p2
    1.59 +    rangePixBegs2, rangePixLens2, bMarginBeg = p2
    1.60 +    height = bMarginBeg + bMargin
    1.61      rangeDict2 = dict(rangesAndOriginsPerSeq(sortedRanges2, rangePixBegs2,
    1.62                                               rangePixLens2, bpPerPix))
    1.63  
    1.64 @@ -919,12 +923,12 @@
    1.65      rangeDict1 = expandedSeqDict(rangeDict1)
    1.66      annots1 = readAnnotations(opts, sortedRanges1,
    1.67                                opts.bed1, opts.rmsk1, opts.genePred1, opts.gap1)
    1.68 -    boxes1 = bedBoxes(annots1, rangeDict1, tMargin, height, True, bpPerPix)
    1.69 +    boxes1 = bedBoxes(annots1, rangeDict1, tMargin, bMarginBeg, 1, bpPerPix)
    1.70  
    1.71      rangeDict2 = expandedSeqDict(rangeDict2)
    1.72      annots2 = readAnnotations(opts, sortedRanges2,
    1.73                                opts.bed2, opts.rmsk2, opts.genePred2, opts.gap2)
    1.74 -    boxes2 = bedBoxes(annots2, rangeDict2, lMargin, width, False, bpPerPix)
    1.75 +    boxes2 = bedBoxes(annots2, rangeDict2, lMargin, rMarginBeg, 0, bpPerPix)
    1.76  
    1.77      boxes = sorted(itertools.chain(boxes1, boxes2))
    1.78  
    1.79 @@ -966,11 +970,11 @@
    1.80          im.paste(axis2, (0, 0))
    1.81  
    1.82      for i in rangePixBegs1[1:]:
    1.83 -        box = i - opts.border_pixels, tMargin, i, height
    1.84 +        box = i - opts.border_pixels, tMargin, i, bMarginBeg
    1.85          im.paste(opts.border_color, box)
    1.86  
    1.87      for i in rangePixBegs2[1:]:
    1.88 -        box = lMargin, i - opts.border_pixels, width, i
    1.89 +        box = lMargin, i - opts.border_pixels, rMarginBeg, i
    1.90          im.paste(opts.border_color, box)
    1.91  
    1.92      im.save(args[1])