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'
41 LIMIT_TO_TAX_CODE = true
46 OUTPUT_OPT = 'OUTPUT:'
48 INPUT_PART = 'INPUT_PART:'
51 PBS_O_WORKDIR = '$PBS_O_WORKDIR/'
52 TMP_CMD_FILE_SUFFIX = '__QSUB'
55 if ( !File.exists?( PARAMETER_FILE ) )
56 puts( '[' + NAME + '] > parameters file "' + PARAMETER_FILE + '" not found' )
59 puts( '[' + NAME + '] > reading ' + PARAMETER_FILE )
67 open( PARAMETER_FILE ).each { |line|
68 if ( line.length > 1 && line =~ /^[^#]\S+/ )
69 if line =~ /^#{PRG}\s+(\S+)/
72 if line =~ /^\s*#{OPT}\s+(\S+.+)/
75 if line =~ /^\s*#{VOPT}\s+(\S+.+)/
78 if line =~ /^\s*#{SUFFIX}\s+(\S+)/
81 if line =~ /^\s*#{INPUT_PART}\s+(\S+)/
84 if line =~ /^\s*#{OUTPUT_OPT}\s+(\S+.+)/
90 puts( '[' + NAME + '] > no program name found in parameters file "' + PARAMETER_FILE + '"' )
93 puts( '[' + NAME + '] > program: ' + prg )
94 puts( '[' + NAME + '] > option : ' + opt )
96 puts( '[' + NAME + '] > voption: ' + vopt )
98 puts( '[' + NAME + '] > suffix : ' + suffix )
99 if ( input_part.length > 0 )
100 puts( '[' + NAME + '] > input: ' + input_part )
102 if ( output_opt.length > 0 )
103 puts( '[' + NAME + '] > output opt : ' + output_opt )
109 files = Dir.entries( "." )
112 if ( !File.directory?( file ) && file !~ /^\./ && file !~ /#{PARAMETER_FILE}/ )
114 if ( input_part.length > 0 && file !~ /#{input_part}/ )
119 outputfile = file.to_str
121 if outputfile =~ /^([A-Z0-9]{3,5})[_\.]/
126 if outputfile =~ /(.+)\..{1,5}/
130 if output_opt.length > 0
132 output_opt + ' ' + PBS_O_WORKDIR + outputfile + suffix + ' ' +
134 PBS_O_WORKDIR + file.to_str +
136 elsif vopt.length > 0
137 cmd = prg + ' ' + opt + ' ' + vopt + ' ' + PBS_O_WORKDIR + file.to_str +
138 ' > ' + PBS_O_WORKDIR + vopt + "_" + outputfile + suffix
140 cmd = prg + ' ' + opt + ' ' + PBS_O_WORKDIR + file.to_str +
141 ' > ' + PBS_O_WORKDIR + outputfile + suffix
143 tmp_cmd_file = file.to_str + TMP_CMD_FILE_SUFFIX
144 if File.exists?( tmp_cmd_file )
145 File.delete( tmp_cmd_file )
147 open( tmp_cmd_file, 'w' ) do |f|
150 puts( '[' + NAME + '] > excuting ' + cmd )
151 IO.popen( 'qsub ' + tmp_cmd_file , 'r+' ) do |pipe|
156 if File.exists?( tmp_cmd_file )
157 File.delete( tmp_cmd_file )
162 puts( '[' + NAME + '] > OK.' )