annotate scripts/S01_phylip2fasta.py @ 5:0d2da4c020dc draft

planemo upload for repository https://github.com/abims-sbr/adaptsearch commit df6ba874c5e5f0cde12c9253b5c192e4a35f2280
author abims-sbr
date Thu, 18 Jan 2018 08:13:26 -0500
parents 49017ea906b5
children e0bea88bb09f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
1 #!/usr/bin/python
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
2
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
3 ## AUTHOR: Eric Fontanillas
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
4 ## LAST VERSION: 20/08/14 by Julie BAFFARD
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
5
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
6 ## DESCRIPTION: formatting a fasta format into phylip format for using with PAML
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
7
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
8 import string, os, sys
3
49017ea906b5 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit cf1b9c905931ca2ca25faa4844d45c908756472f
abims-sbr
parents: 2
diff changeset
9 """
2
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
10 if len(sys.argv) == 1:
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
11 print "put arguments!!"
3
49017ea906b5 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit cf1b9c905931ca2ca25faa4844d45c908756472f
abims-sbr
parents: 2
diff changeset
12 print "USAGE: S01_phylip2fasta.py INPUT OUTPUT"
49017ea906b5 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit cf1b9c905931ca2ca25faa4844d45c908756472f
abims-sbr
parents: 2
diff changeset
13 """
2
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
14
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
15 ## INPUT
5
0d2da4c020dc planemo upload for repository https://github.com/abims-sbr/adaptsearch commit df6ba874c5e5f0cde12c9253b5c192e4a35f2280
abims-sbr
parents: 3
diff changeset
16 """
3
49017ea906b5 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit cf1b9c905931ca2ca25faa4844d45c908756472f
abims-sbr
parents: 2
diff changeset
17 if os.path.isfile(sys.argv[1]) :
49017ea906b5 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit cf1b9c905931ca2ca25faa4844d45c908756472f
abims-sbr
parents: 2
diff changeset
18 f1 = sys.argv[1]
49017ea906b5 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit cf1b9c905931ca2ca25faa4844d45c908756472f
abims-sbr
parents: 2
diff changeset
19 else:
49017ea906b5 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit cf1b9c905931ca2ca25faa4844d45c908756472f
abims-sbr
parents: 2
diff changeset
20 print "No existing phylip file ; exiting ..."
49017ea906b5 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit cf1b9c905931ca2ca25faa4844d45c908756472f
abims-sbr
parents: 2
diff changeset
21 exit()
5
0d2da4c020dc planemo upload for repository https://github.com/abims-sbr/adaptsearch commit df6ba874c5e5f0cde12c9253b5c192e4a35f2280
abims-sbr
parents: 3
diff changeset
22 """
0d2da4c020dc planemo upload for repository https://github.com/abims-sbr/adaptsearch commit df6ba874c5e5f0cde12c9253b5c192e4a35f2280
abims-sbr
parents: 3
diff changeset
23 f1 = sys.argv[1]
2
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
24 F1 = open("%s" %f1, 'r')
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
25
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
26 ## OUTPUT
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
27 f2 = sys.argv[2]
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
28 F2 = open("%s" %f2, 'w')
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
29
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
30 ###### def1 ######
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
31 # Dans un multialignement fasta, cette fonction permet de formatter les noms de chaque sequence fasta
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
32
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
33 def format(File_IN):
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
34 c = 0
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
35 fichier = ""
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
36 while 1 :
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
37 c = c + 1
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
38 next = File_IN.readline()
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
39 if not next :
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
40 break
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
41
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
42 S1 = string.split(next, "\t") # list : [name, sequence] --- BUG CORRECTED : "\t" instead of " "
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
43 fasta_name = S1[0] # get sequence name
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
44 fasta_seq = S1[1][:-1] # get sequence without the terminal '\n'
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
45 fichier = fichier + ">" + fasta_name + "\n" + fasta_seq + "\n"
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
46
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
47 return (fichier,c)
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
48 #-#-#-#-#-#-#-#-#-#-#
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
49
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
50 ###################
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
51 ### RUN RUN RUN ###
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
52 ###################
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
53
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
54 F1.readline() ## jump the first line
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
55 fichier_txt, c = format(F1) ### DEF1 ###
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
56 F2.write(fichier_txt)
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
57 F1.close()
92615a423389 planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 44a89d5eeb82789bfc643b33c11f391281b6374b
abims-sbr
parents:
diff changeset
58 F2.close()