File Coverage

blib/lib/Bio/Polloc/GroupCriteria/operator/num.pm
Criterion Covered Total %
statement 7 42 16.6
branch 0 36 0.0
condition 0 3 0.0
subroutine 3 5 60.0
pod 2 2 100.0
total 12 88 13.6


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             Bio::Polloc::GroupCriteria::operator::num - A numeric operator
4              
5             =head1 AUTHOR - Luis M. Rodriguez-R
6              
7             Email lmrodriguezr at gmail dot com
8              
9             =cut
10              
11             package Bio::Polloc::GroupCriteria::operator::num;
12 3     3   17 use base qw(Bio::Polloc::GroupCriteria::operator);
  3         6  
  3         247  
13 3     3   15 use strict;
  3         6  
  3         2035  
14             our $VERSION = 1.0503; # [a-version] from Bio::Polloc::Polloc::Version
15              
16              
17             =head1 APPENDIX
18              
19             Methods provided by the package
20              
21             =head2 new
22              
23             Generic initialization method.
24              
25             =head3 Arguments
26              
27             See L<Bio::Polloc::GroupCriteria::operator->new()>
28              
29             =head3 Returns
30              
31             A L<Bio::Polloc::GroupCriteria::operator::bool> object.
32              
33             =cut
34              
35             sub new {
36 0     0 1 0 my($caller,@args) = @_;
37 0         0 my $self = $caller->SUPER::new(@args);
38 0         0 $self->_initialize(@args);
39 0         0 return $self;
40             }
41              
42             =head2 operate
43              
44             =head3 Returns
45              
46             A numeric value.
47              
48             =cut
49              
50             sub operate {
51 0     0 1 0 my $self = shift;
52 0 0       0 return $self->val if defined $self->val;
53 0 0 0     0 $self->throw('Bad operators', $self->operators)
54             unless ref($self->operators)
55             and ref($self->operators)=~/ARRAY/;
56 0         0 my $o1 = $self->operators->[0]->operate;
57 0 0       0 $self->throw("Undefined first operator") unless defined $o1;
58 0         0 my $o2 = $self->operators->[1]->operate;
59 0 0       0 $self->throw("Undefined second operator") unless defined $o2;
60 0 0       0 return ($o1 + $o2) if $self->operation =~ /^\s*(?:\+)\s*$/i;
61 0 0       0 return ($o1 - $o2) if $self->operation =~ /^\s*(?:\-)\s*$/i;
62 0 0       0 return ($o1 * $o2) if $self->operation =~ /^\s*(?:\*)\s*$/i;
63 0 0       0 return ($o1 / $o2) if $self->operation =~ /^\s*(?:\/)\s*$/i;
64 0 0       0 return ($o1 % $o2) if $self->operation =~ /^\s*(?:%)\s*$/i;
65 0 0       0 return ($o1 ** $o2) if $self->operation =~ /^\s*(?:\*\*|\^)\s*$/i;
66 0 0       0 if($self->operation =~ /^\s*aln-(sim|score)(?: with)?\s*$/i){
67 0         0 my $ret = lc $1;
68 0 0       0 return unless $self->_load_module('Bio::Tools::Run::Alignment::Muscle');
69 0         0 my $factory = Bio::Tools::Run::Alignment::Muscle->new();
70 0         0 $factory->quiet(1);
71 0 0       0 UNIVERSAL::can($o1, 'isa') or $self->throw('First operator must be an object', $o1);
72 0 0       0 UNIVERSAL::can($o2, 'isa') or $self->throw('First operator must be an object', $o2);
73 0 0       0 $o1->isa('Bio::Seq') or $self->throw('First operator must be a Bio::Seq object', $o1);
74 0 0       0 $o2->isa('Bio::Seq') or $self->throw('Second operator must be a Bio::Seq object', $o2);
75 0         0 $o1->id('op1');
76 0         0 $o2->id('op2');
77 0         0 my $aln = $factory->align([$o1, $o2]);
78 0         0 my $out = 0;
79 0 0       0 $out = ($ret eq 'sim') ? $aln->overall_percentage_identity('long')/100 : $aln->score;
80 0         0 $factory->cleanup(); # This is to solve the issue #1
81 0 0       0 defined $out or $self->throw('Empty value for '.$ret, $self, 'Bio::Polloc::Polloc::UnexpectedException');
82 0         0 return $out;
83             }
84 0         0 $self->throw("Unknown numeric operation", $self->operation);
85             }
86              
87             =head1 INTERNAL METHODS
88              
89             Methods intended to be used only within the scope of Bio::Polloc::*
90              
91             =head2 _initialize
92              
93             =cut
94              
95 39     39   67 sub _initialize { }
96              
97             1;