code: def iron(sequence):
      r_indel = re.compile(r'(-[a-y]|[a-y]-)')
      orig_sequence = sequence
      while r_indel.search(sequence):
          in_insert = False
          in_gap = False
          seen_gaps = 0
          inserts = []
          outchars = []
          for char in sequence:
              if in_insert:
                  if char.islower():
                      inserts.append(char)
                  elif char.isupper():
                      in_insert = False
                      outchars.extend(inserts)
                      inserts = []
                      outchars.append('-' * seen_gaps)
                      seen_gaps = 0
                      outchars.append(char)
                  else:
                      assert char == '-'
                      if not inserts:
                          in_insert = False
                          in_gap = True
                          seen_gaps += 1
                      else:
                          outchars.append(inserts.pop(0).upper())
                          if not inserts:
                              in_insert = False
                              in_gap = True
              elif in_gap:
                  if char.islower():
                      in_insert = True
                      in_gap = False
                      if inserts:
                          outchars.extend(inserts)
                          outchars.append('-' * seen_gaps)
                          seen_gaps = 0
                      inserts = [char]
                  elif char.isupper():
                      in_gap = False
                      if inserts:
                          outchars.extend(inserts)
                          inserts = []
                      outchars.append('-' * seen_gaps)
                      seen_gaps = 0
                      outchars.append(char)
                  else:
                      assert char == '-'
                      seen_gaps += 1
              else:
                  assert not inserts and not seen_gaps, (
                      "Inserts: %s, gaps: %s, seq: %s, in_ins=%s, in_gap=%s"
                      % (inserts, seen_gaps, sequence, in_insert, in_gap))
                  if char.isupper():
                      outchars.append(char)
                  elif char.islower():
                      inserts.append(char)
                      in_insert = True
                  else:
                      assert char == '-'
                      seen_gaps += 1
                      in_gap = True
          if inserts:
              outchars.extend(inserts)
          if seen_gaps:
              outchars.append('-' * seen_gaps)
          sequence = ''.join(outchars)
          assert (sequence.replace('-', '').upper()
                  ==
                  orig_sequence.replace('-', '').upper()), \
                  '\nOrig: ' + orig_sequence + \
                  '\nIron: ' + sequence
      return sequence