Iterator for repeatmasker coordinate annotation files. These files describe
  the location of repeat occurrences. There is (optionally) a two-line header
  with the names of the fields (ignored by the iterator, if present). Each line
  is a record of an occurrence. The description of fields for each line is
  given in from_repeat_masker_string.

  :param fh:              stream-like object, or string filename, to load the
                          annotations from
  :param alignment_index: an IndexedFile for full alignments; keys should be
                          repeat-masker IDs
  :param header:          if True, expect and discard the two-line header;
                          otherwise we will expect there is no header
  :param verbose:         if True, output additional status messages about
                          progress to stderr.

def repeat_masker_iterator(fh, alignment_index=None,
                           header=True, verbose=False):
  """
  Iterator for repeatmasker coordinate annotation files. These files describe
  the location of repeat occurrences. There is (optionally) a two-line header
  with the names of the fields (ignored by the iterator, if present). Each line
  is a record of an occurrence. The description of fields for each line is
  given in from_repeat_masker_string.

  :param fh:              stream-like object, or string filename, to load the
                          annotations from
  :param alignment_index: an IndexedFile for full alignments; keys should be
                          repeat-masker IDs
  :param header:          if True, expect and discard the two-line header;
                          otherwise we will expect there is no header
  :param verbose:         if True, output additional status messages about
                          progress to stderr.
  """

  strm = fh
  if type(fh).__name__ == "str":
    strm = open(fh)

  # try to get an idea of how much data we have...
  if verbose:
    try:
      total = os.path.getsize(strm.name)
      pind = ProgressIndicator(totalToDo=total, messagePrefix="completed",
                               messageSuffix="of processing " + strm.name)
    except AttributeError as e:
      sys.stderr.write(str(e))
      sys.stderr.write("completed [unknown] of processing index")
      verbose = False

  if header:
    # chomp first 2 lines
    next(strm)
    next(strm)

  for line in strm:
    if verbose:
      pind.done = strm.tell()
      pind.showProgress()

    line = line.strip()
    if line == "":
      continue
    rto = retrotransposon.from_repeat_masker_string(line)
    if alignment_index is not None:
      rto.pairwise_alignment =\
          JustInTimePairwiseAlignment(alignment_index, rto.uniq_id)
    yield rto