2014-05-23 56 views
-3

我試着從Biopython開始。所以我可以在其中做我的論文。但這真的讓我思考三次。顯示功能丟失,當我嘗試一個整數值時,它不起作用,並且字符串的情況也是如此。請幫助。謝謝。Biopython - 字符串分配錯誤

鏈接:

http://imgur.com/87Gw9E5

+0

「它不起作用」是一個非常模糊的錯誤描述。 – timgeb

+3

你'while'條件是檢查0是否大於某物的長度。你實際上並沒有顯示「功能」的定義,但除非它是某種可怕的被黑客入侵的對象,它以某種方式返回一個負值,否則你的循環永遠不會運行。 – geoffspear

回答

1

Biopython的傢伙實際上很容易處理這些功能。你的問題是字符串管理(普通的Python)。我已使用format,但您可以使用%運算符。

另外在Python中,你很少在循環時保持計數。 Python不是C.

from Bio import SeqIO 

for record in SeqIO.parse("NG_009616.gb", "genbank"): 

    # You don't have to take care of the number of features with a while 
    # Loop all of them. 
    for feature in record.features: 
     print "Attributes of feature" 
     print "Type {0}".format(feature.type) 
     print "Start {0}".format(feature.location.start) 
     print "End {0}".format(feature.location.end) 
     print "Qualifiers {0}".format(feature.qualifiers) 
     # This is the right way to extract the sequence: 
     print "Sequence {0}".format(feature.location.extract(record).seq) 
     print "Sub-features {0}".format(feature.sub_features) 
2

Biopython似乎相當強勁對我來說,可能的誤差是由於它的經驗不足。

你有幾個錯誤,其中之一是你忘了用「」結束字符串。下面的幾行

print "location start, features[ftNum].location.start # note location.start" 
print "feature qualifiers,features[ftNum].qualifiers" 

應更正爲

print "location start", features[ftNum].location.start # note location.start 
print "feature qualifiers", features[ftNum].qualifiers 

此外,由於Wooble指出了while循環的條件是錯誤的。我猜你的意思是反轉「>」,也就是說,功能的數量應該大於零。

請添加一些示例數據和錯誤消息。