Attribute.pm 3.95 KB
Newer Older
1
2
3
4
5
6
#
# Ensembl module for Bio::EnsEMBL::Attribute
#
# Copyright (c) 2004 Ensembl
#
# You may distribute this module under the same terms as perl itself
7

8
# POD documentation - main docs before the code
9
10
11
12
13
14
15
16
17

=head1 NAME

Bio::EnsEMBL::Attribute - A generic Attribute class.

=head1 SYNOPSIS

  use Bio::EnsEMBL::Attribute;

18
19
20
21
22
  my $attribute = Bio::EnsEMBL::Attribute->new
       (-CODE => 'myCode',
        -NAME => 'My Attribute',
        -DESCRIPTION => 'This is my attribute description.',
        -VALUE => '10023');
23

24
25
  print $attrib->name(), "\n";
  print $attrib->code(), "\n";
26
  print $attrib->description(), "\n";
27
  print $attrib->value(), "\n";
28
29
30
31
32
33
34
35
36

=head1 DESCRIPTION

This is a generic attribute class used to represent attributes
associated with seq_regions (and their Slices) and MiscFeatures.

Also see B<Bio::EnsEMBL::Slice>, B<Bio::EnsEMBL::MiscFeature> and
B<Bio::EnsEMBL::DBSQL::AttributeAdaptor>.

37
38
39
40
41
42
43
=head1 CONTACT

This modules is part of the Ensembl project http://www.ensembl.org

Questions can be posted to the ensembl-dev mailing list:
ensembl-dev@ebi.ac.uk

44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
=head1 METHODS

=cut

use strict;
use warnings;

package Bio::EnsEMBL::Attribute;

use Bio::EnsEMBL::Utils::Argument qw(rearrange);

=head2 new

  Arg [-CODE]   : string - the code for this attribute
  Arg [-NAME]   : string - a human readable name for this attribute
59
  Arg [-DESCRIPTION]   : string - a description for this attribute
60
61
62
63
  Arg [-VALUE]  : value  - the value of this attribute
  Example    :   my $attribute = Bio::EnsEMBL::Attribute->new
                      (-CODE => 'myCode',
                       -NAME => 'My Attribute',
64
                       -DESCRIPTION => 'This is my attribute description.',
65
66
67
68
69
                       -VALUE => '10023');
  Description: Constructor.  Instantiates a Bio::EnsEMBL::Attribute object.
  Returntype : Bio::EnsEMBL::Attribute
  Exceptions : none
  Caller     : general
70
  Status     : Stable
71
72
73
74
75
76
77
78
79
80
81

=cut


sub new {
  my $caller = shift;

  # allow to be called as class or object method
  my $class = ref($caller) || $caller;

  my ($code, $name, $desc, $value) =
82
    rearrange([qw(CODE NAME DESCRIPTION VALUE)], @_);
83
84
85

  return bless {'code'    => $code,
                'name'    => $name,
86
                'description' => $desc,
87
88
89
                'value'   => $value}, $class;
}

90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
=head2 new_fast

  Arg [1]    : hashref to be blessed
  Description: Construct a new Bio::EnsEMBL::Attribute using the hashref.
  Exceptions : none
  Returntype : Bio::EnsEMBL::Attribute
  Caller     : general, subclass constructors
  Status     : Stable

=cut


sub new_fast {
  my $class = shift;
  my $hashref = shift;
  return bless $hashref, $class;
}

108
109
110
111
112
113
114
115
116

=head2 code

  Arg [1]    : string $code (optional)x
  Example    : $code = $attribute->code();
  Description: Getter/Setter for code attribute
  Returntype : string
  Exceptions : none
  Caller     : general
117
  Status     : Stable
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135

=cut

sub code {
  my $self = shift;
  $self->{'code'} = shift if(@_);
  return $self->{'code'};
}


=head2 name

  Arg [1]    : string $name (optional)
  Example    : $name = $attribute->name();
  Description: Getter/Setter for name attribute
  Returntype : string
  Exceptions : none
  Caller     : general
136
  Status     : Stable
137
138
139
140
141
142
143
144
145

=cut

sub name {
  my $self = shift;
  $self->{'name'} = shift if(@_);
  return $self->{'name'};
}

146
=head2 description
147

148
149
  Arg [1]    : string $description (optional)
  Example    : $description = $attribute->description();
150
151
152
153
  Description: Getter/Setter for description attribute
  Returntype : string
  Exceptions : none
  Caller     : general
154
  Status     : Stable
155
156
157

=cut

158
sub description {
159
  my $self = shift;
160
161
  $self->{'description'} = shift if(@_);
  return $self->{'description'};
162
163
164
165
166
167
168
169
170
171
172
}


=head2 value

  Arg [1]    : string $value (optional)
  Example    : $value = $attribute->value();
  Description: Getter/Setter for value attribute
  Returntype : string
  Exceptions : none
  Caller     : general
173
  Status     : Stable
174
175
176
177
178
179
180
181
182
183
184

=cut

sub value {
  my $self = shift;
  $self->{'value'} = shift if(@_);
  return $self->{'value'};
}


1;