| 1 | package Bio::MUST::Drivers::Roles::Hmmerable; | ||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: HMMER model-related methods | ||||||||||||||||||||||||||||||||
| 3 | # CONTRIBUTOR: Arnaud DI FRANCO <arnaud.difranco@gmail.com> | ||||||||||||||||||||||||||||||||
| 4 | 5 | $Bio::MUST::Drivers::Roles::Hmmerable::VERSION = '0.252830'; | |||||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use autodie; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use feature qw(say); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | # use Smart::Comments; | ||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 5 | ▶ | use Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use File::Temp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use IPC::System::Simple qw(system); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | 5 | ▶ | use Module::Runtime qw(use_module); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | 5 | ▶ | use Bio::FastParsers; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 18 | 5 | ▶ | use aliased 'Bio::MUST::Core::Ali::Stash'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | 5 | ▶ | use Bio::MUST::Drivers::Utils qw(stringify_args); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub scan { ## no critic (RequireArgUnpacking) | ||||||||||||||||||||||||||||||
|
Subroutine
scan: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 24 | 0 | return shift->_search('hmmscan', @_); | |||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub search { ## no critic (RequireArgUnpacking) | ||||||||||||||||||||||||||||||
|
Subroutine
search: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 28 | 0 | return shift->_search('hmmsearch', @_); | |||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub _search { | ||||||||||||||||||||||||||||||
|
Subroutine
_search: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||
| 32 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 33 | 0 | my $pgm = shift; | |||||||||||||||||||||||||||||||
| 34 | 0 | my $target = shift; | |||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | my $args = shift // {}; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() // {}
MC/DC0%0/1
shift() // {}
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | # provision executable | ||||||||||||||||||||||||||||||||
| 38 | 0 | my $app = use_module('Bio::MUST::Provision::Hmmer')->new; | |||||||||||||||||||||||||||||||
| 39 | 0 | $app->meet(); | |||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | # setup input/output files | ||||||||||||||||||||||||||||||||
| 42 | # Note: we handle both single models and model database... | ||||||||||||||||||||||||||||||||
| 43 | # ... as well as plain target filenames in addition to Ali-like objects | ||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | my $model = $self->can('model') ? $self->model->filename : $self->filename; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | my $in = $target->can('filename') ? $target->filename : $target; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 46 | 0 | my $out = File::Temp->new(UNLINK => 0, EXLOCK => 0, SUFFIX => ".$pgm"); | |||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | # setup output file format and parser subclass | ||||||||||||||||||||||||||||||||
| 49 | 0 | my $parser_class; | |||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if (exists $args->{'--domtblout'} || $pgm eq 'hmmscan') { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
exists $args->{"--domtblout"} or $pgm eq "hmmscan"
MC/DC0%0/2
exists $args->{"--domtblout"} or $pgm eq "hmmscan"
exists $args->{"--domtblout"}
$pgm eq "hmmscan"
Truth table0%0/3
A or B
A= exists $args->{"--domtblout"}B= $pgm eq "hmmscan"
| |||||||||||||||||||||||||||||||||
| 51 | 0 | $args->{'--domtblout'} = $out->filename; | |||||||||||||||||||||||||||||||
| 52 | 0 | $parser_class = 'Bio::FastParsers::Hmmer::DomTable'; | |||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||
| 54 | elsif (exists $args->{'--tblout'} ) { | ||||||||||||||||||||||||||||||||
| 55 | 0 | $args->{'--tblout'} = $out->filename; | |||||||||||||||||||||||||||||||
| 56 | 0 | $parser_class = 'Bio::FastParsers::Hmmer::Table'; | |||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||
| 58 | else { | ||||||||||||||||||||||||||||||||
| 59 | 0 | $args->{'--notextw'} = undef; | |||||||||||||||||||||||||||||||
| 60 | 0 | $args->{'-o'} = $out->filename; | |||||||||||||||||||||||||||||||
| 61 | 0 | $parser_class = 'Bio::FastParsers::Hmmer::Standard'; | |||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | unless ($parser_class) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 64 | 0 | carp '[BMD] Warning: cannot set parser subclass;' | |||||||||||||||||||||||||||||||
| 65 | . ' returning without parser!'; | ||||||||||||||||||||||||||||||||
| 66 | 0 | return; | |||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | # create HMMER command | ||||||||||||||||||||||||||||||||
| 70 | 0 | my $args_str = stringify_args($args); | |||||||||||||||||||||||||||||||
| 71 | 0 | my $cmd = "$pgm $args_str $model $in > /dev/null 2> /dev/null"; | |||||||||||||||||||||||||||||||
| 72 | #### $cmd | ||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | # try to robustly execute HMMER | ||||||||||||||||||||||||||||||||
| 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 parser!'; | ||||||||||||||||||||||||||||||||
| 79 | 0 | return; | |||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | 0 | return $parser_class->new( file => $out->filename ); | |||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | sub emit { | ||||||||||||||||||||||||||||||
|
Subroutine
emit: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 86 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | my $args = shift // { '-C' => undef }; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() // {"-C", undef}
MC/DC0%0/1
shift() // {"-C", undef}
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | # setup input/output files (outfile will be automatically unlinked) | ||||||||||||||||||||||||||||||||
| 90 | 0 | my $model = $self->model->filename; | |||||||||||||||||||||||||||||||
| 91 | 0 | my $out = File::Temp->new(UNLINK => 1, EXLOCK => 0); | |||||||||||||||||||||||||||||||
| 92 | # TODO: check if lifespan of $out temp file long enough for loading | ||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | # create hmmemit command | ||||||||||||||||||||||||||||||||
| 95 | 0 | $args->{'-o'} = $out; | |||||||||||||||||||||||||||||||
| 96 | 0 | my $args_str = stringify_args($args); | |||||||||||||||||||||||||||||||
| 97 | 0 | my $pgm = 'hmmemit'; | |||||||||||||||||||||||||||||||
| 98 | 0 | my $cmd = "$pgm $args_str $model > /dev/null 2> /dev/null"; | |||||||||||||||||||||||||||||||
| 99 | # hmmemit -C -o hmmconsensus_GNTPAN12210.fasta test_emitGNT.hmm | ||||||||||||||||||||||||||||||||
| 100 | #### $cmd | ||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | # try to robustly execute hmmemit | ||||||||||||||||||||||||||||||||
| 103 | 0 | my $ret_code = system( [ 0, 127 ], $cmd); | |||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if ($ret_code == 127) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 105 | 0 | carp "[BMD] Warning: cannot execute $pgm command;" | |||||||||||||||||||||||||||||||
| 106 | . ' returning without seqs!'; | ||||||||||||||||||||||||||||||||
| 107 | 0 | return; | |||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||
| 110 | 0 | return Stash->load( $out->filename ); | |||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||
| 113 | 5 | ▶ | no Moose::Role; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 114 | 5 | 1; | |||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||
| 116 | __END__ | ||||||||||||||||||||||||||||||||