comparison spp_wrapper.py @ 10:c57381059179 draft

Uploaded
author modencode-dcc
date Thu, 07 Feb 2013 23:06:21 -0500
parents dfdaa943f855
children d063cc917090
comparison
equal deleted inserted replaced
9:dfdaa943f855 10:c57381059179
45 cmdline = "%s -s=%s %s -x=%s -fdr=%s -npeak=%s %s %s" % ( cmdline, options['s'], options['speak'], options['x'], options['fdr'], options['npeak'], options['filtchr'], options['rf'] ) 45 cmdline = "%s -s=%s %s -x=%s -fdr=%s -npeak=%s %s %s" % ( cmdline, options['s'], options['speak'], options['x'], options['fdr'], options['npeak'], options['filtchr'], options['rf'] )
46 cmdline = "%s %s %s %s %s %s > default_output.txt" % ( cmdline, options['out'], options['savn'], options['savr'], options['savp'], options['savd'] ) 46 cmdline = "%s %s %s %s %s %s > default_output.txt" % ( cmdline, options['out'], options['savn'], options['savr'], options['savp'], options['savd'] )
47 47
48 #run cmdline 48 #run cmdline
49 #======================================================================================== 49 #========================================================================================
50 tmp_dir = tempfile.mkdtemp() 50 #tmp_dir = tempfile.mkdtemp()
51 tmp_dir = os.path.dirname(options['chip_file'])
51 stderr_name = tempfile.NamedTemporaryFile().name 52 stderr_name = tempfile.NamedTemporaryFile().name
52 proc = subprocess.Popen( args=cmdline, shell=True, cwd=tmp_dir, stderr=open( stderr_name, 'wb' ) ) 53 proc = subprocess.Popen( args=cmdline, shell=True, cwd=tmp_dir, stderr=open( stderr_name, 'wb' ) )
53 proc.wait() 54 proc.wait()
54 55
55 #Do not terminate if error code, allow dataset (e.g. log) creation and cleanup 56 #Do not terminate if error code, allow dataset (e.g. log) creation and cleanup
64 sys.stderr.write( chunk ) 65 sys.stderr.write( chunk )
65 66
66 67
67 #determine if the outputs are there, copy them to the appropriate dir and filename 68 #determine if the outputs are there, copy them to the appropriate dir and filename
68 #======================================================================================== 69 #========================================================================================
70 chip_name = os.path.basename(options['chip_file'])
71 input_name = os.path.basename(options['input_file'])
72
69 created_default_file = os.path.join( tmp_dir, "default_output.txt" ) 73 created_default_file = os.path.join( tmp_dir, "default_output.txt" )
70 if os.path.exists( created_default_file ): 74 if os.path.exists( created_default_file ):
71 shutil.move( created_default_file, output_default_file ) 75 shutil.move( created_default_file, output_default_file )
72 76
73 chip_name = os.path.basename(options['chip_file']) 77 created_narrow_peak = os.path.join( tmp_dir, "%s_VS_%s.narrowPeak" % (chip_name, input_name) )
74 input_name = os.path.basename(options['input_file'])
75 created_narrow_peak = os.path.join( tmp_dir, "%s_VS_%s.narrowPeak.gz" % (chip_name, input_name) )
76 if os.path.exists( created_narrow_peak ): 78 if os.path.exists( created_narrow_peak ):
77 shutil.move( created_narrow_peak, output_narrow_peak ) 79 shutil.move( created_narrow_peak, output_narrow_peak )
78 80
79 created_region_peak = os.path.join( tmp_dir, "%s_VS_%s.regionPeak.gz" % (chip_name, input_name) ) 81 created_region_peak = os.path.join( tmp_dir, "%s_VS_%s.regionPeak" % (chip_name, input_name) )
80 if os.path.exists( created_region_peak ): 82 if os.path.exists( created_region_peak ):
81 shutil.move( created_region_peak, output_region_peak ) 83 shutil.move( created_region_peak, output_region_peak )
82 84
83 created_peakshift_file = os.path.join( tmp_dir, "peakshift.txt" ) 85 created_peakshift_file = os.path.join( tmp_dir, "peakshift.txt" )
84 if os.path.exists( created_peakshift_file ): 86 if os.path.exists( created_peakshift_file ):
85 shutil.move( created_peakshift_file, output_peakshift_file ) 87 shutil.move( created_peakshift_file, output_peakshift_file )
86 88
87 created_rdata_file = os.path.join( tmp_dir, "%s.Rdata" % options['chip_file'] ) 89 created_rdata_file = os.path.join( tmp_dir, "%s.Rdata" % chip_name )
88 if os.path.exists( created_rdata_file ): 90 if os.path.exists( created_rdata_file ):
89 shutil.move( created_rdata_file, output_rdata_file ) 91 shutil.move( created_rdata_file, output_rdata_file )
90 92
91 created_plot_file = os.path.join( tmp_dir, "%s.pdf" % options['chip_file'] ) 93 created_plot_file = os.path.join( tmp_dir, "%s.pdf" % chip_name )
92 if os.path.exists( created_plot_file ): 94 if os.path.exists( created_plot_file ):
93 shutil.move( created_plot_file, output_plot_file ) 95 shutil.move( created_plot_file, output_plot_file )
94 96
95 97
96 os.unlink( stderr_name ) 98 os.unlink( stderr_name )