-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht_coffee_to_fasta.py
55 lines (33 loc) · 1.04 KB
/
t_coffee_to_fasta.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
def convert_tcoffee_to_fasta(filename):
'''
(str) -> None
Read the t-coffee alignment files and save the alignment in fasta format in a text file
'''
tcoffee = open(filename, 'r')
tcoffee.readline()
tcoffee.readline()
ali = {}
for line in tcoffee:
line = line.rstrip()
if line != '':
line = line.split()
if '*' in line[0]:
continue
elif line[0] in ali:
ali[line[0]] += line[1]
else:
ali[line[0]] = line[1]
alignment = open(filename[:-4] + '.txt', 'w')
for gene in ali:
alignment.write('>' + gene + '\n')
alignment.write(ali[gene] + '\n')
tcoffee.close()
alignment.close()
def get_cbrcsp9_fasta(L):
'''
(list) -> None
Convert each tcoffee files in the list L into a fasta file
'''
# hint: assign os.listdir to a variable to get the list of files
for file in L:
convert_tcoffee_to_fasta(file)