| 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 | 5 | $Bio::MUST::Drivers::Hmmer::Model::Temporary::VERSION = '0.210160'; | |||||||||
| 5 | 5 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 5 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 5 | ▶ | use autodie; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 5 | ▶ | use feature qw(say); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 5 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 5 | ▶ | use File::Temp qw(tempfile); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 5 | ▶ | use IPC::System::Simple qw(system); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 5 | ▶ | use Module::Runtime qw(use_module); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 5 | ▶ | use Path::Class; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | 5 | extends 'Bio::MUST::Core::Ali::Temporary'; | |||||||||
| 18 | |||||||||||
| 19 | 5 | ▶ | use aliased 'Bio::FastParsers::Hmmer::Model'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 5 | ▶ | use Bio::MUST::Drivers::Utils qw(stringify_args); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | |||||||||||
| 22 | |||||||||||
| 23 | has 'model_args' => ( | ||||||||||
| 24 | is => 'ro', | ||||||||||
| 25 | isa => 'HashRef', | ||||||||||
| 26 | 0 | ▶ | default => sub { {} }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 27 | 5 | ); | |||||||||
| 28 | |||||||||||
| 29 | 5 | 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 | 5 | 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 | ▶ | return { clean => 1, degap => 0 }; | ||||||||
|
Subroutine
_build_args: not called CC=1 SCAR=6.9
| |||||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | sub _build_model { | ||||||||||
| 49 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_build_model: not called CC=4 SCAR=30.0
| |||||||||||
| 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 | ▶ | unless ($self->count_seqs) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ▶ | $args->{ $self->is_protein ? '--amino' : '--dna' } = undef; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ▶ | if ($ret_code == 127) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | 5 | __PACKAGE__->meta->make_immutable; | |||||||||
| 88 | 5 | 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.210160 | ||||||||||
| 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 | ||||||||||