scripts/last-dotplot
changeset 846 1f46ab956351
parent 845 16060c00b129
child 847 3ca7aa4b27a8
     1.1 --- a/scripts/last-dotplot	Tue Apr 04 11:51:15 2017 +0900
     1.2 +++ b/scripts/last-dotplot	Tue Apr 04 12:15:35 2017 +0900
     1.3 @@ -163,14 +163,28 @@
     1.4      draw = ImageDraw.Draw(im)
     1.5      return [draw.textsize(i, font=font) for i in my_strings]
     1.6  
     1.7 -def get_seq_info(seqLimits, font, fontsize, image_mode):
     1.8 +def sizeText(size):
     1.9 +    suffixes = "bp", "kb", "Mb", "Gb"
    1.10 +    for i, x in enumerate(suffixes):
    1.11 +        j = 10 ** (i * 3)
    1.12 +        if size < j * 10:
    1.13 +            return "%.2g" % (1.0 * size / j) + x
    1.14 +        if size < j * 1000 or i == len(suffixes) - 1:
    1.15 +            return "%.0f" % (1.0 * size / j) + x
    1.16 +
    1.17 +def seqNameAndSizeText(seqName, seqSize):
    1.18 +    return seqName + ": " + sizeText(seqSize)
    1.19 +
    1.20 +def getSeqInfo(seqLimits, font, fontsize, image_mode, isShowSize):
    1.21      '''Return miscellaneous information about the sequences.'''
    1.22      seqNames = seqLimits.keys()
    1.23      seqNames.sort(key=natural_sort_key)
    1.24      seq_sizes = [seqLimits[i][1] - seqLimits[i][0] for i in seqNames]
    1.25 -    name_sizes = get_text_sizes(seqNames, font, fontsize, image_mode)
    1.26 -    margin = max(zip(*name_sizes)[1])  # maximum text height
    1.27 -    return seqNames, seq_sizes, name_sizes, margin
    1.28 +    if isShowSize: seqLabels = map(seqNameAndSizeText, seqNames, seq_sizes)
    1.29 +    else:          seqLabels = seqNames
    1.30 +    labelSizes = get_text_sizes(seqLabels, font, fontsize, image_mode)
    1.31 +    margin = max(zip(*labelSizes)[1])  # maximum text height
    1.32 +    return seqNames, seq_sizes, seqLabels, labelSizes, margin
    1.33  
    1.34  def div_ceil(x, y):
    1.35      '''Return x / y rounded up.'''
    1.36 @@ -382,10 +396,11 @@
    1.37  
    1.38      if not alignments: raise Exception("there are no alignments")
    1.39  
    1.40 -    seq_info1 = get_seq_info(seqLimits1, font, opts.fontsize, image_mode)
    1.41 -    seq_info2 = get_seq_info(seqLimits2, font, opts.fontsize, image_mode)
    1.42 -    seqNames1, seq_sizes1, name_sizes1, margin1 = seq_info1
    1.43 -    seqNames2, seq_sizes2, name_sizes2, margin2 = seq_info2
    1.44 +    i1 = getSeqInfo(seqLimits1, font, opts.fontsize, image_mode, opts.lengths1)
    1.45 +    seqNames1, seq_sizes1, seqLabels1, labelSizes1, margin1 = i1
    1.46 +
    1.47 +    i2 = getSeqInfo(seqLimits2, font, opts.fontsize, image_mode, opts.lengths2)
    1.48 +    seqNames2, seq_sizes2, seqLabels2, labelSizes2, margin2 = i2
    1.49  
    1.50      warn("choosing bp per pixel...")
    1.51      pix_limit1 = opts.width  - margin1
    1.52 @@ -442,9 +457,9 @@
    1.53              elif store_value == 3: im.putpixel(xy, overlap_color)
    1.54  
    1.55      if opts.fontsize != 0:
    1.56 -        axis1 = get_axis_image(seqNames1, name_sizes1, seq_starts1, seq_pix1,
    1.57 +        axis1 = get_axis_image(seqLabels1, labelSizes1, seq_starts1, seq_pix1,
    1.58                                 font, image_mode, opts)
    1.59 -        axis2 = get_axis_image(seqNames2, name_sizes2, seq_starts2, seq_pix2,
    1.60 +        axis2 = get_axis_image(seqLabels2, labelSizes2, seq_starts2, seq_pix2,
    1.61                                 font, image_mode, opts)
    1.62          axis2 = axis2.transpose(Image.ROTATE_270)  # !!! bug hotspot
    1.63          im.paste(axis1, (0, 0))
    1.64 @@ -490,10 +505,15 @@
    1.65                    help="trim unaligned sequence flanks from the 1st genome")
    1.66      op.add_option("--trim2", action="store_true",
    1.67                    help="trim unaligned sequence flanks from the 2nd genome")
    1.68 +    op.add_option("--lengths1", action="store_true",
    1.69 +                  help="show sequence lengths for the 1st genome")
    1.70 +    op.add_option("--lengths2", action="store_true",
    1.71 +                  help="show sequence lengths for the 2nd genome")
    1.72      op.add_option("--bed1", metavar="FILE",
    1.73                    help="read genome1 annotations from bed file")
    1.74      op.add_option("--bed2", metavar="FILE",
    1.75                    help="read genome2 annotations from bed file")
    1.76 +
    1.77      og = optparse.OptionGroup(op, "Unsequenced gap options")
    1.78      og.add_option("--gap1", metavar="FILE",
    1.79                    help="read genome1 unsequenced gaps from agp or gap file")