-
Notifications
You must be signed in to change notification settings - Fork 9
/
100b_fasta2flat.py
47 lines (37 loc) · 1.09 KB
/
100b_fasta2flat.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
'''
Created on Feb 25, 2013
@author: vgupta
'''
### script was made for formatting the longest ORF to flat file
### check output with
# python ~/script/python/100b_fasta2flat.py -i 02_Stegodyphous_cdna.refined.fa.orf.tr_longest_frame
import os,sys,getopt, re
from C_loadFasta import *
### main argument to
def options(argv):
infile = ''
gff3 = ''
try:
opts, args = getopt.getopt(argv,"hi:",["ifile="])
except getopt.GetoptError:
print 'python 100b_fasta2flat.py -i <inputfile>'
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print 'python 100b_fasta2flat.py -i <inputfile>'
sys.exit()
elif opt in ("-i", "--ifile"):
infile = arg
return infile
def makeflat(file):
o = open('flat_file.txt','w')
for line in open(file,'r'):
line = line.strip()
if line[0]=='>':
o.write('\n'+line.split('_fr')[0][1:] +'\t')
else:
o.write(line)
o.close()
if __name__ == "__main__":
file = options(sys.argv[1:])
makeflat(file)