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