3 See the NOTICE file distributed with
this work
for additional information
4 regarding copyright ownership.
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
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.
23 Please email comments or questions to the
public Ensembl
24 developers list at <http:
26 Questions may also be sent to the Ensembl help desk at
49 # Can add attributes to the misc feature and associate with various
53 -NAME =>
'1MB clone set',
54 -DESCRIPTION =>
'1MB CloneSet'
58 -CODE =>
'tilingpath',
59 -NAME =>
'tiling path set'
75 -VALUE =>
'AL42131.4',
80 # can associate a misc feature with any number of sets
82 $mfeat->add_MiscSet($clone_set);
83 $mfeat->add_MiscSet($tiling_path_set);
85 # can add arbitrary attributes to a misc feature
87 $mfeat->add_Attribute($attrib1);
88 $mfeat->add_Attribute($attrib2);
89 $mfeat->add_Attribute($attrib3);
91 my ($name_attrib) = @{ $mfeat->get_all_Attributes(
'name') };
92 my @all_attribs = @{ $mfeat->get_all_Attributes() };
94 my @all_sets = @{ $mfeat->get_all_MiscSets() };
95 my ($clone_set) = @{ $mfeat->get_all_CloneSets(
'clone') };
98 # Can do normal feature operations as well
99 $mfeat = $mfeat->transform(
'supercontig');
100 print $mfeat->slice->seq_region_name,
' ', $mfeat->start,
'-',
106 MiscFeatures are extremely general features with a location, and an
107 arbitrary group of attributes. They are grouped with other features of
116 package Bio::EnsEMBL::MiscFeature;
128 use constant SEQUENCE_ONTOLOGY => {
130 term =>
'biological_region',
135 Arg [-SLICE]: Bio::EnsEMBL::SLice - Represents the sequence that
this
136 feature is on. The coordinates of the created feature are
137 relative to the start of the slice.
138 Arg [-START]: The start coordinate of
this feature relative to the start
139 of the slice it is sitting on. Coordinates start at 1 and
141 Arg [-END] : The end coordinate of
this feature relative to the start of
142 the slice it is sitting on. Coordinates start at 1 and are
144 Arg [-STRAND]: The orientation of
this feature. Valid values are 1,-1,0.
145 Arg [-SEQNAME] : A seqname to be used instead of the
default name of the
146 of the slice. Useful
for features that
do not have an
147 attached slice such as protein features.
148 Arg [-dbID] : (optional)
internal database
id
154 -analysis => $analysis);
156 of
this method are instantiated, rather than
this class itself.
158 Exceptions : Thrown on invalid -SLICE, -ANALYSIS, -STRAND ,-ADAPTOR arguments
159 Caller : general, subclass constructors
168 my $self = $class->SUPER::new(@_);
170 $self->{
'attributes'} = [];
180 Example : $misc_feature->add_attribute($attribute);
181 Description: Adds an attribute to
this misc. feature
183 Exceptions :
throw on wrong argument type
190 my ($self, $attrib) = @_;
192 if( ! defined $attrib || ! $attrib->isa(
"Bio::EnsEMBL::Attribute" )) {
193 throw(
"You have to provide a Bio::EnsEMBL::Attribute, not a [$attrib]" );
196 $self->{
'attributes'} ||= [];
197 push @{$self->{
'attributes'}}, $attrib
207 Description: Associates
this MiscFeature with a given Set.
209 Exceptions :
throw if the set arg is not provided,
210 throw if the set to be added does not have a code
221 if(!$miscSet || !ref($miscSet) || !$miscSet->isa(
'Bio::EnsEMBL::MiscSet')) {
222 throw(
'Set argument must be a Bio::EnsEMBL::MiscSet');
225 $self->{
'miscSets'} ||= [];
227 push( @{$self->{
'miscSets'}}, $miscSet );
232 =head2 get_all_MiscSets
234 Arg [1] : optional
string $code
235 The code of the set to retrieve
236 Example : $set = $misc_feature->get_all_MiscSets($code);
237 Description: Retrieves a set that
this feature is associated with via its
238 code. Can
return empty lists. Usually returns
about one elements lists.
240 Exceptions :
throw if the code arg is not provided
247 sub get_all_MiscSets {
251 $self->{
'miscSets'} ||= [];
252 if( defined $code ) {
253 my @results = grep { uc($_->code())eq uc( $code ) } @{$self->{
'miscSets'}};
256 return $self->{
'miscSets'};
261 =head2 get_all_Attributes
263 Arg [1] : optional
string $code
264 The code of the Attribute objects to retrieve
265 Example : @attributes = @{ $misc_feature->get_all_Attributes(
'name') };
266 Description: Retrieves a list of Attribute objects
for given code or all
267 of the associated Attributes.
275 sub get_all_Attributes {
282 if( defined $code ) {
283 @results = grep { uc( $_->code() ) eq uc( $code )} @{$self->{
'attributes'}};
286 return $self->{
'attributes'};
290 =head2 get_all_attribute_values
292 Arg [1] :
string $code
293 The code of the Attribute
object values to retrieve
294 Example : @attributes_vals = @{$misc_feature->get_all_attribute_values(
'name')};
295 Description: Retrieves a list of Attribute
object values
for given code or all
296 of the associated Attributes.
297 Returntype : listref of values
304 sub get_all_attribute_values {
307 my @results =
map { uc( $_->code() ) eq uc( $code ) ? $_->value : () }
308 @{$self->{
'attributes'}};
312 =head2 get_scalar_attribute
314 Arg [1] :
string $code
315 The code of the Attribute
object values to retrieve
316 Example : $vals = $misc_feature->get_scalar_attribute(
'name');
317 Description: Retrieves a value
for given code or all
318 of the associated Attributes.
319 Returntype : scalar value
328 sub get_scalar_attribute {
331 my @results = grep { uc( $_->code() ) eq uc( $code )} @{$self->{
'attributes'}};
332 return @results ? $results[0]->value() :
'';
335 sub get_first_scalar_attribute {
337 foreach my $code ( @_ ) {
338 my @results = grep { uc( $_->code() ) eq uc( $code )} @{$self->{
'attributes'}};
339 return $results[0]->value()
if @results;
346 Example : print $kb->display_id();
347 Description: This method returns a
string that is considered to be
348 the
'display' identifier. For misc_features
this is the first
349 name or synonym attribute or
'' if neither are defined.
352 Caller : web drawing code
359 my ($attrib) = @{$self->get_all_Attributes(
'name')};
360 ($attrib) = @{$self->get_all_Attributes(
'synonym')}
if(!$attrib);
361 if( defined $attrib ) {
362 return $attrib->value();
369 =head2 summary_as_hash
371 Example : my $hash = $misc_feature->summary_as_hash();
372 Description: Generates a HashRef compatible with GFFSerializer. Adds
373 all attribute key value pairs plus MiscSet codes and names
381 sub summary_as_hash {
383 my $hash = $self->SUPER::summary_as_hash();
384 my $attributes = $self->get_all_Attributes();
385 foreach my $attr (@{$attributes}) {
386 $hash->{$attr->code()} = $attr->value();
388 my $misc_sets = $self->get_all_MiscSets();
389 foreach my $set (@{$misc_sets}) {
390 push(@{$hash->{misc_set_code}},$set->code());
391 push(@{$hash->{misc_set_name}},$set->name());