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