| 1 | package Bio::FastParsers::Hmmer::Standard::Iteration; | ||||||||||
| 2 | # ABSTRACT: Front-end class for standard HMMER parser | ||||||||||
| 3 | # CONTRIBUTOR: Arnaud DI FRANCO <arnaud.difranco@gmail.com> | ||||||||||
| 4 | 7 | $Bio::FastParsers::Hmmer::Standard::Iteration::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(indexes firstidx mesh); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 7 | ▶ | use Bio::FastParsers::Constants qw(:files); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 7 | ▶ | use aliased 'Bio::FastParsers::Hmmer::Standard::Target'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | |||||||||||
| 16 | # public attributes | ||||||||||
| 17 | |||||||||||
| 18 | 7 | has 'query' => ( | |||||||||
| 19 | is => 'ro', | ||||||||||
| 20 | isa => 'Str', | ||||||||||
| 21 | required => 1, | ||||||||||
| 22 | ); | ||||||||||
| 23 | |||||||||||
| 24 | 7 | has 'query_length' => ( | |||||||||
| 25 | is => 'ro', | ||||||||||
| 26 | isa => 'Int', | ||||||||||
| 27 | required => 1, | ||||||||||
| 28 | ); | ||||||||||
| 29 | |||||||||||
| 30 | 7 | has 'targets' => ( | |||||||||
| 31 | traits => ['Array'], | ||||||||||
| 32 | is => 'ro', | ||||||||||
| 33 | isa => 'ArrayRef[Bio::FastParsers::Hmmer::Standard::Target]', | ||||||||||
| 34 | required => 1, | ||||||||||
| 35 | handles => { | ||||||||||
| 36 | next_target => 'shift', | ||||||||||
| 37 | get_target => 'get', | ||||||||||
| 38 | all_targets => 'elements', | ||||||||||
| 39 | count_targets => 'count', | ||||||||||
| 40 | }, | ||||||||||
| 41 | ); | ||||||||||
| 42 | |||||||||||
| 43 | ## no critic (ProhibitUnusedPrivateSubroutines) | ||||||||||
| 44 | |||||||||||
| 45 | around BUILDARGS => sub { | ||||||||||
| 46 | 10 | ▶ | my ($orig, $class, $iter_block) = @_; | ||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=20.8
| |||||||||||
| 47 | |||||||||||
| 48 | 10 | my %outargs; | |||||||||
| 49 | my @hits; | ||||||||||
| 50 | |||||||||||
| 51 | # Parse Iteration to separate header information (q, qlen), header hit | ||||||||||
| 52 | # table (Hit) and main output information per target (Target). | ||||||||||
| 53 | # Hit and Target are the same entity but Hit is close to what is retrieved | ||||||||||
| 54 | # from a Hmmer::Table output. For now, we chose to conserve Target as | ||||||||||
| 55 | # primary name since it is how it is called in the file. | ||||||||||
| 56 | |||||||||||
| 57 | 10 | my @lines = split /\n/xms, $iter_block; | |||||||||
| 58 | |||||||||||
| 59 | LINE: | ||||||||||
| 60 | 10 | for my $line (@lines) { | |||||||||
| 61 | |||||||||||
| 62 | # parse header | ||||||||||
| 63 | 110 | ▶ | if ($line =~ m/Query:/xms) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 10 | my @fields = split /\s+/xms, $line; | |||||||||
| 65 | 10 | $outargs{'query'} = $fields[1]; | |||||||||
| 66 | 10 | ( $outargs{'query_length'} = $fields[2] ) =~ s/\D//xmsg; | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | # parse Hit | ||||||||||
| 70 | 110 | my @attrs = qw( | |||||||||
| 71 | evalue score bias | ||||||||||
| 72 | best_dom_evalue best_dom_score best_dom_bias | ||||||||||
| 73 | exp dom query_name target_description | ||||||||||
| 74 | ); | ||||||||||
| 75 | |||||||||||
| 76 | 110 | ▶ | if ($line =~ m/^\s+ (\d .*)/xms) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 77 | 20 | my @fields = split /\s+/xms, $1; | |||||||||
| 78 | |||||||||||
| 79 | # Fields | ||||||||||
| 80 | # 0. full seq - evalue | ||||||||||
| 81 | # 1. full seq - score | ||||||||||
| 82 | # 2. full seq - bias | ||||||||||
| 83 | # 3. best domain - evalue | ||||||||||
| 84 | # 4. best domain - score | ||||||||||
| 85 | # 5. best domain - bias | ||||||||||
| 86 | # 6. #domain - exp | ||||||||||
| 87 | # 7. #domain - N | ||||||||||
| 88 | # 8. sequence | ||||||||||
| 89 | # 9. description | ||||||||||
| 90 | |||||||||||
| 91 | # coerce numeric fields to numbers | ||||||||||
| 92 | 20 | @fields[0..7] = map { 0 + $_ } @fields[0..7]; | |||||||||
| 93 | |||||||||||
| 94 | # fixing description | ||||||||||
| 95 | 20 | $fields[9] = join q{ }, @fields[9..$#fields]; | |||||||||
| 96 | # set missing/empty field values to undef | ||||||||||
| 97 | 20 | ▶ | @fields[8..9] = map { $_ || undef } @fields[8..9]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 98 | |||||||||||
| 99 | 20 | my @wanted = @fields[0..9]; | |||||||||
| 100 | 20 | push @hits, { mesh @attrs, @wanted }; | |||||||||
| 101 | } | ||||||||||
| 102 | |||||||||||
| 103 | # process only header | ||||||||||
| 104 | 110 | ▶ | last LINE if $line =~ m/^\>\>/xms; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 105 | } | ||||||||||
| 106 | |||||||||||
| 107 | # split Targets (Hits) | ||||||||||
| 108 | 10 | ▶ | my @target_indexes = indexes { m/^\>\>/xms } @lines; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 109 | 10 | my @targets; | |||||||||
| 110 | 10 | ▶ | for (my $i = 0; $i < @target_indexes; $i++) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 111 | 20 | ▶ | my @block = defined $target_indexes[$i+1] | ||||||||
|
Branch: 1 branch
| |||||||||||
| 112 | ? @lines[ $target_indexes[$i] .. $target_indexes[$i+1] ] | ||||||||||
| 113 | : splice @lines, $target_indexes[$i] | ||||||||||
| 114 | ; | ||||||||||
| 115 | 20 | push @targets, Target->new( { raw => \@block, hit => $hits[$i] } ); | |||||||||
| 116 | } | ||||||||||
| 117 | 10 | $outargs{targets} = \@targets; | |||||||||
| 118 | |||||||||||
| 119 | # return expected constructor hash | ||||||||||
| 120 | 10 | return $class->$orig(%outargs); | |||||||||
| 121 | 7 | }; | |||||||||
| 122 | |||||||||||
| 123 | |||||||||||
| 124 | # aliases for Target/Hit | ||||||||||
| 125 | |||||||||||
| 126 | sub next_hit { | ||||||||||
| 127 | 0 | ▶ | return shift->next_target; | ||||||||
|
Subroutine
next_hit: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 128 | } | ||||||||||
| 129 | |||||||||||
| 130 | sub get_hit { ## no critic (RequireArgUnpacking) | ||||||||||
| 131 | 0 | ▶ | return shift->get_target(@_); | ||||||||
|
Subroutine
get_hit: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 132 | } | ||||||||||
| 133 | |||||||||||
| 134 | sub all_hits { | ||||||||||
| 135 | 0 | ▶ | return shift->all_targets; | ||||||||
|
Subroutine
all_hits: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 136 | } | ||||||||||
| 137 | |||||||||||
| 138 | sub count_hits { | ||||||||||
| 139 | 0 | ▶ | return shift->count_targets; | ||||||||
|
Subroutine
count_hits: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 140 | } | ||||||||||
| 141 | |||||||||||
| 142 | 7 | __PACKAGE__->meta->make_immutable; | |||||||||
| 143 | 7 | 1; | |||||||||
| 144 | |||||||||||
| 145 | __END__ | ||||||||||
| 146 | |||||||||||
| 147 | =pod | ||||||||||
| 148 | |||||||||||
| 149 | =head1 NAME | ||||||||||
| 150 | |||||||||||
| 151 | Bio::FastParsers::Hmmer::Standard::Iteration - Front-end class for standard HMMER parser | ||||||||||
| 152 | |||||||||||
| 153 | =head1 VERSION | ||||||||||
| 154 | |||||||||||
| 155 | version 0.213510 | ||||||||||
| 156 | |||||||||||
| 157 | =head1 SYNOPSIS | ||||||||||
| 158 | |||||||||||
| 159 | use aliased 'Bio::FastParsers::Hmmer::Standard'; | ||||||||||
| 160 | |||||||||||
| 161 | # open and parse hmmsearch output | ||||||||||
| 162 | my $infile = 'test/hmmer.out'; | ||||||||||
| 163 | my $parser = Standard->new(file => $infile); | ||||||||||
| 164 | |||||||||||
| 165 | =head1 DESCRIPTION | ||||||||||
| 166 | |||||||||||
| 167 | # TODO | ||||||||||
| 168 | |||||||||||
| 169 | =head1 AUTHOR | ||||||||||
| 170 | |||||||||||
| 171 | Denis BAURAIN <denis.baurain@uliege.be> | ||||||||||
| 172 | |||||||||||
| 173 | =head1 CONTRIBUTOR | ||||||||||
| 174 | |||||||||||
| 175 | =for stopwords Arnaud DI FRANCO | ||||||||||
| 176 | |||||||||||
| 177 | Arnaud DI FRANCO <arnaud.difranco@gmail.com> | ||||||||||
| 178 | |||||||||||
| 179 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 180 | |||||||||||
| 181 | This software is copyright (c) 2013 by University of Liege / Unit of Eukaryotic Phylogenomics / Denis BAURAIN. | ||||||||||
| 182 | |||||||||||
| 183 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 184 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 185 | |||||||||||
| 186 | =cut | ||||||||||