TypeError: expected bytes, _io.TextIOWrapper found

在使用 python的pysam包处理bam文件时,一直报错

TypeError: expected bytes, _io.TextIOWrapper found

  仔细排查,函数输入是没有问题的

for pileupcolumn in samfile.pileup('chr1',237787):

  最后发现是我在开头写的一句话

with open(indexfile,'r')as fi,open(samfile,'r')as fs,open(outfile,'w')as fo:
        reader = csv.reader(fi,delimiter ='\t')
        samfile = pysam.AlignmentFile(fs,'rb')

问题出在 open(samfile,'r')as fs

将开头写成如下格式

with open(indexfile,'r')as fi,open(outfile,'w')as fo:
        reader = csv.reader(fi,delimiter ='\t')
        samfile = pysam.AlignmentFile(samfile,'rb')

问题解决

posted @ 2017-06-26 16:31  ZzzzHong  阅读(1634)  评论(0)    收藏  举报