-
gbff是NCBI基因组数据库常见的基因组genebank格式文件,在实际分析中,常常需要gff格式或者gtf格式,所以就存在gbff转换gff格式的需求
- 方法请参考
先安装Biopython,见前篇随笔
再安装 bcbio-gff
pip install bcbio-gff
$ pip install bcbio-gff
Collecting bcbio-gff
Downloading bcbio-gff-0.6.6.tar.gz (19 kB)
Requirement already satisfied: six in /ldfssz1/MS_OP/USER/lifan/software/bin/miniconda3/lib/python3.7/site-packages (from bcbio-gff) (1.12.0)
Installing collected packages: bcbio-gff
Running setup.py install for bcbio-gff ... done
Successfully installed bcbio-gff-0.6.6
- 转换代码 Converting other formats to GFF3
from BCBio import GFF
from Bio import SeqIO
in_file = "your_file.gb"
out_file = "your_file.gff"
in_handle = open(in_file)
out_handle = open(out_file, "w")
GFF.write(SeqIO.parse(in_handle, "genbank"), out_handle)
in_handle.close()
out_handle.close()
实践案例一
- 将代码中your_file.gb 改成自己需要转换的文件
GCA_010614865.1_ASM1061486v1_genomic.gbff.gz
- 将代码中your_file.gff改成自己想要生成的gff文件名,如
GCA_010614865.1_ASM1061486v1_genomic.gbff.gff
- 保存改好的代码并命名为
python gbff2gff3.py
- 运行这个脚本
python gbff2gff3.py
报错情况1
$ python gbff2gff3.py
File "gbff2gff3.py", line 28
out_handle.close()from BCBio import GFF
^
SyntaxError: invalid syntax
该报错中提示无效语法
out_handle.close()from BCBio import GFF
,重新审视发现多粘贴了开头代码段from BCBio import GFF
到结尾,删除该结尾处的from BCBio import GFF
可解决
报错情况2
$ python gbff2gff3.py
File "*/miniconda3/lib/python3.7/codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte
该报错中提示
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte
Google是法宝,直接搜索UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte
,得到如下解,见 stackoverflow
表示文件是压缩文件,需要先解压再作为输入文件才可
于是开始解压文件
gunzip -c GCA_010614865.1_ASM1061486v1_genomic.gbff.gz > Sd_genomic.gbff
修改新的对应文件名后再运行脚本
##Converting other formats to GFF3
from BCBio import GFF
from Bio import SeqIO
in_file = "*/GCA_010614865.1_ASM1061486v1/Sd_genomic.gbff"
out_file = "*/GCA_010614865.1_ASM1061486v1/Sd_genomic.gbff.gff"
in_handle = open(in_file)
out_handle = open(out_file, "w")
GFF.write(SeqIO.parse(in_handle, "genbank"), out_handle)
in_handle.close()
out_handle.close()
python gbff2gff3.py
于是得到以下
替换方法:https://github.com/jorvis/biocode/blob/master/gff/convert_genbank_to_gff3.py
总结:转换后并不能得到直接可用的完整注释文件,建议直接搜索已有的注释文件