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