ensembl-hive  2.6
SimpleFeature.pm
Go to the documentation of this file.
1 =head1 LICENSE
2 
3 Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
4 Copyright [2016-2024] EMBL-European Bioinformatics Institute
5 
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 
18 =cut
19 
20 
21 =head1 CONTACT
22 
23  Please email comments or questions to the public Ensembl
24  developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.
25 
26  Questions may also be sent to the Ensembl help desk at
27  <http://www.ensembl.org/Help/Contact>.
28 
29 =cut
30 
31 =head1 NAME
32 
33 Bio::EnsEMBL::SimpleFeature - A simple feature with a location and label
34 
35 =head1 SYNOPSIS
36 
38 
39  $feature = Bio::EnsEMBL::SimpleFeature->new(
40  -start => 100,
41  -end => 220,
42  -strand => -1,
43  -slice => $slice,
44  -analysis => $analysis,
45  -score => 58,
46  -display_label => 'EponineTSS',
47  -dbID => 1230,
48  -adaptor => $adaptor
49  );
50 
51 =head1 DESCRIPTION
52 
53 This is a simple feature which extends the Feature class to add
54 display_label and score attributes.
55 
56 =head1 METHODS
57 
58 =cut
59 
60 use strict;
61 
62 package Bio::EnsEMBL::SimpleFeature;
63 
64 use vars qw(@ISA);
65 
67 use Bio::EnsEMBL::Utils::Argument qw(rearrange);
68 use Scalar::Util qw(weaken isweak);
69 
70 @ISA = qw(Bio::EnsEMBL::Feature);
71 
72 use constant SEQUENCE_ONTOLOGY => {
73  acc => 'SO:0001411',
74  term => 'biological_region',
75 };
76 
77 =head2 new
78 
79  Arg [DISPLAY_LABEL]: The label assigned to this simple feature
80  Arg [...] : Named arguments passed to superclass
81  Example : $feature = Bio::EnsEMBL::SimpleFeature->new
82  (-start => 1,
83  -end => 100,
84  -strand => 1,
85  -slice => $slice,
86  -analysis => $analysis,
87  -adaptor => $adaptor,
88  -dbID => 10,
89  -display_label => 'EponineTSS',
90  -score => 100);
91  Description: Constructs a new Bio::EnsEMBL::Feature. Generally subclasses
92  of this method are instantiated, rather than this class itself.
93  Returntype : Bio::EnsEMBL::Feature
94  Exceptions : Thrown on invalid -SLICE, -ANALYSIS, -STRAND arguments
95  Caller : general, subclass constructors
96  Status : Stable
97 
98 =cut
99 
100 sub new {
101  my $caller = shift;
102 
103  #allow this to be called as class or object method
104  my $class = ref($caller) || $caller;
105  my $self = $class->SUPER::new(@_);
106 
107  my ($display_label, $score) = rearrange(['DISPLAY_LABEL','SCORE'],@_);
108 
109  $self->{'display_label'} = $display_label;
110  $self->{'score'} = $score;
111 
112  return $self;
113 }
114 
115 
116 =head2 display_label
117 
118  Arg [1] : (optional) string $value
119  Example : $label = $simple_feature->display_label();
120  Description: Getter/Setter for the display label associated with this
121  feature.
122  Returntype : string
123  Exceptions : none
124  Caller : general
125  Status : Stable
126 
127 =cut
128 
129 sub display_label{
130  my $self = shift;
131 
132  $self->{'display_label'} = shift if(@_);
133 
134  return $self->{'display_label'};
135 }
136 
137 
138 =head2 display_id
139 
140  Arg [1] : none
141  Example : print $rf->display_id();
142  Description: This method returns a string that is considered to be
143  the 'display' identifier. For simple features this is the
144  display_label if it is available otherwise it is an empty
145  string.
146  Returntype : string
147  Exceptions : none
148  Caller : web drawing code
149  Status : Stable
150 
151 =cut
152 
153 sub display_id {
154  my $self = shift;
155  return $self->{'display_label'} || '';
156 }
157 
158 
159 
160 =head2 score
161 
162  Arg [1] : (optional) string $value
163  Example : $score = $simple_feature->score();
164  Description: Getter/Setter for the score associated with this
165  feature.
166  Returntype : string
167  Exceptions : none
168  Caller : general
169  Status : Stable
170 
171 =cut
172 
173 sub score {
174  my $self = shift;
175  $self->{'score'} = shift if(@_);
176  return $self->{'score'};
177 }
178 
179 
180 =head2 summary_as_hash
181 
182  Example : my $hash = $simple_feature->summary_as_hash();
183  Description: Generates a HashRef compatible with GFFSerializer. Adds
184  score, external_name and logic_name to the basic Feature
185  hash
186  Returntype : Hash
187  Exceptions : none
188  Caller : general
189  Status : Stable
190 
191 =cut
192 
193 sub summary_as_hash {
194  my ($self) = @_;
195  my $hash = $self->SUPER::summary_as_hash();
196  $hash->{score} = $self->score() if $self->score();
197  $hash->{'external_name'} = $self->display_label() if $self->display_label();
198  $hash->{'logic_name'} = $self->analysis->logic_name();
199  delete $hash->{id};
200  return $hash;
201 }
202 
203 
204 1;
Bio::EnsEMBL::Feature
Definition: Feature.pm:47
Bio::EnsEMBL::SimpleFeature
Definition: SimpleFeature.pm:31
Bio::EnsEMBL::Utils::Argument
Definition: Argument.pm:34
Bio::EnsEMBL::SimpleFeature::new
public Bio::EnsEMBL::Feature new()