blib/lib/Chemistry/MacroMol.pm

filter: Statementstmt 36.1% 13 / 36 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 44.4% 4 / 9 Podpod 100% 5 / 5 totaltotal 40.7% 22 / 54 CC 5 SCAR 16.5
CC
5
Cov
32%
domains
12.0
new
6.0
add_domain
6.0
CRAP 5.2
« blib/lib/Parse/Yapp/Grammar.pm ↑ Summary blib/lib/Chemistry/File/Formula.pm »
1 package Chemistry::MacroMol;
2  
3 9 $VERSION = '0.06';
4 # $Id: MacroMol.pm,v 1.6 2004/07/03 19:19:44 itubert Exp $
5  
6 9 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 ▶use base qw(Chemistry::Mol);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 NAME
12  
13 Chemistry::MacroMol - Perl module for macromolecules
14  
15 =head1 SYNOPSIS
16  
17 use Chemistry::MacroMol;
18  
19 my $mol = Chemistry::MacroMol->new(name => 'my big molecule');
20 $mol->new_domain(name => "ASP"); # see Chemistry::Domain for details
21 my @domains = $mol->domains;
22  
23 =head1 DESCRIPTION
24  
25 For the purposes of this module, a macromolecule is just a molecule that
26 consists of several "domains". For example, a protein consists of aminoacid
27 residues, or a nucleic acid consists of bases. Therefore Chemistry::MacroMol
28 is derived from Chemistry::Mol, with additional methods to handle the domains.
29  
30 The way things are currently structured, an atom in a macromolecule "belong"
31 both to the MacroMol object and to a Domain object. This way you can get all the
32 atoms in $protein via $protein->atoms, or to the atoms in residue 123 via
33 $protein->domain(123)->atoms.
34  
35 =head1 METHODS
36  
37 Remember that this class inherits all the methods from Chemistry::Mol. They
38 won't be repeated here.
39  
40 =over 4
41  
42 =item Chemistry::MacroMol->new(name => value, ...)
43  
44 Create a new MacroMol object with the specified attributes. You can use the
45 same attributes as for Chemistry::Mol->new.
46  
47 =cut
48  
49 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
50 0 my $class = shift;
51 0 my %args = @_;
52 0 my $self = bless $class->SUPER::new(), $class;
53 0 $self->{domains} = [];
54 0 $self->$_($args{$_}) for (keys %args);
55 0 return $self;
56 }
57  
58 =item $mol->add_domain($domain, ...)
59  
60 Add one or more Domain objects to the molecule. Returns the last domain added.
61  
62 =cut
63  
64 0 ▶sub add_domain {
Subroutine add_domain: not called CC=2 SCAR=17.9
Pod documented
65 0 my $self = shift;
66 0 for my $b (@_){
67 0 push @{$self->{domains}}, $b;
68 0 $self->{byId}{$b->{id}} = $b;
69 }
70 0 $_[-1];
71 }
72  
73 =item $mol->domain_class
74  
75 Returns the domain class that a macromolecule class expects to use by default.
76 Chemistry::MacroMol objects return "Chemistry::Domain", but subclasses will
77 likely override this method.
78  
79 =cut
80  
81 0 ▶sub domain_class { "Chemistry::Domain" }
Subroutine domain_class: not called CC=1 SCAR=6.9
Pod documented
82  
83 =item $mol->new_domain(name => value, ...)
84  
85 Shorthand for $mol->add_domain($mol->domain_class->new(parent => $mol, name => value, ...));
86  
87 =cut
88  
89 0 ▶sub new_domain {
Subroutine new_domain: not called CC=1 SCAR=6.9
Pod documented
90 0 my $self = shift;
91 0 $self->add_domain(Chemistry::Domain->new(parent => $self, @_));
92 }
93  
94 =item $mol->domains($n1, ...)
95  
96 Returns the domains with the given indices, or all by default. NOTE:
97 the indices start from one (1), not from zero.
98  
99 =cut
100  
101 0 ▶sub domains {
Subroutine domains: not called CC=3 SCAR=24.8
Pod documented
102 0 my $self = shift;
103 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
104 0 my @doms = map {$_ - 1} @_;
105 0 ▶ wantarray ? @{$self->{domains}}[@doms] : $self->{domains}[$doms[-1]];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
106 } else {
107 0 @{$self->{domains}}; # return all
108 }
109 }
110  
111  
112 9 1;
113  
114 =back
115  
116 =head1 VERSION
117  
118 0.06
119  
120 =head1 SEE ALSO
121  
122 L<Chemistry::Domain>, L<Chemistry::Mol>
123  
124 =head1 AUTHOR
125  
126 Ivan Tubert, E<lt>itub@cpan.orgE<gt>
127  
128 =head1 COPYRIGHT AND LICENSE
129  
130 Copyright 2004 by Ivan Tubert
131  
132 This library is free software; you can redistribute it and/or modify
133 it under the same terms as Perl itself.
134  
135 =cut
136  
« blib/lib/Parse/Yapp/Grammar.pm ↑ Summary blib/lib/Chemistry/File/Formula.pm »