我对Python还比较陌生。有没有一种方法可以递归地执行这个函数?我正在寻找匹配对,并排除带有“+”的不匹配对
integ = 3 #number of sequences
evenList = ['GAAGCTCG', 'AAATTT', 'CTCTAGGAC']
oddList = ['CCTCGGGA', 'GGGCCC', 'GAGTACCTG']
def matchList(evenList, oddList, integ):
indexElement = 0
indexList = 0
totalIndexSeq = []
at_List = ['AT', 'TA', 'at', 'ta']
gc_List = ['GC', 'CG', 'gc', 'cg']
for x in evenList:
indexedSeq = ''
for y in x:
if y + oddList[indexList][indexElement] in gc_List:
indexedSeq += str(indexElement)
indexElement += 1
elif y + oddList[indexList][indexElement] in gc_List:
indexedSeq += str(indexElement)
indexElement += 1
elif y + oddList[indexList][indexElement] in at_List:
indexedSeq += str(indexElement)
indexElement += 1
elif y + oddList[indexList][indexElement] in at_List:
indexedSeq += str(indexElement)
indexElement += 1
else:
indexedSeq += "+"
indexElement += 1
indexList += 1
indexElement -= indexElement
totalIndexSeq.append(indexedSeq)
return (totalIndexSeq)
#This returns the positions with mismatched pairs omitted by a "+"
# When you print 'totalIndexSeq'
#['0+234+6+']
#['0+234+6+', '++++++']
#['0+234+6+', '++++++', '012++5678']
它可以做得更简单(是关于DNA上的基因编码吗?):
您对列表的长度没有任何限制(实际上您在代码中也没有使用
integ
)。现在你得告诉我你想递归哪一部分? 我通常建议不要递归,因为资源使用率很高这不适合评论,所以这里是评论(不是答案)。代码是相当冗余的,这使得事情很难识别。相当于:
相关问题 更多 >
编程相关推荐