scripts/last-dotplot
changeset 647 25c8084d7f6e
parent 646 504ecca38a3e
child 648 33e285b3e428
     1.1 --- a/scripts/last-dotplot	Mon Oct 19 11:48:25 2015 +0900
     1.2 +++ b/scripts/last-dotplot	Mon Oct 19 12:25:49 2015 +0900
     1.3 @@ -96,20 +96,20 @@
     1.4      parts[1::2] = map(int, parts[1::2])
     1.5      return parts
     1.6  
     1.7 -def get_text_sizes(my_strings):
     1.8 +def get_text_sizes(my_strings, font, fontsize, image_mode):
     1.9      '''Get widths & heights, in pixels, of some strings.'''
    1.10 -    if opts.fontsize == 0: return [(0, 0) for i in my_strings]
    1.11 +    if fontsize == 0: return [(0, 0) for i in my_strings]
    1.12      image_size = 1, 1
    1.13      im = Image.new(image_mode, image_size)
    1.14      draw = ImageDraw.Draw(im)
    1.15      return [draw.textsize(i, font=font) for i in my_strings]
    1.16  
    1.17 -def get_seq_info(seq_size_dic):
    1.18 +def get_seq_info(seq_size_dic, font, fontsize, image_mode):
    1.19      '''Return miscellaneous information about the sequences.'''
    1.20      seq_names = seq_size_dic.keys()
    1.21      seq_names.sort(key=natural_sort_key)
    1.22      seq_sizes = [seq_size_dic[i] for i in seq_names]
    1.23 -    name_sizes = get_text_sizes(seq_names)
    1.24 +    name_sizes = get_text_sizes(seq_names, font, fontsize, image_mode)
    1.25      margin = max(zip(*name_sizes)[1])  # maximum text height
    1.26      return seq_names, seq_sizes, name_sizes, margin
    1.27  
    1.28 @@ -209,7 +209,8 @@
    1.29              nonoverlapping_labels.append(i)
    1.30      return nonoverlapping_labels
    1.31  
    1.32 -def get_axis_image(seq_names, name_sizes, seq_starts, seq_pix):
    1.33 +def get_axis_image(seq_names, name_sizes, seq_starts, seq_pix,
    1.34 +                   font, image_mode, opts):
    1.35      '''Make an image of axis labels.'''
    1.36      min_pos = seq_starts[0]
    1.37      max_pos = seq_starts[-1] + seq_pix[-1]
    1.38 @@ -274,8 +275,10 @@
    1.39      if not alignments:
    1.40          sys.exit(my_name + ": there are no alignments")
    1.41  
    1.42 -    seq_names1, seq_sizes1, name_sizes1, margin1 = get_seq_info(seq_size_dic1)
    1.43 -    seq_names2, seq_sizes2, name_sizes2, margin2 = get_seq_info(seq_size_dic2)
    1.44 +    seq_info1 = get_seq_info(seq_size_dic1, font, opts.fontsize, image_mode)
    1.45 +    seq_info2 = get_seq_info(seq_size_dic2, font, opts.fontsize, image_mode)
    1.46 +    seq_names1, seq_sizes1, name_sizes1, margin1 = seq_info1
    1.47 +    seq_names2, seq_sizes2, name_sizes2, margin2 = seq_info2
    1.48  
    1.49      warn("choosing bp per pixel...")
    1.50      pix_limit1 = opts.width  - margin1
    1.51 @@ -309,8 +312,10 @@
    1.52              elif store_value == 3: im.putpixel(xy, overlap_color)
    1.53  
    1.54      if opts.fontsize != 0:
    1.55 -        axis1 = get_axis_image(seq_names1, name_sizes1, seq_starts1, seq_pix1)
    1.56 -        axis2 = get_axis_image(seq_names2, name_sizes2, seq_starts2, seq_pix2)
    1.57 +        axis1 = get_axis_image(seq_names1, name_sizes1, seq_starts1, seq_pix1,
    1.58 +                               font, image_mode, opts)
    1.59 +        axis2 = get_axis_image(seq_names2, name_sizes2, seq_starts2, seq_pix2,
    1.60 +                               font, image_mode, opts)
    1.61          axis2 = axis2.rotate(270)
    1.62          im.paste(axis1, (0, 0))
    1.63          im.paste(axis2, (0, 0))