本文整理汇总了Python中pybedtools.BedTool.multi_intersect方法的典型用法代码示例。如果您正苦于以下问题:Python BedTool.multi_intersect方法的具体用法?Python BedTool.multi_intersect怎么用?Python BedTool.multi_intersect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pybedtools.BedTool
的用法示例。
在下文中一共展示了BedTool.multi_intersect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: calc_intersection
# 需要导入模块: from pybedtools import BedTool [as 别名]
# 或者: from pybedtools.BedTool import multi_intersect [as 别名]
def calc_intersection(bedtools, verbose):
intersect_tool = BedTool()
if verbose:
print >>sys.stderr, ">> generating intersection ... "
result = intersect_tool.multi_intersect(i=[bt.fn for bt in bedtools])
return result
示例2: counts
# 需要导入模块: from pybedtools import BedTool [as 别名]
# 或者: from pybedtools.BedTool import multi_intersect [as 别名]
def counts(samples, result_path, peak_ext, bam_ext):
# get the consensus peaks
f = open("%s/peak_coordinates.bed" % result_path, 'w')
x = BedTool()
consensus = x.multi_intersect(i=getfilelist(result_path, "*%s" % peak_ext))
for c in consensus:
# fixing formatting from bedtool object
replicate_counts = c.name
if replicate_counts < 2: continue
fields = [c.chrom, c.start, c.stop, "%s:%d-%d\n" % \
(c.chrom, c.start, c.stop)]
f.write("\t".join(map(str, fields)))
f.close()
# get counts for each sample
jobs = []
countfiles = []
for sample in samples:
bams = getfilelist(result_path, sample + "*%s" % bam_ext)
assert(len(bams) == 1)
outdir = result_path.rstrip("/") + "/" + sample
countsresult = outdir + "/" + sample + ".counts"
countfiles.append(countsresult)
if op.exists(countsresult): continue
cmd = "bedtools coverage -abam %s -b %s > %s" % \
(bams[0], f.name, countsresult)
jobid = bsub(sample + "_counts",
R="select[mem>16] rusage[mem=16] span[hosts=1]",
verbose=True)(cmd)
jobs.append(jobid)
bsub.poll(jobs)
# counts to matrix
allcounts = {}
for cf in countfiles:
cfname = op.basename(cf).split(".counts")[0]
casecounts = {}
for toks in reader(cf, header="chrom start stop name a_overlaps_in_b \
b_with_nonzero length_b frac_b_nonzero".split()):
casecounts[toks['name']] = int(toks['a_overlaps_in_b'])
allcounts[cfname] = casecounts
countsdf = pd.DataFrame(allcounts)
countsdf.to_csv(sys.stdout, sep="\t", header=True)
示例3: counts
# 需要导入模块: from pybedtools import BedTool [as 别名]
# 或者: from pybedtools.BedTool import multi_intersect [as 别名]
def counts(samples, resultsdir):
"""docstring"""
# get the consensus peaks
f = open(resultsdir + "/peak_coordinates.bed", 'w')
x = BedTool()
consensus = x.multi_intersect(i=getfilelist(resultsdir, "*peaks.bed.gz"))
for c in consensus:
replicate_counts = c.name
if replicate_counts < 2: continue
fields = [c.chrom, c.start, c.stop, "%s:%d-%d\n" % (c.chrom, c.start, c.stop)]
f.write("\t".join(map(str, fields)))
f.close()
# get counts for each sample
jobs = []
countfiles = []
for sample in samples:
bams = getfilelist(resultsdir, sample + "*.hg19_novoalign.bam")
assert(len(bams) == 1)
outdir = resultsdir.rstrip("/") + "/" + sample
countsresult = outdir + "/" + sample + ".counts"
countfiles.append(countsresult)
if op.exists(countsresult): continue
cmd = "bedtools coverage -abam " + bams[0] + " -b " + f.name + " > " + countsresult
jobid = bsub(sample + "_counts", R="select[mem>16] rusage[mem=16] span[hosts=1]", verbose=True)(cmd)
jobs.append(jobid)
bsub.poll(jobs)
# counts to matrix
allcounts = {}
for cf in countfiles:
cfname = op.basename(cf).split(".hg19_novoalign.bam")[0]
casecounts = {}
for toks in reader(cf, header="chrom start stop name a_overlaps_in_b b_with_nonzero length_b frac_b_nonzero".split()):
casecounts[toks['name']] = int(toks['a_overlaps_in_b'])
allcounts[cfname] = casecounts
countsdf = pd.DataFrame(allcounts)
countsdf.to_csv(resultsdir + "/sample_counts.csv", sep=",", header=True)