3 # BioPerl module for Bio::FeatureHolderI
5 # Cared for by Hilmar Lapp <hlapp at gmx.net>
7 # Copyright Hilmar Lapp
9 # You may distribute this module under the same terms as perl itself
11 # POD documentation - main docs before the code
15 Bio::FeatureHolderI - the base interface an object with features must implement
20 # get a feature-holding object somehow: for example, Bio::SeqI objects
22 my $seqio = Bio::SeqIO->new(-fh => \*STDIN, -format => 'genbank');
23 while (my $seq = $seqio->next_seq()) {
24 # $seq is-a Bio::FeatureHolderI, hence:
25 my @feas = $seq->get_SeqFeatures();
26 # each element is-a Bio::SeqFeatureI
27 foreach my $fea (@feas) {
28 # do something with the feature objects
34 This is the base interface that all feature-holding objects must
37 Popular feature-holders are for instance L<Bio::Seq> objects. Since
38 L<Bio::SeqFeatureI> defines a sub_SeqFeature() method, most
39 Bio::SeqFeatureI implementations like L<Bio::SeqFeature::Generic> will
40 implement the feature holder interface as well.
46 User feedback is an integral part of the evolution of this and other
47 Bioperl modules. Send your comments and suggestions preferably to
48 the Bioperl mailing list. Your participation is much appreciated.
50 bioperl-l@bioperl.org - General discussion
51 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
55 Report bugs to the Bioperl bug tracking system to help us keep track
56 of the bugs and their resolution. Bug reports can be submitted via the
59 http://bugzilla.open-bio.org/
61 =head1 AUTHOR - Hilmar Lapp
63 Email hlapp at gmx.net
67 Steffen Grossmann [SG], grossman-at-molgen.mpg.de
71 The rest of the documentation details each of the object methods.
72 Internal methods are usually preceded with a _
77 # Let the code begin...
81 package Bio
::FeatureHolderI
;
85 use base
qw(Bio::Root::RootI);
87 =head2 get_SeqFeatures()
90 Function: Get the feature objects held by this feature holder.
92 Returns : an array of Bio::SeqFeatureI implementing objects
95 At some day we may want to expand this method to allow for a feature
96 filter to be passed in.
100 sub get_SeqFeatures
{
101 shift->throw_not_implemented();
104 =head2 add_SeqFeature()
106 Usage : $feat->add_SeqFeature($subfeat);
107 $feat->add_SeqFeature($subfeat,'EXPAND')
108 Function: adds a SeqFeature into the subSeqFeature array.
109 with no 'EXPAND' qualifer, subfeat will be tested
110 as to whether it lies inside the parent, and throw
113 If EXPAND is used, the parent''s start/end/strand will
114 be adjusted so that it grows to accommodate the new
118 Args : a Bio::SeqFeatureI object
123 shift->throw_not_implemented();
127 =head2 remove_SeqFeatures()
129 Usage : $obj->remove_SeqFeatures
130 Function: Removes all sub SeqFeatures. If you want to remove only a subset,
131 remove that subset from the returned array, and add back the rest.
132 Returns : The array of Bio::SeqFeatureI implementing sub-features that was
133 deleted from this feature.
138 sub remove_SeqFeatures
{
139 shift->throw_not_implemented();
144 Title : feature_count
145 Usage : $obj->feature_count()
146 Function: Return the number of SeqFeatures attached to a feature holder.
148 This is before flattening a possible sub-feature tree.
150 We provide a default implementation here that just counts
151 the number of objects returned by get_SeqFeatures().
152 Implementors may want to override this with a more
153 efficient implementation.
155 Returns : integer representing the number of SeqFeatures
158 At some day we may want to expand this method to allow for a feature
159 filter to be passed in.
161 Our default implementation allows for any number of additional
162 arguments and will pass them on to get_SeqFeatures(). I.e., in order to
163 support filter arguments, just support them in get_SeqFeatures().
168 return scalar(shift->get_SeqFeatures(@_));
171 =head2 get_all_SeqFeatures
173 Title : get_all_SeqFeatures
175 Function: Get the flattened tree of feature objects held by this
176 feature holder. The difference to get_SeqFeatures is that
177 the entire tree of sub-features will be flattened out.
179 We provide a default implementation here, so implementors
180 don''t necessarily need to implement this method.
183 Returns : an array of Bio::SeqFeatureI implementing objects
186 At some day we may want to expand this method to allow for a feature
187 filter to be passed in.
189 Our default implementation allows for any number of additional
190 arguments and will pass them on to any invocation of
191 get_SeqFeatures(), wherever a component of the tree implements
192 FeatureHolderI. I.e., in order to support filter arguments, just
193 support them in get_SeqFeatures().
197 sub get_all_SeqFeatures
{
201 foreach my $feat ( $self->get_SeqFeatures(@_) ){
202 push(@flatarr,$feat);
203 &_add_flattened_SeqFeatures
(\
@flatarr,$feat,@_);
206 # needed to deal with subfeatures which appear more than once in the hierarchy [SG]
208 my @uniq_flatarr = ();
209 foreach my $feat (@flatarr) {
210 push(@uniq_flatarr, $feat) unless $seen{$feat}++;
212 return @uniq_flatarr;
215 sub _add_flattened_SeqFeatures
{
216 my ($arrayref,$feat,@args) = @_;
219 if($feat->isa("Bio::FeatureHolderI")) {
220 @subs = $feat->get_SeqFeatures(@args);
221 } elsif($feat->isa("Bio::SeqFeatureI")) {
222 @subs = $feat->sub_SeqFeature();
224 confess
ref($feat)." is neither a FeatureHolderI nor a SeqFeatureI. ".
225 "Don't know how to flatten.";
227 foreach my $sub (@subs) {
228 push(@
$arrayref,$sub);
229 &_add_flattened_SeqFeatures
($arrayref,$sub);
234 sub set_ParentIDs_from_hierarchy
(){
235 # DEPRECATED - use IDHandler
237 require "Bio/SeqFeature/Tools/IDHandler.pm";
238 Bio
::SeqFeature
::Tools
::IDHandler
->new->set_ParentIDs_from_hierarchy($self);
241 sub create_hierarchy_from_ParentIDs
(){
242 # DEPRECATED - use IDHandler
244 require "Bio/SeqFeature/Tools/IDHandler.pm";
245 Bio
::SeqFeature
::Tools
::IDHandler
->new->create_hierarchy_from_ParentIDs($self);