comparison variant_effect_predictor/Bio/FeatureHolderI.pm @ 0:1f6dce3d34e0

Uploaded
author mahtabm
date Thu, 11 Apr 2013 02:01:53 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1f6dce3d34e0
1 # $Id: FeatureHolderI.pm,v 1.2 2002/11/19 07:04:22 lapp Exp $
2 #
3 # BioPerl module for Bio::FeatureHolderI
4 #
5 # Cared for by Hilmar Lapp <hlapp at gmx.net>
6 #
7 # Copyright Hilmar Lapp
8 #
9 # You may distribute this module under the same terms as perl itself
10
11 # POD documentation - main docs before the code
12
13 =head1 NAME
14
15 Bio::FeatureHolderI - the base interface an object with features must implement
16
17 =head1 SYNOPSIS
18
19 use Bio::SeqIO;
20 # get a feature-holding object somehow: for example, Bio::SeqI objects
21 # have features
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
29 }
30 }
31
32 =head1 DESCRIPTION
33
34 This is the base interface that all feature-holding objects must
35 implement.
36
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.
41
42 =head1 FEEDBACK
43
44 =head2 Mailing Lists
45
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.
49
50 bioperl-l@bioperl.org - General discussion
51 http://bioperl.org/MailList.shtml - About the mailing lists
52
53 =head2 Reporting Bugs
54
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
57 email or the web:
58
59 bioperl-bugs@bioperl.org
60 http://bioperl.org/bioperl-bugs/
61
62 =head1 AUTHOR - Hilmar Lapp
63
64 Email hlapp at gmx.net
65
66 Describe contact details here
67
68 =head1 CONTRIBUTORS
69
70 Additional contributors names and emails here
71
72 =head1 APPENDIX
73
74 The rest of the documentation details each of the object methods.
75 Internal methods are usually preceded with a _
76
77 =cut
78
79
80 # Let the code begin...
81
82
83 package Bio::FeatureHolderI;
84 use vars qw(@ISA);
85 use strict;
86 use Carp;
87 use Bio::Root::RootI;
88
89 @ISA = qw( Bio::Root::RootI );
90
91 =head2 get_SeqFeatures
92
93 Title : get_SeqFeatures
94 Usage :
95 Function: Get the feature objects held by this feature holder.
96 Example :
97 Returns : an array of Bio::SeqFeatureI implementing objects
98 Args : none
99
100 At some day we may want to expand this method to allow for a feature
101 filter to be passed in.
102
103 =cut
104
105 sub get_SeqFeatures{
106 shift->throw_not_implemented();
107 }
108
109 =head2 feature_count
110
111 Title : feature_count
112 Usage : $obj->feature_count()
113 Function: Return the number of SeqFeatures attached to a feature holder.
114
115 This is before flattening a possible sub-feature tree.
116
117 We provide a default implementation here that just counts
118 the number of objects returned by get_SeqFeatures().
119 Implementors may want to override this with a more
120 efficient implementation.
121
122 Returns : integer representing the number of SeqFeatures
123 Args : None
124
125 At some day we may want to expand this method to allow for a feature
126 filter to be passed in.
127
128 Our default implementation allows for any number of additional
129 arguments and will pass them on to get_SeqFeatures(). I.e., in order to
130 support filter arguments, just support them in get_SeqFeatures().
131
132 =cut
133
134 sub feature_count {
135 return scalar(shift->get_SeqFeatures(@_));
136 }
137
138 =head2 get_all_SeqFeatures
139
140 Title : get_all_SeqFeatures
141 Usage :
142 Function: Get the flattened tree of feature objects held by this
143 feature holder. The difference to get_SeqFeatures is that
144 the entire tree of sub-features will be flattened out.
145
146 We provide a default implementation here, so implementors
147 don''t necessarily need to implement this method.
148
149 Example :
150 Returns : an array of Bio::SeqFeatureI implementing objects
151 Args : none
152
153 At some day we may want to expand this method to allow for a feature
154 filter to be passed in.
155
156 Our default implementation allows for any number of additional
157 arguments and will pass them on to any invocation of
158 get_SeqFeatures(), wherever a component of the tree implements
159 FeatureHolderI. I.e., in order to support filter arguments, just
160 support them in get_SeqFeatures().
161
162 =cut
163
164 sub get_all_SeqFeatures{
165 my $self = shift;
166 my @flatarr;
167
168 foreach my $feat ( $self->get_SeqFeatures(@_) ){
169 push(@flatarr,$feat);
170 &_add_flattened_SeqFeatures(\@flatarr,$feat,@_);
171 }
172 return @flatarr;
173 }
174
175 sub _add_flattened_SeqFeatures {
176 my ($arrayref,$feat,@args) = @_;
177 my @subs = ();
178
179 if($feat->isa("Bio::FeatureHolderI")) {
180 @subs = $feat->get_SeqFeatures(@args);
181 } elsif($feat->isa("Bio::SeqFeatureI")) {
182 @subs = $feat->sub_SeqFeature();
183 } else {
184 confess ref($feat)." is neither a FeatureHolderI nor a SeqFeatureI. ".
185 "Don't know how to flatten.";
186 }
187 foreach my $sub (@subs) {
188 push(@$arrayref,$sub);
189 &_add_flattened_SeqFeatures($arrayref,$sub);
190 }
191
192 }
193
194 1;