| 1 | # | ||||||||||||||||||||||||||||||||
| 2 | # BioPerl module for Bio::Cluster::ClusterFactory | ||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||
| 4 | # Please direct questions and support issues to <bioperl-l@bioperl.org> | ||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||
| 6 | # Cared for by Hilmar Lapp <hlapp at gmx.net> | ||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||
| 8 | # Copyright Hilmar Lapp | ||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||
| 10 | # You may distribute this module under the same terms as perl itself | ||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | # | ||||||||||||||||||||||||||||||||
| 13 | # (c) Hilmar Lapp, hlapp at gmx.net, 2002. | ||||||||||||||||||||||||||||||||
| 14 | # (c) GNF, Genomics Institute of the Novartis Research Foundation, 2002. | ||||||||||||||||||||||||||||||||
| 15 | # | ||||||||||||||||||||||||||||||||
| 16 | # You may distribute this module under the same terms as perl itself. | ||||||||||||||||||||||||||||||||
| 17 | # Refer to the Perl Artistic License (see the license accompanying this | ||||||||||||||||||||||||||||||||
| 18 | # software package, or see http://www.perl.com/language/misc/Artistic.html) | ||||||||||||||||||||||||||||||||
| 19 | # for the terms under which you may use, modify, and redistribute this module. | ||||||||||||||||||||||||||||||||
| 20 | # | ||||||||||||||||||||||||||||||||
| 21 | # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED | ||||||||||||||||||||||||||||||||
| 22 | # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF | ||||||||||||||||||||||||||||||||
| 23 | # MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||||||||||||||||||||||||||||||||
| 24 | # | ||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | # POD documentation - main docs before the code | ||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | Bio::Cluster::ClusterFactory - Instantiates a new Bio::ClusterI (or derived class) through a factory | ||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | use Bio::Cluster::ClusterFactory; | ||||||||||||||||||||||||||||||||
| 35 | # if you don't provide a default type, the factory will try | ||||||||||||||||||||||||||||||||
| 36 | # some guesswork based on display_id and namespace | ||||||||||||||||||||||||||||||||
| 37 | my $factory = Bio::Cluster::ClusterFactory->new(-type => 'Bio::Cluster::UniGene'); | ||||||||||||||||||||||||||||||||
| 38 | my $clu = $factory->create_object(-description => 'NAT', | ||||||||||||||||||||||||||||||||
| 39 | -display_id => 'Hs.2'); | ||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | This object will build L<Bio::ClusterI> objects generically. | ||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | =head1 FEEDBACK | ||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | =head2 Mailing Lists | ||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | User feedback is an integral part of the evolution of this and other | ||||||||||||||||||||||||||||||||
| 51 | Bioperl modules. Send your comments and suggestions preferably to | ||||||||||||||||||||||||||||||||
| 52 | the Bioperl mailing list. Your participation is much appreciated. | ||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | bioperl-l@bioperl.org - General discussion | ||||||||||||||||||||||||||||||||
| 55 | http://bioperl.org/wiki/Mailing_lists - About the mailing lists | ||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | =head2 Support | ||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | Please direct usage questions or support issues to the mailing list: | ||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | I<bioperl-l@bioperl.org> | ||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | rather than to the module maintainer directly. Many experienced and | ||||||||||||||||||||||||||||||||
| 64 | reponsive experts will be able look at the problem and quickly | ||||||||||||||||||||||||||||||||
| 65 | address it. Please include a thorough description of the problem | ||||||||||||||||||||||||||||||||
| 66 | with code and data examples if at all possible. | ||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | =head2 Reporting Bugs | ||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | Report bugs to the Bioperl bug tracking system to help us keep track | ||||||||||||||||||||||||||||||||
| 71 | of the bugs and their resolution. Bug reports can be submitted via the | ||||||||||||||||||||||||||||||||
| 72 | web: | ||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | https://github.com/bioperl/bioperl-live/issues | ||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | =head1 AUTHOR - Hilmar Lapp | ||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | Email hlapp at gmx.net | ||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | =head1 APPENDIX | ||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | The rest of the documentation details each of the object methods. | ||||||||||||||||||||||||||||||||
| 84 | Internal methods are usually preceded with a _ | ||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | =cut | ||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | # Let the code begin... | ||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | package Bio::Cluster::ClusterFactory; | ||||||||||||||||||||||||||||||||
| 93 | 4 | $Bio::Cluster::ClusterFactory::VERSION = '1.7.3'; | |||||||||||||||||||||||||||||||
| 94 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | 4 | ▶ | use Bio::Root::Root; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | 4 | ▶ | use base qw(Bio::Factory::ObjectFactory); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | =head2 new | ||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | Title : new | ||||||||||||||||||||||||||||||||
| 103 | Usage : my $obj = Bio::Cluster::ClusterFactory->new(); | ||||||||||||||||||||||||||||||||
| 104 | Function: Builds a new Bio::Cluster::ClusterFactory object | ||||||||||||||||||||||||||||||||
| 105 | Returns : Bio::Cluster::ClusterFactory | ||||||||||||||||||||||||||||||||
| 106 | Args : -type => string, name of a ClusterI derived class. | ||||||||||||||||||||||||||||||||
| 107 | If not provided, the factory will have to guess | ||||||||||||||||||||||||||||||||
| 108 | from ID and namespace, which may or may not be | ||||||||||||||||||||||||||||||||
| 109 | successful. | ||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||
| 111 | =cut | ||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||
| 113 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 114 | 2 | my($class,@args) = @_; | |||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||
| 116 | 2 | my $self = $class->SUPER::new(@args); | |||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||
| 118 | 2 | $self->interface("Bio::ClusterI"); | |||||||||||||||||||||||||||||||
| 119 | 2 | ▶ | $self->type($self->type) if $self->type; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | 2 | return $self; | |||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||
| 125 | =head2 create_object | ||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||
| 127 | Title : create_object | ||||||||||||||||||||||||||||||||
| 128 | Usage : my $seq = $factory->create_object(<named parameters>); | ||||||||||||||||||||||||||||||||
| 129 | Function: Instantiates new Bio::ClusterI (or one of its child classes) | ||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||
| 131 | This object allows us to genericize the instantiation of | ||||||||||||||||||||||||||||||||
| 132 | cluster objects. | ||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||
| 134 | Returns : L<Bio::ClusterI> compliant object | ||||||||||||||||||||||||||||||||
| 135 | The return type is configurable using new(-type =>"..."). | ||||||||||||||||||||||||||||||||
| 136 | Args : initialization parameters specific to the type of cluster | ||||||||||||||||||||||||||||||||
| 137 | object we want. Typically | ||||||||||||||||||||||||||||||||
| 138 | -display_id => $name | ||||||||||||||||||||||||||||||||
| 139 | -description => description of the cluster | ||||||||||||||||||||||||||||||||
| 140 | -members => arrayref, members of the cluster | ||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||
| 142 | =cut | ||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||
| 144 | 5 | ▶ | sub create_object { | ||||||||||||||||||||||||||||||
|
Subroutine
create_object: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 145 | 5 | my ($self,@args) = @_; | |||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||
| 147 | 5 | my $type = $self->type(); | |||||||||||||||||||||||||||||||
| 148 | 5 | ▶ | if(! $type) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 149 | # we need to guess this | ||||||||||||||||||||||||||||||||
| 150 | 1 | $type = $self->_guess_type(@args); | |||||||||||||||||||||||||||||||
| 151 | 1 | ▶ | $self->throw("No cluster type set and unable to guess.") unless $type; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 152 | 1 | $self->type($type); | |||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||
| 154 | 5 | return $type->new(-verbose => $self->verbose, @args); | |||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||
| 157 | =head2 _guess_type | ||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||
| 159 | Title : _guess_type | ||||||||||||||||||||||||||||||||
| 160 | Usage : | ||||||||||||||||||||||||||||||||
| 161 | Function: Guesses the right type of L<Bio::ClusterI> implementation | ||||||||||||||||||||||||||||||||
| 162 | based on initialization parameters for the prospective | ||||||||||||||||||||||||||||||||
| 163 | object. | ||||||||||||||||||||||||||||||||
| 164 | Example : | ||||||||||||||||||||||||||||||||
| 165 | Returns : the type (a string, the module name) | ||||||||||||||||||||||||||||||||
| 166 | Args : initialization parameters to be passed to the prospective | ||||||||||||||||||||||||||||||||
| 167 | cluster object | ||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||
| 170 | =cut | ||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||
| 172 | 1 | ▶ | sub _guess_type{ | ||||||||||||||||||||||||||||||
|
Subroutine
_guess_type: called CC=5 SCAR=19.1
| |||||||||||||||||||||||||||||||||
| 173 | 1 | my ($self,@args) = @_; | |||||||||||||||||||||||||||||||
| 174 | 1 | my $type; | |||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||
| 176 | # we can only guess from a certain number of arguments | ||||||||||||||||||||||||||||||||
| 177 | 1 | my ($dispid, $ns, $members) = | |||||||||||||||||||||||||||||||
| 178 | $self->_rearrange([qw(DISPLAY_ID | ||||||||||||||||||||||||||||||||
| 179 | NAMESPACE | ||||||||||||||||||||||||||||||||
| 180 | MEMBERS | ||||||||||||||||||||||||||||||||
| 181 | )], @args); | ||||||||||||||||||||||||||||||||
| 182 | # Unigene namespace or ID? | ||||||||||||||||||||||||||||||||
| 183 | 1 | ▶ | if($ns && (lc($ns) eq "unigene")) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$ns and lc $ns eq "unigene"
MC/DC0%0/2
$ns and lc $ns eq "unigene"
$ns
lc $ns eq "unigene"
Truth table33%1/3
A and B
A= $nsB= lc $ns eq "unigene"
| |||||||||||||||||||||||||||||||||
| 184 | 0 | $type = 'Bio::Cluster::UniGene'; | |||||||||||||||||||||||||||||||
| 185 | ▶ | } elsif($dispid && ($dispid =~ /^Hs\.[0-9]/)) { | |||||||||||||||||||||||||||||||
|
Condition33%1/3
$dispid and $dispid =~ /^Hs\.[0-9]/
MC/DC0%0/2
$dispid and $dispid =~ /^Hs\.[0-9]/
$dispid
$dispid =~ /^Hs\.[0-9]/
Truth table33%1/3
A and B
A= $dispidB= $dispid =~ /^Hs\.[0-9]/
| |||||||||||||||||||||||||||||||||
| 186 | 1 | $type = 'Bio::Cluster::UniGene'; | |||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||
| 188 | # what else could we look for? | ||||||||||||||||||||||||||||||||
| 189 | 1 | return $type; | |||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||
| 192 | 4 | 1; | |||||||||||||||||||||||||||||||