def read_gtf(lines, scaffolds, contig_prefix): table = {} # gene_id -> transcript_id -> exon_number -> feature -> [items] for gtf in text.parse_lines(lines, pysam.asGTF()): if not filter_gtf_record(gtf): update_gtf_table(table, gtf, scaffolds, contig_prefix) return table
def read_bed_file(filename): """Parses a (gzip/bzip2 compressed) BED file, and yields a sequence of records. Comments and empty lines are skipped.""" handle = None try: handle = fileutils.open_ro(filename) for record in text.parse_lines(handle, BEDRecord): yield record finally: if handle: handle.close()
def read_bed_file(filename): """Parses a (gzip/bzip2 compressed) BED file, and yields a sequence of records. Comments and empty lines are skipped.""" handle = None try: handle = fileutils.open_ro(filename) parser = pysam.asBed() for record in text.parse_lines(handle, parser): # Force evaluation of (lazily parsed) properties _ = record.start _ = record.end yield record finally: if handle: handle.close()
def _parse_lines(*args, **kwargs): return list(parse_lines(*args, **kwargs))