File Coverage

blib/lib/Bio/EasyYang.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package Bio::EasyYang;
2              
3             # Library to implement the Yang ML algorithm
4             # This is just a PAML Wrapper
5 1     1   23285 use Bio::Tools::Run::Phylo::PAML::Yn00;
  0            
  0            
6              
7             our $VERSION = 1.00;
8              
9             sub yang {
10              
11             my ($self,$aln,$gen_code) = @_;
12              
13             #
14             # Running Yang (Yn00)
15             #
16             # Create the Yn00 object
17             my $yang = Bio::Tools::Run::Phylo::PAML::Yn00->new();
18            
19             # Set the genetic code
20             $yang->set_parameter("icode", $gen_code);
21            
22             # Append the alignment to Yn00 object
23             $yang->alignment($aln);
24            
25             # Run Yang
26             my ($rc,$parser) = $yang->run();
27            
28            
29             my @dN = ();
30             my @dS = ();
31             my @dN_VAR = ();
32             my @dS_VAR = ();
33             my @N = ();
34             my @S = ();
35             my @omega = ();
36             my @kappa = ();
37             my @t = ();
38            
39             # Take the ML Matrix
40             my $out_str = "";
41             $out_str .= "----------------------------------------------------------------------\n";
42             $out_str .= "N\tS\tdN\tdN_SE\tdS\tdS_SE\tOmega\tKappa\tt\n";
43             $out_str .= "----------------------------------------------------------------------\n";
44            
45             while( my $result = $parser->next_result){
46            
47             my $MLmatrix = $result->get_MLmatrix();
48            
49             for(my $i=0;$i<=$#{$MLmatrix};$i++){
50            
51             for my $item (@{$MLmatrix}[$i]){
52            
53             for(my $j=$i+1;$j<=$#{$item};$j++){
54            
55             my $N = $item->[$j]->{N};
56             my $S = $item->[$j]->{S};
57             my $dN = $item->[$j]->{dN};
58             my $dS = $item->[$j]->{dS};
59             my $dN_SE = $item->[$j]->{dN_SE};
60             my $dS_SE = $item->[$j]->{dS_SE};
61             my $omega = $item->[$j]->{omega};
62             my $kappa = $item->[$j]->{kappa};
63             my $t = $item->[$j]->{t};
64            
65             $dN_SE ? my $dN_VAR = $dN_SE*$dN_SE: 0;
66             $dS_SE ? my $dS_VAR = $dS_SE*$dS_SE: 0;
67            
68             # If there is no result (empty values of dN) then, skip this line
69             if($N || $S || $dS){
70            
71             push(@dN ,$dN);
72             push(@dS ,$dS);
73             push(@dN_VAR ,$dN_VAR);
74             push(@dS_VAR ,$dS_VAR);
75             push(@N ,$N);
76             push(@S ,$S);
77             push(@omega ,$omega);
78             push(@kappa ,$kappa);
79             push(@t ,$t);
80             $out_str.= "$N\t$S\t$dN\t$dN_SE\t$dS\t$dS_SE\t$omega\t$kappa\t$t\n";
81            
82             }else{
83            
84             # We must discuss this awfull solution!!
85            
86             push(@dN ,0);
87             push(@dS ,0);
88             push(@dN_VAR ,0);
89             push(@dS_VAR ,0);
90             push(@N ,0);
91             push(@S ,0);
92             push(@omega ,0);
93             push(@kappa ,0);
94             push(@t ,0);
95             $out_str.= "??\t??\t??\t??\t??\t??\t??\t??\t??\n";
96            
97             }
98             }
99            
100             }
101            
102             }
103            
104             }
105            
106             $out_str .= "----------------------------------------------------------------------\n";
107            
108             my %hash = (
109             yang_table => $out_str,
110             N => \@N,
111             S => \@S,
112             dN => \@dN,
113             dS => \@dS,
114             dN_VAR => \@dN_VAR,
115             dS_VAR => \@dS_VAR,
116             omega => \@omega,
117             kappa => \@kappa,
118             t => \@t
119             );
120            
121             return (%hash);
122              
123             }1;
124              
125             __END__