annotate TEisotools-1.1.a/commons/core/coord/align2set.py @ 15:255c852351c5 draft

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