当前位置: 首页>>代码示例>>Python>>正文


Python BedTool.map方法代码示例

本文整理汇总了Python中pybedtools.BedTool.map方法的典型用法代码示例。如果您正苦于以下问题:Python BedTool.map方法的具体用法?Python BedTool.map怎么用?Python BedTool.map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pybedtools.BedTool的用法示例。


在下文中一共展示了BedTool.map方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: calc_signals

# 需要导入模块: from pybedtools import BedTool [as 别名]
# 或者: from pybedtools.BedTool import map [as 别名]
def calc_signals(bam_filename, region_bed_filename, signal_colnum,
                 region_type, normalize, verbose):

    ''' generator to calculate signals from BED regions mapped onto positive and
    negative strand data.'''

    region_bedtool = BedTool(region_bed_filename)

    # bedtools.map operations
    operations = ('sum','count')

    signal_type = 'raw'
    if normalize:
        signal_type = 'norm'

    for signal_strand in STRANDS:

        signal_bedtool = load_coverage(bam_filename, strand=signal_strand,
                                       verbose=verbose)
        for oper in operations:

            map_bedtool = region_bedtool.map(signal_bedtool, o=oper,
                                             c=signal_colnum, null=0)

            for region_row, signal_row in izip(region_bedtool, map_bedtool):
 
                try:
                    region_name = region_row[3]
                    region_score = region_row[4]
                    region_strand = region_row[5]

                except IndexError:
                    region_name = '%s-%s-%d-%d' % (region_type,
                                                   region_row.chrom,
                                                   region_row.start,
                                                   region_row.end)
                    region_score = 0
                    # default
                    region_strand = 'none'

                if region_strand == '+':
                    region_strand = 'pos'
                elif region_strand == '-':
                    region_strand = 'neg'

                # last field is the calculated signal
                signal = float(signal_row[-1])

                if normalize and signal != 0:
                    region_size = float(region_row.end - region_row.start)
                    signal = signal / region_size

                result = (region_name, region_score, 'region-'+region_strand,
                          region_type, 'signal-'+signal_strand,
                          oper, signal, signal_type)

                yield result
开发者ID:hesselberthlab,项目名称:modmap,代码行数:59,代码来源:signal_analysis.py

示例2: interval_counts

# 需要导入模块: from pybedtools import BedTool [as 别名]
# 或者: from pybedtools.BedTool import map [as 别名]
def interval_counts(bedtool, interval_size, chrom_size_filename,
                    only_chroms, ignore_chroms, verbose):

    result = defaultdict()

    # make windows for analysis
    windows = BedTool().window_maker(w=interval_size,
                                     g=chrom_size_filename).sort()

    # collapse per inteval (comma delim counts, or '0')
    mapresult = windows.map(bedtool, o='collapse', c=4, null=0)

    total_intervals = 0

    for idx, row in enumerate(mapresult):

        if (only_chroms and row.chrom not in only_chroms) or \
           (ignore_chroms and row.chrom in ignore_chroms):
            continue

        if row.end - row.start < interval_size: continue

        nums = [int(i) for i in row.name.split(',')]
        counts = Counter(nums)

        # find number of non-zero counts
        total_counts = sum([i for i in counts.values() if i > 0])

        total_size = int(row.end - row.start)
        num_zeros = total_size - total_counts

        # change the 0 counts to the calculated number 
        counts[0] = num_zeros

        result[idx] = counts

        total_intervals += 1

    if verbose:
        print >>sys.stderr, ">> seen %d intervals of obs data" \
                             % total_intervals

    return (result, total_intervals)
开发者ID:hesselberthlab,项目名称:modmap,代码行数:45,代码来源:random_dist.py

示例3: calc_signals

# 需要导入模块: from pybedtools import BedTool [as 别名]
# 或者: from pybedtools.BedTool import map [as 别名]
def calc_signals(bam_filename, region_bed_filename, signal_colnum, verbose):

    ''' generator to calculate signals from BED regions mapped onto positive and
    negative strand data.'''

    region_bedtool = BedTool(region_bed_filename)

    # bedtools.map operations
    operations = ('sum','count')

    for signal_strand in STRANDS:

        signal_bedtool = load_coverage(bam_filename, strand=signal_strand,
                                       verbose=verbose)
        for oper in operations:

            map_bedtool = region_bedtool.map(signal_bedtool, o=oper,
                                             c=signal_colnum, null=0)

            for region_row, signal_row in izip(region_bedtool, map_bedtool):

                region_name = region_row[3]
                region_score = region_row[4]

                region_strand = region_row[5]
                if region_strand == '+':
                    region_strand = 'pos'
                else:
                    region_strand = 'neg'

                signal = signal_row[6]

                result = (region_name, region_score, region_strand,
                          signal_strand, oper, signal)

                yield result
开发者ID:speach,项目名称:modmap,代码行数:38,代码来源:signal_analysis.py


注:本文中的pybedtools.BedTool.map方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。