程序笔记   发布时间:2022-07-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了pybedtools 提取序列大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

前言

pybedtools 是封装了BEDTools 所有可用的程序。下文学习下pybedtools 如何通过bed文件的坐标提取对应序列

正文

对pybedtools还不了解的参考下这篇文章 在Python中使用BEDTools。

提取序列的方法在BEDTools 中的命令是bedtools getfasta, 在pybedtools中是BedTool.sequence方法。

第一步是创建BEDTool实例, 作为例子,这里用字符串来生成:

a = pybedtools.BedTool("""
chr1 1 10
chr1 50 55""", from_string=True)

# 若从bed文件中生成则
# bed = pybedtools.BedTool(bed_file_path)

指定fasta文件地址

## fasta 是一个软件自带的测试fasta文件地址
fasta = pybedtools.example_filename('test.fa')
a = a.sequence(fi=fasta)
print(open(a.seqfn).read())

输出

>chr1:1-10
GATGAGTCT
>chr1:50-55
CCATC

保存文件,可以通过设置fo参数设置保存地址

a = a.sequence(fi=fasta, fo="a1.fa")

也可以使用save_seqs()方法

a.save_seqs("a2.fa")

Original BEDTools help::

Tool:    bedtools getfasta (aka fastaFromBed)
Version: v2.30.0
Summary: Extract DNA sequences from a fasta file based on feature coordinates.

Usage:   bedtools getfasta [OPTIONS] -fi <fasta> -bed <bed/gff/vcf>

Options: 
        -fi             Input FASTA file
        -fo             Output file (opt., default is STDOUT
        -bed            BED/GFF/VCF file of ranges to extract from -fi
        -name           Use the name field and coordinates for the FASTA header
        -name+          (deprecated) Use the name field and coordinates for the FASTA header
        -nameOnly       Use the name field for the FASTA header
        -split          Given BED12 fmt., extract and concatenate the sequences
                        from the BED "blocks" (e.g., exons)
        -tab            Write output in TAB delimited format.
        -bedOut         Report extract sequences in a tab-delimited BED format instead of in FASTA format.
                        - Default is FASTA format.
        -s              Force strandedness. If the feature occupies the antisense,
                        strand, the sequence will be reverse complemented.
                        - By default, strand information is ignored.
        -fullHeader     Use full fasta header.
                        - By default, only the word before the first space or tab 
                        is used.
        -rna    The FASTA is RNA not DNA. Reverse complementation handled accordingly.

参考

pybedtools.bedtool.BedTool.sequence

大佬总结

以上是大佬教程为你收集整理的pybedtools 提取序列全部内容,希望文章能够帮你解决pybedtools 提取序列所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: