-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathphylip2fasta.py
executable file
·55 lines (38 loc) · 1.04 KB
/
phylip2fasta.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
#!/usr/bin/python
# formatting a fasta format into phylip format for using with PAML
import string, os, sys
if len(sys.argv) == 1:
print "put arguments!!"
print "USAGE: $phylip2fasta.py INPUT OUTPUT"
## INPUT
f1 = sys.argv[1]
F1 = open("%s" %f1, 'r')
## OUTPUT
f2 = sys.argv[2]
F2 = open("%s" %f2, 'w')
###### def1 ######
# Dans un multialignement fasta, cette fonction permet de formatter les noms de chaque sequence fasta
def format(File_IN):
c = 0
fichier = ""
while 1 :
c = c + 1
next = File_IN.readline()
if not next :
break
S1 = string.split(next, "\t")
fasta_name = S1[0]
#print fasta_name
fasta_seq = S1[1][:-1]
#print fasta_seq
fichier = fichier + ">" + fasta_name + "\n" + fasta_seq + "\n"
return (fichier,c)
#-#-#-#-#-#-#-#-#-#-#
###################
### RUN RUN RUN ###
###################
F1.readline() ## jump the first line
fichier_txt, c = format(F1) ### DEF1 ###
F2.write(fichier_txt)
F1.close()
F2.close()