1 #!/usr/local/bin/ruby -w
5 # Copyright:: Copyright (C) 2006-2008 Christian M. Zmasek
6 # License:: GNU Lesser General Public License (LGPL)
8 # $Id: rb_dir_qsub.rb,v 1.15 2009/11/07 02:06:59 cmzmasek Exp $
10 # To execute qsub commands.
11 # Submits PRG for every file in the current directory.
13 # Examples for PARAMETER_FILE:
15 # PRG: /home/user/SOFTWARE/HMMER/hmmer-2.3.2/src/hmmpfam
16 # OPT: -E 20 -A 0 /home/user/DATA/PFAM/Pfam_ls
17 # SUFFIX: _hmmpfam_22_20_ls
19 # PRG: /home/user/SOFTWARE/WUBLAST/tblastn
25 # PRG: /home/czmasek/SOFTWARE/HMMER/hmmer-3.0b2/binaries/intel-linux-x86_64/hmmscan
26 # OPT: -E 2 --notextw --qformat fasta /home/czmasek/DATA/PFAM/PFAM240/Pfam-A.hmm
27 # SUFFIX: .hmmscan30b2_240
31 module ForesterScripts
33 if RUBY_VERSION !~ /1.9/
34 puts( "Your ruby version is #{RUBY_VERSION}, expected 1.9.x " )
38 PARAMETER_FILE = 'parameters.rb_dir_qsub'
45 OUTPUT_OPT = 'OUTPUT:'
47 INPUT_PART = 'INPUT_PART:'
50 PBS_O_WORKDIR = '$PBS_O_WORKDIR/'
51 TMP_CMD_FILE_SUFFIX = '__QSUB'
54 if ( !File.exists?( PARAMETER_FILE ) )
55 puts( '[' + NAME + '] > parameters file "' + PARAMETER_FILE + '" not found' )
58 puts( '[' + NAME + '] > reading ' + PARAMETER_FILE )
66 open( PARAMETER_FILE ).each { |line|
67 if ( line.length > 1 && line =~ /^[^#]\S+/ )
68 if line =~ /^#{PRG}\s+(\S+)/
71 if line =~ /^\s*#{OPT}\s+(\S+.+)/
74 if line =~ /^\s*#{VOPT}\s+(\S+.+)/
77 if line =~ /^\s*#{SUFFIX}\s+(\S+)/
80 if line =~ /^\s*#{INPUT_PART}\s+(\S+)/
83 if line =~ /^\s*#{OUTPUT_OPT}\s+(\S+.+)/
89 puts( '[' + NAME + '] > no program name found in parameters file "' + PARAMETER_FILE + '"' )
92 puts( '[' + NAME + '] > program: ' + prg )
93 puts( '[' + NAME + '] > option : ' + opt )
95 puts( '[' + NAME + '] > voption: ' + vopt )
97 puts( '[' + NAME + '] > suffix : ' + suffix )
98 if ( input_part.length > 0 )
99 puts( '[' + NAME + '] > input: ' + input_part )
101 if ( output_opt.length > 0 )
102 puts( '[' + NAME + '] > output opt : ' + output_opt )
108 files = Dir.entries( "." )
111 if ( !File.directory?( file ) && file !~ /^\./ && file !~ /#{PARAMETER_FILE}/ )
113 if ( input_part.length > 0 && file !~ /#{input_part}/ )
118 outputfile = file.to_str
120 if outputfile =~ /(.+)\..{1,5}/
124 if output_opt.length > 0
126 output_opt + ' ' + PBS_O_WORKDIR + outputfile + suffix + ' ' +
128 PBS_O_WORKDIR + file.to_str +
130 elsif vopt.length > 0
131 cmd = prg + ' ' + opt + ' ' + vopt + ' ' + PBS_O_WORKDIR + file.to_str +
132 ' > ' + PBS_O_WORKDIR + vopt + "_" + outputfile + suffix
134 cmd = prg + ' ' + opt + ' ' + PBS_O_WORKDIR + file.to_str +
135 ' > ' + PBS_O_WORKDIR + outputfile + suffix
137 tmp_cmd_file = file.to_str + TMP_CMD_FILE_SUFFIX
138 if File.exists?( tmp_cmd_file )
139 File.delete( tmp_cmd_file )
141 open( tmp_cmd_file, 'w' ) do |f|
144 puts( '[' + NAME + '] > excuting ' + cmd )
145 IO.popen( 'qsub ' + tmp_cmd_file , 'r+' ) do |pipe|
150 if File.exists?( tmp_cmd_file )
151 File.delete( tmp_cmd_file )
156 puts( '[' + NAME + '] > OK.' )