| 1 | package Bio::FastParsers::Hmmer::Table; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Front-end class for tabular HMMER parser | ||||||||||||||||||||||||||||
| 3 | # CONTRIBUTOR: Arnaud DI FRANCO <arnaud.difranco@gmail.com> | ||||||||||||||||||||||||||||
| 4 | 7 | $Bio::FastParsers::Hmmer::Table::VERSION = '0.221230'; | |||||||||||||||||||||||||||
| 5 | 7 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use autodie; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use List::AllUtils qw(mesh); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 7 | extends 'Bio::FastParsers::Base'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 7 | ▶ | use Bio::FastParsers::Constants qw(:files); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 7 | ▶ | use aliased 'Bio::FastParsers::Hmmer::Table::Hit'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # public attributes (inherited) | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | # private attributes | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 7 | has '_line_iterator' => ( | |||||||||||||||||||||||||||
| 24 | traits => ['Code'], | ||||||||||||||||||||||||||||
| 25 | is => 'ro', | ||||||||||||||||||||||||||||
| 26 | isa => 'CodeRef', | ||||||||||||||||||||||||||||
| 27 | init_arg => undef, | ||||||||||||||||||||||||||||
| 28 | lazy => 1, | ||||||||||||||||||||||||||||
| 29 | builder => '_build_line_iterator', | ||||||||||||||||||||||||||||
| 30 | handles => { | ||||||||||||||||||||||||||||
| 31 | _next_line => 'execute', | ||||||||||||||||||||||||||||
| 32 | }, | ||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | ## no critic (ProhibitUnusedPrivateSubroutines) | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 2 | ▶ | sub _build_line_iterator { | ||||||||||||||||||||||||||
|
Subroutine
_build_line_iterator: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 2 | open my $fh, '<', $self->file; # autodie | |||||||||||||||||||||||||||
| 41 | 2 | ▶ | return sub { <$fh> }; # return closure | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | ## use critic | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 7 | my @attrs = qw( | |||||||||||||||||||||||||||
| 47 | target_name target_accession | ||||||||||||||||||||||||||||
| 48 | query_name query_accession | ||||||||||||||||||||||||||||
| 49 | evalue score bias | ||||||||||||||||||||||||||||
| 50 | best_dom_evalue best_dom_score best_dom_bias | ||||||||||||||||||||||||||||
| 51 | exp reg clu ov env dom rep inc | ||||||||||||||||||||||||||||
| 52 | target_description | ||||||||||||||||||||||||||||
| 53 | ); # DID try to use MOP to get Hit attrs but order was not preserved | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 60 | ▶ | sub next_hit { | ||||||||||||||||||||||||||
|
Subroutine
next_hit: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 57 | 60 | my $self = shift; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | LINE: | ||||||||||||||||||||||||||||
| 60 | 60 | ▶ | while (my $line = $self->_next_line) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | # skip header/comments and empty lines | ||||||||||||||||||||||||||||
| 63 | 64 | chomp $line; | |||||||||||||||||||||||||||
| 64 | 64 | ▶ | next LINE if $line =~ $COMMENT_LINE | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$line =~ /$Bio::FastParsers::Hmmer::Table::COMMENT_LINE/ or $line =~ /$Bio::FastParsers::Hmmer::Table::EMPTY_LINE/
MC/DC50%1/2
$line =~ /$Bio::FastParsers::Hmmer::Table::COMMENT_LINE/ or $line =~ /$Bio::FastParsers::Hmmer::Table::EMPTY_LINE/
$line =~ /$Bio::FastParsers::Hmmer::Table::COMMENT_LINE/
$line =~ /$Bio::FastParsers::Hmmer::Table::EMPTY_LINE/
Truth table66%2/3
A or B
A= $line =~ /$Bio::FastParsers::Hmmer::Table::COMMENT_LINE/B= $line =~ /$Bio::FastParsers::Hmmer::Table::EMPTY_LINE/
| |||||||||||||||||||||||||||||
| 65 | || $line =~ $EMPTY_LINE; | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | # process Hit line | ||||||||||||||||||||||||||||
| 68 | 58 | my @fields = split(/\s+/xms, $line, 19); | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | # Fields | ||||||||||||||||||||||||||||
| 71 | # 0. target name | ||||||||||||||||||||||||||||
| 72 | # 1. accession | ||||||||||||||||||||||||||||
| 73 | # 2. query name | ||||||||||||||||||||||||||||
| 74 | # 3. accession | ||||||||||||||||||||||||||||
| 75 | # 4. E-value | ||||||||||||||||||||||||||||
| 76 | # 5. score | ||||||||||||||||||||||||||||
| 77 | # 6. bias | ||||||||||||||||||||||||||||
| 78 | # 7. E-value | ||||||||||||||||||||||||||||
| 79 | # 8. score | ||||||||||||||||||||||||||||
| 80 | # 9. bias | ||||||||||||||||||||||||||||
| 81 | # 10. exp | ||||||||||||||||||||||||||||
| 82 | # 11. reg | ||||||||||||||||||||||||||||
| 83 | # 12. clu | ||||||||||||||||||||||||||||
| 84 | # 13. ov | ||||||||||||||||||||||||||||
| 85 | # 14. env | ||||||||||||||||||||||||||||
| 86 | # 15. dom | ||||||||||||||||||||||||||||
| 87 | # 16. rep | ||||||||||||||||||||||||||||
| 88 | # 17. inc | ||||||||||||||||||||||||||||
| 89 | # 18. description of target | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | # coerce numeric fields to numbers | ||||||||||||||||||||||||||||
| 92 | 58 | @fields[4..17] = map { 0 + $_ } @fields[4..17]; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | # set missing field values to undef | ||||||||||||||||||||||||||||
| 95 | 58 | ▶ | @fields[1,3,18] = map { $_ eq '-' ? undef : $_ } @fields[1,3,18]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | # return Hit object | ||||||||||||||||||||||||||||
| 98 | 58 | return Hit->new( { mesh @attrs, @fields } ); | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 2 | return; # no more line to read | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 7 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 105 | 7 | 1; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | __END__ | ||||||||||||||||||||||||||||