所以,我有这个代码:
def pairwiseScore(seqA, seqB):
score = 0
length = len(seqA)
similarity = []
for x in xrange(length):
if seqA[x] == seqB[x]:
if (x >= 1) and (seqA[x - 1] == seqB[x - 1]):
score += 3
similarity.append(x)
else:
score += 1
similarity.append(x)
else:
score -= 1
return ''.join((seqA, '\n', ''.join(['|'.rjust(x) for x in similarity]), '\n', seqB, '\n', 'Score: ', str(score)))
这是本练习的解决方案。
它几乎可以正常工作,但是,当我执行时:
print pairwiseScore("ATTCGT", "ATCTAT"), '\n', '\n', pairwiseScore("GATAAATCTGGTCT", "CATTCATCATGCAA")
我得到这个输出:
ATTCGT
|| |
ATCTAT
Score: 2
GATAAATCTGGTCT
| | | | | |
CATTCATCATGCAA
Score: 4
如您所见,这些管道(或垂直条)的格式不正确。
它应该如下所示:
>>> print pairwiseScore("ATTCGT", "ATCTAT")
ATTCGT
|| |
ATCTAT
Score: 2
>>> print pairwiseScore("GATAAATCTGGTCT", "CATTCATCATGCAA")
GATAAATCTGGTCT
|| ||| |
CATTCATCATGCAA
Score: 4
>>>
我的问题是:
这有什么问题:
''.join(['|'.rjust(x) for x in similarity]
功能?我必须如何编辑它,以使这些管道在输出时格式化良好?干杯!