如何让我的代码从RNA链生成成对的序列?

2024-09-29 23:31:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我在让我的代码打印任何东西时遇到问题。M是包含RNA序列CAUCGGUAU中碱基之间所有可能配对的矩阵。代码的目的是显示最佳对数以及这些对在链上的位置。此代码运行,但不返回l,因为“名称l未定义”。l应该是一个包含这些对的向量

M=构建矩阵('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

Tags: ofthe代码chainifisonposition

热门问题