Mercurial > repos > xuebing > sharplabtool
comparison tools/next_gen_conversion/solid_to_fastq.py @ 0:9071e359b9a3
Uploaded
| author | xuebing |
|---|---|
| date | Fri, 09 Mar 2012 19:37:19 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:9071e359b9a3 |
|---|---|
| 1 #!/usr/bin/env python | |
| 2 | |
| 3 """ | |
| 4 Converts SOLiD data to Sanger FASTQ format. | |
| 5 | |
| 6 usage: %prog [options] | |
| 7 -i, --input1=i: Forward reads file | |
| 8 -q, --input2=q: Forward qual file | |
| 9 -I, --input3=I: Reverse reads file | |
| 10 -Q, --input4=Q: Reverse qual file | |
| 11 -o, --output1=o: Forward output | |
| 12 -r, --output2=r: Reverse output | |
| 13 | |
| 14 usage: %prog forward_reads_file forwards_qual_file reverse_reads_file(or_None) reverse_qual_file(or_None) output_file ouptut_id output_dir | |
| 15 """ | |
| 16 | |
| 17 import os, sys, tempfile | |
| 18 from galaxy import eggs | |
| 19 import pkg_resources; pkg_resources.require( "bx-python" ) | |
| 20 from bx.cookbook import doc_optparse | |
| 21 | |
| 22 def stop_err( msg ): | |
| 23 sys.stderr.write( "%s\n" % msg ) | |
| 24 sys.exit() | |
| 25 | |
| 26 def replaceNeg1(fin, fout): | |
| 27 line = fin.readline() | |
| 28 while line.strip(): | |
| 29 fout.write(line.replace('-1', '1')) | |
| 30 line = fin.readline() | |
| 31 fout.seek(0) | |
| 32 return fout | |
| 33 | |
| 34 def __main__(): | |
| 35 #Parse Command Line | |
| 36 options, args = doc_optparse.parse( __doc__ ) | |
| 37 # common temp file setup | |
| 38 tmpf = tempfile.NamedTemporaryFile() #forward reads | |
| 39 tmpqf = tempfile.NamedTemporaryFile() | |
| 40 tmpqf = replaceNeg1(file(options.input2,'r'), tmpqf) | |
| 41 # if paired-end data (have reverse input files) | |
| 42 if options.input3 != "None" and options.input4 != "None": | |
| 43 tmpr = tempfile.NamedTemporaryFile() #reverse reads | |
| 44 # replace the -1 in the qualities file | |
| 45 tmpqr = tempfile.NamedTemporaryFile() | |
| 46 tmpqr = replaceNeg1(file(options.input4,'r'), tmpqr) | |
| 47 cmd1 = "%s/bwa_solid2fastq_modified.pl 'yes' %s %s %s %s %s %s 2>&1" %(os.path.split(sys.argv[0])[0], tmpf.name, tmpr.name, options.input1, tmpqf.name, options.input3, tmpqr.name) | |
| 48 try: | |
| 49 os.system(cmd1) | |
| 50 os.system('gunzip -c %s >> %s' %(tmpf.name,options.output1)) | |
| 51 os.system('gunzip -c %s >> %s' %(tmpr.name,options.output2)) | |
| 52 except Exception, eq: | |
| 53 stop_err("Error converting data to fastq format.\n" + str(eq)) | |
| 54 tmpr.close() | |
| 55 tmpqr.close() | |
| 56 # if single-end data | |
| 57 else: | |
| 58 cmd1 = "%s/bwa_solid2fastq_modified.pl 'no' %s %s %s %s %s %s 2>&1" % (os.path.split(sys.argv[0])[0], tmpf.name, None, options.input1, tmpqf.name, None, None) | |
| 59 try: | |
| 60 os.system(cmd1) | |
| 61 os.system('gunzip -c %s >> %s' % (tmpf.name, options.output1)) | |
| 62 except Exception, eq: | |
| 63 stop_err("Error converting data to fastq format.\n" + str(eq)) | |
| 64 tmpqf.close() | |
| 65 tmpf.close() | |
| 66 sys.stdout.write('converted SOLiD data') | |
| 67 | |
| 68 if __name__=="__main__": __main__() |
