你是怎么做的-&引用;用python?

你是怎么做的-&引用;用python?,python,Python,所以这段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.

所以这段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)) 

因为
!=<代码>-

你用什么来编辑你的代码?文字处理机


这些引号
看起来也很可疑。使用不将这些内容放入代码中的编辑器。

因为
!=<代码>-

你用什么来编辑你的代码?文字处理机


这些引号
看起来也很可疑。使用不将这些内容放入代码中的编辑器。

下面的代码运行时不会出错:

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。您可能需要更改
外显子3_长度
行,因为我不清楚您的意图

要使代码运行,只需更改两个命令:

  • my_dna
    的定义是一个多行字符串,因此需要三个引号。另一方面,如果您希望它是一个单行字符串,那么将它全部放在一行上

  • exon3\u length
    行有两个问题:参数不平衡和试图调用整数

修复这些问题后,代码将运行


代码中使用的引号和减号(与摘录相反)很好。运行代码不需要更改任何代码。

下面的代码运行时不会出错:

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。您可能需要更改
外显子3_长度
行,因为我不清楚您的意图

要使代码运行,只需更改两个命令:

  • my_dna
    的定义是一个多行字符串,因此需要三个引号。另一方面,如果您希望它是一个单行字符串,那么将它全部放在一行上

  • exon3\u length
    行有两个问题:参数不平衡和试图调用整数

修复这些问题后,代码将运行


代码中使用的引号和减号(与摘录相反)很好。运行代码不需要更改任何内容。

这是代码中出错的部分:

exon3\u长度=(基因长度(my\u dna.find('GATCGA'))


先前通过调用dna字符串上的
len
gene\u length
定义为整数。此外,括号不正确,缺少一个括号来关闭外部的一个(这是多余的)。

这是代码出错的部分:

exon3\u长度=(基因长度(my\u dna.find('GATCGA'))


gene\u length
之前通过调用dna字符串上的
len
定义为整数。此外,括号不正确,缺少一个括号来关闭外部的一个(这是多余的)。

'atcgat'
不是
'atcgat'
。请确保您实际使用了正确的引号;“智能引号”会弄乱你的代码。你正在使用大量不必要的括号。我建议你减少使用这些括号;你有一些错误涉及不匹配的括号。“错误不断发生”-请自己报告错误。如果你去看医生,你不会光着身子喊“检查我!”,你告诉他所有的症状。具体来说,你得到了什么错误?那么“atcgat”应该是什么呢?发生了很多错误,我的印象是代码工作了,但显然没有。如果这有关系的话,我正在通过unix在textwrangler上运行它。奇怪的是,textwrangler说它可以用于编程。你的文件是否有
.py
扩展名?
'atcgat'
不是
'atcgat'
。请确保您实际使用了正确的引号;“智能引号”会弄乱您的代码。您使用了大量不必要的括号。我建议减少这些括号;您会遇到一些错误,其中包括不匹配的括号。“错误不断发生”-请自己报告错误。如果你去看医生,你不会光着身子喊“检查我!”,你告诉他所有的症状。具体来说,你得到了什么错误?那么“atcgat”应该是什么呢?发生了很多错误,我的印象是代码工作了,但显然没有。如果这有关系的话,我正在通过unix在textwrangler上运行它。奇怪的是,textwrangler说它可以用于编程。你的文件是否有
.py
extension?这行吗?外显子3长度=(基因长度-(my_dna.find('GATCGA'))是的,但请像这样去除多余的参数
gene_长度-my_dna.find('GATCGA')
这行吗?外显子3长度=(基因长度-(my dna.find('GATCGA'))是的,但是请去掉多余的部分,比如基因长度-我的dna.find('GATCGA')