| 1 | package Bio::MUST::Apps::HmmCleaner::Process; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Process class for HmmCleaner | ||||||||||||||||||||||||||||
| 3 | 3 | $Bio::MUST::Apps::HmmCleaner::Process::VERSION = '0.180750'; | |||||||||||||||||||||||||||
| 4 | 3 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Smart::Comments -ENV; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Modern::Perl; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Bio::MUST::Core 0.180230; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Bio::MUST::Core::Constants qw(:gaps :files); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Bio::FastParsers::Hmmer; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use aliased 'Bio::MUST::Core::Seq'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | ####### [PROCESS] Value of env verbosity : scalar(split ' ', $ENV{Smart_Comments}) | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # ATTRIBUTES | ||||||||||||||||||||||||||||
| 19 | 3 | has 'ali' => ( | |||||||||||||||||||||||||||
| 20 | is => 'ro', | ||||||||||||||||||||||||||||
| 21 | isa => 'Bio::MUST::Core::Ali', | ||||||||||||||||||||||||||||
| 22 | required => 1, | ||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 3 | has 'seq' => ( | |||||||||||||||||||||||||||
| 26 | is => 'ro', | ||||||||||||||||||||||||||||
| 27 | isa => 'Bio::MUST::Core::Seq', | ||||||||||||||||||||||||||||
| 28 | required => 1, | ||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 3 | has 'model' => ( | |||||||||||||||||||||||||||
| 32 | is => 'ro', | ||||||||||||||||||||||||||||
| 33 | isa => 'Bio::MUST::Drivers::Hmmer::Model::Temporary', | ||||||||||||||||||||||||||||
| 34 | required => 1, | ||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 3 | has 'nogap_seq' => ( | |||||||||||||||||||||||||||
| 38 | is => 'ro', | ||||||||||||||||||||||||||||
| 39 | isa => 'Bio::MUST::Core::Seq', | ||||||||||||||||||||||||||||
| 40 | lazy => 1, | ||||||||||||||||||||||||||||
| 41 | builder => '_build_nogap_seq', | ||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 3 | has 'parser' => ( | |||||||||||||||||||||||||||
| 45 | is => 'ro', | ||||||||||||||||||||||||||||
| 46 | isa => 'Bio::FastParsers::Hmmer::Standard', | ||||||||||||||||||||||||||||
| 47 | lazy => 1, | ||||||||||||||||||||||||||||
| 48 | builder => '_build_parser', | ||||||||||||||||||||||||||||
| 49 | ); | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 3 | has 'score' => ( | |||||||||||||||||||||||||||
| 52 | is => 'ro', | ||||||||||||||||||||||||||||
| 53 | isa => 'Str', | ||||||||||||||||||||||||||||
| 54 | lazy => 1, | ||||||||||||||||||||||||||||
| 55 | builder => '_build_scoreseq', | ||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 3 | has 'consider_X' => ( | |||||||||||||||||||||||||||
| 59 | is => 'ro', | ||||||||||||||||||||||||||||
| 60 | isa => 'Bool', | ||||||||||||||||||||||||||||
| 61 | default => 1, | ||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 3 | has 'debug_mode' => ( | |||||||||||||||||||||||||||
| 65 | is => 'ro', | ||||||||||||||||||||||||||||
| 66 | isa => 'Bool', | ||||||||||||||||||||||||||||
| 67 | default => 0, | ||||||||||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | # BUILDER | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # do the hmmsearch and recover the standard parser for current process | ||||||||||||||||||||||||||||
| 73 | sub _build_parser { | ||||||||||||||||||||||||||||
| 74 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_build_parser: called CC=2 SCAR=7.4
| |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 4 | my $hmmer = $self->model; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | # we work without gap | ||||||||||||||||||||||||||||
| 79 | # Hmmsearch output file and parser | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 4 | ▶ | my $target = Bio::MUST::Core::Ali::Temporary->new( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | seqs => [$self->nogap_seq], | ||||||||||||||||||||||||||||
| 83 | args => { | ||||||||||||||||||||||||||||
| 84 | degap => 0, | ||||||||||||||||||||||||||||
| 85 | gapify => 0, | ||||||||||||||||||||||||||||
| 86 | clean => 0, | ||||||||||||||||||||||||||||
| 87 | persistent => ($self->debug_mode) ? 1 : 0, | ||||||||||||||||||||||||||||
| 88 | }, | ||||||||||||||||||||||||||||
| 89 | ); | ||||||||||||||||||||||||||||
| 90 | 4 | my $parser = $hmmer->search( $target, { '--notextw' => undef, }); # removed domE 10e-3 | |||||||||||||||||||||||||||
| 91 | #~ my $parser = $hmmer->search( [$self->nogap_seq], { '--notextw' => undef, '--domE' => 10e-3} ); | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 0 | return $parser; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | sub _build_nogap_seq { | ||||||||||||||||||||||||||||
| 97 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_build_nogap_seq: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 98 | 2 | my $seq = $self->seq; | |||||||||||||||||||||||||||
| 99 | 2 | ▶ | my $nogap_seq = ($self->consider_X) ? $seq->clone->gapify('X')->degap : $seq->clone->gapify->degap; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | ###### [PROCESS] nogap seq : $nogap_seq->seq | ||||||||||||||||||||||||||||
| 101 | 2 | return $nogap_seq; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | sub _build_scoreseq { | ||||||||||||||||||||||||||||
| 105 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_build_scoreseq: called CC=10 SCAR=45.7
| |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 2 | my $target = $self->parser->next_iteration->next_target; | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | my $seqfullid = $self->seq->full_id; | |||||||||||||||||||||||||||
| 110 | 0 | my $seqlength = $self->nogap_seq->seq_len; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | my $concat_scoreseq; | |||||||||||||||||||||||||||
| 113 | 0 | ▶ | if ( defined $target ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | ### [PROCESS] Actual target name : $target->name | ||||||||||||||||||||||||||||
| 115 | 0 | my @domains_info = $target->all_domains; | |||||||||||||||||||||||||||
| 116 | #### [PROCESS] Nb of domains : scalar(@domains_info) | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | # check for ovelapping domains | ||||||||||||||||||||||||||||
| 119 | 0 | ▶ | for(my $i=0; $i<@domains_info; $i++){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 0 | ▶ | for(my $j=$i+1; $j<@domains_info; $j++){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | 0 | my $o = _overlap( $domains_info[$i]->hmm_start, $domains_info[$i]->hmm_end, $domains_info[$j]->hmm_start, $domains_info[$j]->hmm_end ); | |||||||||||||||||||||||||||
| 122 | 0 | ▶ | if ($o > 10) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 0 | carp "WARNING : Repetition of length $o detected in ".$seqfullid."\tdomains: ".$domains_info[$i]->hmm_start.' -> '.$domains_info[$i]->hmm_end.' and '.$domains_info[$j]->hmm_start.' -> '.$domains_info[$j]->hmm_end." \n"; | |||||||||||||||||||||||||||
| 124 | ## TODO: Check what is going on if we have a domain inside a previous one | ||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | ### Concatening all domains on 1 line... | ||||||||||||||||||||||||||||
| 130 | 0 | ▶ | $concat_scoreseq = ( @domains_info == 0 ) ? '' : " " x ($domains_info[0]->ali_start - 1); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | # Condition if no domain found | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 0 | ▶ | if ( @domains_info > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | 0 | ▶ | for (my $i=0; $i<@domains_info; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | ###### [PROCESS] currentscore length : length($concat_scoreseq) | ||||||||||||||||||||||||||||
| 136 | ###### [PROCESS] length of next domain : length($domains_info[$i]->scoreseq) | ||||||||||||||||||||||||||||
| 137 | ###### [PROCESS] domain ali start : $domains_info[$i]->ali_start | ||||||||||||||||||||||||||||
| 138 | ###### [PROCESS] Seq : $domains_info[$i]->seq | ||||||||||||||||||||||||||||
| 139 | ###### [PROCESS] Score seq : $domains_info[$i]->scoreseq | ||||||||||||||||||||||||||||
| 140 | ###### [PROCESS] degap seq : $domains_info[$i]->get_degap_scoreseq | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | # substr of score to remove beginning that could correspond to overlap | ||||||||||||||||||||||||||||
| 143 | 0 | my $add = substr( $domains_info[$i]->get_degap_scoreseq, ( length($concat_scoreseq) - $domains_info[$i]->ali_start + 1 ) ); | |||||||||||||||||||||||||||
| 144 | ###### [PROCESS] Added score : $add | ||||||||||||||||||||||||||||
| 145 | 0 | $concat_scoreseq .= $add; | |||||||||||||||||||||||||||
| 146 | # If current domain is not the last one | ||||||||||||||||||||||||||||
| 147 | 0 | ▶ | if($i+1 != @domains_info){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | # if this domain does not overlap with the next one | ||||||||||||||||||||||||||||
| 149 | 0 | ▶ | if ( $domains_info[$i]->ali_end < $domains_info[$i+1]->ali_start ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | # extend score with blank so that score length is ok to add next domain | ||||||||||||||||||||||||||||
| 151 | 0 | $concat_scoreseq .= " " x ( $domains_info[$i+1]->ali_start - $domains_info[$i]->ali_end - 1); | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | ###### [PROCESS] current $i concat_scoreseq: $concat_scoreseq | ||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | } else { | ||||||||||||||||||||||||||||
| 157 | 0 | carp 'WARNING : No domains found for '.$seqfullid.' in '.$self->ali->file."\n"; | |||||||||||||||||||||||||||
| 158 | # TODO <-> Remove this futur empty seq | ||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 0 | $concat_scoreseq .= " " x ($seqlength - length($concat_scoreseq)); | |||||||||||||||||||||||||||
| 162 | #### [PROCESS] Final concatenated scoreseq : $concat_scoreseq | ||||||||||||||||||||||||||||
| 163 | } else { | ||||||||||||||||||||||||||||
| 164 | ### No target... | ||||||||||||||||||||||||||||
| 165 | 0 | carp 'WARNING : No domains found for '.$seqfullid.' in '.$self->ali->file."\n"; | |||||||||||||||||||||||||||
| 166 | # TODO <-> Remove this futur empty seq | ||||||||||||||||||||||||||||
| 167 | 0 | $concat_scoreseq .= " " x ($seqlength); | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 0 | return $concat_scoreseq; | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | # Given two segment a-b and c-d, give the common part size | ||||||||||||||||||||||||||||
| 174 | # assume a<b and c<d | ||||||||||||||||||||||||||||
| 175 | # This sub is coming from the original script | ||||||||||||||||||||||||||||
| 176 | sub _overlap { | ||||||||||||||||||||||||||||
| 177 | 0 | ▶ | my ($a, $b, $c, $d) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_overlap: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||
| 178 | 0 | my $ret = 0; | |||||||||||||||||||||||||||
| 179 | 0 | ▶ | if( ($c <= $b) and ($b <= $d) ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$c <= $b and $b <= $d
MC/DC0%0/2
$c <= $b and $b <= $d
$c <= $b
$b <= $d
Truth table0%0/3
A and B
A= $c <= $bB= $b <= $d
| |||||||||||||||||||||||||||||
| 180 | 0 | $ret = $b-$c; | |||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | 0 | ▶ | if( ($c <= $a) and ($a <= $d) ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$c <= $a and $a <= $d
MC/DC0%0/2
$c <= $a and $a <= $d
$c <= $a
$a <= $d
Truth table0%0/3
A and B
A= $c <= $aB= $a <= $d
| |||||||||||||||||||||||||||||
| 183 | 0 | ▶ | if($ret == 0){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 184 | 0 | $ret = $d-$a; | |||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | else{ | ||||||||||||||||||||||||||||
| 187 | 0 | $ret-=$a-$c; | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | 0 | ▶ | if( ($a < $c) and ($d < $b) ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$a < $c and $d < $b
MC/DC0%0/2
$a < $c and $d < $b
$a < $c
$d < $b
Truth table0%0/3
A and B
A= $a < $cB= $d < $b
| |||||||||||||||||||||||||||||
| 191 | 0 | $ret = $d-$c; | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | 0 | return $ret; | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | sub DEMOLISH { | ||||||||||||||||||||||||||||
| 197 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
DEMOLISH: called CC=2 SCAR=8.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 2 | ▶ | $self->parser->remove unless ($self->debug_mode); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 0 | return; | |||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 3 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 206 | 3 | 1; | |||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | __END__ | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | =pod | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | =head1 NAME | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | Bio::MUST::Apps::HmmCleaner::Process - Process class for HmmCleaner | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | =head1 VERSION | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | version 0.180750 | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | Arnaud Di Franco <arnaud.difranco@gmail.fr> | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | This software is copyright (c) 2018 by Arnaud Di Franco. | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 231 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | =cut | ||||||||||||||||||||||||||||