Mercurial > repos > mahtabm > ensembl
comparison variant_effect_predictor/Bio/Search/Hit/HitFactory.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: HitFactory.pm,v 1.3 2002/10/22 07:45:17 lapp Exp $ | |
2 # | |
3 # BioPerl module for Bio::Search::Hit::HitFactory | |
4 # | |
5 # Cared for by Jason Stajich <jason@bioperl.org> | |
6 # | |
7 # Copyright Jason Stajich | |
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::Search::Hit::HitFactory - A factory to create Bio::Search::Hit::HitI objects | |
16 | |
17 =head1 SYNOPSIS | |
18 | |
19 use Bio::Search::Hit::HitFactory; | |
20 my $factory = new Bio::Search::Hit::HitFactory(); | |
21 my $resultobj = $factory->create(@args); | |
22 | |
23 =head1 DESCRIPTION | |
24 | |
25 This is a general way of hiding the object creation process so that we | |
26 can dynamically change the objects that are created by the SearchIO | |
27 parser depending on what format report we are parsing. | |
28 | |
29 This object is for creating new Hits. | |
30 | |
31 =head1 FEEDBACK | |
32 | |
33 =head2 Mailing Lists | |
34 | |
35 User feedback is an integral part of the evolution of this and other | |
36 Bioperl modules. Send your comments and suggestions preferably to | |
37 the Bioperl mailing list. Your participation is much appreciated. | |
38 | |
39 bioperl-l@bioperl.org - General discussion | |
40 http://bioperl.org/MailList.shtml - About the mailing lists | |
41 | |
42 =head2 Reporting Bugs | |
43 | |
44 Report bugs to the Bioperl bug tracking system to help us keep track | |
45 of the bugs and their resolution. Bug reports can be submitted via | |
46 email or the web: | |
47 | |
48 bioperl-bugs@bioperl.org | |
49 http://bugzilla.bioperl.org/ | |
50 | |
51 =head1 AUTHOR - Jason Stajich | |
52 | |
53 Email jason@bioperl.org | |
54 | |
55 Describe contact details here | |
56 | |
57 =head1 CONTRIBUTORS | |
58 | |
59 Additional contributors names and emails here | |
60 | |
61 =head1 APPENDIX | |
62 | |
63 The rest of the documentation details each of the object methods. | |
64 Internal methods are usually preceded with a _ | |
65 | |
66 =cut | |
67 | |
68 | |
69 # Let the code begin... | |
70 | |
71 | |
72 package Bio::Search::Hit::HitFactory; | |
73 use vars qw(@ISA $DEFAULT_TYPE); | |
74 use strict; | |
75 | |
76 use Bio::Root::Root; | |
77 use Bio::Factory::ObjectFactoryI; | |
78 | |
79 @ISA = qw(Bio::Root::Root Bio::Factory::ObjectFactoryI ); | |
80 | |
81 BEGIN { | |
82 $DEFAULT_TYPE = 'Bio::Search::Hit::GenericHit'; | |
83 } | |
84 | |
85 =head2 new | |
86 | |
87 Title : new | |
88 Usage : my $obj = new Bio::Search::Hit::HitFactory(); | |
89 Function: Builds a new Bio::Search::Hit::HitFactory object | |
90 Returns : Bio::Search::Hit::HitFactory | |
91 Args : | |
92 | |
93 | |
94 =cut | |
95 | |
96 sub new { | |
97 my($class,@args) = @_; | |
98 | |
99 my $self = $class->SUPER::new(@args); | |
100 my ($type) = $self->_rearrange([qw(TYPE)],@args); | |
101 $self->type($type) if defined $type; | |
102 return $self; | |
103 } | |
104 | |
105 =head2 create | |
106 | |
107 Title : create | |
108 Usage : $factory->create(%args) | |
109 Function: Create a new L<Bio::Search::Hit::HitI> object | |
110 Returns : L<Bio::Search::Hit::HitI> | |
111 Args : hash of initialization parameters | |
112 | |
113 | |
114 =cut | |
115 | |
116 sub create{ | |
117 my ($self,@args) = @_; | |
118 my $type = $self->type; | |
119 eval { $self->_load_module($type) }; | |
120 if( $@ ) { $self->throw("Unable to load module $type"); } | |
121 return $type->new(@args); | |
122 } | |
123 | |
124 | |
125 =head2 type | |
126 | |
127 Title : type | |
128 Usage : $factory->type('Bio::Search::Hit::GenericHit'); | |
129 Function: Get/Set the Hit creation type | |
130 Returns : string | |
131 Args : [optional] string to set | |
132 | |
133 | |
134 =cut | |
135 | |
136 sub type{ | |
137 my ($self,$type) = @_; | |
138 if( defined $type ) { | |
139 # redundancy with the create method which also calls _load_module | |
140 # I know - but this is not a highly called object so I am going | |
141 # to leave it in | |
142 eval {$self->_load_module($type) }; | |
143 if( $@ ){ $self->warn("Cannot find module $type, unable to set type"); } | |
144 else { $self->{'_type'} = $type; } | |
145 } | |
146 return $self->{'_type'} || $DEFAULT_TYPE; | |
147 } | |
148 | |
149 1; |