sync w/ main trunk
[bioperl-live.git] / Bio / SeqIO / abi.pm
blobd6bc2daa3b2f2e5853951522baae21ee57058ea7
1 # $Id$
2 # BioPerl module for Bio::SeqIO::abi
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Aaron Mackey <amackey@virginia.edu>
8 # Copyright Aaron Mackey
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::SeqIO::abi - abi trace sequence input/output stream
18 =head1 SYNOPSIS
20 Do not use this module directly. Use it via the Bio::SeqIO class.
22 =head1 DESCRIPTION
24 This object can transform Bio::Seq objects to and from abi trace
25 files. To optionally read the trace graph data (which can be used
26 to draw chromatographs, for instance), set the optional
27 '-read_graph_data' flag or the read_graph_data method to a value
28 evaluating to TRUE.
30 =head1 FEEDBACK
32 =head2 Mailing Lists
34 User feedback is an integral part of the evolution of this and other
35 Bioperl modules. Send your comments and suggestions preferably to one
36 of the Bioperl mailing lists. Your participation is much appreciated.
38 bioperl-l@bioperl.org - General discussion
39 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
41 =head2 Support
43 Please direct usage questions or support issues to the mailing list:
45 L<bioperl-l@bioperl.org>
47 rather than to the module maintainer directly. Many experienced and
48 reponsive experts will be able look at the problem and quickly
49 address it. Please include a thorough description of the problem
50 with code and data examples if at all possible.
52 =head2 Reporting Bugs
54 Report bugs to the Bioperl bug tracking system to help us keep track
55 the bugs and their resolution.
56 Bug reports can be submitted via the web:
58 http://bugzilla.open-bio.org/
60 =head1 AUTHORS - Aaron Mackey
62 Email: amackey@virginia.edu
64 =head1 APPENDIX
66 The rest of the documentation details each of the object
67 methods. Internal methods are usually preceded with a _
69 =cut
71 # Let the code begin...
73 package Bio::SeqIO::abi;
74 use vars qw(@ISA $READ_AVAIL);
75 use strict;
77 use Bio::SeqIO;
78 use Bio::Seq::SeqFactory;
80 push @ISA, qw( Bio::SeqIO );
82 sub BEGIN {
83 eval { require Bio::SeqIO::staden::read; };
84 if ($@) {
85 $READ_AVAIL = 0;
86 } else {
87 push @ISA, "Bio::SeqIO::staden::read";
88 $READ_AVAIL = 1;
92 sub _initialize {
93 my($self,@args) = @_;
94 $self->SUPER::_initialize(@args);
95 my ($get_trace) = $self->_rearrange([qw(get_trace_data)],@args);
96 $get_trace && $self->get_trace_data(1);
97 if( ! defined $self->sequence_factory ) {
98 $self->sequence_factory(Bio::Seq::SeqFactory->new(-verbose => $self->verbose(), -type => 'Bio::Seq::Quality'));
100 unless ($READ_AVAIL) {
101 Bio::Root::Root->throw( -class => 'Bio::Root::SystemException',
102 -text => "Bio::SeqIO::staden::read is not available; make sure the bioperl-ext package has been installed successfully!"
107 =head2 next_seq
109 Title : next_seq
110 Usage : $seq = $stream->next_seq()
111 Function: returns the next sequence in the stream
112 Returns : Bio::Seq::Quality object
113 Args : NONE
115 =cut
117 sub next_seq {
119 my ($self) = @_;
121 my ($seq, $id, $desc, $qual) = $self->read_trace($self->_fh, 'abi');
123 # create the seq object
124 my ($base_locs, $a_trace, $c_trace, $g_trace, $t_trace, $points, $max_height);
125 if ($self->get_trace_data) {
126 ($base_locs, $a_trace, $c_trace, $g_trace, $t_trace, $points, $max_height) = $self->read_trace_with_graph($self->_fh, 'abi');
127 } else {
128 $base_locs = [];
131 # create the seq object
132 $seq = $self->sequence_factory->create(-seq => $seq,
133 -id => $id,
134 -primary_id => $id,
135 -desc => $desc,
136 -alphabet => 'DNA',
137 -qual => $qual,
138 -trace => join (" ", @{$base_locs}),
139 -trace_data => { a_trace => $a_trace,
140 c_trace => $c_trace,
141 g_trace => $g_trace,
142 t_trace => $t_trace,
143 max_height => $max_height,
144 num_points => $points }
146 return $seq;
149 =head2 write_seq
151 Title : write_seq
152 Usage : $stream->write_seq(@seq)
153 Function: writes the $seq object into the stream
154 Returns : 1 for success and 0 for error
155 Args : Bio::Seq object
158 =cut
160 sub write_seq {
161 my ($self,@seq) = @_;
163 my $fh = $self->_fh;
164 foreach my $seq (@seq) {
165 $self->write_trace($fh, $seq, 'abi');
168 $self->flush if $self->_flush_on_write && defined $self->_fh;
169 return 1;
172 =head2 get_trace_data
174 Title : get_trace_data
175 Usage : $stream->get_trace_data(1)
176 Function: set boolean flag to retrieve the trace data (possibly for
177 output)
178 Returns : bool value, TRUE = retrieve trace data (default FALSE)
179 Args : bool value
181 =cut
183 sub get_trace_data {
184 my ($self, $val) = @_;
185 $self->{_get_trace_data} = $val ? 1 : 0;
186 $self->{_get_trace_data};