1.1 --- a/scripts/last-dotplot Fri Jul 31 15:04:20 2020 +0900
1.2 +++ b/scripts/last-dotplot Fri Jul 31 15:24:44 2020 +0900
1.3 @@ -784,6 +784,16 @@
1.4 draw.text(position, text, font=font, fill=fill)
1.5 return im
1.6
1.7 +def annoTextImage(opts, image_mode, font, margin, length, boxes, isLeftAlign):
1.8 + image_size = margin, length
1.9 + im = Image.new(image_mode, image_size, opts.margin_color)
1.10 + draw = ImageDraw.Draw(im)
1.11 + for layer, color, isTop, beg, end, name, nameBeg, nameLen in boxes:
1.12 + xPosition = 0 if isLeftAlign else margin - nameLen
1.13 + position = xPosition, nameBeg
1.14 + draw.text(position, name, font=font, fill="black")
1.15 + return im
1.16 +
1.17 def rangesPerSeq(sortedRanges):
1.18 for seqName, group in itertools.groupby(sortedRanges, itemgetter(0)):
1.19 yield seqName, sorted(group)
1.20 @@ -850,7 +860,8 @@
1.21 readGaps(opts, gapFile, rangeDict)))
1.22 names = set(i[5] for i in annots)
1.23 textSizes = dict(sizesPerText(names, font, textDraw))
1.24 - return annots, textSizes
1.25 + margin = max(i[0] for i in textSizes.values()) if textSizes else 0
1.26 + return annots, textSizes, margin
1.27
1.28 def lastDotplot(opts, args):
1.29 logLevel = logging.INFO if opts.verbose else logging.WARNING
1.30 @@ -922,13 +933,11 @@
1.31
1.32 a1 = readAnnotations(opts, font, textDraw, sortedRanges1,
1.33 opts.bed1, opts.rmsk1, opts.genePred1, opts.gap1)
1.34 - annots1, annoTextSizes1 = a1
1.35 + annots1, annoTextSizes1, bMargin = a1
1.36
1.37 a2 = readAnnotations(opts, font, textDraw, sortedRanges2,
1.38 opts.bed2, opts.rmsk2, opts.genePred2, opts.gap2)
1.39 - annots2, annoTextSizes2 = a2
1.40 -
1.41 - bMargin = rMargin = 0 # xxx
1.42 + annots2, annoTextSizes2, rMargin = a2
1.43
1.44 maxPixels1 = opts.width - lMargin - rMargin
1.45 maxPixels2 = opts.height - tMargin - bMargin
1.46 @@ -1003,6 +1012,14 @@
1.47 im.paste(axis1, (0, 0))
1.48 im.paste(axis2, (0, 0))
1.49
1.50 + annoImage1 = annoTextImage(opts, image_mode, font, bMargin, width,
1.51 + boxes1, False)
1.52 + annoImage1 = annoImage1.transpose(Image.ROTATE_90)
1.53 + annoImage2 = annoTextImage(opts, image_mode, font, rMargin, height,
1.54 + boxes2, True)
1.55 + im.paste(annoImage1, (0, bMarginBeg))
1.56 + im.paste(annoImage2, (rMarginBeg, 0))
1.57 +
1.58 for i in rangePixBegs1[1:]:
1.59 box = i - opts.border_pixels, tMargin, i, bMarginBeg
1.60 im.paste(opts.border_color, box)