0
|
1 =head1 LICENSE
|
|
2
|
|
3 Copyright (c) 1999-2012 The European Bioinformatics Institute and
|
|
4 Genome Research Limited. All rights reserved.
|
|
5
|
|
6 This software is distributed under a modified Apache license.
|
|
7 For license details, please see
|
|
8
|
|
9 http://www.ensembl.org/info/about/code_licence.html
|
|
10
|
|
11 =head1 CONTACT
|
|
12
|
|
13 Please email comments or questions to the public Ensembl
|
|
14 developers list at <dev@ensembl.org>.
|
|
15
|
|
16 Questions may also be sent to the Ensembl help desk at
|
|
17 <helpdesk@ensembl.org>.
|
|
18
|
|
19 =cut
|
|
20
|
|
21 =head1 NAME
|
|
22
|
|
23 Bio::EnsEMBL::MiscFeature - A miscelaneous feature with arbitrary features and
|
|
24 associations.
|
|
25
|
|
26 =head1 SYNOPSIS
|
|
27
|
|
28 use Bio::EnsEMBL::MiscFeature;
|
|
29 use Bio::EnsEMBL::MiscSet;
|
|
30 use Bio::EnsEMBL::Attribute;
|
|
31
|
|
32 my $mfeat = Bio::EnsEMBL::MiscFeature->new(
|
|
33 -START => 1200,
|
|
34 -END => 100_000,
|
|
35 -STRAND => 1,
|
|
36 -SLICE => $slice
|
|
37 );
|
|
38
|
|
39 # Can add attributes to the misc feature and associate with various
|
|
40 # sets
|
|
41 my $clone_set = Bio::EnsEMBL::MiscSet->new(
|
|
42 -CODE => 'clone',
|
|
43 -NAME => '1MB clone set',
|
|
44 -DESCRIPTION => '1MB CloneSet'
|
|
45 );
|
|
46
|
|
47 my $tiling_path_set = Bio::EnsEMBL::MiscSet->new(
|
|
48 -CODE => 'tilingpath',
|
|
49 -NAME => 'tiling path set'
|
|
50 );
|
|
51
|
|
52 my $attrib1 = Bio::EnsEMBL::Attribute->new(
|
|
53 -VALUE => 'RLX12451',
|
|
54 -CODE => 'name',
|
|
55 -NAME => 'name'
|
|
56 );
|
|
57
|
|
58 my $attrib2 = Bio::EnsEMBL::Attribute->new(
|
|
59 -VALUE => '4',
|
|
60 -CODE => 'version',
|
|
61 -NAME => 'version'
|
|
62 );
|
|
63
|
|
64 my $attrib3 = Bio::EnsEMBL::Attribute->new(
|
|
65 -VALUE => 'AL42131.4',
|
|
66 -CODE => 'synonym',
|
|
67 -NAME => 'synonym'
|
|
68 );
|
|
69
|
|
70 # can associate a misc feature with any number of sets
|
|
71
|
|
72 $mfeat->add_MiscSet($clone_set);
|
|
73 $mfeat->add_MiscSet($tiling_path_set);
|
|
74
|
|
75 # can add arbitrary attributes to a misc feature
|
|
76
|
|
77 $mfeat->add_Attribute($attrib1);
|
|
78 $mfeat->add_Attribute($attrib2);
|
|
79 $mfeat->add_Attribute($attrib3);
|
|
80
|
|
81 my ($name_attrib) = @{ $mfeat->get_all_Attributes('name') };
|
|
82 my @all_attribs = @{ $mfeat->get_all_Attributes() };
|
|
83
|
|
84 my @all_sets = @{ $mfeat->get_all_MiscSets() };
|
|
85 my ($clone_set) = @{ $mfeat->get_all_CloneSets('clone') };
|
|
86
|
|
87
|
|
88 # Can do normal feature operations as well
|
|
89 $mfeat = $mfeat->transform('supercontig');
|
|
90 print $mfeat->slice->seq_region_name, ' ', $mfeat->start, '-',
|
|
91 $mfeat->end;
|
|
92
|
|
93
|
|
94 =head1 DESCRIPTION
|
|
95
|
|
96 MiscFeatures are extremely general features with a location, and an
|
|
97 arbitrary group of attributes. They are grouped with other features of
|
|
98 the same 'type' through the use of MiscSets (see Bio::EnsEMBL::MiscSet).
|
|
99 Attributes are attached in the fom of Bio::EnsEMBL::Attribute objects.
|
|
100 See Bio::EnsEMBL::DBSQL::MiscFeatureAdaptor for ways to fetch or store
|
|
101 MiscFeatures.
|
|
102
|
|
103 =cut
|
|
104
|
|
105
|
|
106 package Bio::EnsEMBL::MiscFeature;
|
|
107
|
|
108 use strict;
|
|
109 use warnings;
|
|
110
|
|
111 use Bio::EnsEMBL::Feature;
|
|
112 use Bio::EnsEMBL::Utils::Exception qw(throw);
|
|
113 use Scalar::Util qw(weaken isweak);
|
|
114
|
|
115 use vars qw(@ISA);
|
|
116
|
|
117 @ISA = qw(Bio::EnsEMBL::Feature);
|
|
118
|
|
119 =head2 new
|
|
120
|
|
121 Arg [-SLICE]: Bio::EnsEMBL::SLice - Represents the sequence that this
|
|
122 feature is on. The coordinates of the created feature are
|
|
123 relative to the start of the slice.
|
|
124 Arg [-START]: The start coordinate of this feature relative to the start
|
|
125 of the slice it is sitting on. Coordinates start at 1 and
|
|
126 are inclusive.
|
|
127 Arg [-END] : The end coordinate of this feature relative to the start of
|
|
128 the slice it is sitting on. Coordinates start at 1 and are
|
|
129 inclusive.
|
|
130 Arg [-STRAND]: The orientation of this feature. Valid values are 1,-1,0.
|
|
131 Arg [-SEQNAME] : A seqname to be used instead of the default name of the
|
|
132 of the slice. Useful for features that do not have an
|
|
133 attached slice such as protein features.
|
|
134 Arg [-dbID] : (optional) internal database id
|
|
135 Arg [-ADAPTOR]: (optional) Bio::EnsEMBL::DBSQL::BaseAdaptor
|
|
136 Example : $feature = Bio::EnsEMBL::MiscFeature->new(-start => 1,
|
|
137 -end => 100,
|
|
138 -strand => 1,
|
|
139 -slice => $slice,
|
|
140 -analysis => $analysis);
|
|
141 Description: Constructs a new Bio::EnsEMBL::Feature. Generally subclasses
|
|
142 of this method are instantiated, rather than this class itself.
|
|
143 Returntype : Bio::EnsEMBL::MiscFeature
|
|
144 Exceptions : Thrown on invalid -SLICE, -ANALYSIS, -STRAND ,-ADAPTOR arguments
|
|
145 Caller : general, subclass constructors
|
|
146 Status : Stable
|
|
147
|
|
148 =cut
|
|
149
|
|
150
|
|
151 sub new {
|
|
152 my $class = shift;
|
|
153
|
|
154 my $self = $class->SUPER::new(@_);
|
|
155
|
|
156 $self->{'attributes'} = [];
|
|
157
|
|
158 return $self;
|
|
159 }
|
|
160
|
|
161
|
|
162 =head2 new_fast
|
|
163
|
|
164 Arg [...] : hashref to bless as new MiscFeature
|
|
165 Example : $miscfeature = Bio::EnsEMBL::MiscFeature->new_fast();
|
|
166 Description: Creates a new Miscfeature.
|
|
167 Returntype : Bio::EnsEMBL::MiscFeature
|
|
168 Exceptions : none
|
|
169 Caller : general
|
|
170 Status : Stable
|
|
171
|
|
172 =cut
|
|
173
|
|
174
|
|
175 sub new_fast {
|
|
176 my $class = shift;
|
|
177 my $hashref = shift;
|
|
178
|
|
179 $hashref->{'attributes'} ||= [];
|
|
180
|
|
181 my $self = bless $hashref, $class;
|
|
182 weaken($self->{adaptor}) if ( ! isweak($self->{adaptor}) );
|
|
183 return $self;
|
|
184 }
|
|
185
|
|
186
|
|
187
|
|
188 =head2 add_Attribute
|
|
189
|
|
190 Arg [1] : Bio::EnsEMBL::Attribute $attribute
|
|
191 Example : $misc_feature->add_attribute($attribute);
|
|
192 Description: Adds an attribute to this misc. feature
|
|
193 Returntype : none
|
|
194 Exceptions : throw on wrong argument type
|
|
195 Caller : general
|
|
196 Status : Stable
|
|
197
|
|
198 =cut
|
|
199
|
|
200 sub add_Attribute {
|
|
201 my ($self, $attrib) = @_;
|
|
202
|
|
203 if( ! defined $attrib || ! $attrib->isa( "Bio::EnsEMBL::Attribute" )) {
|
|
204 throw( "You have to provide a Bio::EnsEMBL::Attribute, not a [$attrib]" );
|
|
205 }
|
|
206
|
|
207 $self->{'attributes'} ||= [];
|
|
208 push @{$self->{'attributes'}}, $attrib
|
|
209 }
|
|
210
|
|
211
|
|
212
|
|
213 =head2 add_MiscSet
|
|
214
|
|
215 Arg [1] : Bio::EnsEMBL::MiscSet $set
|
|
216 The set to add
|
|
217 Example : $misc_feature->add_MiscSet(Bio::EnsEMBL::MiscSet->new(...));
|
|
218 Description: Associates this MiscFeature with a given Set.
|
|
219 Returntype : none
|
|
220 Exceptions : throw if the set arg is not provided,
|
|
221 throw if the set to be added does not have a code
|
|
222 Caller : general
|
|
223 Status : Stable
|
|
224
|
|
225 =cut
|
|
226
|
|
227
|
|
228 sub add_MiscSet {
|
|
229 my $self = shift;
|
|
230 my $miscSet = shift;
|
|
231
|
|
232 if(!$miscSet || !ref($miscSet) || !$miscSet->isa('Bio::EnsEMBL::MiscSet')) {
|
|
233 throw('Set argument must be a Bio::EnsEMBL::MiscSet');
|
|
234 }
|
|
235
|
|
236 $self->{'miscSets'} ||= [];
|
|
237
|
|
238 push( @{$self->{'miscSets'}}, $miscSet );
|
|
239 }
|
|
240
|
|
241
|
|
242
|
|
243 =head2 get_all_MiscSets
|
|
244
|
|
245 Arg [1] : optional string $code
|
|
246 The code of the set to retrieve
|
|
247 Example : $set = $misc_feature->get_all_MiscSets($code);
|
|
248 Description: Retrieves a set that this feature is associated with via its
|
|
249 code. Can return empty lists. Usually returns about one elements lists.
|
|
250 Returntype : listref of Bio::EnsEMBL::MiscSet
|
|
251 Exceptions : throw if the code arg is not provided
|
|
252 Caller : general
|
|
253 Status : Stable
|
|
254
|
|
255 =cut
|
|
256
|
|
257
|
|
258 sub get_all_MiscSets {
|
|
259 my $self = shift;
|
|
260 my $code = shift;
|
|
261
|
|
262 $self->{'miscSets'} ||= [];
|
|
263 if( defined $code ) {
|
|
264 my @results = grep { uc($_->code())eq uc( $code ) } @{$self->{'miscSets'}};
|
|
265 return \@results;
|
|
266 } else {
|
|
267 return $self->{'miscSets'};
|
|
268 }
|
|
269 }
|
|
270
|
|
271
|
|
272 =head2 get_all_Attributes
|
|
273
|
|
274 Arg [1] : optional string $code
|
|
275 The code of the Attribute objects to retrieve
|
|
276 Example : @attributes = @{ $misc_feature->get_all_Attributes('name') };
|
|
277 Description: Retrieves a list of Attribute objects for given code or all
|
|
278 of the associated Attributes.
|
|
279 Returntype : listref of Bio::EnsEMBL::Attribute
|
|
280 Exceptions :
|
|
281 Caller : general
|
|
282 Status : Stable
|
|
283
|
|
284 =cut
|
|
285
|
|
286 sub get_all_Attributes {
|
|
287 my $self = shift;
|
|
288 my $code = shift;
|
|
289
|
|
290 my @results;
|
|
291 my $result;
|
|
292
|
|
293 if( defined $code ) {
|
|
294 @results = grep { uc( $_->code() ) eq uc( $code )} @{$self->{'attributes'}};
|
|
295 return \@results;
|
|
296 } else {
|
|
297 return $self->{'attributes'};
|
|
298 }
|
|
299 }
|
|
300
|
|
301 =head2 get_all_attribute_values
|
|
302
|
|
303 Arg [1] : string $code
|
|
304 The code of the Attribute object values to retrieve
|
|
305 Example : @attributes_vals = @{$misc_feature->get_all_attribute_values('name')};
|
|
306 Description: Retrieves a list of Attribute object values for given code or all
|
|
307 of the associated Attributes.
|
|
308 Returntype : listref of values
|
|
309 Exceptions :
|
|
310 Caller : general
|
|
311 Status : Stable
|
|
312
|
|
313 =cut
|
|
314
|
|
315 sub get_all_attribute_values {
|
|
316 my $self = shift;
|
|
317 my $code = shift;
|
|
318 my @results = map { uc( $_->code() ) eq uc( $code ) ? $_->value : () }
|
|
319 @{$self->{'attributes'}};
|
|
320 return \@results;
|
|
321 }
|
|
322
|
|
323 =head2 get_scalar_attribute
|
|
324
|
|
325 Arg [1] : string $code
|
|
326 The code of the Attribute object values to retrieve
|
|
327 Example : $vals = $misc_feature->get_scalar_attribute('name');
|
|
328 Description: Retrieves a value for given code or all
|
|
329 of the associated Attributes.
|
|
330 Returntype : scalar value
|
|
331 Exceptions :
|
|
332 Caller : general
|
|
333 Status : Stable
|
|
334
|
|
335
|
|
336 =cut
|
|
337
|
|
338
|
|
339 sub get_scalar_attribute {
|
|
340 my $self = shift;
|
|
341 my $code = shift;
|
|
342 my @results = grep { uc( $_->code() ) eq uc( $code )} @{$self->{'attributes'}};
|
|
343 return @results ? $results[0]->value() : '';
|
|
344 }
|
|
345
|
|
346 sub get_first_scalar_attribute {
|
|
347 my $self = shift;
|
|
348 foreach my $code ( @_ ) {
|
|
349 my @results = grep { uc( $_->code() ) eq uc( $code )} @{$self->{'attributes'}};
|
|
350 return $results[0]->value() if @results;
|
|
351 }
|
|
352 return '';
|
|
353 }
|
|
354 =head2 display_id
|
|
355
|
|
356 Arg [1] : none
|
|
357 Example : print $kb->display_id();
|
|
358 Description: This method returns a string that is considered to be
|
|
359 the 'display' identifier. For misc_features this is the first
|
|
360 name or synonym attribute or '' if neither are defined.
|
|
361 Returntype : string
|
|
362 Exceptions : none
|
|
363 Caller : web drawing code
|
|
364 Status : Stable
|
|
365
|
|
366 =cut
|
|
367
|
|
368 sub display_id {
|
|
369 my $self = shift;
|
|
370 my ($attrib) = @{$self->get_all_Attributes('name')};
|
|
371 ($attrib) = @{$self->get_all_Attributes('synonym')} if(!$attrib);
|
|
372 if( defined $attrib ) {
|
|
373 return $attrib->value();
|
|
374 } else {
|
|
375 return '';
|
|
376 }
|
|
377 }
|
|
378
|
|
379
|
|
380
|
|
381
|
|
382 1;
|