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_x.rb,v 1.8 2008/09/16 23:31:39 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
26 module ForesterScripts
28 if RUBY_VERSION !~ /1.9/
29 puts( "Your ruby version is #{RUBY_VERSION}, expected 1.9.x " )
33 PARAMETER_FILE = 'parameters.rb_dir_x'
40 OUTPUT_OPT = 'OUTPUT:' # TODO e.g. > or -o
42 INPUT_PART = 'INPUT_PART:'
46 if ( !File.exists?( PARAMETER_FILE ) )
47 puts( '[' + NAME + '] > parameters file "' + PARAMETER_FILE + '" not found' )
50 puts( '[' + NAME + '] > reading ' + PARAMETER_FILE )
57 open( PARAMETER_FILE ).each { |line|
58 if ( line.length > 1 && line =~ /^[^#]\S+/ )
59 if line =~ /^#{PRG}\s+(\S+)/
62 if line =~ /^\s*#{OPT}\s+(\S+.+)/
65 if line =~ /^\s*#{VOPT}\s+(\S+.+)/
68 if line =~ /^\s*#{SUFFIX}\s+(\S+)/
71 if line =~ /^\s*#{INPUT_PART}\s+(\S+)/
77 puts( '[' + NAME + '] > no program name found in parameters file "' + PARAMETER_FILE + '"' )
80 puts( '[' + NAME + '] > program: ' + prg )
81 puts( '[' + NAME + '] > option : ' + opt )
83 puts( '[' + NAME + '] > voption: ' + vopt )
85 puts( '[' + NAME + '] > suffix : ' + suffix )
86 if ( input_part.length > 0 )
87 puts( '[' + NAME + '] > input : ' + input_part )
93 files = Dir.entries( "." )
96 if ( !File.directory?( file ) && file !~ /^\./ && file !~ /#{PARAMETER_FILE}/ )
98 if ( input_part.length > 0 && file !~ /#{input_part}/ )
104 cmd = 'nohup ' + prg + ' ' + opt + ' ' + vopt + ' ' + file.to_str +
105 ' > ' + vopt + "_" + file.to_str + suffix + ' &'
107 cmd = 'nohup ' + prg + ' ' + opt + ' ' + file.to_str +
108 ' > ' + file.to_str + suffix + ' &'
111 puts( '[' + NAME + '] > excuting ' + cmd )
113 spawn( cmd, STDERR => "/dev/null" )
115 IO.popen( cmd , 'r+' ) do |pipe|
125 puts( '[' + NAME + '] > OK.' )