annotate commons/tools/blast2align.py @ 19:9bcfa7936eec

Deleted selected files
author m-zytnicki
date Mon, 29 Apr 2013 03:23:29 -0400
parents 94ab73e8a190
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
1 #!/usr/bin/env python
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
2
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
3 import sys
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
4 import getopt
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
5
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
6
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
7 def help():
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
8 print
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
9 print "usage: blast2align.py [ options ]"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
10 print "options:"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
11 print " -h: this help"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
12 print " -i: input file name (format=tabulated BLAST)"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
13 print " -o: output file name (format=align, default=inFileName+'.align')"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
14 print
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
15
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
16
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
17 def blast2align( inFile, outFile ):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
18 inFileHandler = open( inFile, "r" )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
19 outFileHandler = open( outFile, "w" )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
20 while True:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
21 line = inFileHandler.readline()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
22 if line == "":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
23 break
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
24 if line[0] != "#":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
25 data = line.split("\t")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
26 qryName = data[0]
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
27 sbjName = data[1]
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
28 percId = data[2]
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
29 qryStart = data[6]
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
30 qryEnd = data[7]
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
31 sbjStart = data[8]
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
32 sbjEnd = data[9]
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
33 Eval = data[10]
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
34 bitScore = data[11][:-1]
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
35 string = "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n" % ( qryName, qryStart, qryEnd, sbjName, sbjStart, sbjEnd, Eval, bitScore, percId )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
36 outFileHandler.write( string )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
37 inFileHandler.close()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
38 outFileHandler.close()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
39
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
40
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
41 def main():
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
42 inFileName = ""
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
43 outFileName = ""
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
44
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
45 try:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
46 opts, args = getopt.getopt(sys.argv[1:],"hi:o:")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
47 except getopt.GetoptError, err:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
48 sys.stderr.write( "%s\n" % str(err) )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
49 help()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
50 sys.exit(1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
51 for o,a in opts:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
52 if o == "-h":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
53 help()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
54 sys.exit(0)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
55 elif o == "-i":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
56 inFileName = a
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
57 elif o == "-o":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
58 outFileName = a
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
59
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
60 if inFileName == "":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
61 msg = "ERROR: missing input file name (-i)"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
62 sys.stderr.write( "%s\n" % msg )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
63 help()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
64 sys.exit(1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
65
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
66 if outFileName == "":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
67 outFileName = inFileName + ".align"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
68
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
69 blast2align( inFileName, outFileName )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
70
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
71 return 0
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
72
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
73
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
74 if __name__ == "__main__":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
75 main()