2 # bioperl module for Bio::SeqFeature::Tools::FeatureNamer
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Chris Mungall <cjm@fruitfly.org>
8 # Copyright Chris Mungall
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
16 Bio::SeqFeature::Tools::FeatureNamer - generates unique persistent names for features
21 use Bio::SeqFeature::Tools::FeatureNamer;
23 # first fetch a genbank SeqI object
25 Bio::SeqIO->new(-file=>'AE003644.gbk',
27 $seq = $seqio->next_seq();
29 $namer = Bio::SeqFeature::Tools::FeatureNamer->new;
30 my @features = $seq->get_SeqFeatures;
31 foreach my $feature (@features) {
32 $namer->name_feature($feature) unless $feature->display_name;
37 This is a helper class for providing names for SeqFeatures
39 The L<Bio::SeqFeatureI> class provides a display_name
40 method. Typically the display_name is not set when parsing formats
41 such as genbank - instead properties such as B<label>, B<product> or
42 B<gene> are set in a somewhat inconsistent manner.
44 In addition, when generating subfeatures (for example, exons that are
45 subfeatures of a transcript feature), it is often desirable to name
46 these subfeatures before either exporting to another format or
47 reporting to the user.
49 This module is intended to help given uniform display_names to
50 features and their subfeatures.
54 Currently the naming policy is hardcoded. It may be desirable to allow
55 plugging in variations on naming policies; this could be done either
56 by subclassing, anonymous subroutines (closures) or
57 parameterization. Contact the author if you feel you have need for a
58 different naming policy
65 User feedback is an integral part of the evolution of this and other
66 Bioperl modules. Send your comments and suggestions preferably to the
67 Bioperl mailing lists Your participation is much appreciated.
69 bioperl-l@bioperl.org - General discussion
70 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
74 Please direct usage questions or support issues to the mailing list:
76 I<bioperl-l@bioperl.org>
78 rather than to the module maintainer directly. Many experienced and
79 reponsive experts will be able look at the problem and quickly
80 address it. Please include a thorough description of the problem
81 with code and data examples if at all possible.
85 report bugs to the Bioperl bug tracking system to help us keep track
86 the bugs and their resolution. Bug reports can be submitted via the
89 https://github.com/bioperl/bioperl-live/issues
91 =head1 AUTHOR - Chris Mungall
93 Email: cjm AT fruitfly DOT org
97 The rest of the documentation details each of the object
98 methods. Internal methods are usually preceded with a _
103 # Let the code begin...
105 package Bio
::SeqFeature
::Tools
::FeatureNamer
;
108 # Object preamble - inherits from Bio::Root::Root
110 use base
qw(Bio::Root::Root);
115 Usage : $unflattener = Bio::SeqFeature::Tools::FeatureNamer->new();
116 Function: constructor
118 Returns : a new Bio::SeqFeature::Tools::FeatureNamer
125 my($class,@args) = @_;
126 my $self = $class->SUPER::new
(@args);
129 # $self->_rearrange([qw(TYPEMAP
133 # $typemap && $self->typemap($typemap);
134 return $self; # success - we hope!
140 Usage : $namer->name_feature($sf);
141 Function: sets display_name
144 Args : L<Bio::SeqFeatureI>
146 This method calls generate_feature_name() and uses the returned value
147 to set the display_name of the feature
152 my ($self, $sf) = @_;
153 my $name = $self->generate_feature_name($sf);
154 $sf->display_name($name);
157 =head2 name_contained_features
159 Title : name_contained_features
160 Usage : $namer->name_contained_features($sf);
161 Function: sets display_name for all features contained by sf
164 Args : L<Bio::SeqFeatureI>
166 iterates through all subfeatures of a certain feature (using
167 get_all_SeqFeatures) and names each subfeatures, based on the
168 generated name for the holder feature
170 A subfeature is named by concatenating the generated name of the
171 container feature with the type and a number.
173 For example, if the containing feature is a gene with display name
174 B<dpp>, subfeatures will be named dpp-mRNA-1 dpp-mRNA2 dpp-exon1
179 sub name_contained_features
{
181 my $cname = $self->generate_feature_name($sf);
182 my @subsfs = $sf->get_all_SeqFeatures;
183 my %num_by_type = ();
184 foreach my $ssf (@subsfs) {
185 my $type = $ssf->primary_tag;
186 my $num = $num_by_type{$type} || 0;
188 $num_by_type{$type} = $num;
189 $ssf->display_name("$cname-$type-$num");
194 =head2 generate_feature_name
196 Title : generate_feature_name
197 Usage : $name = $namer->generate_feature_name($sf);
198 Function: derives a sensible human readable name for a $sf
201 Args : L<Bio::SeqFeatureI>
203 returns a generated name (but does not actually set display_name).
205 If display_name is already set, the method will return this
207 Otherwise, the name will depend on the property:
221 (in order of priority)
225 sub generate_feature_name
{
226 my ($self, $sf) = @_;
228 my $name = $sf->display_name;
230 if ($sf->has_tag("label")) {
231 ($name) = $sf->get_tag_values("label");
233 elsif ($sf->has_tag("product")) {
234 ($name) = $sf->get_tag_values("product");
236 elsif ($sf->primary_tag eq 'gene' &&
237 $sf->has_tag("gene")) {
238 ($name) = $sf->get_tag_values("gene");
240 elsif ($sf->primary_tag eq 'gene' &&
241 $sf->has_tag("locus_tag")) {
242 ($name) = $sf->get_tag_values("locus_tag");
245 $name = $sf->display_name;