code: def _balanced_strand_gen(base_aligns, limit):
      '''given collection of random {aligns}, returns alternating forward/reverse
      strands up to {total_aligns}; will return smaller of forward/reverse
      collection if less than total_aligns'''
      predicate=lambda align: align.is_reverse
      gen1, gen2 = itertools.tee((predicate(align), align) for align in base_aligns)
      for_strand_gen = (align for pred, align in gen1 if not pred)
      rev_strand_gen = (align for pred, align in gen2 if pred)
      combined_gen = iter_zip(for_strand_gen, rev_strand_gen)
      interleaved_gen = (align for for_rev_aligns in combined_gen for align in for_rev_aligns)
      return itertools.islice(interleaved_gen, limitf _balanced_strand_gen(base_aligns, limit):
      '''given collection of random {aligns}, returns alternating forward/reverse
      strands up to {total_aligns}; will return smaller of forward/reverse
      collection if less than total_aligns'''
      predicate=lambda align: align.is_reverse
      gen1, gen2 = itertools.tee((predicate(align), align) for align in base_aligns)
      for_strand_gen = (align for pred, align in gen1 if not pred)
      rev_strand_gen = (align for pred, align in gen2 if pred)
      combined_gen = iter_zip(for_strand_gen, rev_strand_gen)
      interleaved_gen = (align for for_rev_aligns in combined_gen for align in for_rev_aligns)
      return itertools.islice(interleaved_gen, limit)
docs: given collection of random {aligns}, returns alternating forward/reverse
      strands up to {total_aligns}; will return smaller of forward/reverse
      collection if less than total_aligns