tag fourth (and hopefully last) alpha
[bioperl-live.git] / branch-1-6 / Bio / SeqIO / ztr.pm
blob9772d962bd4e07c19818c2fcefaef0d1ed550506
1 # $Id$
2 # BioPerl module for Bio::SeqIO::ztr
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::ztr - ztr 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 ztr trace
25 files.
27 =head1 FEEDBACK
29 =head2 Mailing Lists
31 User feedback is an integral part of the evolution of this and other
32 Bioperl modules. Send your comments and suggestions preferably to one
33 of the Bioperl mailing lists. Your participation is much appreciated.
35 bioperl-l@bioperl.org - General discussion
36 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
38 =head2 Support
40 Please direct usage questions or support issues to the mailing list:
42 I<bioperl-l@bioperl.org>
44 rather than to the module maintainer directly. Many experienced and
45 reponsive experts will be able look at the problem and quickly
46 address it. Please include a thorough description of the problem
47 with code and data examples if at all possible.
49 =head2 Reporting Bugs
51 Report bugs to the Bioperl bug tracking system to help us keep track
52 the bugs and their resolution.
53 Bug reports can be submitted via the web:
55 http://bugzilla.open-bio.org/
57 =head1 AUTHORS - Aaron Mackey
59 Email: amackey@virginia.edu
61 =head1 APPENDIX
63 The rest of the documentation details each of the object
64 methods. Internal methods are usually preceded with a _
66 =cut
68 # Let the code begin...
70 package Bio::SeqIO::ztr;
71 use vars qw(@ISA $READ_AVAIL);
72 use strict;
74 use Bio::SeqIO;
75 use Bio::Seq::SeqFactory;
77 push @ISA, qw( Bio::SeqIO );
79 sub BEGIN {
80 eval { require Bio::SeqIO::staden::read; };
81 if ($@) {
82 $READ_AVAIL = 0;
83 } else {
84 push @ISA, "Bio::SeqIO::staden::read";
85 $READ_AVAIL = 1;
89 sub _initialize {
90 my($self,@args) = @_;
91 $self->SUPER::_initialize(@args);
92 if( ! defined $self->sequence_factory ) {
93 $self->sequence_factory(Bio::Seq::SeqFactory->new(-verbose => $self->verbose(), -type => 'Bio::Seq::Quality'));
96 my ($compression) = $self->_rearrange([qw[COMPRESSION]], @args);
97 $compression = 2 unless defined $compression;
98 $self->compression($compression);
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, 'ztr');
123 # create the seq object
124 $seq = $self->sequence_factory->create(-seq => $seq,
125 -id => $id,
126 -primary_id => $id,
127 -desc => $desc,
128 -alphabet => 'DNA',
129 -qual => $qual
131 return $seq;
134 =head2 write_seq
136 Title : write_seq
137 Usage : $stream->write_seq(@seq)
138 Function: writes the $seq object into the stream
139 Returns : 1 for success and 0 for error
140 Args : Bio::Seq object
143 =cut
145 sub write_seq {
146 my ($self,@seq) = @_;
148 my $fh = $self->_fh;
149 foreach my $seq (@seq) {
150 $self->write_trace($fh, $seq, 'ztr' . $self->compression);
153 $self->flush if $self->_flush_on_write && defined $self->_fh;
154 return 1;
157 =head2 compression
159 Title : compression
160 Usage : $stream->compression(3);
161 Function: determines the level of ZTR compression
162 Returns : the current (or newly set) value.
163 Args : 1, 2 or 3 - any other (defined) value will cause the compression
164 to be reset to the default of 2.
167 =cut
169 sub compression {
171 my ($self, $val) = @_;
173 if (defined $val) {
174 if ($val =~ m/^1|2|3$/o) {
175 $self->{_compression} = $val;
176 } else {
177 $self->{_compression} = 2;
181 return $self->{_compression};