blib/lib/Bioinfo/PBS.pm

filter: Statementstmt 36.3% 24 / 66 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 28.5% 4 / 14 Podpod 100% 4 / 4 totaltotal 31.3% 32 / 102 CC 8 SCAR 17.6
CC
8
Cov
30%
__ANON__
12.0
job_stat
12.0
get_sh
6.0
CRAP 5.8
« blib/lib/Bioinfo/Fasta.pm ↑ Summary blib/lib/Bioinfo/App/Cmd/Blast/Cmd/SplitSubmitB.pm »
1 package Bioinfo::PBS;
2 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use Modern::Perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use IO::All;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 our $VERSION = '0.1.14'; # VERSION:
8 # ABSTRACT: my perl module and CLIs for Biology
9  
10  
11 has cpu => (
12 is => 'rw',
13 isa => 'Int',
14 0 ▶ default => sub {'1'},
Subroutine __ANON__: not called CC=1 SCAR=6.9
15 2 lazy => 1,
16 );
17  
18  
19 has name => (
20 is => 'rw',
21 isa => 'Str',
22 0 ▶ default => sub { 'yanxq' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
23 2 lazy => 1,
24 );
25  
26  
27 has queue_name => (
28 is => 'rw',
29 isa => 'Str',
30 0 ▶ default => sub { 'batch' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
31 2 lazy => 1,
32 );
33  
34  
35 2 has cmd => (
36 is => 'rw',
37 isa => 'Str',
38 required => 1,
39 );
40  
41  
42 has path => (
43 is => 'rw',
44 isa => 'Str',
45 0 ▶ default => sub { '$PBS_O_WORKDIR' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
46 2 lazy => 1,
47 );
48  
49  
50 2 has job_id => (
51 is => 'ro',
52 writer => '_set_job_id',
53 isa => 'Int',
54 );
55  
56  
57 has priority => (
58 is => 'rw',
59 isa => 'Int',
60 0 ▶ default => sub { '1' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
61 2 lazy => 1,
62 );
63  
64 2 has _sh_name => (
65 is => 'rw',
66 isa => 'Str',
67 );
68  
69  
70 around BUILDARGS => sub {
71 0 ▶ my $orig = shift;
Subroutine __ANON__: not called CC=3 SCAR=24.8
72 0 my $class = shift;
73 0 ▶ my %para = @_ == 1 && ref $_[0] ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 && ref $_[0] ? : 0 0 0
Condition0%0/3
@_ == 1 and ref $_[0]
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and ref $_[0]
@_ == 1 ref $_[0]
Truth table0%0/3
A and B
A= @_ == 1B= ref $_[0]
ABresult
0X0
100
111
74 0 return $class->$orig(%para);
75 2 };
76  
77  
78  
79 sub get_sh {
80 0 ▶ my ($self, $sh_name) = @_;
Subroutine get_sh: not called CC=2 SCAR=17.9
Pod documented
81 0 ▶ $sh_name ||= $self->name . "_" . time . ".sh";
Condition0%0/2
$sh_name ||= $self->name . '_' . time . '.sh'
l!l
00
MC/DC0%0/1
$sh_name ||= $self->name . '_' . time . '.sh'
$sh_name
Truth table0%0/2
A
A= $sh_name
Aresult
11
00
82 0 my ($path, $cmd) = ($self->path, $self->cmd);
83 0 chdir $path;
84 0 my $sh_content =<<EOF;
85 cd $path
86 echo "Directory is $path"
87 NP=`cat \$PBS_NODEFILE|wc -l`
88 echo \$NP
89 echo "Excuting Hosts is flowing:"
90 cat \$PBS_NODEFILE
91 echo "begin time: `date`"
92 echo "CMD: $cmd"
93 $cmd
94 echo "finish time: `date`"
95 echo "DONE";
96 EOF
97 0 io($sh_name)->print($sh_content);
98 0 $self->_sh_name($sh_name);
99 #say "task setted attr sh_name:". $self->_sh_name. "\n";
100 0 return $sh_name;
101 }
102  
103  
104 sub qsub {
105 0 ▶ my $self = shift;
Subroutine qsub: not called CC=2 SCAR=17.9
Pod documented
106 0 my $sh_name = $self->get_sh;
107 0 my ($name, $cpu) = ($self->name, $self->cpu);
108 0 my $queue_name = $self->queue_name;
109 0 my $qsub_result = `qsub -l nodes=1:ppn=$cpu -q $queue_name -N $name $sh_name`;
110 0 say "qsub result: $qsub_result\n";
111 0 ▶ if ($qsub_result =~/^(\d+?)\./) {
Branch: 1 branch
BranchTrueFalseTotal
if ($qsub_result =~ /^(\d+?)\./u) { } 0 0 0
112 0 say "job_id: $1\n";
113 0 $self->_set_job_id($1);
114 } else {
115 0 say "Error: fail to qsub $sh_name; \nqsub output: $qsub_result\n";
116 }
117 0 return $self;
118 }
119  
120  
121 sub wait {
122 0 ▶ my $self = shift;
Subroutine wait: not called CC=2 SCAR=17.9
Pod documented
123 0 ▶ while ($self->job_stat) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->job_stat) 0 0 0
124 0 sleep(120);
125 }
126 0 return 0;
127 }
128  
129  
130 sub job_stat {
131 0 ▶ my $self = shift;
Subroutine job_stat: not called CC=3 SCAR=24.8
Pod documented
132 0 my $o = $self->name . ".o" . $self->job_id;
133 0 ▶ if (-e $o) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $o) { } 0 0 0
134 0 my $out = `tail -1 $o`;
135 0 chomp($out);
136 0 ▶ if ($out eq "DONE") {
Branch: 1 branch
BranchTrueFalseTotal
if ($out eq 'DONE') { } 0 0 0
137 0 return 0;
138 } else {
139 0 return 1;
140 }
141 } else {
142 0 return -1;
143 }
144 }
145  
146 2 __PACKAGE__->meta->make_immutable;
147  
148 2 1;
149  
150 __END__
151  
152 =pod
153  
154 =encoding UTF-8
155  
156 =head1 NAME
157  
158 Bioinfo::PBS - my perl module and CLIs for Biology
159  
160 =head1 VERSION
161  
162 version 0.1.14
163  
164 =head1 SYNOPSIS
165  
166 use Bioinfo::PBS;
167 my $para = {
168 cpu => 2,
169 name => 'blast',
170 cmd => 'ls -alh; pwd',
171 };
172 my $pbs_obj = Bioinfo::PBS->new($para);
173 $pbs_obj->qsub;
174  
175 =head1 DESCRIPTION
176  
177 This module is created to simplify process of task submitting in PBS system,
178 and waiting for the finish of multiple tasks.
179  
180 =head1 ATTRIBUTES
181  
182 =head2 cpu
183  
184 cpu number that will apply
185  
186 =head2 name
187  
188 prefix of output of STANDARD and ERR
189  
190 =head2 queue_name
191  
192 =head2 cmd
193  
194 the command that will be submitted to cluster
195  
196 =head2 path
197  
198 the path that cmd will execute in
199  
200 =head2 job_id
201  
202 the job id of qsub
203  
204 =head2 priority
205  
206 the priority during the process of Batch submmit in Queue
207  
208 =head1 METHODS
209  
210 =head2 get_sh
211  
212 get shell file that will used in qsub
213  
214 =head2 qsub
215  
216 submit the program to cluster
217  
218 =head2 wait
219  
220 wait until the program finished in cluster
221  
222 =head2 job_stat
223  
224 get the status of job. C<0> will be return if the job has completed
225  
226 =head1 AUTHOR
227  
228 Yan Xueqing <yanxueqing621@163.com>
229  
230 =head1 COPYRIGHT AND LICENSE
231  
232 This software is copyright (c) 2017 by Yan Xueqing.
233  
234 This is free software; you can redistribute it and/or modify it under
235 the same terms as the Perl 5 programming language system itself.
236  
237 =cut
« blib/lib/Bioinfo/Fasta.pm ↑ Summary blib/lib/Bioinfo/App/Cmd/Blast/Cmd/SplitSubmitB.pm »