python - 如何识别有效的 DNA 序列?
问题描述
我刚刚开始学习如何在 python 中编码,并将其应用于生物信息学领域。不过,我在下一个程序时遇到了麻烦:
首先你引入一个 dna 序列(由 g、c、t、a 和 n 组成),使用命令 dna=input("enter your sequence: ")
然后,我尝试确定 DNA 序列是否只有 g、c、t、a 和 n 字符(不具体按该顺序)。如果没有,我希望程序说:不对,再输入一个序列;然后让你输入一个新的序列(并重复检查过程)。如果它只有这些字符,我希望程序继续前进,但我无法做到这一点。
到目前为止,这或多或少是我所做的......它适用于具有 3 个或更多字符的序列,但是如果您在“不对,请再次输入序列:”之后写一个字母(无论哪个),它就会明白当它不是时,它是一个有效的序列。
def Start():
dna=input("Enter a sequence: ")
for i in range(len(dna)):
if dna[i] not in "actgn":
dna=input("Not right, enter a sequence again: ")
else:
break
print("here the program will continue")
解决方案
尝试这个:
dna=input("Enter a sequence: ")
sequenceCorrect = False
while not sequenceCorrect:
sequenceCorrect = True
for i in range(len(dna)):
if dna[i] not in "actgn":
sequenceCorrect = False
if not sequenceCorrect:
dna=input("Incorrect Sequence Please Try Again: ")
print("here the program will continue")
推荐阅读
- sql - 如何用 MAX 小计
- php - Docker 连接到本地主机
- android - 什么时候在 Kotlin 中传递函数类型是有益的?
- c# - 如果请求模型不正确,则 OnActionExecuting 不执行
- javascript - UnhandledPromiseRejectionWarning:SyntaxError:JSON 输入意外结束
- javascript - Angular 材质 mat-menu 重新加载页面
- python - 计算不包括开始日期的工作日,并使用 busday_count 包括结束日期
- firebase - 如何自动更新和回滚 Firebase 托管站点 + Cloud Run 服务?
- c# - 在托管服务中添加多个队列
- alert - 将 EMA 添加到警报查询