我一直在尝试将 DNA 序列与熊猫对齐,但由于某种原因,这条线
if mat[i][0] == mat[0][j]
计算需要很长时间。它没有冻结,因为我可以对其进行测试并看到它正在计算,但是填充矩阵需要很长时间。这是熊猫的问题吗?有没有更好的解决方案来获取我想要的数据?
import numpy as np
from Bio import SeqIO
import pandas as pd
#Import the fasta files
seq1 = SeqIO.read("eyeless.fasta", "fasta")
seq2 = SeqIO.read("aniridia.fasta", "fasta")
#Initializes the matrix with blank values except for the top left corner which will be a 0
mat = pd.DataFrame(index=range(len(seq1.seq)+2), columns=pd.Series(range(len(seq2.seq)+2)))
mat.loc[0] = pd.Series(list('x'+'x'+seq2.seq))
mat[0] = pd.Series(list('x'+ 'x'+seq1.seq))
mat[1][1] = 0
#Initialize the first row and first column
for i in range(2,len(seq2.seq)+2):
mat[i][1] = mat[i-1][1] - 1
for j in range(2,len(seq1.seq)+2):
mat[1][j] = mat[1][j-1] - 1
print(mat)
v1 = 0
v2 = 0
#This section of the code goes through the matrix and determines if there will be a match, mismatch, or gap
for i in range(2,len(seq2.seq)+2):
for j in range(2,len(seq1.seq)+2):
#Match found, calculate score from this
if mat[i][0] == mat[0][j]:
v1 = mat[i-1][j-1] + 2
v2 = mat[i-1][j-1] - 1
mat[i][j] = max(v1,v2)
print("\nHere is the completed matrix:")
print(mat)
print("\nThe optimal score is:")
print(mat[len(t)+1][len(s)+1])
fasta 文件'eyeless' 是 X79493,'aniridia' 是来自https://www.ncbi.nlm.nih.gov的 AY707088 。
一开始我可以正确打印矩阵,但是在双 for 循环之后需要几分钟来计算。这是到目前为止我得到的输出的一个例子:这里注意这只是第一个的开始
print(mat)
陈述