Mercurial > repos > yufei-luo > s_mart
diff commons/tools/blast2align.py @ 18:94ab73e8a190
Uploaded
author | m-zytnicki |
---|---|
date | Mon, 29 Apr 2013 03:20:15 -0400 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/commons/tools/blast2align.py Mon Apr 29 03:20:15 2013 -0400 @@ -0,0 +1,75 @@ +#!/usr/bin/env python + +import sys +import getopt + + +def help(): + print + print "usage: blast2align.py [ options ]" + print "options:" + print " -h: this help" + print " -i: input file name (format=tabulated BLAST)" + print " -o: output file name (format=align, default=inFileName+'.align')" + print + + +def blast2align( inFile, outFile ): + inFileHandler = open( inFile, "r" ) + outFileHandler = open( outFile, "w" ) + while True: + line = inFileHandler.readline() + if line == "": + break + if line[0] != "#": + data = line.split("\t") + qryName = data[0] + sbjName = data[1] + percId = data[2] + qryStart = data[6] + qryEnd = data[7] + sbjStart = data[8] + sbjEnd = data[9] + Eval = data[10] + bitScore = data[11][:-1] + 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 ) + outFileHandler.write( string ) + inFileHandler.close() + outFileHandler.close() + + +def main(): + inFileName = "" + outFileName = "" + + try: + opts, args = getopt.getopt(sys.argv[1:],"hi:o:") + except getopt.GetoptError, err: + sys.stderr.write( "%s\n" % str(err) ) + help() + sys.exit(1) + for o,a in opts: + if o == "-h": + help() + sys.exit(0) + elif o == "-i": + inFileName = a + elif o == "-o": + outFileName = a + + if inFileName == "": + msg = "ERROR: missing input file name (-i)" + sys.stderr.write( "%s\n" % msg ) + help() + sys.exit(1) + + if outFileName == "": + outFileName = inFileName + ".align" + + blast2align( inFileName, outFileName ) + + return 0 + + +if __name__ == "__main__": + main()