Refactoring.
authorMartin C. Frith
Mon Oct 19 11:43:47 2015 +0900 (2015-10-19)
changeset 6459daf814fa381
parent 644 08cf5e7f1629
child 646 504ecca38a3e
Refactoring.
scripts/last-dotplot
     1.1 --- a/scripts/last-dotplot	Mon Oct 19 11:30:34 2015 +0900
     1.2 +++ b/scripts/last-dotplot	Mon Oct 19 11:43:47 2015 +0900
     1.3 @@ -122,7 +122,7 @@
     1.4      '''Return the total pixels needed for sequences of the given sizes.'''
     1.5      return sum([div_ceil(i, bp_per_pix) for i in seq_sizes])
     1.6  
     1.7 -def get_bp_per_pix(seq_sizes, pix_limit):
     1.8 +def get_bp_per_pix(seq_sizes, pix_tween_seqs, pix_limit):
     1.9      '''Get the minimum bp-per-pixel that fits in the size limit.'''
    1.10      seq_num = len(seq_sizes)
    1.11      seq_pix_limit = pix_limit - pix_tween_seqs * (seq_num - 1)
    1.12 @@ -143,7 +143,7 @@
    1.13          pix_tot += i
    1.14      return seq_starts
    1.15  
    1.16 -def get_pix_info(seq_sizes, margin):
    1.17 +def get_pix_info(seq_sizes, bp_per_pix, pix_tween_seqs, margin):
    1.18      '''Return pixel information about the sequences.'''
    1.19      seq_pix = [div_ceil(i, bp_per_pix) for i in seq_sizes]
    1.20      seq_starts = get_seq_starts(seq_pix, pix_tween_seqs, margin)
    1.21 @@ -200,7 +200,7 @@
    1.22      sort_key    = text_width - range_size
    1.23      return sort_key, label_start, label_end, text
    1.24  
    1.25 -def get_nonoverlapping_labels(labels):
    1.26 +def get_nonoverlapping_labels(labels, label_space):
    1.27      '''Get a subset of non-overlapping axis labels, greedily.'''
    1.28      nonoverlapping_labels = []
    1.29      for i in labels:
    1.30 @@ -218,7 +218,7 @@
    1.31                zip(seq_names, name_sizes, seq_starts, seq_pix)]
    1.32      labels = [i for i in labels if i[1] >= min_pos and i[2] <= max_pos]
    1.33      labels.sort()
    1.34 -    labels = get_nonoverlapping_labels(labels)
    1.35 +    labels = get_nonoverlapping_labels(labels, label_space)
    1.36      image_size = max_pos, height
    1.37      im = Image.new(image_mode, image_size, border_shade)
    1.38      draw = ImageDraw.Draw(im)
    1.39 @@ -279,13 +279,17 @@
    1.40      seq_names2, seq_sizes2, name_sizes2, margin2 = get_seq_info(seq_size_dic2)
    1.41  
    1.42      warn("choosing bp per pixel...")
    1.43 -    bp_per_pix1 = get_bp_per_pix(seq_sizes1, opts.width  - margin1)
    1.44 -    bp_per_pix2 = get_bp_per_pix(seq_sizes2, opts.height - margin2)
    1.45 +    pix_limit1 = opts.width  - margin1
    1.46 +    pix_limit2 = opts.height - margin2
    1.47 +    bp_per_pix1 = get_bp_per_pix(seq_sizes1, pix_tween_seqs, pix_limit1)
    1.48 +    bp_per_pix2 = get_bp_per_pix(seq_sizes2, pix_tween_seqs, pix_limit2)
    1.49      bp_per_pix = max(bp_per_pix1, bp_per_pix2)
    1.50      warn("bp per pixel = " + str(bp_per_pix))
    1.51  
    1.52 -    seq_pix1, seq_starts1, width  = get_pix_info(seq_sizes1, margin1)
    1.53 -    seq_pix2, seq_starts2, height = get_pix_info(seq_sizes2, margin2)
    1.54 +    seq_pix1, seq_starts1, width  = get_pix_info(seq_sizes1, bp_per_pix,
    1.55 +                                                 pix_tween_seqs, margin1)
    1.56 +    seq_pix2, seq_starts2, height = get_pix_info(seq_sizes2, bp_per_pix,
    1.57 +                                                 pix_tween_seqs, margin2)
    1.58      seq_start_dic1 = dict(zip(seq_names1, seq_starts1))
    1.59      seq_start_dic2 = dict(zip(seq_names2, seq_starts2))
    1.60