こんにちは私は、DNAの各塩基の塩基含有量を計算する簡単なプログラムを作成しようとしています。私は私の現在の設定または「no_c定義されていません」「no_c代入する前に参照した」と私は問題を解決する方法を見つけ出すことはできません割り当てエラーを取得しておく。Pythonのインスタンス変数?代入エラーを取得し続ける
#!/usr/bin/python
#computing the atgc content of a DNA string
class Base_counter(object):
def __init__(self, DNA):
self.DNA = DNA
no_c = 0
no_a = 0
no_g= 0
no_t= 0
def c_counter(self):
for base in self.DNA:
if base == 'c':
no_c = no_c + 1
return no_c
def g_counter(self):
for base in self.DNA:
if base == 'g':
no_g+=1
return no_g
def a_counter(self):
for base in self.DNA:
if base == 'a':
no_a+=1
return no_a
def t_counter(self):
for base in self.DNA:
if base == 't':
no_a+=1
return no_t
def gc_percentage(self):
return no_c + no_g/len(self.DNA)
def at_percentage(self):
return no_a + no_t/len(self.DNA)
def g_percentage(self):
return no_g/len(self.DNA)
def a_percentage(self):
return no_a/len(self.DNA)
def t_percentage(self):
return no_t/len(self.DNA)
def c_percentage(self):
return no_c/len(self.DNA)
def main():
dna= 'gcgctat'
analyzer = Base_counter(dna)
print analyzer.no_c
print analyzer.c_counter()
#print analyzer.c_percentage()
if __name__ == '__main__':
main()
問題に遭遇したときの設定を説明するのではなく、後で人々が検索するのに役立つように、質問にタグを付けるようにしてください。例えば、この質問は、バイオインフォマティクスまたはDNAシーケンシングとは関係がありません。 –