生信工具

genbank文件转换成NCBI提交数据时的.tbl文件(gen

2018-07-09  本文已影响940人  小明的数据分析笔记本

.tbl文件格式介绍 https://www.ncbi.nlm.nih.gov/Sequin/table.html

方法一:转换格式的perl脚本

ftp://ftp.ncbi.nlm.nih.gov//toolbox/ncbi_tools/converters/scripts/gbf2tbl.pl

用法
perl gbf2tbl.pl genbankfile_name
方法二:在线程序 GB2sequin

网址 https://chlorobox.mpimp-golm.mpg.de/GenBank2Sequin.html

推荐文献
GB2sequin — A file converter preparing custom Genbank files for database submission

叶绿体基因组提交到NCBI的流程
可以利用微信搜索 《如何优雅地向NCBI上传线粒体基因组序列》, 这篇文章介绍了利用Bankit提交线粒体基因组序列至NCBI的流程,同样适用于叶绿体基因组序列

写在结尾的废话

这个学期一直在看和叶绿体基因组相关的文章,目前学习到向NCBI提交完整的叶绿体基因组序列,需要准备的文件包括叶绿体基因组fasta文件和注释文件,注释文件要求的格式为.tbl,按照常理应该会有已经造好的轮子来利用常规的注释文件(比如genbank格式,或者gff3格式)来生成.tbl文件,可是自己找了将近两天的时间竟然没有找到(找到了一些python脚本或者小软件,但是都没有运行成功;同时也找到了NCBI提供的小软件table2asn_GFF3,目测功能是利用gff3格式的注释文件生成.tbl文件,试运行了一下,可是参数太多,暂时还没有搞明白该怎么使用),自己也尝试着写了一些脚本,奈何能力有限没有能够解决,前前后后大约折腾了4天左右的时间,之后因为忙一些其他事情中断了一个星期左右,今天再次尝试的时候发现原来叶绿体基因组注释在线工具GeSeq https://chlorobox.mpimp-golm.mpg.de/geseq.html 中包括了格式转换的工具GB2sequin,然后找到了这篇文献来看又发现了格式转换用到的perl脚本,暂时解决了提交序列的问题!

小小感悟:

面对解决不了的问题不要着急,只需要停下来让脑子休息下然后在重新出发!

更新20190102

推荐一篇论文

Complete plastome sequences from Bertholletia excelsa and 23 related species yield informative markers for Lecythidaceae

from Bio import SeqIO
with open("rpl16.gb","gb"):
  for rec in SeqIO.parse("sequence.gb","gb"):
    for feature in rec.features:
      if feature.type == "CDS":
        feature.qualifiers["yan"] = "ming"
        feature.qualifiers["kobe"] = "bryant"
    SeqIO.write(rec,fw,"gb")
from Bio import SeqIO
for rec in SeqIO.parse("fileName.gb"):
  for feature in rec.features:
    if feature.type == "gene" and feature.qualifiers.__contains__("note"):
      feature.qualifiers.pop("note")
  fw = open("output_file.gb","w")
  SeqIO.write(rec,fw,"gb")
fw.close()
x = {}
x["yan"] = "ming"
x["kobe"] = "bryant"
x
x.pop("kobe")
x
import fnmatch
fnmatch.fnmatch("abc.gb","*.gb") #返回True
import os
for file in os.lsidir("./"):
  if fnmatch.fnmatch(file,"*.gb"):
    print(file)

接下来是为genbank文件添加product字段

import os
import fnmatch
from Bio import SeqIO
fileName = []
for file in os.listdir("./")
  if fnmatch.fnmatch(file,"*.gb"):
    fileName.append(file)
products = {}
for file in fileName:
  for rec in SeqIO.parse(file,"gb"):
    for feature in rec.features:
      if feature.type == "CDS" or feature.type == "tRNA"
        products[feature.qualifiers["gene"][0]] = features.qualifiers["product"][0]
with open("output_1.gb","w") as fw:
  for rec in SeqIO.parse("own_gb_file.gb","gb"):
    for feature in rec.features:
      if feature.type == "CDS" or feature.type == "tRNA":
        feature.qualifiers["product"] = products[feature.qualifiers["gene"][0]]
    SeqIO.write(rec,fw,"gb")

理解了SeqIO解析genbank格式文件的数据存储后,自己应该也可以写一个简单的脚本将genbank格式的文件转化成.tbl文件,好好想一想该如何实现;SeqIO模块的源码自己抽时间要多看几遍!

更新2019018

自己的叶绿体基因组数据注释是使用在线程序GeSeq做的,输出结果genBank文件中包括intron和exon的信息,不想要这部分信息,想写个脚本删掉

for rec in SeqIo.parse(“input_file.gb”,"gb"):
 fea_index = [] 
 for a,b in enumerate(rec.features):
   if b.type == "intron" or b.type == "exon":
    fea_index.append(a)
  for i in fea_index:
    rec.features.pop(i)
  fw = open("output_file.gb","w")
  SeqIO.write(rec,fw,"gb")
  fw.close()

一直遇到报错IndexError: pop index out of range
想了好长时间才想明白: rec 里面存储的内容删除一项后,对应的后面的内容的index会相应迁移,比如有1,5,7,9,12五个数字,对应的位置分别是1,2,3,4,5;如果删除前两个,12对应的位置就有原来的5 改为了3

for rec in SeqIO.parse("注释文件/完成/Malus_baccata_C108_1.gb","gb"):  
    fea_index = []
    for a,b in enumerate(rec.features):
        if b.type == "exon" or b.type == "intron":
            fea_index.append(a)
        for s,i in enumerate(fea_index):
          rec.features.pop(i-s) ######
    fw = open("1.gb","w")
    SeqIO.write(rec,fw,"gb")
    fw.close()
上一篇 下一篇

猜你喜欢

热点阅读