简体   繁体   English

如何使用biopython将基因库文件的序列编辑并保存到新的基因库文件中?

[英]How do I edit AND SAVE the sequence of a genbank file to a NEW genbank file using biopython?

I have a .gbk file that's wrong, and I have the list of corrections that follows the format of 我有一个错误的.gbk文件,并且我有遵循以下格式的更正列表:

"Address of Nuclotide: correct nucleotide" “核苷酸的地址:正确的核苷酸”

1:T
2:C
4:A
63:A
324:G
etc...

I know how to open and parse exact original sequence with 我知道如何打开和解析确切的原始序列

list(SeqIO.parse(sys.argv[1], "genbank"))[0].seq 

I just need to know how to replace it with my own nucleotide corrections. 我只需要知道如何用我自己的核苷酸校正替换它即可。 I've tried 我试过了

seq_records[0].seq = "".join(dna_refseq)

Where the dna_refseq is a was just a list that constitutes the entire genome dna_refseq是a的地方只是构成整个基因组的列表

I literally cannot find this specific action anywhere in the documentation or online, and intuitively, this is something that biopython should be capable of. 从字面上看,我无法在文档中或在线上找到此特定操作,从直觉上讲,这是biopython应该能够做到的。

You are assigning a string where a Bio.Seq object is expected. 您正在分配期望Bio.Seq对象的字符串。 For me, this works: 对我来说,这有效:

from Bio import Seq
from Bio import SeqIO

my_entries = list(SeqIO.parse('my_file.gb', 'genbank'))
my_entry = my_entries[0]

# Make a new Seq object and assing to my_entry.seq. 'TTT' is just an example sequence
my_entry.seq = Seq.Seq('TTT', my_entry.seq.alphabet) 

# Write back to file
SeqIO.write(my_entries, 'my_updated_file.gb', 'genbank')

If your Genbank file has only one entry, you might consider using SeqIO.read : 如果您的Genbank文件只有一个条目,则可以考虑使用SeqIO.read

my_entry = SeqIO.read('my_file.gb', 'genbank')

my_entry.seq = Seq.Seq('TTT', my_entry.seq.alphabet)
SeqIO.write(my_entry, 'my_updated_file.gb', 'genbank')

Alternatively, you can directly convert the sequence into a mutable sequence and manipulate it directly: 另外,您可以将序列直接转换为可变序列并直接对其进行操作:

from Bio import SeqIO

my_entry = list(SeqIO.parse('my_file.gb', 'genbank'))[0]
my_entry.seq = my_entry.seq.tomutable()

my_entry.seq[0] = 'T'  # Remember that Genbank position 1 is 0 in seq
my_entry.seq[1] = 'C'
....
SeqIO.write(my_entry, 'my_updated_file.gb', 'genbank')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM