@@ -0,0 +1,1549 @@
+#! /usr/bin/python%0A%0Aimport sys%0Aimport argparse%0Aimport os.path%0Aimport re%0Aimport gzip%0A%0A%0A%0A#define global variables%0Acomments = %5B%5D%0Acalls = %5B%5D%0Afilecount=1%0A###DEFINING FUNCTIONS%0A%0A%0A###%0Aparser = argparse.ArgumentParser(description='split vcf file into n sub files')%0Aparser.add_argument('in_vcf', metavar='%3CVCF file%3E', help='input vcf file (gzipped possible)')%0Aparser.add_argument('-n', '--number', action='store', metavar='%3Cint%3E', type=int, default=100000, help='number of calls per file')%0Aparser.add_argument('-o', '--out_prefix', action='store', metavar='%3Cstring%3E', default='out', help='prefix for output files, the file number will be appended to this')%0Aargs = parser.parse_args()%0A%0A#check input%0Aif len(sys.argv) %3C 2:   #if the script is called without any arguments display the usage%0A    parser.print_usage()%0A    sys.exit(1)%0A%0Aif not os.path.isfile(args.in_vcf):%0A%09print %22Please provide path to valid vcf file%22%0A%09sys.exit(0)%0A%0Aprint %22Splitting %25s into chunks of %25s calls -%3E fileprefix: %25s%22 %25(args.in_vcf, args.number, args.out_prefix) %0A%0Aif args.in_vcf.endswith(%22gz%22):%0A%09FH = gzip.open(args.in_vcf,'rb')%0Aelse:%0A%09FH = open(args.in_vcf,'r')%0A%0Afor line in FH:%0A%09if line.startswith(%22#%22):%0A#%09%09print line%0A%09%09comments.append(line)%0A%09else:%0A%09%09calls.append(line)%0A%0A%09if len(calls) == args.number:%0A%09%09print %22writing: %25s-%2508d.vcf%22 %25(args.out_prefix, filecount)%0A%09%09OUT = open(args.out_prefix+%22-%2508d.vcf%22 %25(filecount), 'w')%0A%09%09for l in comments:%0A%09%09%09OUT.write(l)%0A%09%09for c in calls:%0A%09%09%09OUT.write(c)%0A%09%09filecount+=1%0A%09%09calls = %5B%5D%0A%09%09OUT.close()%0A#%09%09OUT = open(args.out_prefix+%22%22)%0A%0AFH.close()%0A%0A%0A

split vcf