File Coverage

blib/lib/Bio/MUST/Drivers/Hmmer/Model/Temporary.pm
Criterion Covered Total %
statement 33 52 63.4
branch 0 6 0.0
condition n/a
subroutine 11 13 84.6
pod n/a
total 44 71 61.9


line stmt bran cond sub pod time code
1             package Bio::MUST::Drivers::Hmmer::Model::Temporary;
2             # ABSTRACT: Internal class for HMMER3 driver
3             # CONTRIBUTOR: Arnaud DI FRANCO <arnaud.difranco@gmail.com>
4             $Bio::MUST::Drivers::Hmmer::Model::Temporary::VERSION = '0.193030';
5 5     5   34 use Moose;
  5         11  
  5         38  
6 5     5   39346 use namespace::autoclean;
  5         22  
  5         48  
7              
8 5     5   428 use autodie;
  5         10  
  5         43  
9 5     5   23607 use feature qw(say);
  5         11  
  5         446  
10              
11 5     5   35 use Carp;
  5         18  
  5         415  
12 5     5   45 use File::Temp qw(tempfile);
  5         9  
  5         340  
13 5     5   31 use IPC::System::Simple qw(system);
  5         9  
  5         268  
14 5     5   30 use Module::Runtime qw(use_module);
  5         8  
  5         39  
15 5     5   333 use Path::Class;
  5         12  
  5         423  
16              
17             extends 'Bio::MUST::Core::Ali::Temporary';
18              
19 5     5   35 use aliased 'Bio::FastParsers::Hmmer::Model';
  5         10  
  5         60  
20 5     5   1069 use Bio::MUST::Drivers::Utils qw(stringify_args);
  5         10  
  5         1882  
21              
22              
23             has 'model_args' => (
24             is => 'ro',
25             isa => 'HashRef',
26             default => sub { {} },
27             );
28              
29             has 'model' => (
30             is => 'ro',
31             isa => 'Maybe[Bio::FastParsers::Hmmer::Model]',
32             init_arg => undef,
33             lazy => 1,
34             builder => '_build_model',
35             );
36              
37             with 'Bio::MUST::Drivers::Roles::Hmmerable' => {
38             -excludes => [ qw(scan) ]
39             };
40              
41             ## no critic (ProhibitUnusedPrivateSubroutines)
42              
43             # overload Ali::Temporary default builder
44             sub _build_args {
45 0     0     return { clean => 1, degap => 0 };
46             }
47              
48             sub _build_model {
49 0     0     my $self = shift;
50              
51             # provision executable
52 0           my $app = use_module('Bio::MUST::Provision::Hmmer')->new;
53 0           $app->meet();
54              
55             # skip model creation if no seqs
56 0 0         unless ($self->count_seqs) {
57 0           carp '[BMD] Warning: no sequence provided; returning without model!';
58 0           return;
59             }
60              
61             # setup input/output files
62 0           my $in = $self->filename;
63 0           my $out = File::Temp->new(UNLINK => 0, EXLOCK => 0, SUFFIX => '.hmm');
64              
65             # format hmmbuild (optional) arguments
66 0           my $args = $self->model_args;
67 0 0         $args->{ $self->is_protein ? '--amino' : '--dna' } = undef;
68 0           my $args_str = stringify_args($args);
69              
70             # create hmmbuild command
71 0           my $pgm = 'hmmbuild';
72 0           my $cmd = "$pgm $args_str $out $in > /dev/null 2> /dev/null";
73              
74             # try to robustly execute hmmbuild
75 0           my $ret_code = system( [ 0, 127 ], $cmd);
76 0 0         if ($ret_code == 127) {
77 0           carp "[BMD] Warning: cannot execute $pgm command;"
78             . ' returning without model!';
79 0           return;
80             }
81              
82 0           return Model->new( file => $out->filename );
83             }
84              
85             ## use critic
86              
87             __PACKAGE__->meta->make_immutable;
88             1;
89              
90             __END__
91              
92             =pod
93              
94             =head1 NAME
95              
96             Bio::MUST::Drivers::Hmmer::Model::Temporary - Internal class for HMMER3 driver
97              
98             =head1 VERSION
99              
100             version 0.193030
101              
102             =head1 SYNOPSIS
103              
104             # TODO
105              
106             =head1 DESCRIPTION
107              
108             # TODO
109              
110             =head1 AUTHOR
111              
112             Denis BAURAIN <denis.baurain@uliege.be>
113              
114             =head1 CONTRIBUTOR
115              
116             =for stopwords Arnaud DI FRANCO
117              
118             Arnaud DI FRANCO <arnaud.difranco@gmail.com>
119              
120             =head1 COPYRIGHT AND LICENSE
121              
122             This software is copyright (c) 2013 by University of Liege / Unit of Eukaryotic Phylogenomics / Denis BAURAIN.
123              
124             This is free software; you can redistribute it and/or modify it under
125             the same terms as the Perl 5 programming language system itself.
126              
127             =cut