これは長くなりますが、これを効果的に説明する方法が他にわかりません。
最初のファイルには文字のリストがあり、2 番目のファイルは 3 文字のリストで、一致する識別子文字 (タブで区切られています) です。
2 番目のファイルでは、3 文字をアイテムとして、1 文字を対応するキーとして辞書を作成しました。私がする必要があるのは、最初のリストから一度に 3 文字を取り出し、それを辞書と比較することです。一致する場合は、対応するキーを取得して、印刷する新しいリストに追加する必要があります。一致が「*」文字の場合、リストと辞書の比較を続行しないようにする必要があります。
追加機能を使用して比較してから新しいリストを作成するのに問題があります。
最初の入力ファイルの一部を次に示します。
Seq0
ATGGAAGCGAGGATGtGa
これが2番目の部分です:
AUU I
AUC I
AUA I
CUU L
GUU V
UGA *
これまでの私のコードは次のとおりです。
input = open("input.fasta", "r")
codons = open("codons.txt", "r")
counts = 1
amino_acids = {}
for lines in codons:
lines = lines.strip()
codon, acid = lines.split("\t")
amino_acids[codon] = acid
counts += 1
count = 1
for line in input:
if count%2 == 0:
line = line.upper()
line = line.strip()
line = line.replace(" ", "")
line = line.replace("T", "U")
import re
if not re.match("^[AUCG]*$", line):
print "Error!"
if re.match("^[AUCG]*$", line):
mrna = len(line)/3
first = 0
last = 3
while mrna != 0:
codon = line[first:last]
first += 3
last += 3
mrna -= 1
list = []
if codon == amino_acids[codon]:
list.append(acid)
if acid == "*":
mrna = 0
for acid in list:
print acid
したがって、出力を次のようにしたいと思います。
M L I V *
しかし、私はこれにさえ近づいていません。助けてください!