основной:
stops = ['TAA','TAG','TGA']
names = {} file = '/Users/svetlana/Downloads/E.coli.sequence.txt' with open(file, 'r') as fasta:
- for line in fasta:
if line[0] == '>':
- header = line.strip()[1:]
names[header] =
- names[header] += line.strip()
- header = line.strip()[1:]
for key, val in names.items():
- for i in range(0,len(val[:-3]),3):
- if val[i:i+3] in stops:
- print(key) break
- if val[i:i+3] in stops:
вспомогательный:
stops = {'TGA': 0,
- 'TAA': 0, 'TAG': 0}
file = input() with open(file, 'r') as fasta:
sec = for line in fasta:
if line[0] != '>':
- sec += line.strip()
- if sec[i:i+3] in stops:
- stops[sec[i:i+3]] += 1
with open('out.txt', 'w') as output:
- for key, val in stops.items():
- print(key, val, sep=' ', file=output)