生信分析Pysam应用

Pysam应用

Pysam包是一个处理基因组数据的python模块,它打包了htslib-1.3、samtools-1.3和bcftools-1.3的核心功能,能在编程时非常灵活的处理bam和bcf文档,实现python处理基因组数据的无缝衔接,而不用在python进程内部调用samtools、bcftools等软件。

函数

Pysam的函数有很多,主要的读取函数有:

AlignmentFile:读取BAM/CRAM/SAM文件;

VariantFile:读取变异数据(VCF或者BCF);

TabixFile:读取由tabix索引的文件;

FastaFile:读取fasta序列文件;

FastqFile:读取fastq测序序列文件

FastaFile:读取fasta序列文件

importpysam##1构建FastaFile对象,调用后返回对象,dir(对象)查看其内置方法refGenome="Homo_sapiens_assembly19.fasta"refseq=pysam.FastaFile(refGenome)dir(refseq)[__class__,__contains__,__delattr__,__dir__,__doc__,__enter__,__eq__,__exit__,__format__,__ge__,__getattribute__,__getitem__,__gt__,__hash__,__init__,__le__,__len__,__lt__,__ne__,__new__,__pyx_vtable__,__reduce__,__reduce_ex__,__repr__,__setattr__,__setstate__,__sizeof__,__str__,__subclasshook__,_open,close,closed,fetch,filename,get_reference_length,is_open,lengths,nreferences,references]##2用fetch函数随机读取序列,查看其使用方法help(object.fetch())###提取整条序列refseq.fetch("chr1")AGCTACTGCTAGCATACGATCTAACGTAGCTCTCTCAGCCGATATTCGCGAT###提取具体位点的碱基,比如上述从左数起第5,6个碱基AC####Python风格半开区间:半开区间碱基位置编号从0开始。refseq.fetch("chr1",4,6)AC####Samtools风格闭区间:碱基位置编号从1开始refseq.fetch(region="chr1:5-6")AC

AlignmentFile:读取BAM/CRAM/SAM文件

##1构建AlignmentFile对象,调用后返回对象,dir(对象)查看其内置方法samfile=pysam.AlignmentFile("example.bam","rb")dir(samfile)[__class__,__delattr__,__dir__,__doc__,__enter__,__eq__,__exit__,__format__,__ge__,__getattribute__,__gt__,__hash__,__init__,__iter__,__le__,__lt__,__ne__,__new__,__next__,__pyx_vtable__,__reduce__,__reduce_ex__,__repr__,__setattr__,__setstate__,__sizeof__,__str__,__subclasshook__,_open,add_hts_options,category,check_index,check_truncation,close,closed,



转载请注明地址:http://www.gongjingmilanagjml.com/glzz/8011.html
  • 上一篇文章:
  • 下一篇文章: 没有了
  • 热点文章

    • 没有热点文章

    推荐文章

    • 没有推荐文章