tag fourth (and hopefully last) alpha
[bioperl-live.git] / branch-1-6 / Bio / Seq / SeqFactory.pm
blobe46740b80170222c6e3c52425301e0248f146b7f
1 # $Id$
3 # BioPerl module for Bio::Seq::SeqFactory
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
7 # Cared for by Jason Stajich <jason@bioperl.org>
9 # Copyright Jason Stajich
11 # You may distribute this module under the same terms as perl itself
13 # POD documentation - main docs before the code
15 =head1 NAME
17 Bio::Seq::SeqFactory - Instantiates a new Bio::PrimarySeqI (or derived class) through a factory
19 =head1 SYNOPSIS
21 use Bio::Seq::SeqFactory;
22 my $factory = Bio::Seq::SeqFactory->new();
23 my $seq = $factory->create(-seq => 'WYRAVLC',
24 -id => 'name');
26 # If you want the factory to create Bio::Seq objects instead
27 # of the default Bio::PrimarySeq objects, use the -type parameter:
29 my $factory = Bio::Seq::SeqFactory->new(-type => 'Bio::Seq');
32 =head1 DESCRIPTION
34 This object will build L<Bio::PrimarySeqI> and L<Bio::SeqI> objects
35 generically.
37 =head1 FEEDBACK
39 =head2 Mailing Lists
41 User feedback is an integral part of the evolution of this and other
42 Bioperl modules. Send your comments and suggestions preferably to
43 the Bioperl mailing list. Your participation is much appreciated.
45 bioperl-l@bioperl.org - General discussion
46 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
48 =head2 Support
50 Please direct usage questions or support issues to the mailing list:
52 I<bioperl-l@bioperl.org>
54 rather than to the module maintainer directly. Many experienced and
55 reponsive experts will be able look at the problem and quickly
56 address it. Please include a thorough description of the problem
57 with code and data examples if at all possible.
59 =head2 Reporting Bugs
61 Report bugs to the Bioperl bug tracking system to help us keep track
62 of the bugs and their resolution. Bug reports can be submitted via the
63 web:
65 http://bugzilla.open-bio.org/
67 =head1 AUTHOR - Jason Stajich
69 Email jason@bioperl.org
71 =head1 APPENDIX
73 The rest of the documentation details each of the object methods.
74 Internal methods are usually preceded with a _
76 =cut
79 # Let the code begin...
82 package Bio::Seq::SeqFactory;
83 use strict;
86 use base qw(Bio::Root::Root Bio::Factory::SequenceFactoryI);
88 =head2 new
90 Title : new
91 Usage : my $obj = Bio::Seq::SeqFactory->new();
92 Function: Builds a new Bio::Seq::SeqFactory object
93 Returns : Bio::Seq::SeqFactory
94 Args : -type => string, name of a PrimarySeqI derived class
95 This is optional. Default=Bio::PrimarySeq.
97 =cut
99 sub new {
100 my($class,@args) = @_;
101 my $self = $class->SUPER::new(@args);
102 my ($type) = $self->_rearrange([qw(TYPE)], @args);
103 if( ! defined $type ) {
104 $type = 'Bio::PrimarySeq';
106 $self->type($type);
107 return $self;
111 =head2 create
113 Title : create
114 Usage : my $seq = $seqbuilder->create(-seq => 'CAGT', -id => 'name');
115 Function: Instantiates new Bio::SeqI (or one of its child classes)
116 This object allows us to genericize the instantiation of sequence
117 objects.
118 Returns : Bio::PrimarySeq object (default)
119 The return type is configurable using new(-type =>"...").
120 Args : initialization parameters specific to the type of sequence
121 object we want. Typically
122 -seq => $str,
123 -display_id => $name
125 =cut
127 sub create {
128 my ($self,@args) = @_;
129 return $self->type->new(-verbose => $self->verbose, @args);
132 =head2 type
134 Title : type
135 Usage : $obj->type($newval)
136 Function:
137 Returns : value of type
138 Args : newvalue (optional)
141 =cut
143 sub type{
144 my ($self,$value) = @_;
145 if( defined $value) {
146 eval "require $value";
147 if( $@ ) { $self->throw("$@: Unrecognized Sequence type for SeqFactory '$value'");}
149 my $a = bless {},$value;
150 unless( $a->isa('Bio::PrimarySeqI') ||
151 $a->isa('Bio::Seq::QualI') ) {
152 $self->throw("Must provide a valid Bio::PrimarySeqI or Bio::Seq::QualI or child class to SeqFactory Not $value");
154 $self->{'type'} = $value;
156 return $self->{'type'};