Metabolic/Dynamics/Reaction.pm

filter: Statementstmt 69.1% 47 / 68 Branchbran 58.3% 14 / 24 Conditioncond 22.2% 2 / 9 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 5 totaltotal 59.3% 70 / 118 CC 22 SCAR 35.0
CC
22
Cov
62%
fullinfo
90.0
kinetics
10.1
parameters
3.0
CRAP 33.2
« Metabolic/MatrixOps.pm ↑ Summary Metabolic/Network.pm »
1 package Bio::Metabolic::Dynamics::Reaction;
2  
3 1 require 5.005_62;
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 require Exporter;
8  
9 1 our $VERSION = '0.06';
10  
11 =head2 Method kinetics
12  
13 Sets the rate expression of the reaction. The rate is expressed by a Math::Symbolic
14 object and accessible by the method rate(). Additional, some parameters will be set.
15 The first argument specifies the template to determine the rate expression.
16  
17 The following templates are available at the moment:
18 'linear', 'linear_reversible' : multilinear reversible kinetics
19 results in the parameters 'k+' and 'k-'.
20 'linear_irreversible' : mutlilinear irreversible (forward) kinetics
21 results in the parameter 'k'
22  
23 =cut
24  
25 6 ▶sub Bio::Metabolic::Reaction::kinetics {
Subroutine kinetics: called CC=10 SCAR=23.1
Pod undocumented
26  
27 # determines the reaction rate by some templates. Presently supported templates:
28 # 'linear' (same as 'linear_reversible')
29 # 'linear_irreversible'
30 6 my $reaction = shift;
31 6 my $kinetics = shift;
32  
33 6 my %old_params = %{ $reaction->parameters() };
34 6 ▶ if ( $kinetics eq 'linear' || $kinetics eq 'linear_reversible' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($kinetics eq 'linear' or $kinetics eq 'linear_reversible') { } 5 1 6
elsif ($kinetics eq 'linear_irreversible') { } 1 0 1
Condition66%2/3
$kinetics eq "linear" or $kinetics eq "linear_reversible"
l!l&&r!l&&!r
501
MC/DC50%1/2
$kinetics eq "linear" or $kinetics eq "linear_reversible"
$kinetics eq "linear" $kinetics eq "linear_reversible"
Truth table66%2/3
A or B
A= $kinetics eq "linear"B= $kinetics eq "linear_reversible"
ABresult
1X1
011
000
35 5 my $varname = $reaction->name;
36 5 my $kplus = Math::Symbolic::Variable->new( "kplus_" . $varname );
37 5 my $kminus = Math::Symbolic::Variable->new( "kminus_" . $varname );
38 5 my %param_hash = (
39 'k+' => $kplus,
40 'k-' => $kminus,
41  
42 %old_params,
43  
44 # 'k1' => $kminus,
45 # 'k-1' => $kplus
46 );
47 5 $reaction->parameters( \%param_hash );
48  
49 5 my %terms;
50 5 foreach my $dir ( -1, 1 ) {
51 10 ▶ my $pkey = $dir == -1 ? 'k+' : 'k-';
Branch: 1 branch
BranchTrueFalseTotal
$dir == -1 ? : 5 5 10
52 10 $terms{$dir} = $reaction->parameter($pkey);
53 10 foreach my $substrate ( $reaction->dir($dir)->list ) {
54 12 ▶ my $sterm =
Branch: 1 branch
BranchTrueFalseTotal
abs $reaction->st_coefficient($substrate) == 1 ? : 11 1 12
55 abs( $reaction->st_coefficient($substrate) ) == 1
56 ? $substrate->var
57 : Math::Symbolic::Operator->new( '^', $substrate->var,
58 abs( $reaction->st_coefficient($substrate) ) );
59 $terms{$dir} =
60 12 Math::Symbolic::Operator->new( '*', $terms{$dir}, $sterm );
61 }
62  
63 # $terms{$dir} = Math::Symbolic::Operator->new('neg',$terms{$dir}) if $dir == 1;
64 }
65  
66 $reaction->rate(
67 5 Math::Symbolic::Operator->new( '-', $terms{-1}, $terms{1} ) );
68 }
69 elsif ( $kinetics eq 'linear_irreversible' ) {
70 1 my $varname = $reaction->name;
71 1 my $k = Math::Symbolic::Variable->new( "k_" . $varname );
72 1 my %param_hash = (
73 'k' => $k,
74 %old_params,
75 );
76 1 $reaction->parameters( \%param_hash );
77  
78 1 my $rate = $reaction->parameter('k');
79 1 foreach my $substrate ( $reaction->in->list ) {
80 1 ▶ my $sterm =
Branch: 1 branch
BranchTrueFalseTotal
abs $reaction->st_coefficient($substrate) == 1 ? : 1 0 1
81 abs( $reaction->st_coefficient($substrate) ) == 1
82 ? $substrate->var
83 : Math::Symbolic::Operator->new( '^', $substrate->var,
84 abs( $reaction->st_coefficient($substrate) ) );
85 1 $rate = Math::Symbolic::Operator->new( '*', $rate, $sterm );
86 }
87  
88 1 $reaction->rate($rate);
89 }
90 else {
91 0 croak( "unknown reaction rate scheme \"" . $kinetics . "\"" );
92 }
93 }
94  
95 =head2 Method rate
96  
97 Optional argument: Sets the rate expression.
98 Returns the rate expression.
99  
100 Rate expressions are Math::Symbolic objects.
101  
102 =cut
103  
104 22 ▶sub Bio::Metabolic::Reaction::rate {
Subroutine rate: called CC=2 SCAR=6.9
Pod undocumented
105  
106 # use this subroutine to set or retrieve the rate expression for the reaction
107 22 my $reaction = shift;
108 22 ▶ return $reaction->{'rate'} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 16 6 22
109  
110 6 $reaction->{'rate'} = shift;
111 }
112  
113 =head2 Method parameters
114  
115 Optional argument: Sets the parameters.
116 Returns the parameters.
117  
118 Parameters are given as hashrefs and are set e.g. by the method kinetics.
119  
120 =cut
121  
122 14 ▶sub Bio::Metabolic::Reaction::parameters {
Subroutine parameters: called CC=3 SCAR=11.0
Pod undocumented
123 14 my $reaction = shift;
124 14 ▶ return $reaction->{'parameters'} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 8 6 14
125  
126 6 my $param = shift;
127 6 ▶ croak("Parameters must be given as hashref!") unless ref($param) =~ /^HASH/;
Branch: 1 branch
BranchTrueFalseTotal
unless ref($param) =~ /^HASH/ 0 6 6
128 6 $reaction->{'parameters'} = $param;
129 }
130  
131 =head2 Method parameter
132  
133 Returns the parameter specified by the argument or undef if that parameter
134 is not defined.
135  
136 =cut
137  
138 19 ▶sub Bio::Metabolic::Reaction::parameter {
Subroutine parameter: called CC=2 SCAR=8.4
Pod undocumented
139  
140 # get parameter: $p = $r->parameter(key)
141 # set parameter: $r->parameter(key, variable);
142 19 my $reaction = shift;
143 19 my $param_key = shift;
144 19 ▶ return $reaction->{'parameters'}->{$param_key} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 19 0 19
145  
146 0 my $variable = shift;
147 0 $reaction->{'parameters'}->{$param_key} = $variable;
148 }
149  
150 0 ▶sub Bio::Metabolic::Reaction::fullinfo {
Subroutine fullinfo: not called CC=9 SCAR=45.0
Pod undocumented
151 0 my $reaction = shift;
152  
153 0 my $retstr;
154 0 my $subsdir = {
155 -1 => [],
156 1 => []
157 };
158 0 foreach my $dir ( -1, 1 ) {
159 0 foreach my $substrate ( $reaction->dir($dir)->list ) {
160 0 ▶ for (
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= abs $reaction->st_coefficient($substrate)) 0 0 0
161 my $i = 1 ;
162 $i <= abs( $reaction->st_coefficient($substrate) ) ;
163 $i++
164 )
165 {
166 0 push( @{ $subsdir->{$dir} }, "$substrate" );
167 }
168 }
169 }
170  
171 $retstr =
172 0 join( "+", @{ $subsdir->{-1} } ) . "->"
173 0 . join( "+", @{ $subsdir->{1} } ) . "\n";
174  
175 0 ▶ if ( defined( $reaction->rate ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $reaction->rate) 0 0 0
176 0 $retstr .= "rate: " . $reaction->rate . "\n";
177 0 foreach my $param ( keys( %{ $reaction->parameters } ) ) {
178 0 ▶ if ( ref( $reaction->parameter($param) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $reaction->parameter($param) and ref $reaction->parameter($param) eq "Math::Symbolic::Variable" and defined $reaction->parameter($param)->value) 0 0 0
Condition0%0/6
ref $reaction->parameter($param) and ref $reaction->parameter($param) eq "Math::Symbolic::Variable" and defined $reaction->parameter($param)->value
!ll&&!rl&&r
000
ref $reaction->parameter($param) and ref $reaction->parameter($param) eq "Math::Symbolic::Variable"
!ll&&!rl&&r
000
MC/DC0%0/3
ref $reaction->parameter($param) and ref $reaction->parameter($param) eq "Math::Symbolic::Variable" and defined $reaction->parameter($param)->value
ref $reaction->parameter($param) ref $reaction->parameter($param) eq "Math::Symbolic::Variable" defined $reaction->parameter($param)->value
Truth table0%0/4
A and B and C
A= ref $reaction->parameter($param)B= ref $reaction->parameter($param) eq "Math::Symbolic::Variable"C= defined $reaction->parameter($param)->value
ABCresult
0XX0
10X0
1100
1111
179 && ref( $reaction->parameter($param) ) eq
180 'Math::Symbolic::Variable'
181 && defined $reaction->parameter($param)->value )
182 {
183 0 $retstr .= "\t"
184 . $reaction->parameter($param) . "="
185 . $reaction->parameter($param)->value . "\n";
186 }
187 }
188 }
189  
190 0 return $retstr;
191 }
« Metabolic/MatrixOps.pm ↑ Summary Metabolic/Network.pm »