File Coverage

blib/lib/Bio/MUST/Drivers/Mafft.pm
Criterion Covered Total %
statement 33 64 51.5
branch 0 10 0.0
condition 0 2 0.0
subroutine 11 15 73.3
pod 0 3 0.0
total 44 94 46.8


line stmt bran cond sub pod time code
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             $Bio::MUST::Drivers::Mafft::VERSION = '0.210160';
5 6     6   4785411 use Moose;
  6         22  
  6         46  
6 6     6   42275 use namespace::autoclean;
  6         17  
  6         49  
7              
8 6     6   588 use autodie;
  6         15  
  6         42  
9 6     6   33455 use feature qw(say);
  6         16  
  6         533  
10              
11             # use Smart::Comments;
12              
13 6     6   60 use Carp;
  6         16  
  6         443  
14 6     6   41 use IPC::System::Simple qw(system);
  6         13  
  6         325  
15 6     6   55 use Module::Runtime qw(use_module);
  6         25  
  6         60  
16 6     6   530 use Path::Class qw(file);
  6         16  
  6         327  
17              
18 6     6   50 use Bio::MUST::Core;
  6         15  
  6         316  
19             extends 'Bio::FastParsers::Base';
20              
21 6     6   589 use Bio::MUST::Drivers::Utils qw(stringify_args);
  6         15  
  6         402  
22 6     6   55 use aliased 'Bio::MUST::Core::Ali';
  6         15  
  6         51  
23              
24              
25             sub align_all { ## no critic (RequireArgUnpacking)
26 0     0 0   return shift->_mafft('align_all', @_);
27             }
28              
29             sub seqs2profile { ## no critic (RequireArgUnpacking)
30 0     0 0   return shift->_mafft('seqs2profile', @_);
31             }
32              
33             sub profile2profile { ## no critic (RequireArgUnpacking)
34 0     0 0   my $out = shift->_mafft('profile2profile' , @_);
35 0 0         return $out if $out;
36              
37 0           carp '[BMD] Warning: cannot align profiles; returning nothing!';
38 0           return;
39             }
40              
41             sub _mafft {
42 0     0     my $self = shift;
43 0           my $mode = shift;
44 0           my $profile; # conditional declaring is bad...
45 0 0         $profile = shift unless $mode eq 'align_all';
46 0   0       my $args = shift // {};
47              
48             #### in _mafft
49              
50             # provision executable
51 0           my $app = use_module('Bio::MUST::Provision::Mafft')->new;
52 0           $app->meet();
53              
54             # setup input/output files
55 0           my $infile = $self->filename;
56 0           my $outfile = $infile . '.mafft';
57              
58 0 0         $args->{$profile} = undef if $profile; # should come last (no --)
59 0           my $args_str = stringify_args($args);
60              
61 0           my %opt_for = (
62             align_all => q{},
63             seqs2profile => '--add',
64             profile2profile => '--addprofile',
65             );
66              
67             # create mafft command
68 0           my $pgm = 'mafft'; # linsi, ginsi,... do not work
69 0           my $cmd = "$pgm $opt_for{$mode} $infile $args_str > $outfile 2> /dev/null";
70             #### $cmd
71              
72             # try to robustly execute mafft
73 0           my $ret_code = system( [ 0, 1, 127 ], $cmd);
74 0 0         if ($ret_code == 127) {
75 0           carp "[BMD] Warning: cannot execute $pgm command; returning nothing!";
76 0           return;
77             }
78 0 0         if ($ret_code == 1) {
79 0           carp "[BMD] Warning: $pgm cannot align files; returning nothing!";
80 0           file($outfile)->remove; # ugly but needed
81 0           return;
82             }
83             # TODO: try to bypass shell (need for absolute path to executable then)
84              
85 0           my $out = Ali->load($outfile);
86              
87             # unlink temp files
88 0           file($outfile)->remove;
89              
90             # return Ali
91 0           return $out;
92             }
93              
94              
95              
96             __PACKAGE__->meta->make_immutable;
97             1;
98              
99             __END__
100              
101             =pod
102              
103             =head1 NAME
104              
105             Bio::MUST::Drivers::Mafft - Bio::MUST driver for running the MAFFT program
106              
107             =head1 VERSION
108              
109             version 0.210160
110              
111             =head1 SYNOPSIS
112              
113             # TODO
114              
115             =head1 DESCRIPTION
116              
117             # TODO
118              
119             =head1 AUTHOR
120              
121             Denis BAURAIN <denis.baurain@uliege.be>
122              
123             =head1 CONTRIBUTOR
124              
125             =for stopwords Amandine BERTRAND
126              
127             Amandine BERTRAND <amandine.bertrand@doct.uliege.be>
128              
129             =head1 COPYRIGHT AND LICENSE
130              
131             This software is copyright (c) 2013 by University of Liege / Unit of Eukaryotic Phylogenomics / Denis BAURAIN.
132              
133             This is free software; you can redistribute it and/or modify it under
134             the same terms as the Perl 5 programming language system itself.
135              
136             =cut