last-dotplot: fix crash on annotation names
authorMartin C. Frith
Wed Oct 14 13:49:25 2020 +0900 (19 months ago)
changeset 11322b38a62095d1
parent 1131 ef402c72783a
child 1133 04663552433d
last-dotplot: fix crash on annotation names
scripts/last-dotplot
     1.1 --- a/scripts/last-dotplot	Wed Oct 14 11:50:32 2020 +0900
     1.2 +++ b/scripts/last-dotplot	Wed Oct 14 13:49:25 2020 +0900
     1.3 @@ -371,7 +371,7 @@
     1.4      o1, oB1 = twoValuesFromOption(opts.strands1, ":")
     1.5      o2, oB2 = twoValuesFromOption(opts.strands2, ":")
     1.6      if o1 == "1" and o2 == "1":
     1.7 -        raise Exception("the strand options have circular dependency")
     1.8 +        raise RuntimeError("the strand options have circular dependency")
     1.9      seqRanges1 = list(rangesWithStrandInfo(seqRanges1, o1, alignments, 0))
    1.10      seqRanges2 = list(rangesWithStrandInfo(seqRanges2, o2, alignments, 1))
    1.11      seqRangesB1 = list(rangesWithStrandInfo(seqRangesB1, oB1, alignmentsB, 0))
    1.12 @@ -380,7 +380,7 @@
    1.13      o1, oB1 = twoValuesFromOption(opts.sort1, ":")
    1.14      o2, oB2 = twoValuesFromOption(opts.sort2, ":")
    1.15      if o1 == "3" and o2 == "3":
    1.16 -        raise Exception("the sort options have circular dependency")
    1.17 +        raise RuntimeError("the sort options have circular dependency")
    1.18      if o1 != "3":
    1.19          s1 = mySortedRanges(seqRanges1, o1, None, None, None)
    1.20      if o2 != "3":
    1.21 @@ -461,7 +461,7 @@
    1.22      numOfRanges = len(rangeSizes)
    1.23      maxPixelsInRanges = maxPixels - pixTweenRanges * (numOfRanges - 1)
    1.24      if maxPixelsInRanges < numOfRanges:
    1.25 -        raise Exception("can't fit the image: too many sequences?")
    1.26 +        raise RuntimeError("can't fit the image: too many sequences?")
    1.27      negLimit = -maxPixelsInRanges
    1.28      negBpPerPix = sum(rangeSizes) // negLimit
    1.29      while True:
    1.30 @@ -699,6 +699,7 @@
    1.31  def bedBoxes(beds, rangeDict, limit, isTop, bpPerPix, textSizes):
    1.32      cover = [(limit, limit)]
    1.33      for layer, color, seqName, bedBeg, bedEnd, name in reversed(beds):
    1.34 +        textWidth, textHeight = textSizes[name]
    1.35          for rangeBeg, rangeEnd, isReverseRange, origin in rangeDict[seqName]:
    1.36              beg = max(bedBeg, rangeBeg)
    1.37              end = min(bedEnd, rangeEnd)
    1.38 @@ -719,14 +720,13 @@
    1.39                          pixBeg = (origin + beg) // bpPerPix
    1.40                      else:
    1.41                          pixEnd = div_ceil(origin + end, bpPerPix)
    1.42 -            textWidth, textHeight = textSizes[name]
    1.43              nameBeg = (pixBeg + pixEnd - textHeight) // 2
    1.44              nameEnd = nameBeg + textHeight
    1.45 +            n = ""
    1.46              if name and all(e <= nameBeg or b >= nameEnd for b, e in cover):
    1.47                  cover.append((nameBeg, nameEnd))
    1.48 -            else:
    1.49 -                name = ""
    1.50 -            yield layer, color, isTop, pixBeg, pixEnd, name, nameBeg, textWidth
    1.51 +                n = name
    1.52 +            yield layer, color, isTop, pixBeg, pixEnd, n, nameBeg, textWidth
    1.53  
    1.54  def drawAnnotations(im, boxes, tMargin, bMarginBeg, lMargin, rMarginBeg):
    1.55      # xxx use partial transparency for different-color overlaps?
    1.56 @@ -882,7 +882,7 @@
    1.57      logging.info("reading alignments...")
    1.58      alnData = readAlignments(args[0], opts)
    1.59      alignments, seqRanges1, coverDict1, seqRanges2, coverDict2 = alnData
    1.60 -    if not alignments: raise Exception("there are no alignments")
    1.61 +    if not alignments: raise RuntimeError("there are no alignments")
    1.62      logging.info("cutting...")
    1.63      coverDict1 = dict(mergedRangesPerSeq(coverDict1))
    1.64      coverDict2 = dict(mergedRangesPerSeq(coverDict2))
    1.65 @@ -1149,6 +1149,6 @@
    1.66  
    1.67      try: lastDotplot(opts, args)
    1.68      except KeyboardInterrupt: pass  # avoid silly error message
    1.69 -    except Exception as e:
    1.70 +    except RuntimeError as e:
    1.71          prog = os.path.basename(sys.argv[0])
    1.72          sys.exit(prog + ": error: " + str(e))