comparison bismark_methylation_extractor.py @ 3:91f07ff056ca draft

Uploaded
author bgruening
date Mon, 14 Apr 2014 16:43:14 -0400
parents 62c6da72dd4a
children
comparison
equal deleted inserted replaced
2:82814a8a2395 3:91f07ff056ca
25 parser = argparse.ArgumentParser(description='Wrapper for the bismark methylation caller.') 25 parser = argparse.ArgumentParser(description='Wrapper for the bismark methylation caller.')
26 26
27 # input options 27 # input options
28 parser.add_argument( '--bismark_path', dest='bismark_path', help='Path to the bismark perl scripts' ) 28 parser.add_argument( '--bismark_path', dest='bismark_path', help='Path to the bismark perl scripts' )
29 29
30 parser.add_argument( '--infile', help='Input file in SAM format.' ) 30 parser.add_argument( '--infile', help='Input file in SAM or BAM format.' )
31 parser.add_argument( '--single-end', dest='single_end', action="store_true" ) 31 parser.add_argument( '--single-end', dest='single_end', action="store_true" )
32 parser.add_argument( '--paired-end', dest='paired_end', action="store_true" ) 32 parser.add_argument( '--paired-end', dest='paired_end', action="store_true" )
33 33
34 parser.add_argument( '--report-file', dest='report_file' ) 34 parser.add_argument( '--report-file', dest='report_file' )
35 parser.add_argument( '--comprehensive', action="store_true" ) 35 parser.add_argument( '--comprehensive', action="store_true" )
36 parser.add_argument( '--merge-non-cpg', dest='merge_non_cpg', action="store_true" ) 36 parser.add_argument( '--merge-non-cpg', dest='merge_non_cpg', action="store_true" )
37 parser.add_argument( '--no-overlap', dest='no_overlap', action="store_true" ) 37 parser.add_argument( '--no-overlap', dest='no_overlap', action="store_true" )
38 parser.add_argument( '--compress' ) 38 parser.add_argument( '--compress' )
91 if args.merge_non_cpg: 91 if args.merge_non_cpg:
92 additional_opts += ' --merge_non_CpG ' 92 additional_opts += ' --merge_non_CpG '
93 if args.report_file: 93 if args.report_file:
94 additional_opts += ' --report ' 94 additional_opts += ' --report '
95 95
96 96 #detect BAM file, use samtools view if it is a bam file
97 # Final command: 97 f = open (args.infile, 'rb')
98 cmd = cmd % (output_dir, additional_opts, args.infile) 98 sig = f.read(4)
99 f.close()
100 if sig == '\x1f\x8b\x08\x04' :
101 cmd = cmd % (output_dir, additional_opts, '-')
102 cmd = 'samtools view %s | %s' % (args.infile, cmd )
103 else :
104 cmd = cmd % (output_dir, additional_opts, args.infile)
99 105
100 # Run 106 # Run
101 try: 107 try:
102 tmp_out = tempfile.NamedTemporaryFile().name 108 tmp_out = tempfile.NamedTemporaryFile().name
103 tmp_stdout = open( tmp_out, 'wb' ) 109 tmp_stdout = open( tmp_out, 'wb' )