示例#1
0
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)
示例#2
0
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)
示例#3
0
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
示例#4
0
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
示例#5
0

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
示例#6
0

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