本文整理汇总了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
示例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)
示例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