【问题标题】:Trying to read file in FASTA format and then write to another file in Genbank format尝试以 FASTA 格式读取文件,然后以 Genbank 格式写入另一个文件
【发布时间】:2019-11-25 18:00:57
【问题描述】:

尝试使用 BioPython 中的 SeqSeqIO 对象读取包含基因组序列的文件。无法使用打开命令。程序应接受一个命令行参数,其中包含包含输入基因组的 FASTA 文件的名称。

它创建了文件,但文件中没有任何内容。不确定我错过了什么?

这就是我所拥有的:

    from Bio.Seq import Seq                                                 
    from Bio import SeqIO
    from Bio.SeqRecord import SeqRecord
    from Bio.Alphabet import IUPAC

    recordlist = []

    for SeqRecord in SeqIO.parse('bacterium_genome.fna', 'fasta'):
        myseq = SeqRecord.seq
        myseq.alphabet = IUPAC.unambiguous_dna
        recordlist.append(SeqRecord)


    SeqIO.write(recordlist, 'bacterium_genome.gb', 'gb')

【问题讨论】:

    标签: python bioinformatics biopython fasta genbank


    【解决方案1】:

    您正在做的事情实际上应该可以工作(假设一个有效的非空输入 FASTA 文件),但由于不必要的导入而没有那么优雅。您可以改为直接修改字母表,然后将序列记录写入输出文件句柄每次迭代:

    from Bio import SeqIO
    from Bio.Alphabet import IUPAC
    
    with open('bacterium_genome.gb', 'w') as out_f:
        for record in SeqIO.parse('bacterium_genome.fna', 'fasta'):
            record.seq.alphabet = IUPAC.unambiguous_dna
            SeqIO.write(record, out_f, 'genbank')
    

    【讨论】:

    • 我尽量不使用“with open”
    猜你喜欢
    • 2012-08-31
    • 2016-01-14
    • 2017-10-22
    • 1970-01-01
    • 2023-04-02
    • 2019-05-19
    • 2013-09-04
    • 2020-12-18
    • 1970-01-01
    相关资源
    最近更新 更多