Metabolic/Substrate.pm

filter: Statementstmt 90.6% 58 / 64 Branchbran 69.2% 18 / 26 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 14 / 14 Podpod 100% 10 / 10 totaltotal 85.2% 104 / 122 CC 18 SCAR 13.6
CC
18
Cov
83%
substrate_to_string
9.3
equals
6.0
new
4.0
CRAP 3.9
« Metabolic/Dynamics/Network.pm ↑ Summary Metabolic/Substrate/Cluster.pm »
1  
2 =head1 NAME
3  
4 Bio::Metabolic::Substrate - Perl extension for the description of biochemical substrates
5  
6 =head1 SYNOPSIS
7  
8 use Bio::Metabolic::Substrate;
9  
10 my $sub1 = Bio::Metabolic::Substrate->new('Water');
11  
12 my $sub2 = Bio::Metabolic::Substrate->new('Oxygen', {o => 2});
13  
14 =head1 DESCRIPTION
15  
16 This class implements the object class representing Biochemical Compounds (Substrates)
17 occurring in biochemical reactions.
18 Substrates must contain a name and arbitrary many attributes.
19  
20 =head2 EXPORT
21  
22 None
23  
24 =head2 OVERLOADED OPERATORS
25  
26 String Conversion
27 $string = "$substrate";
28 print "\$substrate = '$substrate'\n";
29  
30 Equality
31 if ($sub1 == $sub2)
32 if ($sub1 != $sub2)
33  
34 Lexical comparison
35 $cmp = $sub1 cmp $sub2;
36
37  
38  
39  
40  
41 =head1 AUTHOR
42  
43 Oliver Ebenhöh, oliver.ebenhoeh@rz.hu-berlin.de
44  
45 =head1 SEE ALSO
46  
47 Bio::Metabolic.
48  
49 =cut
50  
51 package Bio::Metabolic::Substrate;
52  
53 5 require 5.005_62;
54 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
55 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
56  
57 5 require Exporter;
58  
59 #use AutoLoader qw(AUTOLOAD);
60  
61 #use Math::Symbolic;
62 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
63  
64 use overload
65 5 ▶ "\"\"" => \&substrate_to_string,
Subroutine BEGIN: called CC=1 SCAR=0.0
66 "==" => \&equals,
67 "!=" => \&not_equals,
68 5 "cmp" => \&compare_names;
69  
70 5 our $VERSION = '0.06';
71  
72 =head1 METHODS
73  
74 =head2 Constructor new
75  
76 First argument must specify the name. Second argument is a hash reference of
77 key-value pairs defining the object attributes. Attributes are optional.
78  
79 Upon creation, each substrate object gets associated with a variable
80 (Math::Symbolic::Variable object) which is accessible by the accessor method
81 var(). The purpose for this is the automatic creation of ordinary differential
82 equation systems describing the dynamic behaviour of a metabolic system.
83  
84 Returns a Bio::Metabolic::Substrate.
85  
86 =cut
87  
88 23 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod documented
89 23 my $pkg = shift;
90 23 ▶ $pkg = ref($pkg) if ref($pkg);
Branch: 1 branch
BranchTrueFalseTotal
if ref $pkg 2 21 23
91  
92 23 ▶ my $name = shift()
Condition50%1/2
shift() || croak('no name has been provided for constructor new')
l!l
230
MC/DC0%0/1
shift() || croak('no name has been provided for constructor new')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
93 || croak("no name has been provided for constructor new");
94  
95 23 ▶ my $attr = @_ ? shift() : {};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 4 19 23
96  
97 23 my $self = {
98 name => $name,
99  
100 # var => Math::Symbolic::Variable->new($name),
101 attributes => $attr,
102 };
103  
104 23 bless $self => $pkg;
105 }
106  
107 =head2 Method copy
108  
109 copy() returns a copy of the object. Attributes are cloned. The variable
110 associated with the substrate (see var() below) is new defined and the value
111 (if existing) is not copied.
112  
113 =cut
114  
115 1 ▶sub copy {
Subroutine copy: called CC=2 SCAR=7.0
Pod documented
116 1 my $orig = shift;
117 1 ▶ $orig = shift unless ref($orig);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $orig 0 1 1
118  
119 1 my %attr = %{ $orig->attributes };
120  
121 1 return $orig->new( $orig->name, \%attr );
122 }
123  
124 =head2 Method name
125  
126 Optional argument: sets the object's name. Returns the object's name.
127  
128 =cut
129  
130 980 ▶sub name {
Subroutine name: called CC=2 SCAR=7.1
Pod documented
131 980 my $self = shift;
132 980 ▶ $self->{name} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 980 980
133 980 return $self->{name};
134 }
135  
136 =head2 Method attributes
137  
138 Optional argument: sets the object's attributes. Returns the object's
139 attributes.
140  
141 =cut
142  
143 242 ▶sub attributes {
Subroutine attributes: called CC=2 SCAR=7.1
Pod documented
144 242 my $self = shift;
145 242 ▶ $self->{attributes} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 242 242
146 242 return $self->{attributes};
147 }
148  
149 =head2 Method var
150  
151 Optional argument: sets the object's variable. Returns the object's
152 variable (Math::Symbolic::Variable object).
153  
154 =cut
155  
156 #sub var {
157 # my $self = shift;
158 # $self->{var} = shift if @_;
159 # return $self->{var};
160 #}
161  
162 =head2 Method fix
163  
164 Sets the value of the object's variable, thus fixing the substrate's
165 concentration.
166  
167 =cut
168  
169 #sub fix {
170 # my $self = shift;
171 # my $value = shift;
172  
173 # return $self->var->value($value);
174 #}
175  
176 =head2 Method release
177  
178 Sets the value of the object's variable to undef, thus releasing the substrate's
179 concentration.
180  
181 =cut
182  
183 #sub release {
184 # shift->var->value(undef);
185 #}
186  
187 =head2 Method get_attribute
188  
189 Argument specifies the attribute name. Returns the attribute value or undef
190 if such an attribute does not exist.
191  
192 =cut
193  
194 2 ▶sub get_attribute {
Subroutine get_attribute: called CC=1 SCAR=0.0
Pod documented
195 2 my $self = shift;
196 2 my $attr_name = shift;
197  
198 2 return $self->attributes->{$attr_name};
199 }
200  
201 =head2 Method substrate_to_string
202  
203 Returns a readable string. The string consists of the object's attributes listed
204 in braces. If the object does not have any attributes, the string consists of
205 the object's name in square brackets.
206  
207 =cut
208  
209 224 ▶sub substrate_to_string {
Subroutine substrate_to_string: called CC=4 SCAR=22.3
Pod documented
210 224 my $substrate = shift;
211 224 my $attributes = $substrate->attributes;
212  
213 224 ▶ return "[" . $substrate->name . "]" unless keys(%$attributes);
Branch: 1 branch
BranchTrueFalseTotal
unless keys %$attributes 224 0 224
214  
215 0 my $str = "{";
216 0 foreach my $k ( keys(%$attributes) ) {
217 0 ▶ $str .= "," if ( $str !~ /\{$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $str =~ /\{$/ 0 0 0
218 0 $str .= "'$k'=>$attributes->{$k}";
219 }
220 0 $str .= "}";
221 0 return $str;
222 }
223  
224 =head2 Method equals
225  
226 Compares two substrates. If one of the substrates has attributes the set of
227 attributes is compared. If both objects are without attributes, the names are
228 compared. Returns 1 upon equality, 0 otherwise.
229  
230 =cut
231  
232 6 ▶sub equals {
Subroutine equals: called CC=6 SCAR=18.0
Pod documented
233 6 my ( $s1, $s2 ) = @_;
234 6 my $sub1 = $s1->attributes;
235 6 my $sub2 = $s2->attributes;
236  
237 6 my @sub1_keys = keys(%$sub1);
238 6 my @sub2_keys = keys(%$sub2);
239  
240 6 ▶ return 0 if ( @sub1_keys != @sub2_keys );
Branch: 1 branch
BranchTrueFalseTotal
if @sub1_keys != @sub2_keys 0 6 6
241  
242 6 ▶ return ( $s1->name eq $s2->name ) unless @sub2_keys;
Branch: 1 branch
BranchTrueFalseTotal
unless @sub2_keys 2 4 6
243  
244 4 my $k;
245 4 foreach $k (@sub2_keys) {
246 return 0 if ( !defined( $sub2->{$k} )
247 4 ▶ || $sub2->{$k} ne $sub1->{$k} );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $sub2->{$k} or $sub2->{$k} ne $sub1->{$k} 2 2 4
Condition66%2/3
not defined $sub2->{$k} or $sub2->{$k} ne $sub1->{$k}
l!l&&r!l&&!r
022
MC/DC50%1/2
not defined $sub2->{$k} or $sub2->{$k} ne $sub1->{$k}
not defined $sub2->{$k} $sub2->{$k} ne $sub1->{$k}
Truth table66%2/3
not(A) or B
A= not defined $sub2->{$k}B= $sub2->{$k} ne $sub1->{$k}
ABresult
1X1
011
000
248 }
249  
250 2 return 1;
251 }
252  
253 =head2 Method not_equals
254  
255 Compares two substrates. If one of the substrates has attributes the set of
256 attributes is compared. If both objects are without attributes, the names are
257 compared. Returns 0 upon equality, 1 otherwise.
258  
259 =cut
260  
261 3 ▶sub not_equals {
Subroutine not_equals: called CC=1 SCAR=0.0
Pod documented
262 3 return 1 - equals(@_);
263 }
264  
265 =head2 Method is_empty
266  
267 returns 1 if the object does not have any attributes
268  
269 =cut
270  
271 2 ▶sub is_empty {
Subroutine is_empty: called CC=2 SCAR=6.9
Pod documented
272 2 my $substrate = shift->attributes;
273 2 ▶ return keys(%$substrate) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
keys %$substrate ? : 1 1 2
274 }
275  
276 =head2 Method compare_names
277  
278 Lexical comparison of the object names or optionally strings.
279  
280 =cut
281  
282 5 ▶sub compare_names {
Subroutine compare_names: called CC=3 SCAR=11.0
Pod documented
283 5 my $s1 = shift;
284 5 ▶ my $n1 = ref($s1) ? $s1->name : $s1;
Branch: 1 branch
BranchTrueFalseTotal
ref $s1 ? : 5 0 5
285 5 my $s2 = shift;
286 5 ▶ my $n2 = ref($s2) ? $s2->name : $s2;
Branch: 1 branch
BranchTrueFalseTotal
ref $s2 ? : 4 1 5
287 5 return $n1 cmp $n2;
288 }
289  
290 5 1;
291 __END__
« Metabolic/Dynamics/Network.pm ↑ Summary Metabolic/Substrate/Cluster.pm »