2 回答
TA贡献1836条经验 获得超4个赞
我希望我没有替你做功课。我看到已经使用 .sub 发布了答案,但您只要求使用循环
def clean(text):
cleaned_text=""
for i in range(0, len(text)):
if text[i] in "agtc":
cleaned_text=cleaned_text+text[i]
else:
cleaned_text=cleaned_text+"n"
return cleaned_text
print(clean("agct7ttczttctgactgcaacgggcaatatgtctctxtgtggattaaaaaaagagtgtcygatagcagcttctgaactggttacctgcc"))
# returns agctnttcnttctgactgcaacgggcaatatgtctctntgtggattaaaaaaagagtgtcngatagcagcttctgaactggttacctgcc
TA贡献1876条经验 获得超6个赞
使用re.sub:
Import re
dna = 'gtgagtaaattaaaattttnttgacttaggtcactaaptactttaaccaatataggbatagcgcacagacagataaaaattacagagtac'
dna = re.sub(r'[^ACTG]','N',dna.upper())
print(dna)
添加回答
举报