| 1 | # | ||||||||||||||||||||||
| 2 | # bioperl module for Bio::SeqFeature::Tools::FeatureNamer | ||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||
| 4 | # Please direct questions and support issues to <bioperl-l@bioperl.org> | ||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||
| 6 | # Cared for by Chris Mungall <cjm@fruitfly.org> | ||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||
| 8 | # Copyright Chris Mungall | ||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||
| 10 | # You may distribute this module under the same terms as perl itself | ||||||||||||||||||||||
| 11 | |||||||||||||||||||||||
| 12 | # POD documentation - main docs before the code | ||||||||||||||||||||||
| 13 | |||||||||||||||||||||||
| 14 | =head1 NAME | ||||||||||||||||||||||
| 15 | |||||||||||||||||||||||
| 16 | Bio::SeqFeature::Tools::FeatureNamer - generates unique persistent names for features | ||||||||||||||||||||||
| 17 | |||||||||||||||||||||||
| 18 | =head1 SYNOPSIS | ||||||||||||||||||||||
| 19 | |||||||||||||||||||||||
| 20 | use Bio::SeqIO; | ||||||||||||||||||||||
| 21 | use Bio::SeqFeature::Tools::FeatureNamer; | ||||||||||||||||||||||
| 22 | |||||||||||||||||||||||
| 23 | # first fetch a genbank SeqI object | ||||||||||||||||||||||
| 24 | $seqio = | ||||||||||||||||||||||
| 25 | Bio::SeqIO->new(-file=>'AE003644.gbk', | ||||||||||||||||||||||
| 26 | -format=>'GenBank'); | ||||||||||||||||||||||
| 27 | $seq = $seqio->next_seq(); | ||||||||||||||||||||||
| 28 | |||||||||||||||||||||||
| 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; | ||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||
| 34 | |||||||||||||||||||||||
| 35 | =head1 DESCRIPTION | ||||||||||||||||||||||
| 36 | |||||||||||||||||||||||
| 37 | This is a helper class for providing names for SeqFeatures | ||||||||||||||||||||||
| 38 | |||||||||||||||||||||||
| 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. | ||||||||||||||||||||||
| 43 | |||||||||||||||||||||||
| 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. | ||||||||||||||||||||||
| 48 | |||||||||||||||||||||||
| 49 | This module is intended to help given uniform display_names to | ||||||||||||||||||||||
| 50 | features and their subfeatures. | ||||||||||||||||||||||
| 51 | |||||||||||||||||||||||
| 52 | =head1 TODO | ||||||||||||||||||||||
| 53 | |||||||||||||||||||||||
| 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 | ||||||||||||||||||||||
| 59 | |||||||||||||||||||||||
| 60 | |||||||||||||||||||||||
| 61 | =head1 FEEDBACK | ||||||||||||||||||||||
| 62 | |||||||||||||||||||||||
| 63 | =head2 Mailing Lists | ||||||||||||||||||||||
| 64 | |||||||||||||||||||||||
| 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. | ||||||||||||||||||||||
| 68 | |||||||||||||||||||||||
| 69 | bioperl-l@bioperl.org - General discussion | ||||||||||||||||||||||
| 70 | http://bioperl.org/wiki/Mailing_lists - About the mailing lists | ||||||||||||||||||||||
| 71 | |||||||||||||||||||||||
| 72 | =head2 Support | ||||||||||||||||||||||
| 73 | |||||||||||||||||||||||
| 74 | Please direct usage questions or support issues to the mailing list: | ||||||||||||||||||||||
| 75 | |||||||||||||||||||||||
| 76 | I<bioperl-l@bioperl.org> | ||||||||||||||||||||||
| 77 | |||||||||||||||||||||||
| 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. | ||||||||||||||||||||||
| 82 | |||||||||||||||||||||||
| 83 | =head2 Reporting Bugs | ||||||||||||||||||||||
| 84 | |||||||||||||||||||||||
| 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 | ||||||||||||||||||||||
| 87 | web: | ||||||||||||||||||||||
| 88 | |||||||||||||||||||||||
| 89 | https://github.com/bioperl/bioperl-live/issues | ||||||||||||||||||||||
| 90 | |||||||||||||||||||||||
| 91 | =head1 AUTHOR - Chris Mungall | ||||||||||||||||||||||
| 92 | |||||||||||||||||||||||
| 93 | Email: cjm AT fruitfly DOT org | ||||||||||||||||||||||
| 94 | |||||||||||||||||||||||
| 95 | =head1 APPENDIX | ||||||||||||||||||||||
| 96 | |||||||||||||||||||||||
| 97 | The rest of the documentation details each of the object | ||||||||||||||||||||||
| 98 | methods. Internal methods are usually preceded with a _ | ||||||||||||||||||||||
| 99 | |||||||||||||||||||||||
| 100 | =cut | ||||||||||||||||||||||
| 101 | |||||||||||||||||||||||
| 102 | |||||||||||||||||||||||
| 103 | # Let the code begin... | ||||||||||||||||||||||
| 104 | |||||||||||||||||||||||
| 105 | package Bio::SeqFeature::Tools::FeatureNamer; | ||||||||||||||||||||||
| 106 | 1 | $Bio::SeqFeature::Tools::FeatureNamer::VERSION = '1.7.8'; | |||||||||||||||||||||
| 107 | 1 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 108 | |||||||||||||||||||||||
| 109 | # Object preamble - inherits from Bio::Root::Root | ||||||||||||||||||||||
| 110 | |||||||||||||||||||||||
| 111 | 1 | ▶ | use base qw(Bio::Root::Root); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 112 | |||||||||||||||||||||||
| 113 | =head2 new | ||||||||||||||||||||||
| 114 | |||||||||||||||||||||||
| 115 | Title : new | ||||||||||||||||||||||
| 116 | Usage : $unflattener = Bio::SeqFeature::Tools::FeatureNamer->new(); | ||||||||||||||||||||||
| 117 | Function: constructor | ||||||||||||||||||||||
| 118 | Example : | ||||||||||||||||||||||
| 119 | Returns : a new Bio::SeqFeature::Tools::FeatureNamer | ||||||||||||||||||||||
| 120 | Args : see below | ||||||||||||||||||||||
| 121 | |||||||||||||||||||||||
| 122 | |||||||||||||||||||||||
| 123 | =cut | ||||||||||||||||||||||
| 124 | |||||||||||||||||||||||
| 125 | 0 | ▶ | sub new { | ||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 126 | 0 | my($class,@args) = @_; | |||||||||||||||||||||
| 127 | 0 | my $self = $class->SUPER::new(@args); | |||||||||||||||||||||
| 128 | |||||||||||||||||||||||
| 129 | # my($typemap) = | ||||||||||||||||||||||
| 130 | # $self->_rearrange([qw(TYPEMAP | ||||||||||||||||||||||
| 131 | # )], | ||||||||||||||||||||||
| 132 | # @args);# | ||||||||||||||||||||||
| 133 | |||||||||||||||||||||||
| 134 | # $typemap && $self->typemap($typemap); | ||||||||||||||||||||||
| 135 | 0 | return $self; # success - we hope! | |||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||
| 137 | |||||||||||||||||||||||
| 138 | =head2 name_feature | ||||||||||||||||||||||
| 139 | |||||||||||||||||||||||
| 140 | Title : name_feature | ||||||||||||||||||||||
| 141 | Usage : $namer->name_feature($sf); | ||||||||||||||||||||||
| 142 | Function: sets display_name | ||||||||||||||||||||||
| 143 | Example : | ||||||||||||||||||||||
| 144 | Returns : | ||||||||||||||||||||||
| 145 | Args : L<Bio::SeqFeatureI> | ||||||||||||||||||||||
| 146 | |||||||||||||||||||||||
| 147 | This method calls generate_feature_name() and uses the returned value | ||||||||||||||||||||||
| 148 | to set the display_name of the feature | ||||||||||||||||||||||
| 149 | |||||||||||||||||||||||
| 150 | =cut | ||||||||||||||||||||||
| 151 | |||||||||||||||||||||||
| 152 | 0 | ▶ | sub name_feature { | ||||||||||||||||||||
|
Subroutine
name_feature: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 153 | 0 | my ($self, $sf) = @_; | |||||||||||||||||||||
| 154 | 0 | my $name = $self->generate_feature_name($sf); | |||||||||||||||||||||
| 155 | 0 | $sf->display_name($name); | |||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||
| 157 | |||||||||||||||||||||||
| 158 | =head2 name_contained_features | ||||||||||||||||||||||
| 159 | |||||||||||||||||||||||
| 160 | Title : name_contained_features | ||||||||||||||||||||||
| 161 | Usage : $namer->name_contained_features($sf); | ||||||||||||||||||||||
| 162 | Function: sets display_name for all features contained by sf | ||||||||||||||||||||||
| 163 | Example : | ||||||||||||||||||||||
| 164 | Returns : | ||||||||||||||||||||||
| 165 | Args : L<Bio::SeqFeatureI> | ||||||||||||||||||||||
| 166 | |||||||||||||||||||||||
| 167 | iterates through all subfeatures of a certain feature (using | ||||||||||||||||||||||
| 168 | get_all_SeqFeatures) and names each subfeatures, based on the | ||||||||||||||||||||||
| 169 | generated name for the holder feature | ||||||||||||||||||||||
| 170 | |||||||||||||||||||||||
| 171 | A subfeature is named by concatenating the generated name of the | ||||||||||||||||||||||
| 172 | container feature with the type and a number. | ||||||||||||||||||||||
| 173 | |||||||||||||||||||||||
| 174 | For example, if the containing feature is a gene with display name | ||||||||||||||||||||||
| 175 | B<dpp>, subfeatures will be named dpp-mRNA-1 dpp-mRNA2 dpp-exon1 | ||||||||||||||||||||||
| 176 | dpp-exon2 etc | ||||||||||||||||||||||
| 177 | |||||||||||||||||||||||
| 178 | =cut | ||||||||||||||||||||||
| 179 | |||||||||||||||||||||||
| 180 | 0 | ▶ | sub name_contained_features{ | ||||||||||||||||||||
|
Subroutine
name_contained_features: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||
| 181 | 0 | my ($self,$sf) = @_; | |||||||||||||||||||||
| 182 | 0 | my $cname = $self->generate_feature_name($sf); | |||||||||||||||||||||
| 183 | 0 | my @subsfs = $sf->get_all_SeqFeatures; | |||||||||||||||||||||
| 184 | 0 | my %num_by_type = (); | |||||||||||||||||||||
| 185 | 0 | foreach my $ssf (@subsfs) { | |||||||||||||||||||||
| 186 | 0 | my $type = $ssf->primary_tag; | |||||||||||||||||||||
| 187 | 0 | ▶ | my $num = $num_by_type{$type} || 0; | ||||||||||||||||||||
|
Condition0%0/2
$num_by_type{$type} || 0
MC/DC0%0/1
$num_by_type{$type} || 0
$num_by_type{$type}
Truth table0%0/2
A
A= $num_by_type{$type}
| |||||||||||||||||||||||
| 188 | 0 | $num++; | |||||||||||||||||||||
| 189 | 0 | $num_by_type{$type} = $num; | |||||||||||||||||||||
| 190 | 0 | $ssf->display_name("$cname-$type-$num"); | |||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||
| 192 | 0 | return; | |||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||
| 194 | |||||||||||||||||||||||
| 195 | =head2 generate_feature_name | ||||||||||||||||||||||
| 196 | |||||||||||||||||||||||
| 197 | Title : generate_feature_name | ||||||||||||||||||||||
| 198 | Usage : $name = $namer->generate_feature_name($sf); | ||||||||||||||||||||||
| 199 | Function: derives a sensible human readable name for a $sf | ||||||||||||||||||||||
| 200 | Example : | ||||||||||||||||||||||
| 201 | Returns : str | ||||||||||||||||||||||
| 202 | Args : L<Bio::SeqFeatureI> | ||||||||||||||||||||||
| 203 | |||||||||||||||||||||||
| 204 | returns a generated name (but does not actually set display_name). | ||||||||||||||||||||||
| 205 | |||||||||||||||||||||||
| 206 | If display_name is already set, the method will return this | ||||||||||||||||||||||
| 207 | |||||||||||||||||||||||
| 208 | Otherwise, the name will depend on the property: | ||||||||||||||||||||||
| 209 | |||||||||||||||||||||||
| 210 | =over | ||||||||||||||||||||||
| 211 | |||||||||||||||||||||||
| 212 | =item label | ||||||||||||||||||||||
| 213 | |||||||||||||||||||||||
| 214 | =item product | ||||||||||||||||||||||
| 215 | |||||||||||||||||||||||
| 216 | =item gene | ||||||||||||||||||||||
| 217 | |||||||||||||||||||||||
| 218 | =item locus_tag | ||||||||||||||||||||||
| 219 | |||||||||||||||||||||||
| 220 | =back | ||||||||||||||||||||||
| 221 | |||||||||||||||||||||||
| 222 | (in order of priority) | ||||||||||||||||||||||
| 223 | |||||||||||||||||||||||
| 224 | =cut | ||||||||||||||||||||||
| 225 | |||||||||||||||||||||||
| 226 | 0 | ▶ | sub generate_feature_name { | ||||||||||||||||||||
|
Subroutine
generate_feature_name: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||
| 227 | 0 | my ($self, $sf) = @_; | |||||||||||||||||||||
| 228 | |||||||||||||||||||||||
| 229 | 0 | my $name = $sf->display_name; | |||||||||||||||||||||
| 230 | 0 | ▶ | if (!$name) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 231 | 0 | ▶ | if ($sf->has_tag("label")) { | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 232 | 0 | ($name) = $sf->get_tag_values("label"); | |||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||
| 234 | elsif ($sf->has_tag("product")) { | ||||||||||||||||||||||
| 235 | 0 | ($name) = $sf->get_tag_values("product"); | |||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||
| 237 | ▶ | elsif ($sf->primary_tag eq 'gene' && | |||||||||||||||||||||
|
Condition0%0/3
$sf->primary_tag eq "gene" and $sf->has_tag("gene")
MC/DC0%0/2
$sf->primary_tag eq "gene" and $sf->has_tag("gene")
$sf->primary_tag eq "gene"
$sf->has_tag("gene")
Truth table0%0/3
A and B
A= $sf->primary_tag eq "gene"B= $sf->has_tag("gene")
| |||||||||||||||||||||||
| 238 | $sf->has_tag("gene")) { | ||||||||||||||||||||||
| 239 | 0 | ($name) = $sf->get_tag_values("gene"); | |||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||
| 241 | ▶ | elsif ($sf->primary_tag eq 'gene' && | |||||||||||||||||||||
|
Condition0%0/3
$sf->primary_tag eq "gene" and $sf->has_tag("locus_tag")
MC/DC0%0/2
$sf->primary_tag eq "gene" and $sf->has_tag("locus_tag")
$sf->primary_tag eq "gene"
$sf->has_tag("locus_tag")
Truth table0%0/3
A and B
A= $sf->primary_tag eq "gene"B= $sf->has_tag("locus_tag")
| |||||||||||||||||||||||
| 242 | $sf->has_tag("locus_tag")) { | ||||||||||||||||||||||
| 243 | 0 | ($name) = $sf->get_tag_values("locus_tag"); | |||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||
| 245 | else { | ||||||||||||||||||||||
| 246 | 0 | $name = $sf->display_name; | |||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||
| 249 | 0 | return $name; | |||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||
| 251 | |||||||||||||||||||||||
| 252 | 1 | 1; | |||||||||||||||||||||