| 1 | package Bio::FastParsers::Hmmer::DomTable; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Front-end class for tabular HMMER domain parser | ||||||||||||||||||||||||||||
| 3 | # CONTRIBUTOR: Arnaud DI FRANCO <arnaud.difranco@gmail.com> | ||||||||||||||||||||||||||||
| 4 | 7 | $Bio::FastParsers::Hmmer::DomTable::VERSION = '0.213510'; | |||||||||||||||||||||||||||
| 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::DomTable::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 | sub _build_line_iterator { | ||||||||||||||||||||||||||||
| 38 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_build_line_iterator: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 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 tlen | ||||||||||||||||||||||||||||
| 48 | query_name query_accession qlen | ||||||||||||||||||||||||||||
| 49 | evalue score bias rank of | ||||||||||||||||||||||||||||
| 50 | c_evalue i_evalue dom_score dom_bias | ||||||||||||||||||||||||||||
| 51 | hmm_from hmm_to ali_from ali_to env_from env_to | ||||||||||||||||||||||||||||
| 52 | acc target_description | ||||||||||||||||||||||||||||
| 53 | ); # DID try to use MOP to get Hit attrs but order was not preserved | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | sub next_hit { | ||||||||||||||||||||||||||||
| 57 | 43 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
next_hit: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | LINE: | ||||||||||||||||||||||||||||
| 60 | 43 | ▶ | while (my $line = $self->_next_line) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | # skip header/comments and empty lines | ||||||||||||||||||||||||||||
| 63 | 47 | chomp $line; | |||||||||||||||||||||||||||
| 64 | 47 | ▶ | next LINE if $line =~ $COMMENT_LINE | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$line =~ /$Bio::FastParsers::Hmmer::DomTable::COMMENT_LINE/ or $line =~ /$Bio::FastParsers::Hmmer::DomTable::EMPTY_LINE/
MC/DC50%1/2
$line =~ /$Bio::FastParsers::Hmmer::DomTable::COMMENT_LINE/ or $line =~ /$Bio::FastParsers::Hmmer::DomTable::EMPTY_LINE/
$line =~ /$Bio::FastParsers::Hmmer::DomTable::COMMENT_LINE/
$line =~ /$Bio::FastParsers::Hmmer::DomTable::EMPTY_LINE/
Truth table66%2/3
A or B
A= $line =~ /$Bio::FastParsers::Hmmer::DomTable::COMMENT_LINE/B= $line =~ /$Bio::FastParsers::Hmmer::DomTable::EMPTY_LINE/
| |||||||||||||||||||||||||||||
| 65 | || $line =~ $EMPTY_LINE; | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | # process Hit line | ||||||||||||||||||||||||||||
| 68 | 41 | my @fields = split(/\s+/xms, $line, 23); | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | # Fields | ||||||||||||||||||||||||||||
| 71 | # 0. target name | ||||||||||||||||||||||||||||
| 72 | # 1. target accession | ||||||||||||||||||||||||||||
| 73 | # 2. tlen | ||||||||||||||||||||||||||||
| 74 | # 3. query name | ||||||||||||||||||||||||||||
| 75 | # 4. accession | ||||||||||||||||||||||||||||
| 76 | # 5. qlen | ||||||||||||||||||||||||||||
| 77 | # 6. E-value | ||||||||||||||||||||||||||||
| 78 | # 7. score | ||||||||||||||||||||||||||||
| 79 | # 8. bias | ||||||||||||||||||||||||||||
| 80 | # 9. rank | ||||||||||||||||||||||||||||
| 81 | # 10. of | ||||||||||||||||||||||||||||
| 82 | # 11. c-Evalue | ||||||||||||||||||||||||||||
| 83 | # 12. i-Evalue | ||||||||||||||||||||||||||||
| 84 | # 13. dom_score | ||||||||||||||||||||||||||||
| 85 | # 14. dom_bias | ||||||||||||||||||||||||||||
| 86 | # 15. from (hmm coord) | ||||||||||||||||||||||||||||
| 87 | # 16. to (hmm coord) | ||||||||||||||||||||||||||||
| 88 | # 17. from (ali coord) | ||||||||||||||||||||||||||||
| 89 | # 18. to (ali coord) | ||||||||||||||||||||||||||||
| 90 | # 19. from (env coord) | ||||||||||||||||||||||||||||
| 91 | # 20. to (env coord) | ||||||||||||||||||||||||||||
| 92 | # 21. acc | ||||||||||||||||||||||||||||
| 93 | # 22. description of target | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | # coerce numeric fields to numbers | ||||||||||||||||||||||||||||
| 96 | 41 | @fields[5..21] = map { 0 + $_ } @fields[5..21]; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | # set missing field values to undef | ||||||||||||||||||||||||||||
| 99 | 41 | ▶ | @fields[1,4,22] = map { $_ eq '-' ? undef : $_ } @fields[1,4,22]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | # return Hit object | ||||||||||||||||||||||||||||
| 102 | 41 | return Hit->new( { mesh @attrs, @fields } ); | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 2 | return; # no more line to read | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 7 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 110 | 7 | 1; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | __END__ | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =pod | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | =head1 NAME | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | Bio::FastParsers::Hmmer::DomTable - Front-end class for tabular HMMER domain parser | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | =head1 VERSION | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | version 0.213510 | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | use aliased 'Bio::FastParsers::Hmmer::DomTable'; | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | # open and parse HMMER domain report in tabular format | ||||||||||||||||||||||||||||
| 129 | my $infile = 'test/hmmer.domtblout'; | ||||||||||||||||||||||||||||
| 130 | my $report = DomTable->new( file => $infile ); | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | # loop through hits | ||||||||||||||||||||||||||||
| 133 | while (my $hit = $hit->next_hit) { | ||||||||||||||||||||||||||||
| 134 | my ($target_name, $evalue) = ($hit->target_name, $hit->evalue); | ||||||||||||||||||||||||||||
| 135 | # ... | ||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | # TODO | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | =head2 file | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | Path to HMMER domain report file in tabular format (--domtblout) to be parsed | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | =head1 METHODS | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | =head2 next_hit | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | Shifts the first Hit of the report off and returns it, shortening the report | ||||||||||||||||||||||||||||
| 153 | by 1 and moving everything down. If there are no more Hits in the report, | ||||||||||||||||||||||||||||
| 154 | returns C<undef>. | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | # $report is a Bio::FastParsers::Hmmer::Table | ||||||||||||||||||||||||||||
| 157 | while (my $hit = $report->next_hit) { | ||||||||||||||||||||||||||||
| 158 | # process $hit | ||||||||||||||||||||||||||||
| 159 | # ... | ||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | This method does not accept any arguments. | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | Denis BAURAIN <denis.baurain@uliege.be> | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | =head1 CONTRIBUTOR | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | =for stopwords Arnaud DI FRANCO | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | Arnaud DI FRANCO <arnaud.difranco@gmail.com> | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | This software is copyright (c) 2013 by University of Liege / Unit of Eukaryotic Phylogenomics / Denis BAURAIN. | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 179 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | =cut | ||||||||||||||||||||||||||||