-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplace.py
More file actions
50 lines (36 loc) · 1.81 KB
/
Copy pathreplace.py
File metadata and controls
50 lines (36 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#fin1 X aa, fin2 nultide,fout1 new file
#! /bin/python
with open(r"/home/bowen/AzoFC2-heterodimer/20_select/re-name/aa.fasta", "r") as fin1:
with open(r"/home/bowen/AzoFC2-heterodimer/20_select/re-name/aa-nul-final-3", "w") as fout1:
with open(r"/home/bowen/AzoFC2-heterodimer/20_select/re-name/aa-nul.fasta", "r") as fin2:
# part 1
seq_name = []
char_index = []
for line in fin1.readlines():
line = line.strip()
if line.startswith(">"):
seq_name.append(line.split(">")[1])
else:
char_index.append([index for index, char in enumerate(line) if char == 'F'])
seq_char_index = dict(zip(seq_name, char_index))
seq_char_index = {k: v for k, v in seq_char_index.items() if len(v) != 0}
# part 2
seq_name = []
seq_info = []
for line in fin2.readlines():
line = line.strip()
if line.startswith(">"):
seq_name.append(line.split(">")[1])
else:
seq_info.append([line[i:i+3] for i in range(0, len(line), 3)])
seq_info = dict(zip(seq_name, seq_info))
for key, value in seq_info.items():
if key not in seq_char_index.keys():
seq_info[key] = [x if x not in ["TTC", "TTT"] else "TAG" for x in value]
else:
for index, codon in enumerate(value):
if codon in ["TTC", "TTT"] and index not in seq_char_index[key]:
seq_info[key][index] = "TAG"
for key, value in seq_info.items():
fout1.write(">" + str(key) + "\n")
fout1.write(''.join([x for x in value]) + "\n")