comparison TEisotools-1.0/commons/core/coord/align2set.py @ 6:20ec0d14798e draft

Uploaded
author urgi-team
date Wed, 20 Jul 2016 05:00:24 -0400
parents
children
comparison
equal deleted inserted replaced
5:4093a2fb58be 6:20ec0d14798e
1 #!/usr/bin/env python
2
3 import sys
4 import getopt
5 from commons.core.coord.Align import Align
6
7 def help():
8 print
9 print "usage: %s [ options ]" % ( sys.argv[0].split("/")[-1] )
10 print "options:"
11 print " -h: this help"
12 print " -i: input file name (format='align')"
13 print " -o: output file name (format='set', default=inFileName+'.set')"
14 print " -v: verbosity level (default=0/1)"
15 print
16
17
18 def align2set( inFileName, outFileName ):
19 alignFileHandler = open( inFileName, "r" )
20 setFileHandler = open( outFileName, "w" )
21 iAlign = Align()
22 countAlign = 0
23 while True:
24 line = alignFileHandler.readline()
25 if line == "":
26 break
27 countAlign += 1
28 iAlign.setFromString( line, "\t" )
29 setFileHandler.write( "%i\t%s\t%s\t%i\t%i\n" % ( countAlign,
30 iAlign.getSubjectName(),
31 iAlign.getQueryName(),
32 iAlign.getQueryStart(),
33 iAlign.getQueryEnd() ) )
34 alignFileHandler.close()
35 setFileHandler.close()
36
37
38 def main():
39
40 inFileName = ""
41 outFileName = ""
42 verbose = 0
43
44 try:
45 opts, args = getopt.getopt( sys.argv[1:], "hi:o:v:" )
46 except getopt.GetoptError, err:
47 print str(err)
48 help()
49 sys.exit(1)
50 for o,a in opts:
51 if o == "-h":
52 help()
53 sys.exit(0)
54 elif o == "-i":
55 inFileName = a
56 elif o == "-o":
57 outFileName = a
58 elif o == "-v":
59 verbose = int(a)
60
61 if inFileName == "":
62 print "ERROR: missing input file name"
63 help()
64 sys.exit(1)
65
66 if verbose > 0:
67 print "START %s" % ( sys.argv[0].split("/")[-1] )
68 sys.stdout.flush()
69
70 if outFileName == "":
71 outFileName = "%s.set" % ( inFileName )
72
73 #TODO: move 'align2set' into 'AlignUtils.convertAlignFileIntoPSetFile' with a test
74 # AlignUtils.convertAlignFileIntoPSetFile( inFileName, outFileName )
75
76 align2set( inFileName, outFileName )
77
78 if verbose > 0:
79 print "END %s" % ( sys.argv[0].split("/")[-1] )
80 sys.stdout.flush()
81
82 return 0
83
84
85 if __name__ == "__main__":
86 main()