0
|
1 # $Id: SeqFactory.pm,v 1.8 2002/10/25 22:49:04 lapp Exp $
|
|
2 #
|
|
3 # BioPerl module for Bio::Seq::SeqFactory
|
|
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::Seq::SeqFactory - Instantiates a new Bio::PrimarySeqI (or derived class) through a factory
|
|
16
|
|
17 =head1 SYNOPSIS
|
|
18
|
|
19 use Bio::Seq::SeqFactory;
|
|
20 my $factory = new Bio::Seq::SeqFactory;
|
|
21 my $seq = $factory->create(-seq => 'WYRAVLC',
|
|
22 -id => 'name');
|
|
23
|
|
24 # If you want the factory to create Bio::Seq objects instead
|
|
25 # of the default Bio::PrimarySeq objects, use the -type parameter:
|
|
26
|
|
27 my $factory = new Bio::Seq::SeqFactory(-type => 'Bio::Seq');
|
|
28
|
|
29
|
|
30 =head1 DESCRIPTION
|
|
31
|
|
32 This object will build L<Bio::PrimarySeqI> and L<Bio::SeqI> objects
|
|
33 generically.
|
|
34
|
|
35 =head1 FEEDBACK
|
|
36
|
|
37 =head2 Mailing Lists
|
|
38
|
|
39 User feedback is an integral part of the evolution of this and other
|
|
40 Bioperl modules. Send your comments and suggestions preferably to
|
|
41 the Bioperl mailing list. Your participation is much appreciated.
|
|
42
|
|
43 bioperl-l@bioperl.org - General discussion
|
|
44 http://bioperl.org/MailList.shtml - About the mailing lists
|
|
45
|
|
46 =head2 Reporting Bugs
|
|
47
|
|
48 Report bugs to the Bioperl bug tracking system to help us keep track
|
|
49 of the bugs and their resolution. Bug reports can be submitted via
|
|
50 email or the web:
|
|
51
|
|
52 bioperl-bugs@bioperl.org
|
|
53 http://bugzilla.bioperl.org/
|
|
54
|
|
55 =head1 AUTHOR - Jason Stajich
|
|
56
|
|
57 Email jason@bioperl.org
|
|
58
|
|
59 Describe contact details here
|
|
60
|
|
61 =head1 CONTRIBUTORS
|
|
62
|
|
63 Additional contributors names and emails here
|
|
64
|
|
65 =head1 APPENDIX
|
|
66
|
|
67 The rest of the documentation details each of the object methods.
|
|
68 Internal methods are usually preceded with a _
|
|
69
|
|
70 =cut
|
|
71
|
|
72
|
|
73 # Let the code begin...
|
|
74
|
|
75
|
|
76 package Bio::Seq::SeqFactory;
|
|
77 use vars qw(@ISA);
|
|
78 use strict;
|
|
79
|
|
80 use Bio::Root::Root;
|
|
81 use Bio::Factory::SequenceFactoryI;
|
|
82
|
|
83 @ISA = qw(Bio::Root::Root Bio::Factory::SequenceFactoryI);
|
|
84
|
|
85 =head2 new
|
|
86
|
|
87 Title : new
|
|
88 Usage : my $obj = new Bio::Seq::SeqFactory();
|
|
89 Function: Builds a new Bio::Seq::SeqFactory object
|
|
90 Returns : Bio::Seq::SeqFactory
|
|
91 Args : -type => string, name of a PrimarySeqI derived class
|
|
92 This is optional. Default=Bio::PrimarySeq.
|
|
93
|
|
94 =cut
|
|
95
|
|
96 sub new {
|
|
97 my($class,@args) = @_;
|
|
98 my $self = $class->SUPER::new(@args);
|
|
99 my ($type) = $self->_rearrange([qw(TYPE)], @args);
|
|
100 if( ! defined $type ) {
|
|
101 $type = 'Bio::PrimarySeq';
|
|
102 }
|
|
103 $self->type($type);
|
|
104 return $self;
|
|
105 }
|
|
106
|
|
107
|
|
108 =head2 create
|
|
109
|
|
110 Title : create
|
|
111 Usage : my $seq = $seqbuilder->create(-seq => 'CAGT', -id => 'name');
|
|
112 Function: Instantiates new Bio::SeqI (or one of its child classes)
|
|
113 This object allows us to genericize the instantiation of sequence
|
|
114 objects.
|
|
115 Returns : Bio::PrimarySeq object (default)
|
|
116 The return type is configurable using new(-type =>"...").
|
|
117 Args : initialization parameters specific to the type of sequence
|
|
118 object we want. Typically
|
|
119 -seq => $str,
|
|
120 -display_id => $name
|
|
121
|
|
122 =cut
|
|
123
|
|
124 sub create {
|
|
125 my ($self,@args) = @_;
|
|
126 return $self->type->new(-verbose => $self->verbose, @args);
|
|
127 }
|
|
128
|
|
129 =head2 type
|
|
130
|
|
131 Title : type
|
|
132 Usage : $obj->type($newval)
|
|
133 Function:
|
|
134 Returns : value of type
|
|
135 Args : newvalue (optional)
|
|
136
|
|
137
|
|
138 =cut
|
|
139
|
|
140 sub type{
|
|
141 my ($self,$value) = @_;
|
|
142 if( defined $value) {
|
|
143 eval "require $value";
|
|
144 if( $@ ) { $self->throw("$@: Unrecognized Sequence type for SeqFactory '$value'");}
|
|
145
|
|
146 my $a = bless {},$value;
|
|
147 unless( $a->isa('Bio::PrimarySeqI') ||
|
|
148 $a->isa('Bio::Seq::QualI') ) {
|
|
149 $self->throw("Must provide a valid Bio::PrimarySeqI or Bio::Seq::QualI or child class to SeqFactory Not $value");
|
|
150 }
|
|
151 $self->{'type'} = $value;
|
|
152 }
|
|
153 return $self->{'type'};
|
|
154 }
|
|
155
|
|
156 1;
|