-
gbff是NCBI基因組數(shù)據(jù)庫常見的基因組genebank格式文件寞焙,在實際分析中教沾,常常需要gff格式或者gtf格式焕檬,所以就存在gbff轉(zhuǎn)換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
- 轉(zhuǎn)換代碼 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 改成自己需要轉(zhuǎn)換的文件
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
赂鲤,重新審視發(fā)現(xiàn)多粘貼了開頭代碼段from BCBio import GFF
到結(jié)尾噪径,刪除該結(jié)尾處的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
修改新的對應(yīng)文件名后再運行腳本
##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
總結(jié):轉(zhuǎn)換后并不能得到直接可用的完整注釋文件,建議直接搜索已有的注釋文件