Refactoring.
authorMartin C. Frith
Mon Oct 19 12:34:17 2015 +0900 (2015-10-19)
changeset 64833e285b3e428
parent 647 25c8084d7f6e
child 649 94f7cda3507b
Refactoring.
scripts/last-dotplot
     1.1 --- a/scripts/last-dotplot	Mon Oct 19 12:25:49 2015 +0900
     1.2 +++ b/scripts/last-dotplot	Mon Oct 19 12:34:17 2015 +0900
     1.3 @@ -228,39 +228,10 @@
     1.4          draw.text(position, i[3], font=font, fill=opts.text_color)
     1.5      return im
     1.6  
     1.7 -if __name__ == "__main__":
     1.8 -    my_name = os.path.basename(sys.argv[0])
     1.9 -    usage = """
    1.10 -  %prog --help
    1.11 -  %prog [options] last-tabular-output dotplot.png
    1.12 -  %prog [options] last-tabular-output dotplot.gif
    1.13 -  etc."""
    1.14 -    op = optparse.OptionParser(usage=usage)
    1.15 -    # Replace "width" & "height" with a single "length" option?
    1.16 -    op.add_option("-x", "--width", type="int", default=1000,
    1.17 -                  help="maximum width in pixels (default: %default)")
    1.18 -    op.add_option("-y", "--height", type="int", default=1000,
    1.19 -                  help="maximum height in pixels (default: %default)")
    1.20 -    op.add_option("-f", "--fontfile",
    1.21 -                  help="TrueType or OpenType font file")
    1.22 -    op.add_option("-s", "--fontsize", type="int", default=11,
    1.23 -                  help="TrueType or OpenType font size (default: %default)")
    1.24 -    op.add_option("-c", "--forwardcolor", default="red",
    1.25 -                  help="Color for forward alignments (default: %default)")
    1.26 -    op.add_option("-r", "--reversecolor", default="blue",
    1.27 -                  help="Color for reverse alignments (default: %default)")
    1.28 -    (opts, args) = op.parse_args()
    1.29 -    if len(args) != 2: op.error("2 arguments needed")
    1.30 -
    1.31 +def lastDotplot(opts, args):
    1.32      if opts.fontfile:  font = ImageFont.truetype(opts.fontfile, opts.fontsize)
    1.33      else:              font = ImageFont.load_default()
    1.34  
    1.35 -    opts.text_color = "black"
    1.36 -    opts.background_color = "white"
    1.37 -    opts.pix_tween_seqs = 2  # number of border pixels between sequences
    1.38 -    opts.border_shade = 239, 239, 239  # the shade of grey for border pixels
    1.39 -    opts.label_space = 5     # minimum number of pixels between axis labels
    1.40 -
    1.41      image_mode = 'RGB'
    1.42      forward_color = ImageColor.getcolor(opts.forwardcolor, image_mode)
    1.43      reverse_color = ImageColor.getcolor(opts.reversecolor, image_mode)
    1.44 @@ -329,3 +300,35 @@
    1.45          im.paste(opts.border_shade, box)
    1.46  
    1.47      im.save(args[1])
    1.48 +
    1.49 +if __name__ == "__main__":
    1.50 +    my_name = os.path.basename(sys.argv[0])
    1.51 +    usage = """
    1.52 +  %prog --help
    1.53 +  %prog [options] last-tabular-output dotplot.png
    1.54 +  %prog [options] last-tabular-output dotplot.gif
    1.55 +  etc."""
    1.56 +    op = optparse.OptionParser(usage=usage)
    1.57 +    # Replace "width" & "height" with a single "length" option?
    1.58 +    op.add_option("-x", "--width", type="int", default=1000,
    1.59 +                  help="maximum width in pixels (default: %default)")
    1.60 +    op.add_option("-y", "--height", type="int", default=1000,
    1.61 +                  help="maximum height in pixels (default: %default)")
    1.62 +    op.add_option("-f", "--fontfile",
    1.63 +                  help="TrueType or OpenType font file")
    1.64 +    op.add_option("-s", "--fontsize", type="int", default=11,
    1.65 +                  help="TrueType or OpenType font size (default: %default)")
    1.66 +    op.add_option("-c", "--forwardcolor", default="red",
    1.67 +                  help="Color for forward alignments (default: %default)")
    1.68 +    op.add_option("-r", "--reversecolor", default="blue",
    1.69 +                  help="Color for reverse alignments (default: %default)")
    1.70 +    (opts, args) = op.parse_args()
    1.71 +    if len(args) != 2: op.error("2 arguments needed")
    1.72 +
    1.73 +    opts.text_color = "black"
    1.74 +    opts.background_color = "white"
    1.75 +    opts.pix_tween_seqs = 2  # number of border pixels between sequences
    1.76 +    opts.border_shade = 239, 239, 239  # the shade of grey for border pixels
    1.77 +    opts.label_space = 5     # minimum number of pixels between axis labels
    1.78 +
    1.79 +    lastDotplot(opts, args)