comparison bin/batchqsub.pl @ 1:adc0f7765d85 draft

planemo upload
author bioitcore
date Thu, 07 Sep 2017 15:06:58 -0400
parents
children
comparison
equal deleted inserted replaced
0:d4ca551ca300 1:adc0f7765d85
1
2 # modified from Chenghai Xue's script
3
4 #test if qsub works
5
6 my $qsub_checker = 0;
7 if(system("hash qsub >/dev/null"))
8 {
9 $qsub_checker = 0;
10 }
11 else
12 {
13 $test_randname=random_sessid();
14 system("mkdir $test_randname;");
15 system("echo 'mkdir $test_randname/$test_randname' >$test_randname/$test_randname.sh");
16 system("mkdir $test_randname/qsub_cache");
17 system ("qsub -cwd -v TMPDIR=$test_randname/qsub_cache -V -e $test_randname/qsub_cache -o $test_randname/qsub_cache -N $test_randname $test_randname/$test_randname.sh");
18
19 $status=0;
20 $sec=5;
21 while(1)
22 {
23 $chkresult=`qstat |grep $test_randname |wc -l`;
24 chomp($chkresult);
25 if ($chkresult == 0)
26 {
27 $sec=10;
28 $status++;
29 last if ($status==3);
30 }
31 else
32 {
33 $status=0;
34 $sec=5;
35 }
36 print "QSTAT: $chkresult testing tasks running.....$taskname\n";
37 sleep($sec);
38 }
39 print "QSUB: testing done\n";
40 print "$test_randname/$test_randname\n";
41 if(-d "$test_randname/$test_randname")
42 {
43 $qsub_checker=1;
44 print "QSUB: working well!\n";
45 }
46 #$qsub_checker=`qsub </dev/null 2>&1|grep stdin|wc -l`;
47 system("rm $test_randname -rf");
48 }
49 #$qsub_checker=0;
50 if($qsub_checker == 0)
51 {
52 print "QSUB: No GRID qsub found\n";
53 print "QSUB: if you are using PBS qsub, please wait for the next version! Thanks.\n";
54 print "QSUB: Running in serial mode...\n";
55 system("sh $ARGV[0]");
56 exit;
57 }
58
59 $performListFile = $ARGV[0];
60 $taskname = "";
61 $taskname = $ARGV[1];
62 if (not $taskname)
63 {
64 $taskname=random_sessid();
65 }
66 #$outfullDir = $ARGV[2];
67 $outfullDir ="qsub_cache";
68
69 # correct path
70 if(! (-d $outfullDir) ){
71 system ("mkdir $outfullDir");
72 }
73
74 # create a temp cache
75 @temp = split("/", $0);
76 $prog = pop @temp;
77 $cache = $outfullDir."/".$prog."_".$taskname;
78 if(! (-d $cache) ){
79 system ("mkdir $cache");
80 }
81
82 open (IN_1, "$performListFile") or die "can not open file $performListFile to read\n";
83 @performList = (<IN_1>);
84 chomp @performList;
85 close IN_1 or die "can't close the input file : $!";
86
87
88 $scriptListFile = $outfullDir."/".$taskname."_scripts.list";
89 open (FSCRIPLIST, ">$scriptListFile");
90 for($i=0; $i<@performList; $i++){
91 $scriptFile = $outfullDir."/".$taskname."_script$i.sh";
92 print FSCRIPLIST "$scriptFile\n";
93 open (FOUT, ">$scriptFile");
94
95 # print FOUT "#!/usr/bin/sh\n";
96 print FOUT "$performList[$i]\n";
97
98 # print OUT_1 "$outfile.map\n";
99 close (FOUT);
100 }
101 close (FSCRIPLIST);
102
103 open (IN_2, "$scriptListFile") or die "can not open file $scriptListFile to read\n";
104 $basename=`basename $performListFile`;
105 chop($basename);
106 $taskname=$taskname."_".$basename;
107 #print $basename;
108 while(<IN_2>){
109 $f = $_;
110 chomp $f;
111 @temp = split("/", $f);
112 $base = pop @temp;
113
114 #use default queues
115 # print "/opt/n1ge6/bin/lx24-amd64/qsub -l virtual_free=1.7G -cwd -v TMPDIR=$cache -V -e $cache -o $cache -N $taskname.$base $f\n\n\n";
116 #system ("qsub -l virtual_free=1.7G -cwd -v TMPDIR=$cache -V -e $cache -o $cache -N $taskname.$base $f");
117 system ("qsub -cwd -v TMPDIR=$cache -V -e $cache -o $cache -N $taskname.$base $f");
118
119 }
120 close IN_2 or die "can't close the input file : $!";
121
122 #start to check stats of qsub tasks
123 #######################################
124 my $taskname_query=substr($taskname,0,10);
125
126
127 $status=0;
128 $sec=60;
129 while(1)
130 {
131 $chkresult=`qstat |grep $taskname_query |wc -l`;
132 chomp($chkresult);
133 if ($chkresult == 0)
134 {
135 $sec=10;
136 $status++;
137 last if ($status==3);
138 }
139 else
140 {
141 $status=0;
142 $sec=60;
143 }
144 print "QSTAT: $chkresult tasks running.....$taskname\n";
145 sleep($sec);
146 }
147 print "QSUB: done: $taskname \n";
148 ######################################
149
150 #
151 sub random_sessid
152 {
153 #my @chars = (0..9,a..z,A..Z);
154 my @chars = ('a'..'z','A'..'Z');
155 my $len = 10;
156 my $string = join '', map {$chars[rand(@chars)]} (1..$len);
157 return $string;
158 }