-1
我是編程新手,希望這只是一個簡單的修復。除了當我試圖在序列中查找N
的數目時,所有內容都正在工作。這是我使用的代碼:我得到一個TypeError:並非所有在字符串格式化過程中轉換的參數
from __future__ import division
print "Sequence Information"
f = open('**,fasta','r')
while True:
seqId = f.readline()
#Check if there are still lines
if not seqId: break
seqId = seqId.strip()[1:]
seq = f.readline()
# Find the %GC
gcPercent = ((seq.count('G') + seq.count('g') + seq.count('c') + seq.count('C'))/(len(seq)) *100)
N = (seq.count('N') + 1)
print "%s\t%d\t%.4f" % (seqId, len(seq), gcPercent, N)
我不斷收到以下錯誤:
Traceback (most recent call last):
File "length", line 20, in <module>
print "%s\t%d\t%.4f" % (seqId, len(seq), gcPercent, N)
TypeError: not all arguments converted during string formatting
我怎麼做,所以我可以的N
值添加到第4列?
爲什麼不加上anot她的'\ t%d'呢? – 2014-12-03 18:11:03
你在字符串中有3個'%',但是在下面有4個值! – Kasramvd 2014-12-03 18:11:35
是的,那工作。謝謝! *臉掌* – 2014-12-03 18:17:16