last-dotplot: refactor
authorMartin C. Frith
Thu May 18 14:06:41 2017 +0900 (2017-05-18)
changeset 8591ecdbf2ddb78
parent 858 93d47bb8527f
child 860 6e8ff424ce2b
last-dotplot: refactor
scripts/last-dotplot
     1.1 --- a/scripts/last-dotplot	Thu May 18 14:03:43 2017 +0900
     1.2 +++ b/scripts/last-dotplot	Thu May 18 14:06:41 2017 +0900
     1.3 @@ -290,12 +290,8 @@
     1.4          if not w: continue
     1.5          seqName = w[0]
     1.6          if seqName not in seqLimits: continue
     1.7 -        cropBeg, cropEnd = seqLimits[seqName]
     1.8          beg = int(w[1])
     1.9          end = int(w[2])
    1.10 -        b = max(beg, cropBeg)
    1.11 -        e = min(end, cropEnd)
    1.12 -        if b >= e: continue
    1.13          layer = 900
    1.14          color = "#ffe4ff"
    1.15          if len(w) > 4:
    1.16 @@ -308,7 +304,7 @@
    1.17                      color = "#fff4f4"
    1.18                  elif w[5] == "-":
    1.19                      color = "#f4f4ff"
    1.20 -        yield layer, color, seqName, b, e
    1.21 +        yield layer, color, seqName, beg, end
    1.22  
    1.23  def isExtraFirstGapField(fields):
    1.24      return fields[4].isdigit()
    1.25 @@ -323,19 +319,19 @@
    1.26          if w[4] not in "NU": continue
    1.27          seqName = w[0]
    1.28          if seqName not in seqLimits: continue
    1.29 -        cropBeg, cropEnd = seqLimits[seqName]
    1.30          end = int(w[2])
    1.31          beg = end - int(w[5])  # zero-based coordinate
    1.32 -        b = max(beg, cropBeg)
    1.33 -        e = min(end, cropEnd)
    1.34 -        if b >= e: continue
    1.35          if w[7] == "yes":
    1.36 -            yield 3000, opts.bridged_color, seqName, b, e
    1.37 +            yield 3000, opts.bridged_color, seqName, beg, end
    1.38          else:
    1.39 -            yield 2000, opts.unbridged_color, seqName, b, e
    1.40 +            yield 2000, opts.unbridged_color, seqName, beg, end
    1.41  
    1.42 -def bedBoxes(beds, origins, margin, edge, isTop, bpPerPix):
    1.43 +def bedBoxes(beds, seqLimits, origins, margin, edge, isTop, bpPerPix):
    1.44      for layer, color, seqName, beg, end in beds:
    1.45 +        cropBeg, cropEnd = seqLimits[seqName]
    1.46 +        beg = max(beg, cropBeg)
    1.47 +        end = min(end, cropEnd)
    1.48 +        if beg >= end: continue
    1.49          ori = origins[seqName]
    1.50          if layer <= 1000:
    1.51              # include partly-covered pixels
    1.52 @@ -453,11 +449,11 @@
    1.53  
    1.54      beds1 = itertools.chain(readBed(opts.bed1, seqLimits1),
    1.55                              readGaps(opts, opts.gap1, seqLimits1))
    1.56 -    b1 = bedBoxes(beds1, origins1, margin2, height, True, bpPerPix)
    1.57 +    b1 = bedBoxes(beds1, seqLimits1, origins1, margin2, height, True, bpPerPix)
    1.58  
    1.59      beds2 = itertools.chain(readBed(opts.bed2, seqLimits2),
    1.60                              readGaps(opts, opts.gap2, seqLimits2))
    1.61 -    b2 = bedBoxes(beds2, origins2, margin1, width, False, bpPerPix)
    1.62 +    b2 = bedBoxes(beds2, seqLimits2, origins2, margin1, width, False, bpPerPix)
    1.63  
    1.64      boxes = sorted(itertools.chain(b1, b2))
    1.65      drawAnnotations(im, boxes)