我有一个包含447个基因的Nexus文件,但我需要447个单独的Nexus文件(每个基因一个)有人知道怎么做吗?
编辑:我尝试使用bioPython,但是每个文件只支持一种对齐方式。
发布于 2020-07-18 05:09:26
如果你所说的基因是指序列,那么我可以给你一个命题。可以将nexus文件另存为fasta文件,然后可以读取每个序列并将其保存到fasta文件(这更适合于保存序列)。以下是代码
import os
from Bio.Nexus.Nexus import Nexus
from Bio import SeqIO
if __name__ == '__main__':
# Read the nexus file
with open('test.nexus', 'r') as fh:
N = Nexus()
N.read(fh)
N.export_fasta('seqs.fasta') # Export to temp .fasta file
# Read all sequences
seqs = [record for record in SeqIO.parse('seqs.fasta', 'fasta')]
# Write every seq to "sequence_name".fasta file
for seq in seqs:
SeqIO.write(seq, handle = f'{seq.name}.fasta', format = 'fasta')
# Remove unnecessary temp file.
os.remove('seqs.fasta')结果是包含单个序列的fasta文件。
https://stackoverflow.com/questions/62955777
复制相似问题