def main_wrapper(process_func, argv, ext): args = parse_arguments(argv, ext) args.regions = None if args.regions_fpath: args.regions = collect_bed_regions(args.regions_fpath) sys.stderr.write("Opening %r\n" % (args.infile,)) with pysam.Samfile(args.infile) as handle: sort_bed_by_bamfile(handle, args.regions) return process_func(handle, args)
def main_wrapper(process_func, argv, ext): args = parse_arguments(argv, ext) args.regions = None if args.regions_fpath: args.regions = collect_bed_regions(args.regions_fpath) sys.stderr.write("Opening %r\n" % (args.infile, )) with pysam.Samfile(args.infile) as handle: sort_bed_by_bamfile(handle, args.regions) return process_func(handle, args)
def collect_regions(bedfile, bam_input_handle): """Returns the regions to be genotyped / pileup'd, as a list of bed-regions in the form (contig, start, end), where start is zero-based, and end is open based. """ if bedfile is not None: regions = list(read_bed_file(bedfile)) sort_bed_by_bamfile(bam_input_handle, regions) regions = merge_bed_regions(regions) else: regions = [] for (name, length) in zip(bam_input_handle.references, bam_input_handle.lengths): regions.append((name, 0, length)) return regions
def main_wrapper(process_func, argv, ext): args = parse_arguments(argv, ext) args.regions = None if args.regions_fpath: try: args.regions = collect_bed_regions(args.regions_fpath) except ValueError, error: sys.stderr.write("Failed to parse BED file %r:\n%s\n" % (args.regions_fpath, error)) return 1 sys.stderr.write("Opening %r\n" % (args.infile, )) with pysam.Samfile(args.infile) as handle: sort_bed_by_bamfile(handle, args.regions) return process_func(handle, args) def _get_readgroup(record): try: return record.opt("RG") except KeyError: raise BAMStatsError("Record lacks readgroup tag ('RG'), use of " "--ignore-readgroups is required to process this" "file.\n Record = %r" % (record.qname, )) def _get_readgroup_ignored(_): return None
def main_wrapper(process_func, argv, ext): args = parse_arguments(argv, ext) args.regions = None if args.regions_fpath: try: args.regions = collect_bed_regions(args.regions_fpath) except ValueError, error: sys.stderr.write("Failed to parse BED file %r:\n%s\n" % (args.regions_fpath, error)) return 1 sys.stderr.write("Opening %r\n" % (args.infile,)) with pysam.Samfile(args.infile) as handle: sort_bed_by_bamfile(handle, args.regions) return process_func(handle, args) def _get_readgroup(record): try: return record.opt("RG") except KeyError: raise BAMStatsError("Record lacks readgroup tag ('RG'), use of " "--ignore-readgroups is required to process this" "file.\n Record = %r" % (record.qname,)) def _get_readgroup_ignored(_): return None