-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatchRun.pl
More file actions
executable file
·83 lines (66 loc) · 2.15 KB
/
batchRun.pl
File metadata and controls
executable file
·83 lines (66 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/perl -w
if(scalar(@ARGV) < 2) {
print "Usage: ~ [-p number_of_processes] [-r replaceString] -c 'cluster_cmd' '<cmd with _str_>' <str1> ... <strN>\n";
print "e.g. ~ 'head _str_' /tmp/*.csv\n";
print " _serial_ will be replaced by an automatically assigned serial ID starting from 0\n";
print " ~ -p run in parallel. Default is to run serially (number of processes is 1)\n";
print " ~ -r the string to be replaced. Default is '_str_'\n";
print " ~ -c 'runbuqsub.pl partition long' 'partition.pl _str_ REGION /tmp/region' /tmp/chr*.geneRegion.csv\n";
print " each /tmp/chr?.geneRegion.csv will be run as 'runbuqsub.pl partition.chr?.geneRegion long partition _str_ REGION /tmp/region\n\n";
exit(1);
}
use Flat;
use Util;
use Getopt::Std;
use Parallel::ForkManager;
use Term::ProgressBar;
my(%options);
getopts("p:r:c:", \%options);
my $cluster = (exists $options{"c"})?$options{"c"}:"";
my $rstr = (exists $options{"r"})?$options{"r"}:"_str_";
my $cmd = shift @ARGV;
my @strs = expandIndice(@ARGV);
my $count = 0;
my($pm); # process manager
my(@pids) = ();
if(exists $options{"p"}) {
$pm = new Parallel::ForkManager($options{"p"});
}
else {
$pm = new Parallel::ForkManager(1);
}
my($num) = scalar(@strs);
my $progress_bar = Term::ProgressBar->new($num);
foreach $s (@strs) {
$count++;
my $c = $cmd;
$c =~ s/$rstr/$s/g;
$c =~ s/_serial_/$count/g;
if($cluster) {
my($dir, $stem, $suf) = Util::getDirStemSuffix($s);
my @args = split(/\s+/, $cluster);
$args[1] .= $stem;
$c = join(" ", @args, $c);
}
# https://stackoverflow.com/questions/16538708/how-to-limit-the-child-process-in-perl
$pm->start and next;
system( $c );
$progress_bar->update($count);
$pm->finish;
}
print "_____________________________DONE_____________________________\n";
sub expandIndice {
my(@arr) = @_;
my(@results) = ();
foreach $a (@arr) {
if($a =~ /\-\-/) {
my($start, $end) = split(/\-\-/, $a);
print "start = $start, end = $end\n";
map { push @results, $_; } ($start .. $end);
}
else {
push @results, $a;
}
}
return @results;
}