Bio::Tools::CodonTable::is_start_codon: check in case of ambiguous codons (#266)
[bioperl-live.git] / lib / Bio / Seq / SeqFastaSpeedFactory.pm
blob3aa718c2336d9a9a2747c50daa346d37022739b3
2 # BioPerl module for Bio::Seq::SeqFastaSpeedFactory
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Jason Stajich <jason@bioperl.org>
8 # Copyright Jason Stajich
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
14 =head1 NAME
16 Bio::Seq::SeqFastaSpeedFactory - Rapid creation of Bio::Seq objects through a factory
18 =head1 SYNOPSIS
20 use Bio::Seq::SeqFastaSpeedFactory;
21 my $factory = Bio::Seq::SeqFastaSpeedFactory->new();
22 my $seq = $factory->create( -seq => 'WYRAVLC',
23 -id => 'name' );
25 =head1 DESCRIPTION
27 This factory was designed to build Bio::Seq objects as quickly as possible, but
28 is not as generic as L<Bio::Seq::SeqFactory>. It can be used to create sequences
29 from non-rich file formats. The L<Bio::SeqIO::fasta> sequence parser uses this
30 factory.
32 =head1 FEEDBACK
34 =head2 Mailing Lists
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.
40 bioperl-l@bioperl.org - General discussion
41 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
43 =head2 Support
45 Please direct usage questions or support issues to the mailing list:
47 I<bioperl-l@bioperl.org>
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.
54 =head2 Reporting Bugs
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:
60 https://github.com/bioperl/bioperl-live/issues
62 =head1 AUTHOR - Jason Stajich
64 Email jason@bioperl.org
66 =head1 APPENDIX
68 The rest of the documentation details each of the object methods.
69 Internal methods are usually preceded with a _
71 =cut
74 # Let the code begin...
77 package Bio::Seq::SeqFastaSpeedFactory;
79 use strict;
81 use Bio::Seq;
82 use Bio::PrimarySeq;
84 use base qw(Bio::Root::Root Bio::Factory::SequenceFactoryI);
87 =head2 new
89 Title : new
90 Usage : my $obj = Bio::Seq::SeqFastaSpeedFactory->new();
91 Function: Builds a new Bio::Seq::SeqFastaSpeedFactory object
92 Returns : Bio::Seq::SeqFastaSpeedFactory
93 Args : None
95 =cut
97 sub new {
98 my($class,@args) = @_;
99 my $self = $class->SUPER::new(@args);
100 return $self;
104 =head2 create
106 Title : create
107 Usage : my $seq = $seqbuilder->create(-seq => 'CAGT', -id => 'name');
108 Function: Instantiates a new Bio::Seq object, correctly built but very
109 fast, knowing stuff about Bio::PrimarySeq and Bio::Seq
110 Returns : A Bio::Seq object
111 Args : Initialization parameters for the sequence object we want:
113 -primary_id
114 -display_id
115 -desc
116 -seq
117 -alphabet
119 =cut
121 sub create {
122 my ($self,@args) = @_;
124 my %param = @args;
125 @param{ map { lc $_ } keys %param } = values %param; # lowercase keys
127 my $sequence = $param{'-seq'};
128 my $fulldesc = $param{'-desc'};
129 my $id = defined $param{'-id'} ? $param{'-id'} : $param{'-primary_id'};
130 my $alphabet = $param{'-alphabet'};
132 my $seq = bless {}, 'Bio::Seq';
133 my $t_pseq = $seq->{'primary_seq'} = bless {}, 'Bio::PrimarySeq';
134 $t_pseq->{'seq'} = $sequence;
135 $t_pseq->{'length'} = CORE::length($sequence);
136 $t_pseq->{'desc'} = $fulldesc;
137 $t_pseq->{'display_id'} = $id;
138 $t_pseq->{'primary_id'} = $id;
139 $seq->{'primary_id'} = $id; # currently Bio::Seq does not delegate this
140 if( $sequence and !$alphabet ) {
141 $t_pseq->_guess_alphabet();
142 } elsif ( $sequence and $alphabet ) {
143 $t_pseq->{'alphabet'} = $alphabet;
146 return $seq;