FAST/Bio/Seq/SeqFactory.pm untested

filter: Statementstmt 0.0% 0 / 27 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 48 CC 5 SCAR 23.9
CC
5
Cov
0%
type
20.0
new
6.0
create
2.0
CRAP 10.9
1 #
2 # BioPerl module for FAST::Bio::Seq::SeqFactory
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Jason Stajich <jason@bioperl.org>
7 #
8 # Copyright Jason Stajich
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 FAST::Bio::Seq::SeqFactory - Instantiates a new FAST::Bio::PrimarySeqI (or derived class) through a factory
17  
18 =head1 SYNOPSIS
19  
20 use FAST::Bio::Seq::SeqFactory;
21 my $factory = FAST::Bio::Seq::SeqFactory->new();
22 my $seq = $factory->create(-seq => 'WYRAVLC',
23 -id => 'name');
24  
25 # If you want the factory to create FAST::Bio::Seq objects instead
26 # of the default FAST::Bio::PrimarySeq objects, use the -type parameter:
27  
28 my $factory = FAST::Bio::Seq::SeqFactory->new(-type => 'FAST::Bio::Seq');
29  
30  
31 =head1 DESCRIPTION
32  
33 This object will build L<FAST::Bio::PrimarySeqI> and L<FAST::Bio::SeqI> objects
34 generically.
35  
36 =head1 FEEDBACK
37  
38 =head2 Mailing Lists
39  
40 User feedback is an integral part of the evolution of this and other
41 Bioperl modules. Send your comments and suggestions preferably to
42 the Bioperl mailing list. Your participation is much appreciated.
43  
44 bioperl-l@bioperl.org - General discussion
45 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
46  
47 =head2 Support
48  
49 Please direct usage questions or support issues to the mailing list:
50  
51 I<bioperl-l@bioperl.org>
52  
53 rather than to the module maintainer directly. Many experienced and
54 reponsive experts will be able look at the problem and quickly
55 address it. Please include a thorough description of the problem
56 with code and data examples if at all possible.
57  
58 =head2 Reporting Bugs
59  
60 Report bugs to the Bioperl bug tracking system to help us keep track
61 of the bugs and their resolution. Bug reports can be submitted via the
62 web:
63  
64 https://redmine.open-bio.org/projects/bioperl/
65  
66 =head1 AUTHOR - Jason Stajich
67  
68 Email jason@bioperl.org
69  
70 =head1 APPENDIX
71  
72 The rest of the documentation details each of the object methods.
73 Internal methods are usually preceded with a _
74  
75 =cut
76  
77  
78 # Let the code begin...
79  
80  
81 package FAST::Bio::Seq::SeqFactory;
82 use strict;
83  
84  
85 use base qw(FAST::Bio::Root::Root FAST::Bio::Factory::SequenceFactoryI);
86  
87 =head2 new
88  
89 Title : new
90 Usage : my $obj = FAST::Bio::Seq::SeqFactory->new();
91 Function: Builds a new FAST::Bio::Seq::SeqFactory object
92 Returns : FAST::Bio::Seq::SeqFactory
93 Args : -type => string, name of a PrimarySeqI derived class
94 This is optional. Default=FAST::Bio::PrimarySeq.
95  
96 =cut
97  
98 sub new {
99 my($class,@args) = @_;
100 my $self = $class->SUPER::new(@args);
101 my ($type) = $self->_rearrange([qw(TYPE)], @args);
102 if( ! defined $type ) {
103 $type = 'FAST::Bio::PrimarySeq';
104 }
105 $self->type($type);
106 return $self;
107 }
108  
109  
110 =head2 create
111  
112 Title : create
113 Usage : my $seq = $seqbuilder->create(-seq => 'CAGT', -id => 'name');
114 Function: Instantiates new FAST::Bio::SeqI (or one of its child classes)
115 This object allows us to genericize the instantiation of sequence
116 objects.
117 Returns : FAST::Bio::PrimarySeq object (default)
118 The return type is configurable using new(-type =>"...").
119 Args : initialization parameters specific to the type of sequence
120 object we want. Typically
121 -seq => $str,
122 -display_id => $name
123  
124 =cut
125  
126 sub create {
127 my ($self,@args) = @_;
128 return $self->type->new(-verbose => $self->verbose, @args);
129 }
130  
131 =head2 type
132  
133 Title : type
134 Usage : $obj->type($newval)
135 Function:
136 Returns : value of type
137 Args : newvalue (optional)
138  
139  
140 =cut
141  
142 sub type{
143 my ($self,$value) = @_;
144 if( defined $value) {
145 eval "require $value";
146 if( $@ ) { $self->throw("$@: Unrecognized Sequence type for SeqFactory '$value'");}
147
148 my $a = bless {},$value;
149 unless( $a->isa('FAST::Bio::PrimarySeqI') ||
150 $a->isa('FAST::Bio::Seq::QualI') ) {
151 $self->throw("Must provide a valid FAST::Bio::PrimarySeqI or FAST::Bio::Seq::QualI or child class to SeqFactory Not $value");
152 }
153 $self->{'type'} = $value;
154 }
155 return $self->{'type'};
156 }
157  
158 1;