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