所以这段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)) 发布于 2014-09-16 10:07:32
因为– != -
你用什么来编辑你的代码呢?文字处理器??
这些引述‘看起来也很可疑。使用不会将这些放入代码中的编辑器。
发布于 2014-09-16 10:07:43
下面的代码运行时没有错误:
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,我将括号保留在打印语句中。
要使代码运行,只需要更改两个命令:
my_dna的定义是一个多行字符串,因此它需要三个引号。另一方面,如果你希望它是一个单行字符串,那么就把它全部放在一行上。exon3_length行有两个问题:不平衡的括号和调用整数的尝试。在修复这些问题之后,代码就会运行。
不需要更改一个即可运行代码。
发布于 2014-09-16 10:16:19
这是代码中出错的部分:
exon3_length = (gene_length(my_dna.find('GATCGA'))
前面通过在gene_length字符串上调用len将dna定义为整数。
https://stackoverflow.com/questions/25859577
复制相似问题