| 1 | package Bio::MUST::Drivers::Mafft; | ||||||||||||
| 2 | # ABSTRACT: Bio::MUST driver for running the MAFFT program | ||||||||||||
| 3 | # CONTRIBUTOR: Amandine BERTRAND <amandine.bertrand@doct.uliege.be> | ||||||||||||
| 4 | 6 | $Bio::MUST::Drivers::Mafft::VERSION = '0.252830'; | |||||||||||
| 5 | 6 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 6 | ▶ | use namespace::autoclean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | 6 | ▶ | use autodie; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 6 | ▶ | use feature qw(say); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | 6 | ▶ | use Smart::Comments '###'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | |||||||||||||
| 13 | 6 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | 6 | ▶ | use IPC::System::Simple qw(system); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | 6 | ▶ | use Module::Runtime qw(use_module); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | 6 | ▶ | use Path::Class qw(file); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | |||||||||||||
| 18 | 6 | ▶ | use Bio::MUST::Core; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 19 | 6 | extends 'Bio::FastParsers::Base'; | |||||||||||
| 20 | |||||||||||||
| 21 | 6 | ▶ | use Bio::MUST::Drivers::Utils qw(stringify_args); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 22 | 6 | ▶ | use aliased 'Bio::MUST::Core::Ali'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 23 | |||||||||||||
| 24 | |||||||||||||
| 25 | 0 | ▶ | sub align_all { ## no critic (RequireArgUnpacking) | ||||||||||
|
Subroutine
align_all: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 26 | 0 | return shift->_mafft('align_all', @_); | |||||||||||
| 27 | } | ||||||||||||
| 28 | |||||||||||||
| 29 | 0 | ▶ | sub profile2profile { ## no critic (RequireArgUnpacking) | ||||||||||
|
Subroutine
profile2profile: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 30 | 0 | my $out = shift->_mafft('profile2profile' , @_); | |||||||||||
| 31 | 0 | ▶ | return $out if $out; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 32 | |||||||||||||
| 33 | 0 | carp '[BMD] Warning: cannot align profiles; returning nothing!'; | |||||||||||
| 34 | 0 | return; | |||||||||||
| 35 | } | ||||||||||||
| 36 | |||||||||||||
| 37 | 0 | ▶ | sub seqs2profile { | ||||||||||
|
Subroutine
seqs2profile: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||
| 38 | 0 | my $self = shift; | |||||||||||
| 39 | 0 | my $profile = shift; | |||||||||||
| 40 | 0 | ▶ | my $args = shift // {}; | ||||||||||
|
Condition0%0/2
shift() // {}
MC/DC0%0/1
shift() // {}
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||
| 41 | |||||||||||||
| 42 | # setup specialized options | ||||||||||||
| 43 | 0 | my $mode = 'seqs2profile'; | |||||||||||
| 44 | 0 | for my $suffix ( qw(long fragments) ) { | |||||||||||
| 45 | 0 | my $opt = '--' . $suffix; | |||||||||||
| 46 | 0 | ▶ | if (exists $args->{$opt}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 47 | 0 | $mode =~ s/seqs/$suffix/xms; | |||||||||||
| 48 | 0 | delete $args->{$opt}; | |||||||||||
| 49 | } | ||||||||||||
| 50 | } | ||||||||||||
| 51 | #### $mode | ||||||||||||
| 52 | |||||||||||||
| 53 | 0 | return $self->_mafft($mode, $profile, $args); | |||||||||||
| 54 | } | ||||||||||||
| 55 | |||||||||||||
| 56 | 0 | ▶ | sub _mafft { | ||||||||||
|
Subroutine
_mafft: not called CC=7 SCAR=40.3
| |||||||||||||
| 57 | 0 | my $self = shift; | |||||||||||
| 58 | 0 | my $mode = shift; | |||||||||||
| 59 | 0 | my $profile; # conditional declaring is bad... | |||||||||||
| 60 | 0 | ▶ | $profile = shift unless $mode eq 'align_all'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 61 | 0 | ▶ | my $args = shift // {}; | ||||||||||
|
Condition0%0/2
shift() // {}
MC/DC0%0/1
shift() // {}
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||
| 62 | |||||||||||||
| 63 | #### in _mafft | ||||||||||||
| 64 | |||||||||||||
| 65 | # provision executable | ||||||||||||
| 66 | 0 | my $app = use_module('Bio::MUST::Provision::Mafft')->new; | |||||||||||
| 67 | 0 | $app->meet(); | |||||||||||
| 68 | |||||||||||||
| 69 | # setup input/output files | ||||||||||||
| 70 | 0 | my $infile = $self->filename; | |||||||||||
| 71 | 0 | my $outfile = $infile . '.mafft'; | |||||||||||
| 72 | |||||||||||||
| 73 | 0 | ▶ | $args->{$profile} = undef if $profile; # should come last (no --) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 74 | 0 | my $args_str = stringify_args($args); | |||||||||||
| 75 | |||||||||||||
| 76 | # see https://mafft.cbrc.jp/alignment/server/add.html | ||||||||||||
| 77 | 0 | my %opt_for = ( | |||||||||||
| 78 | align_all => q{}, | ||||||||||||
| 79 | profile2profile => '--addprofile', | ||||||||||||
| 80 | seqs2profile => '--add', | ||||||||||||
| 81 | long2profile => '--addlong', | ||||||||||||
| 82 | fragments2profile => '--addfragments', | ||||||||||||
| 83 | ); | ||||||||||||
| 84 | |||||||||||||
| 85 | # create mafft command | ||||||||||||
| 86 | 0 | my $pgm = 'mafft'; # linsi, ginsi,... do not work | |||||||||||
| 87 | 0 | ▶ | my $final_args = $mode eq 'align_all' ? "$args_str $infile" : "$infile $args_str"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 88 | 0 | my $cmd = "$pgm $opt_for{$mode} $final_args > $outfile 2> /dev/null"; | |||||||||||
| 89 | 0 | ### $cmd | |||||||||||
| 90 | |||||||||||||
| 91 | # try to robustly execute mafft | ||||||||||||
| 92 | 0 | my $ret_code = system( [ 0, 1, 127 ], $cmd); | |||||||||||
| 93 | 0 | ▶ | if ($ret_code == 127) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 94 | 0 | carp "[BMD] Warning: cannot execute $pgm command; returning nothing!"; | |||||||||||
| 95 | 0 | return; | |||||||||||
| 96 | } | ||||||||||||
| 97 | 0 | ▶ | if ($ret_code == 1) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 98 | 0 | carp "[BMD] Warning: $pgm cannot align files; returning nothing!"; | |||||||||||
| 99 | 0 | file($outfile)->remove; # ugly but needed | |||||||||||
| 100 | 0 | return; | |||||||||||
| 101 | } | ||||||||||||
| 102 | # TODO: try to bypass shell (need for absolute path to executable then) | ||||||||||||
| 103 | |||||||||||||
| 104 | 0 | my $out = Ali->load($outfile); | |||||||||||
| 105 | |||||||||||||
| 106 | # unlink temp files | ||||||||||||
| 107 | 0 | file($outfile)->remove; | |||||||||||
| 108 | |||||||||||||
| 109 | # return Ali | ||||||||||||
| 110 | 0 | return $out; | |||||||||||
| 111 | } | ||||||||||||
| 112 | |||||||||||||
| 113 | |||||||||||||
| 114 | |||||||||||||
| 115 | 6 | __PACKAGE__->meta->make_immutable; | |||||||||||
| 116 | 6 | 1; | |||||||||||
| 117 | |||||||||||||
| 118 | __END__ | ||||||||||||