-
Notifications
You must be signed in to change notification settings - Fork 9
/
12al.py
executable file
·73 lines (56 loc) · 1.94 KB
/
12al.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
70
71
72
73
### 12al.py - parse the mirdeep 2 output to the mysql supported output
#python 12al.py -i result_30_05_2012_t_13_17_20.csv -o miRNA_predictions
import sys, getopt
### main argument to
def options(argv):
inputfile = ''
outputfile = ''
try:
opts, args = getopt.getopt(argv,"hi:o:",["ifile=","ofile="])
except getopt.GetoptError:
print 'python 12al.py -i <inputfile> -o <outputfile>'
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print 'test.py -i <inputfile> -o <outputfile>'
sys.exit()
elif opt in ("-i", "--ifile"):
inputfile = arg
elif opt in ("-o", "--ofile"):
outputfile = arg
return inputfile, outputfile
def parse_file(inf,outf):
parse = False
def u2t(seq):
seq_t=''
for i in seq:
if i == 'u':
seq_t += 't'.upper()
else:
seq_t += i.upper()
return seq_t
### open the output file
o = open (outf,'w')
for line in open(inf,'r'):
line = line.strip()
if (len(line) >0):
if line.startswith('mature'):
parse = False
o.close()
if line.startswith('provisional id'):
parse = True
if parse == True:
token = line.split('\t')
string=''
for i in range(6):
o.write(token[i]+'\t')
o.write(u2t(token[13])+'\t')
for i in range(6,13):
o.write(token[i]+'\t')
o.write(token[14]+'\t'+token[15]+'\n')
if __name__ == "__main__":
inf,outf = options(sys.argv[1:])
### open the result output from the mirdeep2 and convert it to the mysql supported format
# 1. col 7 must be the read (12al.py)
# 2. read must only contain capital ATGC letters
parse_file(inf,outf)