所以这个python代码是给我的。这意味着它的工作,但显然我有问题。我只是想知道有没有人能告诉我出了什么问题?你知道吗
当我试着跑的时候,错误总是发生
intron1_length = ((my_dna.find(‘gtcata’)) –
(my_dna.find(‘atcgat’)))
错误为“-”。只是不知道应该去哪里。谢谢!你知道吗
# -*- coding: utf-8 -*-
# We’ll start with “data-aware” way to do this first.
# Since we have the sequence, we can see that exon 1 ends with
# ‘GACTA’. We can use that information, and that method, for
# finding the positions of the elements of this gDNA. This is NOT
# an elegant solution, and would not work if we didn’t know the
# DNA sequence ahead of time.
my_dna = "ATCGATCGATGGTCGAATGACTAgtcatagctatgcatgtagctactc
gatcgtattttattcgatcgatcgatCGATCGATCATGCTATCATCGATCGATATCGATGCATC
GACTACTATgtcatggctatgcatcgatcgtattttattcgatcgttcgatGATCGATCGATCGACTGACTTTGAA"
# here we introduce another useful operator for strings: len
gene_length = len(my_dna)
# we’ll use the starting position of useful substrings in the
# sequence to find the positions of the exon-intron boundaries.
# We’ll then use those to find the length of each segment.
exon1_length = (my_dna.find('Agtcata'))
intron1_length =((my_dna.find('gtcata')) - (my_dna.find('atcgat')))
exon2_length = ((my_dna.find('CGATCG'))- (my_dna.find('Tgtcatg')))
intron2_length = ((my_dna.find('gtcatg'))- (my_dna.find('tGATCGA')))
exon3_length = (gene_length(my_dna.find('GATCGA'))
print ("Gene length:" + str(gene_length))
print ("Exon1 length:" + str(exon1_length))
print ("Intron1 length:" + str(intron1_length))
print ("Exon2 length:" + str(exon2_length))
print ("Intron2 length:" + str(intron2_length))
print ("Exon2 length:" + str(exon3_length))
因为
–
!=-
你用什么来编辑你的代码?文字处理机??你知道吗
这些引语看起来也可疑。使用一个不把这些放在代码中的编辑器。你知道吗
以下代码运行正常:
我在打印语句中保留了括号,假设您使用的是Python3。您可能需要更改
exon3_length
行,因为我不清楚您的意图。你知道吗要使代码运行,只需更改两个命令:
my_dna
的定义是多行字符串,因此需要三个引号。另一方面,如果您希望它是一个单行字符串,那么将它全部放在一行上。exon3_length
行有两个问题:参数不平衡和试图调用整数。解决这些问题后,代码将运行。你知道吗
代码中使用的引号和减号(与摘录相反)很好。运行代码不需要更改任何一个。
这是代码出错的部分:
exon3_length = (gene_length(my_dna.find('GATCGA'))
gene_length
在前面通过调用dna字符串上的len
被定义为整数。另外,括号不正确,缺少一个括号来关闭外部括号(这是多余的)。你知道吗相关问题 更多 >
编程相关推荐