我在获取代码以打印任何内容时遇到问题。 M是一个矩阵,其中包含RNA序列CAUCGGUAU中碱基之间的所有可能配对。该代码的目的是显示对的最佳数量以及这些对在链上的位置。此代码运行,但不会返回l,因为“名称l未定义”。 l应该是包含对的向量。
M = buildmatrix('CAUCGGUAU') p =“ CAUCGGUAU”
def find(M,p):
n=len(p) #length of the RNA sequence
maxlevels=int(M [0,n-1])
lower=np.zeros(maxlevels) #making vectors with all zero elements
upper=np.zeros(maxlevels)
ii=min(1,maxlevels-1)
lower[ii]=0 #this is the position on the chain where pairing can begin, 0 is the first position on the sequence
upper[ii]=n-1 #this is the end of the chain
l=[] #an empty vector that will later contain the optimal pairs
while len(l) < maxlevels:
i=int(lower[ii])
j=int(upper[ii])
if M[i,j]==M[i,j-1]:
upper[ii]=j-1 #the chain has been broken into two sub chains, j-1 is the final position on the sub-chain
else:
t=int(maxovert(i,j,M,p)[0]) #t is the position on the chain where a new bond forms and the chain is split
#into two sub-chains.
l.append([t,j]) #joining the l vector with the values of t and j
ii=ii-1
if M(t+1,j)>0:
ii=ii+1
lower[ii]=t+1 #the second sub-chain begins at position t+1 after a bond has been formed at position t
upper[ii]=j #j is the final position in the sub-chain
if M[i,max(t-1,i)]==0:
ii=ii+1
lower[ii]=i #the first position on the first sub-chain
upper[ii]=t-1 #the last position on the second chain
return l