我有两个非常大的 fasta 文件,都在 2GB 左右。他们有一些序列共享相同的名称,所以它就像:
在 R1.fasta 中:
">ABC001 ACTGTGTCGTG
">ABC003 ACTGTGTCGTG
">ABC005 ACTGTGTCGTG
">ABC010 ACTGTGTCGTG
并在 R2.fasta
">ABC002 ACTGTGTCGTG
">ABC003 ACTGTGTCGTG
">ABC005 ACTGTGTCGTG
">ABC009 ACTGTGTCGTG
我想找到两个文件之间的共享序列,可以写入一个新的 fasta 文件并将两个序列连接起来,因此新文件如下所示:
">ABC003 ACTGTGTCGTG-----ACTGTGTCGTG
">ABC005 ACTGTGTCGTG-----ACTGTGTCGTG
我已经编写了一个 python 脚本来完成这项工作,但它运行得非常慢。我想知道是否有更快的方法来做到这一点。谢谢!代码是这样的:
from Bio import SeqIO
from Bio.Seq import Seq
R1 = 'L008_R1.forward.trim.fasta' #input R1 file
R2 = 'L008_R2.reverse.trim.fasta' # input R2 file
R = 'Gap20.L008.R1.fasta' #output joined fasta
n1 = 0
n2 = 0
for rec1 in SeqIO.parse(R1, 'fasta'): #exam every record in R1 file one by one
n1 = int(rec1.id[5:])
r = rec1
for rec2 in SeqIO.parse(R2,'fasta'):
n2 = int(rec2.id[5:])
if n1 == n2:
seq = rec1.seq+'--------------------'+rec2.seq
r.seq = seq
output = open(R, 'aw') # write to a new fasta file
SeqIO.write(r, output, 'fasta')
break
elif n1 < n2:
else: pass