本文整理汇总了Python中pybedtools.BedTool.window方法的典型用法代码示例。如果您正苦于以下问题:Python BedTool.window方法的具体用法?Python BedTool.window怎么用?Python BedTool.window使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pybedtools.BedTool
的用法示例。
在下文中一共展示了BedTool.window方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: xstream
# 需要导入模块: from pybedtools import BedTool [as 别名]
# 或者: from pybedtools.BedTool import window [as 别名]
def xstream(a, b, distance, updown, out):
"""
find all things in b that are within
distance of a in the given direction
(up or down-stream)
"""
direction = dict(u="l", d="r")[updown[0]]
kwargs = {'sw':True, direction: distance}
if "l" in kwargs: kwargs["r"] = 0
else: kwargs["l"] = 0
a = BedTool(a).saveas()
kwargs['stream'] = True
c = a.window(b, **kwargs)
afields = a.field_count()
seen = collections.defaultdict(set)
for feat in c:
key = "\t".join(feat[:afields])
# keep track of all the feature names that overlap this one
seen[key].update((feat[afields + 3],))
# the entries that did appear in the window
for row in seen:
out.write(row + "\t" + ",".join(sorted(seen[row])) + "\n")
# write the entries that did not appear in the window'ed Bed
for row in a:
key = "\t".join(row[:afields])
if key in seen: continue
out.write(str(row) + "\t.\n")
out.flush()
assert len(BedTool(out.name)) == len(a)
示例2: str
# 需要导入模块: from pybedtools import BedTool [as 别名]
# 或者: from pybedtools.BedTool import window [as 别名]
#!/usr/bin/env python
import os
import sys
import subprocess
sys.path.insert(0,'/mnt/lustre/home/cusanovich/Programs/lib/python2.6/site-packages/pybedtools-0.6.2-py2.6-linux-x86_64.egg/pybedtools')
from pybedtools import BedTool, featurefuncs
windowsize = 10000
windowname = str(windowsize/1000) + 'kb'
indir = '/mnt/lustre/home/cusanovich/Kd_Arrays/GenomeAnnotations/StartAnnots/'
outdir = '/mnt/lustre/home/cusanovich/Kd_Arrays/GenomeAnnotations/FinalAnnots/'
annots = ['GSE31388_eQtlTable_cleaned.bed','sorted_PritchardQTLs_merged.bed','gwascatalog_ucsc_merged.bed']
#annots = ['GSE31388_eQtlTable_cleaned.bed']
jacked = BedTool('/mnt/lustre/home/cusanovich/centipede/hg19_jack_centipede_sorted_pwms_clean.bed')
tss = BedTool('/mnt/lustre/home/cusanovich/Kd_Arrays/Centipede/Annotation/HT12ensemblTSScombinedsorted.bed')
for annot in annots:
print annot
currannot = BedTool(indir + annot)
currout = annot.split('.')[0]
print 'Intersecting...'
inter = jacked.intersect(currannot,wa=True,wb=True).moveto(outdir + windowname + '_' + currout + '_centipede_intersect.bed')
inter = BedTool(outdir + windowname + '_' + currout + '_centipede_intersect.bed')
print 'Calculating midpoints...'
intermid = inter.each(featurefuncs.midpoint).moveto(outdir + windowname + '_' + currout + '_centipede_intersect_midpoint.bed')
print 'Finding TSSs...'
inter = BedTool(outdir + windowname + '_' + currout + '_centipede_intersect_midpoint.bed')
outter = tss.window(intermid,w=windowsize).moveto(outdir + windowname + '_' + currout + '_insite.bed')