本文整理汇总了Python中pybedtools.BedTool.bam_to_bed方法的典型用法代码示例。如果您正苦于以下问题:Python BedTool.bam_to_bed方法的具体用法?Python BedTool.bam_to_bed怎么用?Python BedTool.bam_to_bed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pybedtools.BedTool
的用法示例。
在下文中一共展示了BedTool.bam_to_bed方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BedTool
# 需要导入模块: from pybedtools import BedTool [as 别名]
# 或者: from pybedtools.BedTool import bam_to_bed [as 别名]
fn_sorted = tmpdir + "/sorted.bam"
fn_fixedmates = tmpdir + "/fixedmates.bam"
# sort by id
logging.debug("calling samtools sort")
pysam.sort(args.infile, "-n", "-o{}".format(fn_sorted), "-T sortprefix")
# fix mate information
# also removes secondary and unmapped reads
logging.debug("calling samtools fixmates")
pysam.fixmate("-r", fn_sorted, fn_fixedmates)
# bedtools bam2bed
alns = BedTool(fn_fixedmates)
alns_bedpe = alns.bam_to_bed(bedpe=True, mate1=True, ed=True)
# determine alignment ends and write to file
with (open(args.outfile, "w") if args.outfile is not None else stdout) as out:
for i in alns_bedpe:
chrom = i.fields[0]
fmstart = i.fields[1]
fmend = i.fields[2]
smstart = i.fields[4]
smend = i.fields[5]
readid = i.fields[6]
score = i.fields[7]
fmstrand = i.fields[8]
if fmstrand == "+":
start = fmstart
end = smend