| 1 | package Bio::Gonzales::Search::IO::HMMER3; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Mouse; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use List::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use List::MoreUtils qw/indexes firstidx/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use Bio::Gonzales::Util qw/hash_merge/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 2 | with 'Bio::Gonzales::Util::Role::FileIO'; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 2 | our $VERSION = '0.062'; # VERSION | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 2 | has '_current_query' => ( is => 'rw', default => 0 ); | |||||||||||||||||||||||||||
| 21 | 2 | has '_current_hit' => ( is => 'rw', default => 0 ); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | around BUILDARGS => sub { | ||||||||||||||||||||||||||||
| 24 | 5 | ▶ | my $orig = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.7
| |||||||||||||||||||||||||||||
| 25 | 5 | my $class = shift; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 5 | ▶ | if ( @_ == 1 && Bio::Gonzales::Util::File::is_fh( $_[0] ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ == 1 and Bio::Gonzales::Util::File::is_fh($_[0])
MC/DC0%0/2
@_ == 1 and Bio::Gonzales::Util::File::is_fh($_[0])
@_ == 1
Bio::Gonzales::Util::File::is_fh($_[0])
Truth table33%1/3
A and B
A= @_ == 1B= Bio::Gonzales::Util::File::is_fh($_[0])
| |||||||||||||||||||||||||||||
| 28 | 0 | return $class->$orig( fh => $_[0] ); | |||||||||||||||||||||||||||
| 29 | } else { | ||||||||||||||||||||||||||||
| 30 | 5 | return $class->$orig(@_); | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | 2 | }; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | sub _parse_result { | ||||||||||||||||||||||||||||
| 35 | 5 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_parse_result: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 5 | my $fhi = $self->_fhi; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 5 | my @header = ( [] ); | |||||||||||||||||||||||||||
| 40 | 5 | my @queries = ( [] ); | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 5 | my $current_query; | |||||||||||||||||||||||||||
| 43 | 5 | ▶ | while ( defined( my $l = $fhi->() ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 9769 | $l =~ s/\r\n/\n/; | |||||||||||||||||||||||||||
| 45 | 9769 | chomp $l; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 9769 | ▶ | next if ( $l =~ /^\s*$/ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | #no queries read, yet, so | ||||||||||||||||||||||||||||
| 49 | 8218 | ▶ | if ( !@{ $queries[-1] } && $l =~ /^#/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not @{$queries[-1];} and $l =~ /^#/
MC/DC100%2/2
not @{$queries[-1];} and $l =~ /^#/
not @{$queries[-1];}
$l =~ /^#/
Truth table100%3/3
not(A) and B
A= not @{$queries[-1];}B= $l =~ /^#/
| |||||||||||||||||||||||||||||
| 50 | #parse header | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 51 | push @{ $header[-1] }, $l; | |||||||||||||||||||||||||||
| 53 | } else { | ||||||||||||||||||||||||||||
| 54 | #parsing content | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 8167 | ▶ | if ( $l =~ m@^//$@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 14 | push @queries, []; | |||||||||||||||||||||||||||
| 58 | 14 | push @header, []; | |||||||||||||||||||||||||||
| 59 | } else { | ||||||||||||||||||||||||||||
| 60 | 8153 | push @{ $queries[-1] }, $l; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | pop @header | ||||||||||||||||||||||||||||
| 65 | 5 | ▶ | if ( @{ $header[-1] } == 0 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | pop @queries | ||||||||||||||||||||||||||||
| 67 | 5 | ▶ | if ( @{ $queries[-1] } == 0 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 5 | return ( \@header, \@queries ); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | sub parse { | ||||||||||||||||||||||||||||
| 73 | 5 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
parse: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 5 | my ( $h_raw, $q_raw ) = $self->_parse_result; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 5 | my $q_parsed = $self->_parse_queries($q_raw); | |||||||||||||||||||||||||||
| 78 | 5 | my $q = $self->_format_queries($q_parsed); | |||||||||||||||||||||||||||
| 79 | #my $h = $self->_parse_header($h_raw); | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 5 | return ($q); | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | sub _parse_queries { | ||||||||||||||||||||||||||||
| 85 | 5 | ▶ | my ( $self, $raw_queries ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_parse_queries: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 5 | my @result; | |||||||||||||||||||||||||||
| 88 | 5 | for my $q_raw (@$raw_queries) { | |||||||||||||||||||||||||||
| 89 | # first split into query header and query body | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 14 | my %query; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | #parse query id | ||||||||||||||||||||||||||||
| 94 | 14 | ▶ | if ( $q_raw->[0] =~ /^Query:/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 14 | $query{id} = shift @$q_raw; | |||||||||||||||||||||||||||
| 96 | 14 | $query{id} =~ s/Query:\s+//; | |||||||||||||||||||||||||||
| 97 | 14 | $query{id} =~ s/\s+\[[^\]]+\]$//; | |||||||||||||||||||||||||||
| 98 | } else { | ||||||||||||||||||||||||||||
| 99 | 0 | confess "parsing error: could not parse query id"; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | #parse accession id | ||||||||||||||||||||||||||||
| 103 | 14 | ▶ | if ( $q_raw->[0] =~ /^Accession:/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 7 | $query{accession} = shift @$q_raw; | |||||||||||||||||||||||||||
| 105 | 7 | $query{accession} =~ s/Accession:\s+//; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | #get rid of column descriptions | ||||||||||||||||||||||||||||
| 109 | 14 | ▶ | my $scores_begin = firstidx {/^\s/} @$q_raw; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 110 | 14 | splice( @$q_raw, 0, $scores_begin + 3 ); | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | # find the beginning of the domain annotation | ||||||||||||||||||||||||||||
| 113 | 14 | ▶ | my $domain_ann_begin = firstidx {/^\S/} @$q_raw; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 114 | 14 | $query{scores} = [ splice( @$q_raw, 0, $domain_ann_begin ) ]; | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | #get rid of Domain blah blah line | ||||||||||||||||||||||||||||
| 117 | 14 | shift @$q_raw; | |||||||||||||||||||||||||||
| 118 | 14 | ▶ | my $footer_begin = firstidx { $_ !~ /^(?:(?:>>)|(?:\s+))/ } @$q_raw; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | #cut out the query body and also get rid of the fancy column descriptions | ||||||||||||||||||||||||||||
| 121 | 14 | $query{domain_annotation} = [ grep { $_ !~ /^(\s+#|[-\s]+$)/ } splice( @$q_raw, 0, $footer_begin ) ]; | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | #the rest is internal statistics | ||||||||||||||||||||||||||||
| 124 | 14 | $query{internal_stat} = [@$q_raw]; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 14 | push @result, \%query; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 5 | return \@result; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | sub _parse_header { | ||||||||||||||||||||||||||||
| 133 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_parse_header: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | sub _format_queries { | ||||||||||||||||||||||||||||
| 138 | 5 | ▶ | my ( $self, $parsed_queries, $has_alignments_included ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_format_queries: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 5 | my %queries; | |||||||||||||||||||||||||||
| 141 | 5 | for my $pq (@$parsed_queries) { | |||||||||||||||||||||||||||
| 142 | 14 | my %hits; | |||||||||||||||||||||||||||
| 143 | 14 | my %current_hit = (); | |||||||||||||||||||||||||||
| 144 | 14 | my $skip_lines = 1; | |||||||||||||||||||||||||||
| 145 | 14 | for my $p ( @{ $pq->{domain_annotation} } ) { | |||||||||||||||||||||||||||
| 146 | #>> sph|PGSC0003DMP200011920 (sph) PGSC0003DMT200017313 Protein | ||||||||||||||||||||||||||||
| 147 | 3558 | ▶ | if ( $p =~ /^>>\s*(\S+)/ ) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 148 | 1442 | ▶ | if (%current_hit) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | 1416 | $hits{ $current_hit{id} } = $current_hit{domain_annotations}; | |||||||||||||||||||||||||||
| 150 | 1416 | %current_hit = (); | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | 1442 | $current_hit{id} = $1; | |||||||||||||||||||||||||||
| 153 | 1442 | $skip_lines = 0; | |||||||||||||||||||||||||||
| 154 | ▶ | } elsif ( !$skip_lines && $p =~ /^\s*\d+/ ) { | |||||||||||||||||||||||||||
|
Condition100%3/3
not $skip_lines and $p =~ /^\s*\d+/
MC/DC100%2/2
not $skip_lines and $p =~ /^\s*\d+/
not $skip_lines
$p =~ /^\s*\d+/
Truth table100%3/3
not(A) and B
A= not $skip_linesB= $p =~ /^\s*\d+/
| |||||||||||||||||||||||||||||
| 155 | 1849 | ▶ | $current_hit{domain_annotations} //= []; | ||||||||||||||||||||||||||
|
Condition100%2/2
$current_hit{"domain_annotations"} //= []
MC/DC100%1/1
$current_hit{"domain_annotations"} //= []
$current_hit{"domain_annotations"}
Truth table100%2/2
A
A= $current_hit{"domain_annotations"}
| |||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 1849 | my %domain_annotation = ( | |||||||||||||||||||||||||||
| 158 | score => substr( $p, 7, 6 ), | ||||||||||||||||||||||||||||
| 159 | bias => substr( $p, 14, 5 ), | ||||||||||||||||||||||||||||
| 160 | c_evalue => substr( $p, 20, 9 ), | ||||||||||||||||||||||||||||
| 161 | i_evalue => substr( $p, 30, 9 ), | ||||||||||||||||||||||||||||
| 162 | hmm_from => substr( $p, 40, 7 ), | ||||||||||||||||||||||||||||
| 163 | hmm_to => substr( $p, 48, 7 ), | ||||||||||||||||||||||||||||
| 164 | align_from => substr( $p, 59, 7 ), | ||||||||||||||||||||||||||||
| 165 | align_to => substr( $p, 67, 7 ), | ||||||||||||||||||||||||||||
| 166 | env_from => substr( $p, 78, 7 ), | ||||||||||||||||||||||||||||
| 167 | env_to => substr( $p, 86, 7 ), | ||||||||||||||||||||||||||||
| 168 | acc => substr( $p, 97, 4 ), | ||||||||||||||||||||||||||||
| 169 | ); | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | #remove leading spaces | ||||||||||||||||||||||||||||
| 172 | 1849 | map { $domain_annotation{$_} =~ s/^\s*// } keys %domain_annotation; | |||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 1849 | push @{ $current_hit{domain_annotations} }, \%domain_annotation; | |||||||||||||||||||||||||||
| 175 | } elsif ( $p =~ /^\s*Alignments for each domain:/ ) { | ||||||||||||||||||||||||||||
| 176 | # we found all domains, so skip till next ">>" | ||||||||||||||||||||||||||||
| 177 | 14 | %current_hit = (); | |||||||||||||||||||||||||||
| 178 | 14 | $skip_lines = 1; | |||||||||||||||||||||||||||
| 179 | 14 | next; | |||||||||||||||||||||||||||
| 180 | } else { | ||||||||||||||||||||||||||||
| 181 | 253 | $skip_lines = 1; | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | $hits{ $current_hit{id} } = $current_hit{domain_annotations} | ||||||||||||||||||||||||||||
| 185 | 3544 | ▶ | if (%current_hit); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | #compose id of query id/name and accession id/name | ||||||||||||||||||||||||||||
| 188 | 14 | my $id = $pq->{id}; | |||||||||||||||||||||||||||
| 189 | $id .= "#" . $pq->{accession} | ||||||||||||||||||||||||||||
| 190 | 14 | ▶ | if ( exists( $pq->{accession} ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 191 | 14 | ▶ | $queries{$id} //= {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$queries{$id} //= {}
MC/DC0%0/1
$queries{$id} //= {}
$queries{$id}
Truth table50%1/2
A
A= $queries{$id}
| |||||||||||||||||||||||||||||
| 192 | #id => { hit_id => [ { hit information }, ... ] } | ||||||||||||||||||||||||||||
| 193 | 14 | hash_merge( $queries{$id}, \%hits ); | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | 5 | return \%queries; | |||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 2 | 1; | |||||||||||||||||||||||||||