original_docstring: Orders a set of BED regions, such that processing matches
      (as far as possible) the layout of the BAM file. This may be
      used to ensure that extraction of regions occurs (close to)
      linearly.
docstring: Orders a set of BED regions, such that processing matches
  (as far as possible) the layout of the BAM file. This may be
  used to ensure that extraction of regions occurs (close to)
  linearly.
docstring_tokens: Orders a set of BED regions such that processing matches ( as far as possible ) the layout of the BAM file . This may be used to ensure that extraction of regions occurs ( close to ) linearly .
code: def sort_bed_by_bamfile(bamfile: AlignmentFile, regions: List[BEDRecord]):
      """Orders a set of BED regions, such that processing matches
      (as far as possible) the layout of the BAM file. This may be
      used to ensure that extraction of regions occurs (close to)
      linearly."""
      if not regions:
          return
  
      references = bamfile.references
      indices = dict(zip(references, range(len(references))))
      infinite = float("inf")
  
      def _by_bam_layout(it: BEDRecord):
          return (indices.get(it.contig, infinite), it.contig, it.start, it.end)
  
      regions.sort(key=_by_bam_layout)
code_tokens: def sort_bed_by_bamfile ( bamfile : AlignmentFile , regions : List [ BEDRecord ] ) : if not regions : return references = bamfile . references indices = dict ( zip ( references , range ( len ( references ) ) ) ) infinite = float ( "inf" ) def _by_bam_layout ( it : BEDRecord ) : return ( indices . get ( it . contig , infinite ) , it . contig , it . start , it . end ) regions . sort ( key = _by_bam_layout )
short_docstring: Orders a set of BED regions, such that processing matches
  (as far as possible) the layout of the BAM file.
short_docstring_tokens: Orders a set of BED regions such that processing matches ( as far as possible ) the layout of the BAM file .
comment: """Orders a set of BED regions, such that processing matches
      (as far as possible) the layout of the BAM file. This may be
      used to ensure that extraction of regions occurs (close to)
      linearly."""