annotate commons/core/coord/align2set.py @ 6:769e306b7933

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