code: def get_segments(ranges, extra, minsegment=40):
      
      from jcvi.utils.range import range_chain, LEFT, RIGHT
  
      NUL = 2
      selected, score = range_chain(ranges)
  
      endpoints = [(x.start, NUL) for x in selected]
      endpoints += [(x[0], LEFT) for x in extra]
      endpoints += [(x[1], RIGHT) for x in extra]
      endpoints.sort()
  
      current_left = 0
      for a, ai in endpoints:
  
          if ai == LEFT:
              current_left = a
          if ai == RIGHT:
              yield current_left, a
          elif ai == NUL:
              if a - current_left < minsegment:
                  continue
              yield current_left, a - 1
              current_left = a
docs: Given a list of Range, perform chaining on the ranges and select a highest
      scoring subset and cut based on their boundaries. Let's say the projection
      of the synteny blocks onto one axis look like the following.
  
      1=====10......20====30....35====~~
  
      Then the segmentation will yield a block [1, 20), [20, 35), using an
      arbitrary right extension rule. Extra are additional end breaks for
      chromosomes.