나는 입력 파일에서 DNA 서열을 취하여 루프를 사용하여 개별 A의 T 's C 's와 G 's의 수를 세고, "ATCG"가 아닌 문자가 있다면 I 예를 들어 내 입력 파일이 "오류"를 인쇄해야합니다for 루프로 파이썬 계산 뉴클레오티드
Seq1 AAAGCGT Seq2 금주 모임 tGcGt의 t Seq3 AF GtgA cCTg
I가 함께 왔어요 코드 :
acount = 0
ccount = 0
gcount = 0
tcount = 0
for line in input:
line=line.strip('\n')
if line[0] == ">":
print line + "\n"
output.write(line+"\n")
else:
line=line.upper()
list=line.split()
for list in line:
if list == "A":
acount = acount +
#print acount
elif list == "C":
ccount = ccount +
#print ccount
elif list == "T":
tcount = tcount +
#print tcount
elif list == "G":
gcount=gcount +1
#print gcount
elif list != 'A'or 'T' or 'G' or 'C':
break
그래서 각 줄에 총계가 있어야하지만 내 코드는 전체 파일에 대해 A의 T 's 등을 합산합니다. 내 출력이 원하는 뭔가
같은 Seq1 : 총 A의 3 총 C의 : 등 각 시퀀스.
달성을 위해 내 코드를 해결하기 위해 할 수있는 아이디어가 있습니까?
import re
def countNucleotides(filePath):
aCount = []
gCount = []
cCount = []
tCount = []
with open(filePath, 'rb') as data:
for line in data:
if not re.match(r'[agctAGCT]+',line):
break
aCount.append(notCount(line,'a'))
gCount.append(notCount(line,'g'))
cCount.append(notCount(line,'c'))
tCount.append(notCount(line,'t'))
def notCount(line, character):
appearances = 0
for item in line:
if item == character:
appearances += 1
return appearances
당신은 그러나 인쇄 할 수 있습니다 당신은 그 후 싶습니다
각 for 루프 반복의 처음에'acount'를 재설정하십시오. – Blender