Bio/Seq/SeqFactory.pm

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