Mercurial > repos > abims-sbr > blastalign
view scripts/S01_phylip2fasta.py @ 6:e0bea88bb09f draft
planemo upload for repository https://github.com/abims-sbr/adaptsearch commit 76e603ecd0118c8060d972b675a13db858956eb6
author | abims-sbr |
---|---|
date | Thu, 18 Jan 2018 09:02:24 -0500 |
parents | 0d2da4c020dc |
children |
line wrap: on
line source
#!/usr/bin/python ## AUTHOR: Eric Fontanillas ## LAST VERSION: 20/08/14 by Julie BAFFARD ## DESCRIPTION: 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: S01_phylip2fasta.py INPUT OUTPUT" """ ## INPUT if os.path.isfile(sys.argv[1]) : f1 = sys.argv[1] else: print "No existing phylip file ; exiting ..." exit() 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") # list : [name, sequence] --- BUG CORRECTED : "\t" instead of " " fasta_name = S1[0] # get sequence name fasta_seq = S1[1][:-1] # get sequence without the terminal '\n' 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()