-
Notifications
You must be signed in to change notification settings - Fork 8
/
transform_fasta_in_monoline.py
executable file
·74 lines (44 loc) · 1.6 KB
/
transform_fasta_in_monoline.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/python
# -*- coding: utf-8 -*-
#-------------------------------------
#
# SCRIPT PYTHON Trasnform_fasta_in_monoline.py
# Take a Fasta file. If sequences of a contig are split in several lines, it will paste them in one line
# Yan Holtz, yan1166@hotmail.com
#-------------------------------------
import os
import sys
import re
try:
import argparse
except ImportError:
print"oops, the import /argparse/ didn't work"
parser = argparse.ArgumentParser(description= '\n\nTake a Fasta file. If sequences of a contig are split in several lines, it will paste them in one line\n\n')
parser.add_argument('-input', required=True, help=' Fasta input ')
args = parser.parse_args()
fic1=args.input
#------------------------------------------------------------------------------------------------------
name=fic1+"_monoline"
tmp=open(name,"w")
debut="yes"
for line in open(fic1) :
line=line.strip()
if line.startswith(">") :
#1/ Je finis le contig précédent (sauf dans le cas du premier)
if debut != "yes":
tmp.write(sequence+"\n")
#2/ J'initialise le suivant.
tmp.write(line+"\n")
sequence=""
debut="no"
else :
sequence=sequence+line
#Attention a ne pas oublier la derniere séquence !
tmp.write(sequence)
#Et j'écrase le fichier d'origine
commande="mv "+name+" "+fic1
os.system(commande)
print "\n----------------------\n"
print "done ! Chaque séquence de votre Fasta ne prend maintenant qu'une seule ligne !"
print "\n----------------------\n"
#------------------------------------------------------------------------------------------------------