blib/lib/Bioinfo/App/Cmd/Blast/Cmd/SplitSubmitB.pm untested

filter: Statementstmt 0.0% 0 / 85 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 97 CC 3 SCAR 16.7
CC
3
Cov
0%
execute
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 5.3
1 package Bioinfo::App::Cmd::Blast::Cmd::SplitSubmitB;
2 use Modern::Perl;
3 use Moo;
4 use MooX::Cmd;
5 use MooX::Options prefer_commandline => 1;
6 use IO::All;
7 use Bioinfo::PBS::Queue;
8  
9 our $VERSION = '0.1.14'; # VERSION:
10 # ABSTRACT: submit blast after splitting a fasta file into multiple files;
11  
12  
13 option indir => (
14 is => 'ro',
15 required => 1,
16 format => 's',
17 short => 'i',
18 doc => 'the dir include fasta format file'
19 );
20  
21  
22 option split_num => (
23 is => 'ro',
24 format => 'i',
25 short => 's',
26 default => sub { '20' },
27 doc => 'number of files that the fasta file will be split. Default:20'
28 );
29  
30  
31 option blast_cpu => (
32 is => 'ro',
33 format => 'i',
34 short => 'c',
35 default => sub { '8' },
36 doc => 'cpu number will be used by blastp in each node of Cluster.default:8',
37 );
38  
39  
40 option parallel_task_num => (
41 is => 'ro',
42 format => 'i',
43 short => 'p',
44 default => sub { '20' },
45 doc => 'the task number will be running at the same time. default:20',
46 );
47  
48  
49 option db => (
50 is => 'rw',
51 format => 's',
52 short => 'd',
53 default => sub { 'nr_plant' },
54 doc => 'the database that blast will use, should be absolute path. default:nr_plant',
55 );
56  
57  
58 option type => (
59 is => 'rw',
60 format => 's',
61 short => 't',
62 default => sub { 'pbs' },
63 doc => "where the blast will be runned [local, pbs] default:pbs"
64 );
65  
66  
67 option blast => (
68 is => 'rw',
69 format => 's',
70 short => 'b',
71 default => sub { 'blastp' },
72 doc => 'which blast program will be used default:blastp',
73 );
74  
75  
76 option queue_name => (
77 is => 'rw',
78 format => 's',
79 short => 'n',
80 default => sub { 'blast_' . time },
81 doc => 'which blast program will be used default:blast.time',
82 );
83  
84  
85 option max_target_seqs => (
86 is => 'rw',
87 format => 's',
88 short => 'm',
89 default => sub { 10 },
90 doc => 'the parameter used in blast. default:10',
91 );
92  
93  
94 option outfmt => (
95 is => 'rw',
96 format => 's',
97 short => 'f',
98 default => sub { 5 },
99 doc => 'the parameter used in blast default:5',
100 );
101  
102  
103 option prefix => (
104 is => 'ro',
105 format => 's',
106 short => 'x',
107 default => sub { '' },
108 doc => 'the prefix of the split file',
109 );
110  
111  
112 option evalue => (
113 is => 'ro',
114 format => 's',
115 short => 'e',
116 default => sub { '1e-5' },
117 doc => 'evalue parameter passed to blast',
118 );
119  
120  
121  
122  
123 sub execute {
124 my ($self, $args_ref, $chain_ref) = @_;
125 $self->options_usage unless (@$args_ref);
126 my $indir = $self->indir;
127 my $blast = $self->blast;
128 my $cpu = $self->blast_cpu;
129 my $parallel_task_num = $self->parallel_task_num;
130 #my $db = io($self->db)->absolute->pathname;
131 my $db = $self->db;
132 my $queue_name = $self->queue_name;
133 my $split_num = $self->split_num;
134 my $prefix = $self->prefix;
135 my $max_target_seqs = $self->max_target_seqs;
136 my $outfmt = $self->outfmt;
137 my $evalue = $self->evalue;
138 my @fa_dirs;
139  
140 my @io_fas = io($indir)->filter(sub {$_->filename =~/\.pep$|\.fa$|\.fasta$/})->all_files;
141 my $pbs = Bioinfo::PBS::Queue->new( name => $queue_name,
142 parallel => $parallel_task_num);
143  
144 for my $fa (@io_fas) {
145 my $fa_name = $fa->filename;
146 my $fa_name_short = $fa_name;
147 $fa_name_short =~s/\.fa|\.pep|\.fasta//;
148  
149 push @fa_dirs, $fa_name_short;
150 system("biotools fasta split -i $fa_name -n $split_num -o $fa_name_short");
151 my $path = io("$fa_name_short")->absolute->pathname;
152 for (my $i = 1; $i <= $split_num; $i++) {
153 my $fasta = "$prefix$i.fa";
154 my $cmd;
155 if ($outfmt == 5) {
156 #say "blast output mode: 5";
157 my $outfile = "$fasta.xml";
158 $cmd = "$blast -query $fasta -out $outfile -db $db -parse_deflines -outfmt $outfmt -evalue $evalue -num_threads $cpu -max_target_seqs $max_target_seqs";
159 $cmd .= "\nbiotools blast parsexml -i $outfile -o $fasta.xls";
160 } else {
161 #say "blast output mode: 6";
162 my $outfile = "$fasta.xls";
163 $cmd = "$blast -query $fasta -out $outfile -db $db -parse_deflines -outfmt $outfmt -evalue $evalue -num_threads $cpu -max_target_seqs $max_target_seqs";
164 }
165 # say $cmd;
166 my $para = {
167 cpu => $cpu,
168 name => $i,
169 cmd => $cmd,
170 path => $path,
171 };
172 $pbs->add_tasks($para);
173 }
174 }
175 $pbs->execute;
176 for my $dir (@fa_dirs) {
177 system("cat $dir/*xls >$dir.xls");
178 system("cat $dir/*xls.m8 >$dir.xls.m8");
179 }
180 say "finished";
181  
182 }
183  
184 1;
185  
186 __END__
187  
188 =pod
189  
190 =encoding UTF-8
191  
192 =head1 NAME
193  
194 Bioinfo::App::Cmd::Blast::Cmd::SplitSubmitB - submit blast after splitting a fasta file into multiple files;
195  
196 =head1 VERSION
197  
198 version 0.1.14
199  
200 =head1 SYNOPSIS
201  
202 use Bioinfo::App::Cmd::Blast::Cmd::SplitSubmitB;
203 Bioinfo::App::Cmd::Blast::Cmd::SplitSubmit->new_with_cmd;
204  
205 example:
206 biotools blast splitsubmitb -c 1 -d /path/db -i ./ -m 2 -p 7 -s 10 -n blastt
207  
208 =head1 DESCRIPTION
209  
210 this module splits a fasta file into multiple files, then submit these files on parallel.
211  
212 =head1 ATTRIBUTES
213  
214 =head2 indir
215  
216 The input file is a file of fasta format
217  
218 =head2 split_num
219  
220 number of files that the fasta file will be split
221  
222 =head2 blast_cpu
223  
224 the cpu number will be set on blast
225  
226 =head2 parallel_task_num
227  
228 the task number will be running at the same time
229  
230 =head2 db
231  
232 the database that blast will use
233  
234 =head2 type
235  
236 =head2 blast
237  
238 the subcomand in blast+, such as [blastp blastx],default:blastp
239  
240 =head2 queue_name
241  
242 the name of PBS queue
243  
244 =head2 max_target_seqs
245  
246 the parameter used in blast
247  
248 =head2 outfmt
249  
250 parameter used in blast
251  
252 =head2 prefix
253  
254 the prefix of the split file
255  
256 =head2 evalue
257  
258 parameter passed to blast
259  
260 =head1 METHODS
261  
262 =head2 execute
263  
264 =head1 AUTHOR
265  
266 Yan Xueqing <yanxueqing621@163.com>
267  
268 =head1 COPYRIGHT AND LICENSE
269  
270 This software is copyright (c) 2017 by Yan Xueqing.
271  
272 This is free software; you can redistribute it and/or modify it under
273 the same terms as the Perl 5 programming language system itself.
274  
275 =cut