Egaz/Command/template.pm

filter: Statementstmt 89.5% 197 / 220 Branchbran 56.3% 53 / 94 Conditioncond 73.3% 11 / 15 MC/DCmcdc 40.0% 4 / 10 Subroutinesub 100% 21 / 21 Podpod 37.5% 6 / 16 totaltotal 77.6% 292 / 376 CC 60 SCAR 27.3
CC
60
Cov
79%
execute
30.5
validate_args
20.1
gen_circos
13.0
CRAP 15.3
« Egaz/Command/lav2axt.pm ↑ Summary Egaz/Command/normalize.pm »
1 package App::Egaz::Command::template;
2 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 19 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 19 ▶use App::Egaz -command;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 19 ▶use App::Egaz::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶sub abstract {
Subroutine abstract: called CC=1 SCAR=0.0
Pod documented
10 2 return 'create pipeline files';
11 }
12  
13 6 ▶sub opt_spec {
Subroutine opt_spec: called CC=1 SCAR=0.0
Pod documented
14 return (
15 6 [ "mode" => hidden => {
16 default => "multi",
17 one_of => [
18 [ "multi" => "multiple genome alignments, orthologs" ],
19 [ "self" => "self genome alignments, paralogs" ],
20 [ "prep" => "prepare sequences" ],
21 ],
22 }
23 ],
24 [],
25 [ "outdir|o=s", "Output directory", { default => "." }, ],
26 [ "queue=s", "QUEUE_NAME", { default => "mpi" }, ],
27 [ "separate", "separate each Target-Query groups", ],
28 [ "tmp=s", "user defined tempdir", ],
29 [ "parallel|p=i", "number of threads", { default => 2 }, ],
30 [ "verbose|v", "verbose mode", ],
31 [],
32 [ "length=i", "minimal length of alignment fragments", { default => 1000 }, ],
33 [ "partition", "use partitioned sequences if available", ],
34 [ "msa=s", "aligning program for refine alignments", { default => "mafft" }, ],
35 [ "taxon=s", "taxon.csv for this project", ],
36 [ "aligndb", "create aligndb scripts", ],
37 [],
38 [ "multiname=s", "naming multiply alignment", ],
39 [ "outgroup=s", "the name of outgroup", ],
40 [ "tree=s", "a predefined guiding tree for multiz", ],
41 [ "order", "multiple alignments with original order (using fake_tree.nwk)", ],
42 [ "fasttree", "use FastTree instead of RaxML to create a phylotree", ],
43 [ "mash", "create guiding tree by mash", ],
44 [ "vcf", "create vcf files", ],
45 [],
46 [ "circos", "create circos script", ],
47 [],
48 [ "repeatmasker=s", "options passed to RepeatMasker", ],
49 [ "perseq=s@", "split these files by names", ],
50 [ "min=i", "minimal length of sequences", { default => 5000 }, ],
51 [ "about=i", "split sequences to chunks about approximate size", { default => 5000000 }, ],
52 [ "suffix=s@",
53 "suffix of wanted files",
54 { default => [ "_genomic.fna.gz", ".fsa_nt.gz" ] },
55 ],
56 [ "exclude=s", "regex to exclude some files", { default => "_from_" }, ],
57 { show_defaults => 1, }
58 );
59 }
60  
61 6 ▶sub usage_desc {
Subroutine usage_desc: called CC=1 SCAR=0.0
Pod documented
62 6 return "egaz template [options] <path/seqdir> [more path/seqdir]";
63 }
64  
65 1 ▶sub description {
Subroutine description: called CC=1 SCAR=0.0
Pod documented
66 1 my $desc;
67 1 $desc .= ucfirst(abstract) . ".\n";
68 1 $desc .= <<'MARKDOWN';
69  
70 * `path/seqdir` are directories containing multiple .fa files that represent genomes
71  
72 * Each .fa files in `path/target` should contain only one sequences, otherwise second or latter
73 sequences will be omitted
74  
75 * Species/strain names in result files are the basenames of `path/seqdir`
76  
77 * Default --multiname is the basename of --outdir. This option is for more than one aligning
78 combinations
79  
80 * without --tree, or --mash, the order of multiz stitch is the same as the one from
81 command line
82  
83 * --tree > --order > --mash
84  
85 * --outgroup uses basename, not full path. *DON'T* set --outgroup to target
86  
87 * --taxon may also contain unused taxonomy terms, for the construction of chr_length.csv
88  
89 * --preq is designed for NCBI ASSEMBLY and WGS, `path/seqdir` are directories containing multiple
90 directories
91  
92 * By default, `RAxML` is used to produce a phylotree. Turn on `--fasttree` to use FastTree, which is
93 less accurate and doesn't support outgroups by itself
94  
95 MARKDOWN
96  
97 1 return $desc;
98 }
99  
100 5 ▶sub validate_args {
Subroutine validate_args: called CC=13 SCAR=30.0
Pod documented
101 5 my ( $self, $opt, $args ) = @_;
102  
103 5 ▶ if ( @{$args} < 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$args;} < 1) 1 4 5
104 1 my $message = "This command need one or more directories.\n\tIt found";
105 1 $message .= sprintf " [%s]", $_ for @{$args};
106 1 $message .= ".\n";
107 1 $self->usage_error($message);
108 }
109 4 for ( @{$args} ) {
110 6 ▶ if ( !Path::Tiny::path($_)->is_dir ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (Path::Tiny::path($_)->is_dir) 1 5 6
111 1 $self->usage_error("The input directory [$_] doesn't exist.");
112 }
113 }
114  
115 3 ▶ if ( $opt->{mode} eq "multi" and @{$args} < 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"mode"} eq "multi" and @{$args;} < 2) 0 3 3
Condition66%2/3
$opt->{"mode"} eq "multi" and @{$args;} < 2
!ll&&!rl&&r
210
MC/DC0%0/2
$opt->{"mode"} eq "multi" and @{$args;} < 2
$opt->{"mode"} eq "multi" @{$args;} < 2
Truth table66%2/3
A and B
A= $opt->{"mode"} eq "multi"B= @{$args;} < 2
ABresult
0X0
100
111
116 0 $self->usage_error("Multiple alignments need at least 2 directories");
117 }
118  
119 3 ▶ if ( $opt->{tree} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"tree"}) 0 3 3
120 0 ▶ if ( !Path::Tiny::path( $opt->{tree} )->is_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not Path::Tiny::path($opt->{'tree'})->is_file) { } 0 0 0
121 0 $self->usage_error("The tree file [$opt->{tree}] doesn't exist.");
122 }
123 else {
124 0 $opt->{tree} = Path::Tiny::path( $opt->{tree} )->absolute()->stringify();
125 }
126 }
127  
128 3 ▶ if ( $opt->{taxon} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"taxon"}) 0 3 3
129 0 ▶ if ( !Path::Tiny::path( $opt->{taxon} )->is_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not Path::Tiny::path($opt->{'taxon'})->is_file) { } 0 0 0
130 0 $self->usage_error("The taxon file [$opt->{taxon}] doesn't exist.");
131 }
132 else {
133 0 $opt->{taxon} = Path::Tiny::path( $opt->{taxon} )->absolute()->stringify();
134 }
135  
136 }
137  
138 3 $opt->{outdir} = Path::Tiny::path( $opt->{outdir} )->absolute()->stringify();
139  
140 3 ▶ if ( !$opt->{multiname} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opt->{"multiname"}) 3 0 3
141 3 $opt->{multiname} = Path::Tiny::path( $opt->{outdir} )->basename();
142 }
143  
144 3 $opt->{parallel2} = int( $opt->{parallel} / 2 );
145 3 ▶ $opt->{parallel2} = 2 if $opt->{parallel2} < 2;
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"parallel2"} < 2 3 0 3
146  
147 }
148  
149 3 ▶sub execute {
Subroutine execute: called CC=25 SCAR=34.2
Pod documented
150 3 my ( $self, $opt, $args ) = @_;
151  
152 3 print STDERR "Create templates for [$opt->{mode}] genome alignments\n";
153  
154 #----------------------------#
155 # prepare working dir
156 #----------------------------#
157 3 $opt->{outdir} = Path::Tiny::path( $opt->{outdir} )->absolute();
158 3 $opt->{outdir}->mkpath();
159 3 $opt->{outdir} = $opt->{outdir}->stringify();
160 3 print STDERR "Working directory [$opt->{outdir}]\n";
161  
162 3 ▶ if ( $opt->{mode} eq "multi" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opt->{'mode'} eq 'multi') { } 1 2 3
elsif ($opt->{'mode'} eq 'self') { } 1 1 2
163 1 Path::Tiny::path( $opt->{outdir}, 'Pairwise' )->mkpath();
164 1 Path::Tiny::path( $opt->{outdir}, 'Results' )->mkpath();
165 }
166 elsif ( $opt->{mode} eq "self" ) {
167 1 Path::Tiny::path( $opt->{outdir}, 'Pairwise' )->mkpath();
168 1 Path::Tiny::path( $opt->{outdir}, 'Processing' )->mkpath();
169 1 Path::Tiny::path( $opt->{outdir}, 'Results' )->mkpath();
170 1 Path::Tiny::path( $opt->{outdir}, 'Circos' )->mkpath();
171 }
172  
173 3 $args = [ map { Path::Tiny::path($_)->absolute()->stringify() } @{$args} ];
174  
175 #----------------------------#
176 # names and directories
177 #----------------------------#
178 3 print STDERR "Associate names and directories\n";
179 3 my @data;
180 {
181 3 my %taxon_of;
182 3 ▶ if ( $opt->{taxon} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"taxon"}) 0 3 3
183 0 for my $line ( Path::Tiny::path( $opt->{taxon} )->lines ) {
184 0 my @fields = split /,/, $line;
185 0 ▶ if ( $#fields >= 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#fields >= 2) 0 0 0
186 0 $taxon_of{ $fields[0] } = $fields[1];
187 }
188 }
189 }
190 @data = map {
191 { dir => $_,
192 name => Path::Tiny::path($_)->basename(),
193 taxon => exists $taxon_of{ Path::Tiny::path($_)->basename() }
194 5 ▶ ? $taxon_of{ Path::Tiny::path($_)->basename() }
Branch: 1 branch
BranchTrueFalseTotal
exists $taxon_of{Path::Tiny::path($_)->basename} ? : 0 5 5
195 : 0,
196 }
197 3 } @{$args};
198 }
199  
200 # move $opt->{outgroup} to last
201 3 ▶ if ( $opt->{mode} eq "multi" and $opt->{outgroup} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"mode"} eq "multi" and $opt->{"outgroup"}) 0 3 3
Condition66%2/3
$opt->{"mode"} eq "multi" and $opt->{"outgroup"}
!ll&&!rl&&r
210
MC/DC0%0/2
$opt->{"mode"} eq "multi" and $opt->{"outgroup"}
$opt->{"mode"} eq "multi" $opt->{"outgroup"}
Truth table66%2/3
A and B
A= $opt->{"mode"} eq "multi"B= $opt->{"outgroup"}
ABresult
0X0
100
111
202 0 my ($exist) = grep { $_->{name} eq $opt->{outgroup} } @data;
203 0 ▶ if ( !defined $exist ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $exist) 0 0 0
204 0 Carp::confess "--outgroup [$opt->{outgroup}] does not exist!\n";
205 }
206  
207 0 @data = grep { $_->{name} ne $opt->{outgroup} } @data;
208 0 push @data, $exist;
209 }
210 3 $opt->{data} = \@data; # store in $opt
211  
212 print STDERR YAML::Syck::Dump( $opt->{data} )
213 3 ▶ if $opt->{verbose} and $opt->{mode} ne "prep";
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"verbose"} and $opt->{"mode"} ne "prep" 2 1 3
Condition66%2/3
$opt->{"verbose"} and $opt->{"mode"} ne "prep"
!ll&&!rl&&r
012
MC/DC50%1/2
$opt->{"verbose"} and $opt->{"mode"} ne "prep"
$opt->{"verbose"} $opt->{"mode"} ne "prep"
Truth table66%2/3
A and B
A= $opt->{"verbose"}B= $opt->{"mode"} ne "prep"
ABresult
0X0
100
111
214  
215 # genome.lst
216 3 ▶ if ( $opt->{mode} ne "prep" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"mode"} ne "prep") 2 1 3
217 2 print STDERR "Create genome.lst\n";
218 2 my $fh = Path::Tiny::path( $opt->{outdir}, "genome.lst" )->openw;
219 2 for my $i ( 0 .. $#data ) {
220 4 print {$fh} "$data[$i]->{name}\n";
221 }
222 2 close $fh;
223 }
224  
225 # If there's no phylo tree, generate a fake one.
226 3 ▶ if ( $opt->{mode} eq "multi" and !$opt->{tree} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"mode"} eq "multi" and not $opt->{"tree"}) 1 2 3
Condition66%2/3
$opt->{"mode"} eq "multi" and not $opt->{"tree"}
!ll&&!rl&&r
201
MC/DC50%1/2
$opt->{"mode"} eq "multi" and not $opt->{"tree"}
$opt->{"mode"} eq "multi" not $opt->{"tree"}
Truth table66%2/3
A and not(B)
A= $opt->{"mode"} eq "multi"B= not $opt->{"tree"}
ABresult
0X0
100
111
227 1 print STDERR "Create fake_tree.nwk\n";
228 1 my $fh = Path::Tiny::path( $opt->{outdir}, "fake_tree.nwk" )->openw;
229 1 print {$fh} "(" x ( scalar(@data) - 1 ) . "$data[0]->{name}";
230 1 for my $i ( 1 .. $#data ) {
231 1 print {$fh} ",$data[$i]->{name})";
232 }
233 1 print {$fh} ";\n";
234 1 close $fh;
235 }
236  
237 #----------------------------#
238 # prep *.sh files
239 #----------------------------#
240 3 ▶ if ( $opt->{mode} eq "prep" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"mode"} eq "prep") 1 2 3
241 1 $self->gen_prep( $opt, $args );
242 }
243  
244 #----------------------------#
245 # multi *.sh files
246 #----------------------------#
247 3 ▶ if ( $opt->{mode} eq "multi" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"mode"} eq "multi") 1 2 3
248 1 $self->gen_pair( $opt, $args );
249  
250 # $self->gen_rawphylo( $opt, $args ) if $opt->{rawphylo};
251 1 $self->gen_multi( $opt, $args );
252 1 ▶ $self->gen_vcf( $opt, $args ) if $opt->{vcf};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"vcf"} 1 0 1
253 }
254  
255 #----------------------------#
256 # self *.sh files
257 #----------------------------#
258 3 ▶ if ( $opt->{mode} eq "self" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"mode"} eq "self") 1 2 3
259 1 $self->gen_self( $opt, $args );
260 1 $self->gen_proc( $opt, $args );
261 1 ▶ $self->gen_circos( $opt, $args ) if $opt->{circos};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"circos"} 1 0 1
262 }
263  
264 3 ▶ if ( $opt->{mode} eq "multi" or $opt->{mode} eq "self" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"mode"} eq "multi" or $opt->{"mode"} eq "self") 2 1 3
Condition100%3/3
$opt->{"mode"} eq "multi" or $opt->{"mode"} eq "self"
l!l&&r!l&&!r
111
MC/DC100%2/2
$opt->{"mode"} eq "multi" or $opt->{"mode"} eq "self"
$opt->{"mode"} eq "multi" $opt->{"mode"} eq "self"
Truth table100%3/3
A or B
A= $opt->{"mode"} eq "multi"B= $opt->{"mode"} eq "self"
ABresult
1X1
011
000
265 2 $self->gen_mash( $opt, $args );
266  
267 2 ▶ $self->gen_aligndb( $opt, $args ) if $opt->{aligndb};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"aligndb"} 2 0 2
268 2 $self->gen_packup( $opt, $args );
269 }
270 }
271  
272 1 ▶sub gen_prep {
Subroutine gen_prep: called CC=5 SCAR=16.2
Pod undocumented
273 1 my ( $self, $opt, $args ) = @_;
274  
275 1 my @patterns = map {"*$_"} @{ $opt->{suffix} };
276 0 my %perseq = map { $_ => 1, } @{ $opt->{perseq} };
277  
278 1 my @files;
279 1 for ( @{$args} ) {
280 1 push @files, File::Find::Rule->file->name(@patterns)->in($_);
281 }
282  
283 {
284 1 @files = grep { !/$opt->{exclude}/ } @files;
285 1 @files = map { Path::Tiny::path($_)->absolute()->stringify } @files;
286 @files = map {
287 1 { basename => Path::Tiny::path($_)->parent()->basename(),
288 2 ▶ perseq => exists $perseq{ Path::Tiny::path($_)->parent()->basename() }
Branch: 1 branch
BranchTrueFalseTotal
exists $perseq{Path::Tiny::path($_)->parent->basename} ? : 0 2 2
289 ? 1
290 : 0,
291 file => $_,
292 }
293 } @files;
294  
295 1 ▶ print STDERR YAML::Syck::Dump \@files if $opt->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"verbose"} 1 0 1
296 }
297  
298 1 my $tt = Template->new( INCLUDE_PATH => [ File::ShareDir::dist_dir('App-Egaz') ], );
299 1 my $template;
300 my $sh_name;
301  
302 1 $sh_name = "0_prep.sh";
303 1 print STDERR "Create $sh_name\n";
304 1 $template = <<'EOF';
305 [% INCLUDE header.tt2 %]
306  
307 #----------------------------#
308 # [% sh %]
309 #----------------------------#
310 log_warn [% sh %]
311  
312 [% FOREACH item IN files -%]
313 log_info [% item.basename %]
314  
315 if [ -d [% item.basename %] ]; then
316 log_debug "[% item.basename %] presents"
317 else
318 log_debug Processing [% item.file %]
319  
320 egaz prepseq \
321 [% item.file %] \
322 [% IF not item.perseq -%]
323 --about [% opt.about %] \
324 [% END -%]
325 [% IF opt.repeatmasker -%]
326 --repeatmasker "[% opt.repeatmasker %]" \
327 [% END -%]
328 --min [% opt.min %] --gi -v \
329 -o [% opt.outdir %]/[% item.basename %]
330 fi
331  
332 [% END -%]
333  
334 exit;
335  
336 EOF
337 $tt->process(
338 \$template,
339 { args => $args,
340 opt => $opt,
341 files => \@files,
342 sh => $sh_name,
343 },
344 1 ▶ Path::Tiny::path( $opt->{outdir}, $sh_name )->stringify
Branch: 1 branch
BranchTrueFalseTotal
$tt->process(\$template, {"args", $args, "opt", $opt, "files", \@files, "sh", $sh_name}, Path::Tiny::path($opt->{"outdir"}, $sh_name)->stringify) or "Template"->Carp::confess->error 1 0 1
345 ) or Carp::confess Template->error;
346  
347 }
348  
349 2 ▶sub gen_aligndb {
Subroutine gen_aligndb: called CC=6 SCAR=18.1
Pod undocumented
350 2 my ( $self, $opt, $args ) = @_;
351  
352 2 my $tt = Template->new( INCLUDE_PATH => [ File::ShareDir::dist_dir('App-Egaz') ], );
353 2 my $template;
354 my $sh_name;
355  
356 2 $sh_name = "6_chr_length.sh";
357 2 print STDERR "Create $sh_name\n";
358 2 $template = <<'EOF';
359 [% INCLUDE header.tt2 %]
360  
361 #----------------------------#
362 # [% sh %]
363 #----------------------------#
364 log_warn [% sh %]
365  
366 mkdir -p Results;
367  
368 echo "common_name,taxon_id,chr,length,assembly" > Results/chr_length.csv
369  
370 [% FOREACH item IN opt.data -%]
371 # [% item.name %]
372 perl -nla -F"\t" -e '
373 print qq{[% item.name %],[% item.taxon %],$F[0],$F[1],}
374 ' \
375 [% item.dir %]/chr.sizes \
376 >> Results/chr_length.csv;
377  
378 [% END -%]
379  
380 log_info chr_length.csv generated
381  
382 exit;
383  
384 EOF
385 $tt->process(
386 \$template,
387 { args => $args,
388 opt => $opt,
389 sh => $sh_name,
390 },
391 2 ▶ Path::Tiny::path( $opt->{outdir}, $sh_name )->stringify
Branch: 1 branch
BranchTrueFalseTotal
$tt->process(\$template, {"args", $args, "opt", $opt, "sh", $sh_name}, Path::Tiny::path($opt->{"outdir"}, $sh_name)->stringify) or "Template"->Carp::confess->error 2 0 2
392 ) or Carp::confess Template->error;
393  
394 2 ▶ if ( $opt->{mode} eq "multi" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opt->{'mode'} eq 'multi') { } 1 1 2
elsif ($opt->{'mode'} eq 'self') { } 1 0 1
395 1 $sh_name = "7_multi_aligndb.sh";
396 1 print STDERR "Create $sh_name\n";
397 1 $template = <<'EOF';
398 [% INCLUDE header.tt2 %]
399  
400 #----------------------------#
401 # [% sh %]
402 #----------------------------#
403 log_warn [% sh %]
404  
405 mkdir -p Results;
406  
407 cd Results
408  
409 #----------------------------#
410 # Create anno.yml
411 #----------------------------#
412 log_info create anno.json
413  
414 if [ -e [% opt.data.0.dir -%]/anno.json ]; then
415 cp [% opt.data.0.dir -%]/anno.json anno.json;
416 else
417 if [ -e [% opt.data.0.dir -%]/cds.json ]; then
418 cp [% opt.data.0.dir -%]/cds.json cds.json;
419 else
420 spanr gff --tag CDS \
421 [% opt.data.0.dir -%]/*.gff \
422 -o cds.json
423 fi
424  
425 if [ -e [% opt.data.0.dir -%]/repeat.json ]; then
426 cp [% opt.data.0.dir -%]/repeat.json repeat.json;
427 else
428 spanr gff \
429 [% opt.data.0.dir -%]/*.rm.gff \
430 -o repeat.json
431 fi
432  
433 # create empty cds.json or repeat.json
434 spanr genome [% opt.data.0.dir -%]/chr.sizes -o chr.json
435 spanr compare --op diff chr.json chr.json -o empty.json
436  
437 for type in cds repeat; do
438 if [ ! -e ${type}.json ]; then
439 cp empty.json ${type}.json
440 fi
441 done
442  
443 spanr merge \
444 cds.json repeat.json \
445 -o anno.json
446  
447 rm -f repeat.json cds.json chr.json empty.json
448 fi
449  
450 #----------------------------#
451 # alignDB.pl
452 #----------------------------#
453 log_info run alignDB.pl
454  
455 alignDB.pl \
456 -d [% opt.multiname %] \
457 --da [% opt.outdir %]/[% opt.multiname %]_refined \
458 -a [% opt.outdir %]/Results/anno.json \
459 [% IF opt.outgroup -%]
460 --outgroup \
461 [% END -%]
462 --chr [% opt.outdir %]/Results/chr_length.csv \
463 --lt [% opt.length %] --parallel [% opt.parallel %] --batch 10 \
464 --run 1,2,5,10,21,30-32,40-42,44
465  
466 exit;
467  
468 EOF
469 $tt->process(
470 \$template,
471 { args => $args,
472 opt => $opt,
473 sh => $sh_name,
474 },
475 1 ▶ Path::Tiny::path( $opt->{outdir}, $sh_name )->stringify
Branch: 1 branch
BranchTrueFalseTotal
$tt->process(\$template, {"args", $args, "opt", $opt, "sh", $sh_name}, Path::Tiny::path($opt->{"outdir"}, $sh_name)->stringify) or "Template"->Carp::confess->error 1 0 1
476 ) or Carp::confess Template->error;
477 }
478 elsif ( $opt->{mode} eq "self" ) {
479 1 $sh_name = "7_self_aligndb.sh";
480 1 print STDERR "Create $sh_name\n";
481 1 $template = <<'EOF';
482 [% INCLUDE header.tt2 %]
483  
484 #----------------------------#
485 # [% sh %]
486 #----------------------------#
487 log_warn [% sh %]
488  
489 mkdir -p Results;
490  
491 cd Results
492  
493 #----------------------------#
494 # [% opt.multiname %]
495 #----------------------------#
496 # steal multiname from --multi
497  
498 log_info init_alignDB
499  
500 alignDB.pl \
501 -d [% opt.multiname %]_self \
502 --chr [% opt.outdir %]/Results/chr_length.csv \
503 --run 1
504  
505  
506 #----------------------------#
507 # gen_alignDB.pl
508 #----------------------------#
509 # gen_alignDB to existing database
510  
511 log_info gen_alignDB
512  
513 [% FOREACH item IN opt.data -%]
514 # [% item.name %]
515 alignDB.pl \
516 -d [% opt.multiname %]_self \
517 --da [% opt.outdir %]/Results/[% item.name %]/[% item.name %].pair.fas \
518 --lt 1000 --parallel [% opt.parallel %] \
519 --run 2
520  
521 [% END -%]
522  
523 #----------------------------#
524 # rest steps
525 #----------------------------#
526 alignDB.pl \
527 -d [% opt.multiname %]_self \
528 --parallel [% opt.parallel %] --batch 10 \
529 --run 5,10,21,30-32,40,42,44
530  
531 exit;
532  
533 EOF
534 $tt->process(
535 \$template,
536 { args => $args,
537 opt => $opt,
538 sh => $sh_name,
539 },
540 1 ▶ Path::Tiny::path( $opt->{outdir}, $sh_name )->stringify
Branch: 1 branch
BranchTrueFalseTotal
$tt->process(\$template, {"args", $args, "opt", $opt, "sh", $sh_name}, Path::Tiny::path($opt->{"outdir"}, $sh_name)->stringify) or "Template"->Carp::confess->error 1 0 1
541 ) or Carp::confess Template->error;
542  
543 }
544 }
545  
546 2 ▶sub gen_packup {
Subroutine gen_packup: called CC=2 SCAR=7.0
Pod undocumented
547 2 my ( $self, $opt, $args ) = @_;
548  
549 2 my $tt = Template->new( INCLUDE_PATH => [ File::ShareDir::dist_dir('App-Egaz') ], );
550 2 my $sh_name = "9_pack_up.sh";
551 2 my $template = "9_pack_up.tt2.sh";
552  
553 2 print STDERR "Create $sh_name\n";
554  
555 $tt->process(
556 $template,
557 { args => $args,
558 opt => $opt,
559 sh => $sh_name,
560 },
561 2 ▶ Path::Tiny::path( $opt->{outdir}, $sh_name )->stringify
Branch: 1 branch
BranchTrueFalseTotal
$tt->process($template, {"args", $args, "opt", $opt, "sh", $sh_name}, Path::Tiny::path($opt->{"outdir"}, $sh_name)->stringify) or "Template"->Carp::confess->error 2 0 2
562 ) or Carp::confess Template->error;
563 }
564  
565 1 ▶sub gen_pair {
Subroutine gen_pair: called CC=2 SCAR=7.0
Pod undocumented
566 1 my ( $self, $opt, $args ) = @_;
567  
568 1 my $tt = Template->new( INCLUDE_PATH => [ File::ShareDir::dist_dir('App-Egaz') ], );
569 1 my $sh_name = "1_pair.sh";
570 1 my $template = "1_pair.tt2.sh";
571  
572 1 print STDERR "Create $sh_name\n";
573  
574 $tt->process(
575 $template,
576 { args => $args,
577 opt => $opt,
578 sh => $sh_name,
579 },
580 1 ▶ Path::Tiny::path( $opt->{outdir}, $sh_name )->stringify
Branch: 1 branch
BranchTrueFalseTotal
$tt->process($template, {"args", $args, "opt", $opt, "sh", $sh_name}, Path::Tiny::path($opt->{"outdir"}, $sh_name)->stringify) or "Template"->Carp::confess->error 1 0 1
581 ) or Carp::confess Template->error;
582 }
583  
584 2 ▶sub gen_mash {
Subroutine gen_mash: called CC=2 SCAR=7.0
Pod undocumented
585 2 my ( $self, $opt, $args ) = @_;
586  
587 2 my $tt = Template->new( INCLUDE_PATH => [ File::ShareDir::dist_dir('App-Egaz') ], );
588 2 my $sh_name = "2_mash.sh";
589 2 my $template = "2_mash.tt2.sh";
590  
591 2 print STDERR "Create $sh_name\n";
592  
593 $tt->process(
594 $template,
595 { args => $args,
596 opt => $opt,
597 sh => $sh_name,
598 },
599 2 ▶ Path::Tiny::path( $opt->{outdir}, $sh_name )->stringify
Branch: 1 branch
BranchTrueFalseTotal
$tt->process($template, {"args", $args, "opt", $opt, "sh", $sh_name}, Path::Tiny::path($opt->{"outdir"}, $sh_name)->stringify) or "Template"->Carp::confess->error 2 0 2
600 ) or Carp::confess Template->error;
601 }
602  
603 1 ▶sub gen_multi {
Subroutine gen_multi: called CC=2 SCAR=7.0
Pod undocumented
604 1 my ( $self, $opt, $args ) = @_;
605  
606 1 my $tt = Template->new( INCLUDE_PATH => [ File::ShareDir::dist_dir('App-Egaz') ], );
607 1 my $sh_name = "3_multi.sh";
608 1 my $template = "3_multi.tt2.sh";
609  
610 1 print STDERR "Create $sh_name\n";
611  
612 $tt->process(
613 $template,
614 { args => $args,
615 opt => $opt,
616 sh => $sh_name,
617 },
618 1 ▶ Path::Tiny::path( $opt->{outdir}, $sh_name )->stringify
Branch: 1 branch
BranchTrueFalseTotal
$tt->process($template, {"args", $args, "opt", $opt, "sh", $sh_name}, Path::Tiny::path($opt->{"outdir"}, $sh_name)->stringify) or "Template"->Carp::confess->error 1 0 1
619 ) or Carp::confess Template->error;
620 }
621  
622 1 ▶sub gen_vcf {
Subroutine gen_vcf: called CC=2 SCAR=7.0
Pod undocumented
623 1 my ( $self, $opt, $args ) = @_;
624  
625 1 my $tt = Template->new( INCLUDE_PATH => [ File::ShareDir::dist_dir('App-Egaz') ], );
626 1 my $sh_name = "4_vcf.sh";
627 1 my $template = "4_vcf.tt2.sh";
628  
629 1 print STDERR "Create $sh_name\n";
630  
631 $tt->process(
632 $template,
633 { args => $args,
634 opt => $opt,
635 sh => $sh_name,
636 },
637 1 ▶ Path::Tiny::path( $opt->{outdir}, $sh_name )->stringify
Branch: 1 branch
BranchTrueFalseTotal
$tt->process($template, {"args", $args, "opt", $opt, "sh", $sh_name}, Path::Tiny::path($opt->{"outdir"}, $sh_name)->stringify) or "Template"->Carp::confess->error 1 0 1
638 ) or Carp::confess Template->error;
639 }
640  
641 1 ▶sub gen_self {
Subroutine gen_self: called CC=2 SCAR=7.0
Pod undocumented
642 1 my ( $self, $opt, $args ) = @_;
643  
644 1 my $tt = Template->new( INCLUDE_PATH => [ File::ShareDir::dist_dir('App-Egaz') ], );
645 1 my $sh_name = "1_self.sh";
646 1 my $template = "1_self.tt2.sh";
647  
648 1 print STDERR "Create $sh_name\n";
649  
650 $tt->process(
651 $template,
652 { args => $args,
653 opt => $opt,
654 sh => $sh_name,
655 },
656 1 ▶ Path::Tiny::path( $opt->{outdir}, $sh_name )->stringify
Branch: 1 branch
BranchTrueFalseTotal
$tt->process($template, {"args", $args, "opt", $opt, "sh", $sh_name}, Path::Tiny::path($opt->{"outdir"}, $sh_name)->stringify) or "Template"->Carp::confess->error 1 0 1
657 ) or Carp::confess Template->error;
658 }
659  
660 1 ▶sub gen_proc {
Subroutine gen_proc: called CC=2 SCAR=7.0
Pod undocumented
661 1 my ( $self, $opt, $args ) = @_;
662  
663 1 my $tt = Template->new( INCLUDE_PATH => [ File::ShareDir::dist_dir('App-Egaz') ], );
664 1 my $sh_name = "3_proc.sh";
665 1 my $template = "3_proc.tt2.sh";
666  
667 1 print STDERR "Create $sh_name\n";
668  
669 $tt->process(
670 $template,
671 { args => $args,
672 opt => $opt,
673 sh => $sh_name,
674 },
675 1 ▶ Path::Tiny::path( $opt->{outdir}, $sh_name )->stringify
Branch: 1 branch
BranchTrueFalseTotal
$tt->process($template, {"args", $args, "opt", $opt, "sh", $sh_name}, Path::Tiny::path($opt->{"outdir"}, $sh_name)->stringify) or "Template"->Carp::confess->error 1 0 1
676 ) or Carp::confess Template->error;
677 }
678  
679 1 ▶sub gen_circos {
Subroutine gen_circos: called CC=8 SCAR=25.7
Pod undocumented
680 1 my ( $self, $opt, $args ) = @_;
681  
682 1 my $tt = Template->new( INCLUDE_PATH => [ File::ShareDir::dist_dir('App-Egaz') ], );
683  
684 # circos.conf and karyotype.id.txt
685 1 for my $item ( @{ $opt->{data} } ) {
686 print STDERR "Create circos.conf for $item->{name}\n"
687 2 ▶ if $opt->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"verbose"} 2 0 2
688 $tt->process(
689 "circos.conf.tt2",
690 { dir => $opt->{outdir},
691 id => $item->{name},
692 },
693 2 ▶ Path::Tiny::path( $opt->{outdir}, 'Circos', $item->{name}, "circos.conf" )->stringify
Branch: 1 branch
BranchTrueFalseTotal
$tt->process("circos.conf.tt2", {"dir", $opt->{"outdir"}, "id", $item->{"name"}}, Path::Tiny::path($opt->{"outdir"}, "Circos", $item->{"name"}, "circos.conf")->stringify) or "Template"->Carp::confess->error 2 0 2
694 ) or Carp::confess Template->error;
695  
696 # copy prebuilt karyotype file
697 2 ▶ if ( $item->{taxon} != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item->{"taxon"} != 0) 0 2 2
698 0 my $karyo = Path::Tiny::path( File::ShareDir::dist_dir('App-Egaz'),
699 "share", "karyotype", "karyotype.$item->{taxon}.txt" );
700  
701 0 ▶ if ( $karyo->is_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($karyo->is_file) 0 0 0
702 print STDERR " Copy prebuilt karyotype.$item->{name}.txt\n"
703 0 ▶ if $opt->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"verbose"} 0 0 0
704 $karyo->copy( $opt->{outdir}, 'Circos', $item->{name},
705 0 "karyotype.$item->{name}.txt" );
706 }
707 }
708 }
709  
710 # 4_circos.sh
711 1 my $template;
712 my $sh_name;
713  
714 1 $sh_name = "4_circos.sh";
715 1 print STDERR "Create $sh_name\n";
716 1 $template = <<'EOF';
717 [% INCLUDE header.tt2 %]
718  
719 #----------------------------#
720 # [% sh %]
721 #----------------------------#
722 log_warn [% sh %]
723  
724 mkdir -p Pairwise
725  
726 [% FOREACH item IN opt.data -%]
727 [% id = item.name -%]
728 #----------------------------#
729 # [% id %]
730 #----------------------------#
731 log_info [% id %]
732 cd [% opt.outdir %]/Circos/[% id %]
733  
734 #----------------------------#
735 # karyotype
736 #----------------------------#
737 log_debug Adjust karyotype
738  
739 # generate karyotype files
740 if [ ! -e karyotype.[% id %].txt ]; then
741 log_debug Create default karyotype
742 perl -anl -e '$i++; print qq{chr - $F[0] $F[0] 0 $F[1] chr$i}' \
743 [% item.dir %]/chr.sizes \
744 > karyotype.[% id %].txt
745 fi
746  
747 # spaces among chromosomes
748 if [[ $(perl -n -e '$l++; END{print qq{$l\n}}' [% item.dir %]/chr.sizes ) > 1 ]]; then
749 log_debug Multiple chromosomes
750 perl -nlpi -e 's/ default = 0r/ default = 0.005r/;' circos.conf
751 perl -nlpi -e 's/show_label = no/show_label = yes/;' circos.conf
752 fi
753  
754 # chromosome units
755 SIZE=$(perl -an -F'\t' -e '$s += $F[1]; END{print qq{$s\n}}' [% item.dir %]/chr.sizes )
756 log_debug "Genome size ${SIZE}"
757 if [ ${SIZE} -ge 1000000000 ]; then
758 echo " * Set chromosome unit to 1 Mbp"
759 perl -nlpi -e 's/chromosomes_units = 1000/chromosomes_units = 100000/;' circos.conf
760 elif [ ${SIZE} -ge 100000000 ]; then
761 echo " * Set chromosome unit to 100 kbp"
762 perl -nlpi -e 's/chromosomes_units = 1000/chromosomes_units = 100000/;' circos.conf
763 elif [ ${SIZE} -ge 10000000 ]; then
764 echo " * Set chromosome unit to 10 kbp"
765 perl -nlpi -e 's/chromosomes_units = 1000/chromosomes_units = 10000/;' circos.conf
766 else
767 echo " * Keep chromosome unit as 1 kbp"
768 fi
769  
770 #----------------------------#
771 # gff to highlight
772 #----------------------------#
773 log_debug Create highlight files
774  
775 if [ ${SIZE} -ge 10000000 ]; then
776 # avoid errors of too many highlights
777 touch highlight.features.[% id %].txt
778 touch highlight.repeats.[% id %].txt
779 else
780 # coding and other features
781 perl -anl -e '
782 /^#/ and next;
783 $F[0] =~ s/\.\d+//;
784 $color = q{};
785 $F[2] eq q{CDS} and $color = q{chr9};
786 $F[2] eq q{ncRNA} and $color = q{dark2-8-qual-1};
787 $F[2] eq q{rRNA} and $color = q{dark2-8-qual-2};
788 $F[2] eq q{tRNA} and $color = q{dark2-8-qual-3};
789 $F[2] eq q{tmRNA} and $color = q{dark2-8-qual-4};
790 $color and ($F[4] - $F[3] > 49) and print qq{$F[0] $F[3] $F[4] fill_color=$color};
791 ' \
792 [% item.dir %]/*.gff \
793 > highlight.features.[% id %].txt
794  
795 # repeats
796 perl -anl -e '
797 /^#/ and next;
798 $F[0] =~ s/\.\d+//;
799 $color = q{};
800 $F[2] eq q{region} and $F[8] =~ /mobile_element|Transposon/i and $color = q{chr15};
801 $F[2] =~ /repeat/ and $F[8] !~ /RNA/ and $color = q{chr15};
802 $color and ($F[4] - $F[3] > 49) and print qq{$F[0] $F[3] $F[4] fill_color=$color};
803 ' \
804 [% item.dir %]/*.gff \
805 > highlight.repeats.[% id %].txt
806 fi
807  
808 #----------------------------#
809 # links of paralog ranges
810 #----------------------------#
811 log_debug Create link files
812  
813 for n in 2 3 4-50; do
814 linkr filter [% opt.outdir %]/Results/[% id %]/[% id %].links.tsv -n ${n} -o stdout \
815 > links.copy${n}.tsv
816  
817 if [ "${n}" == "4-50" ]; then
818 linkr circos links.copy${n}.tsv -o [% id %].linkN.txt --highlight
819 else
820 linkr circos links.copy${n}.tsv -o [% id %].link${n}.txt
821 fi
822  
823 rm links.copy${n}.tsv
824 done
825  
826 #----------------------------#
827 # run circos
828 #----------------------------#
829 log_info Run circos
830 circos -noparanoid -conf circos.conf
831  
832 [% END -%]
833  
834 exit;
835  
836 EOF
837 $tt->process(
838 \$template,
839 { args => $args,
840 opt => $opt,
841 sh => $sh_name,
842 },
843 1 ▶ Path::Tiny::path( $opt->{outdir}, $sh_name )->stringify
Branch: 1 branch
BranchTrueFalseTotal
$tt->process(\$template, {"args", $args, "opt", $opt, "sh", $sh_name}, Path::Tiny::path($opt->{"outdir"}, $sh_name)->stringify) or "Template"->Carp::confess->error 1 0 1
844 ) or Carp::confess Template->error;
845  
846 }
847  
848 19 1;
« Egaz/Command/lav2axt.pm ↑ Summary Egaz/Command/normalize.pm »