| 1 | package App::Egaz::Command::raxml; | ||||||||||
| 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 'raxml wrapper to construct phylogenetic trees'; | |||||||||
| 11 | } | ||||||||||
| 12 | |||||||||||
| 13 | 3 | ▶ | sub opt_spec { | ||||||||
|
Subroutine
opt_spec: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 14 | return ( | ||||||||||
| 15 | 3 | [ "outfile|o=s", "Output filename. [stdout] for screen", { default => "stdout" }, ], | |||||||||
| 16 | [ "outgroup=s", "the name of outgroup if exists", ], | ||||||||||
| 17 | [ "seed|s=i", "specify a random number seed", ], | ||||||||||
| 18 | [ "bootstrap|b=i", "the number of alternative runs", { default => 100 }, ], | ||||||||||
| 19 | [ "tmp=s", "user defined tempdir", ], | ||||||||||
| 20 | [ "parallel|p=i", "number of threads", { default => 2 }, ], | ||||||||||
| 21 | [ "verbose|v", "verbose mode", ], | ||||||||||
| 22 | { show_defaults => 1, } | ||||||||||
| 23 | ); | ||||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | 3 | ▶ | sub usage_desc { | ||||||||
|
Subroutine
usage_desc: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 27 | 3 | return "egaz raxml [options] <infile> [more infiles]"; | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | 1 | ▶ | sub description { | ||||||||
|
Subroutine
description: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 31 | 1 | my $desc; | |||||||||
| 32 | 1 | $desc .= ucfirst(abstract) . ".\n"; | |||||||||
| 33 | 1 | $desc .= <<'MARKDOWN'; | |||||||||
| 34 | |||||||||||
| 35 | * <infile> should be a blocked fasta file (*.fas) | ||||||||||
| 36 | * use `fasops concat` to create a temp relaxed phylip file | ||||||||||
| 37 | * `raxmlHPC` or `raxmlHPC-*` should be in $PATH | ||||||||||
| 38 | * `raxml` is very sensitive to CPU resources. Any competitions on cores will dramatically slow down it. | ||||||||||
| 39 | |||||||||||
| 40 | MARKDOWN | ||||||||||
| 41 | |||||||||||
| 42 | 1 | return $desc; | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 2 | ▶ | sub validate_args { | ||||||||
|
Subroutine
validate_args: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 46 | 2 | my ( $self, $opt, $args ) = @_; | |||||||||
| 47 | |||||||||||
| 48 | 2 | ▶ | if ( @{$args} < 1 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | 1 | my $message = "This command need one or more input files.\n\tIt found"; | |||||||||
| 50 | 1 | $message .= sprintf " [%s]", $_ for @{$args}; | |||||||||
| 51 | 1 | $message .= ".\n"; | |||||||||
| 52 | 1 | $self->usage_error($message); | |||||||||
| 53 | } | ||||||||||
| 54 | 1 | for ( @{$args} ) { | |||||||||
| 55 | 1 | ▶ | if ( !Path::Tiny::path($_)->is_file ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 1 | $self->usage_error("The input file [$_] doesn't exist."); | |||||||||
| 57 | } | ||||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 0 | ▶ | sub execute { | ||||||||
|
Subroutine
execute: not called CC=14 SCAR=53.5
Pod
documented
| |||||||||||
| 63 | 0 | my ( $self, $opt, $args ) = @_; | |||||||||
| 64 | |||||||||||
| 65 | # absolute pathes as we will chdir to tempdir later | ||||||||||
| 66 | 0 | my @infiles; | |||||||||
| 67 | 0 | for my $infile ( @{$args} ) { | |||||||||
| 68 | 0 | push @infiles, Path::Tiny::path($infile)->absolute->stringify; | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 0 | ▶ | if ( lc $opt->{outfile} ne "stdout" ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | 0 | $opt->{outfile} = Path::Tiny::path( $opt->{outfile} )->absolute->stringify; | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | # record cwd, we'll return there | ||||||||||
| 76 | 0 | my $cwd = Path::Tiny->cwd; | |||||||||
| 77 | 0 | my $tempdir; | |||||||||
| 78 | 0 | ▶ | if ( $opt->{tmp} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | $tempdir = Path::Tiny->tempdir( | ||||||||||
| 80 | TEMPLATE => "raxml_XXXXXXXX", | ||||||||||
| 81 | DIR => $opt->{tmp}, | ||||||||||
| 82 | 0 | ); | |||||||||
| 83 | } | ||||||||||
| 84 | else { | ||||||||||
| 85 | 0 | $tempdir = Path::Tiny->tempdir("raxml_XXXXXXXX"); | |||||||||
| 86 | } | ||||||||||
| 87 | 0 | chdir $tempdir; | |||||||||
| 88 | |||||||||||
| 89 | 0 | my $basename = $tempdir->basename(); | |||||||||
| 90 | 0 | $basename =~ s/\W+/_/g; | |||||||||
| 91 | |||||||||||
| 92 | { # .phy | ||||||||||
| 93 | 0 | my $cmd = "fasops names $infiles[0] -o stdout > names.list"; | |||||||||
| 94 | 0 | App::Egaz::Common::exec_cmd( $cmd, { verbose => $opt->{verbose}, } ); | |||||||||
| 95 | 0 | ▶ | if ( !$tempdir->child("names.list")->is_file ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 96 | 0 | Carp::croak "Failed: fasops names\n"; | |||||||||
| 97 | } | ||||||||||
| 98 | |||||||||||
| 99 | 0 | $cmd = "gzip -dcf "; | |||||||||
| 100 | 0 | $cmd .= join " ", @infiles; | |||||||||
| 101 | 0 | $cmd .= " |"; | |||||||||
| 102 | 0 | $cmd .= " fasops concat stdin names.list --relaxed -o stdout > $basename.phy"; | |||||||||
| 103 | 0 | App::Egaz::Common::exec_cmd( $cmd, { verbose => $opt->{verbose}, } ); | |||||||||
| 104 | 0 | ▶ | if ( !$tempdir->child("$basename.phy")->is_file ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 105 | 0 | Carp::croak "Failed: fasops concat\n"; | |||||||||
| 106 | } | ||||||||||
| 107 | } | ||||||||||
| 108 | |||||||||||
| 109 | { # run raxml | ||||||||||
| 110 | 0 | my $exe; | |||||||||
| 111 | 0 | for ( | |||||||||
| 112 | qw{raxmlHPC-PTHREADS-AVX raxmlHPC-PTHREADS-SSE3 raxmlHPC-PTHREADS raxmlHPC-AVX raxmlHPC-SSE3 raxmlHPC} | ||||||||||
| 113 | ) | ||||||||||
| 114 | { | ||||||||||
| 115 | 0 | ▶ | if ( IPC::Cmd::can_run($_) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 116 | 0 | $exe = $_; | |||||||||
| 117 | 0 | last; | |||||||||
| 118 | } | ||||||||||
| 119 | } | ||||||||||
| 120 | 0 | ▶ | if ( !defined $exe ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 121 | 0 | Carp::croak "Failed: can't find raxmlHPC executables\n"; | |||||||||
| 122 | } | ||||||||||
| 123 | |||||||||||
| 124 | 0 | my $seed; | |||||||||
| 125 | 0 | ▶ | if ( $opt->{seed} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 126 | 0 | $seed = $opt->{seed}; | |||||||||
| 127 | } | ||||||||||
| 128 | else { | ||||||||||
| 129 | 0 | $seed = int( rand(10000) ); | |||||||||
| 130 | } | ||||||||||
| 131 | 0 | ▶ | print STDERR "Random seed is [$seed]\n" if $opt->{verbose}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 132 | |||||||||||
| 133 | 0 | my $cmd | |||||||||
| 134 | = "$exe -T $opt->{parallel} -f a -m GTRGAMMA -p $seed -x $seed -N $opt->{bootstrap}"; | ||||||||||
| 135 | 0 | ▶ | if ( $opt->{outgroup} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 136 | 0 | $cmd .= " -o $opt->{outgroup}"; | |||||||||
| 137 | } | ||||||||||
| 138 | 0 | $cmd .= " -n $basename -s $basename.phy"; | |||||||||
| 139 | 0 | App::Egaz::Common::exec_cmd( $cmd, { verbose => $opt->{verbose}, } ); | |||||||||
| 140 | |||||||||||
| 141 | 0 | ▶ | if ( !$tempdir->child("RAxML_bipartitions.$basename")->is_file ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 142 | 0 | Carp::croak "Failed: raxml\n"; | |||||||||
| 143 | } | ||||||||||
| 144 | } | ||||||||||
| 145 | |||||||||||
| 146 | { # outputs | ||||||||||
| 147 | 0 | ▶ | if ( lc $opt->{outfile} ne "stdout" ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 148 | 0 | Path::Tiny::path("RAxML_bipartitions.$basename")->copy( $opt->{outfile} ); | |||||||||
| 149 | } | ||||||||||
| 150 | else { | ||||||||||
| 151 | 0 | print Path::Tiny::path("RAxML_bipartitions.$basename")->slurp; | |||||||||
| 152 | } | ||||||||||
| 153 | } | ||||||||||
| 154 | |||||||||||
| 155 | 0 | chdir $cwd; | |||||||||
| 156 | } | ||||||||||
| 157 | |||||||||||
| 158 | 19 | 1; | |||||||||