在Python 3中比较DNA序列

时间:2015-01-30 19:17:52

标签: python string list python-3.x

到目前为止,我的计划是:

seq_a = "TGGAGGCAATGGCGGCCAGCA"
seq_b = "GACTCCTCCTCCTCCTGCTCA"    
len_a = len(seq_a)    
len_b = len(seq_b)    
print("Length of Sequence A: " + str(len_a))    
print()    
print("Length of Sequence B: " + str(len_b))
print()

def sequence_compare(seq_a, seq_b):
        len1 = len(seq_a)
        len2 = len(seq_b)
        mismatches = []
        for pos in range (0, min(len1, len2)) :
              if seq_a[pos] != seq_b[pos]:
                  mismatches.append('|')
              else:
                  mismatches.append(' ')
        print (seq_a)
        print (mismatches)
        print (seq_b)
sequence_compare(seq_a,seq_b)

我希望输出符合以下几行:

TGGAGGCAATGGCGGCCAGCA
||||||||| |||||||||
GACTCCTCCTCCTCCTGCTCA

但输出是:

TGGAGGCAATGGCGGCCAGCA
['|', '|', '|', '|', '|', '|', '|', '|', '|', ' ', '|', '|', '|', '|', '|', '|', '|', '|', '|', ' ', ' ']
GACTCCTCCTCCTCCTGCTCA

1 个答案:

答案 0 :(得分:5)

你很近..

print ("".join(mismatches))

将按照要求进行操作和打印

||||||||| |||||||||