def regularWigIterator(fd, verbose=False, sortedby=None, scoreType=int):
  """
    @param sortedBy: if not None, should be one of ITERATOR_SORTED_BY_START
                     indicating an order that the input stream must be
                     sorted in
    @raise WigIteratorError: if sortedBy is set and stream is not sorted
  """
  if verbose:
    try:
      totalLines = linesInFile(fd)
      pind = ProgressIndicator(totalToDo=totalLines,
                               messagePrefix="completed",
                               messageSuffix="of processing " + getFDName(fd))
    except AttributeError:
      sys.stderr.write("WigIterator -- warning: "
                       + "unable to show progress for stream")
      verbose = False

  chromsSeen = set()
  prev = None

  fh = openFD(fd)
  for line in fh:
    if verbose:
      pind.done += 1
      pind.showProgress()

    line = line.strip()
    if line == "":
      continue
    e = parseWigString(line, scoreType=scoreType)

    # on same chrom as the prev item, make sure order is right
    if prev is not None and sortedby is not None and e.chrom == prev.chrom:
      if sortedby == ITERATOR_SORTED_START and prev.start > e.start:
        raise WigIteratorError("bed file " + fd.name
                               + " not sorted by start index - saw item "
                               + str(prev) + " before " + str(e))

    # starting a new chrom.. make sure we haven't already seen it
    if prev is not None and prev.chrom != e.chrom:
      if (sortedby == ITERATOR_SORTED_START) and\
         (e.chrom in chromsSeen or prev.chrom > e.chrom):
        raise WigIteratorError("BED file " + fd.name
                               + " not sorted by chrom")
      chromsSeen.add(e.chrom)

    # all good..
    yield e
    prev = e
def regularWigIterator ( fd , verbose = False , sortedby = None , scoreType = int ) : if verbose : try : totalLines = linesInFile ( fd ) pind = ProgressIndicator ( totalToDo = totalLines , messagePrefix = "completed" , messageSuffix = "of processing " + getFDName ( fd ) ) except AttributeError : sys . stderr . write ( "WigIterator -- warning: " + "unable to show progress for stream" ) verbose = False chromsSeen = set ( ) prev = None fh = openFD ( fd ) for line in fh : if verbose : pind . done += 1 pind . showProgress ( ) line = line . strip ( ) if line == "" : continue e = parseWigString ( line , scoreType = scoreType ) if prev is not None and sortedby is not None and e . chrom == prev . chrom : if sortedby == ITERATOR_SORTED_START and prev . start > e . start : raise WigIteratorError ( "bed file " + fd . name + " not sorted by start index - saw item " + str ( prev ) + " before " + str ( e ) ) if prev is not None and prev . chrom != e . chrom : if ( sortedby == ITERATOR_SORTED_START ) and ( e . chrom in chromsSeen or prev . chrom > e . chrom ) : raise WigIteratorError ( "BED file " + fd . name + " not sorted by chrom" ) chromsSeen . add ( e . chrom ) yield e prev = e
@param sortedBy: if not None, should be one of ITERATOR_SORTED_BY_START
                     indicating an order that the input stream must be
                     sorted in
    @raise WigIteratorError: if sortedBy is set and stream is not sorted