File Coverage

Bio/Seq/SeqFastaSpeedFactory.pm
Criterion Covered Total %
statement 34 35 97.1
branch 4 6 66.6
condition 3 6 50.0
subroutine 6 6 100.0
pod 2 2 100.0
total 49 55 89.0


line stmt bran cond sub pod time code
1             #
2             # BioPerl module for Bio::Seq::SeqFastaSpeedFactory
3             #
4             # Please direct questions and support issues to
5             #
6             # Cared for by Jason Stajich
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::SeqFastaSpeedFactory - Rapid creation of Bio::Seq objects through a factory
17              
18             =head1 SYNOPSIS
19              
20             use Bio::Seq::SeqFastaSpeedFactory;
21             my $factory = Bio::Seq::SeqFastaSpeedFactory->new();
22             my $seq = $factory->create( -seq => 'WYRAVLC',
23             -id => 'name' );
24              
25             =head1 DESCRIPTION
26              
27             This factory was designed to build Bio::Seq objects as quickly as possible, but
28             is not as generic as L. It can be used to create sequences
29             from non-rich file formats. The L sequence parser uses this
30             factory.
31              
32             =head1 FEEDBACK
33              
34             =head2 Mailing Lists
35              
36             User feedback is an integral part of the evolution of this and other
37             Bioperl modules. Send your comments and suggestions preferably to
38             the Bioperl mailing list. Your participation is much appreciated.
39              
40             bioperl-l@bioperl.org - General discussion
41             http://bioperl.org/wiki/Mailing_lists - About the mailing lists
42              
43             =head2 Support
44              
45             Please direct usage questions or support issues to the mailing list:
46              
47             I
48              
49             rather than to the module maintainer directly. Many experienced and
50             reponsive experts will be able look at the problem and quickly
51             address it. Please include a thorough description of the problem
52             with code and data examples if at all possible.
53              
54             =head2 Reporting Bugs
55              
56             Report bugs to the Bioperl bug tracking system to help us keep track
57             of the bugs and their resolution. Bug reports can be submitted via the
58             web:
59              
60             https://github.com/bioperl/bioperl-live/issues
61              
62             =head1 AUTHOR - Jason Stajich
63              
64             Email jason@bioperl.org
65              
66             =head1 APPENDIX
67              
68             The rest of the documentation details each of the object methods.
69             Internal methods are usually preceded with a _
70              
71             =cut
72              
73              
74             # Let the code begin...
75              
76              
77             package Bio::Seq::SeqFastaSpeedFactory;
78 26     26   175 use strict;
  26         48  
  26         693  
79              
80 26     26   3313 use Bio::Seq;
  26         55  
  26         878  
81 26     26   141 use Bio::PrimarySeq;
  26         44  
  26         606  
82              
83 26     26   108 use base qw(Bio::Root::Root Bio::Factory::SequenceFactoryI);
  26         36  
  26         7866  
84              
85              
86             =head2 new
87              
88             Title : new
89             Usage : my $obj = Bio::Seq::SeqFastaSpeedFactory->new();
90             Function: Builds a new Bio::Seq::SeqFastaSpeedFactory object
91             Returns : Bio::Seq::SeqFastaSpeedFactory
92             Args : None
93              
94             =cut
95              
96             sub new {
97 43     43 1 92 my($class,@args) = @_;
98 43         188 my $self = $class->SUPER::new(@args);
99 43         118 return $self;
100             }
101              
102              
103             =head2 create
104              
105             Title : create
106             Usage : my $seq = $seqbuilder->create(-seq => 'CAGT', -id => 'name');
107             Function: Instantiates a new Bio::Seq object, correctly built but very
108             fast, knowing stuff about Bio::PrimarySeq and Bio::Seq
109             Returns : A Bio::Seq object
110             Args : Initialization parameters for the sequence object we want:
111             -id
112             -primary_id
113             -display_id
114             -desc
115             -seq
116             -alphabet
117              
118             =cut
119              
120             sub create {
121 78     78 1 654 my ($self,@args) = @_;
122            
123 78         273 my %param = @args;
124 78         282 @param{ map { lc $_ } keys %param } = values %param; # lowercase keys
  390         692  
125            
126 78         169 my $sequence = $param{'-seq'};
127 78         121 my $fulldesc = $param{'-desc'};
128 78 50       289 my $id = defined $param{'-id'} ? $param{'-id'} : $param{'-primary_id'};
129 78         259 my $alphabet = $param{'-alphabet'};
130              
131 78         242 my $seq = bless {}, 'Bio::Seq';
132 78         568 my $t_pseq = $seq->{'primary_seq'} = bless {}, 'Bio::PrimarySeq';
133 78         186 $t_pseq->{'seq'} = $sequence;
134 78         186 $t_pseq->{'length'} = CORE::length($sequence);
135 78         128 $t_pseq->{'desc'} = $fulldesc;
136 78         154 $t_pseq->{'display_id'} = $id;
137 78         107 $t_pseq->{'primary_id'} = $id;
138 78         104 $seq->{'primary_id'} = $id; # currently Bio::Seq does not delegate this
139 78 100 66     284 if( $sequence and !$alphabet ) {
    50 33        
140 75         214 $t_pseq->_guess_alphabet();
141             } elsif ( $sequence and $alphabet ) {
142 0         0 $t_pseq->{'alphabet'} = $alphabet;
143             }
144              
145 78         271 return $seq;
146             }
147              
148             1;
149