annotate splicetrap/bin/batchqsub.pl @ 7:37a16ff93dd9 draft default tip

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