| 1 | # BioPerl module for FAST::Bio::SeqIO::ztr | ||
| 2 | # | ||
| 3 | # Please direct questions and support issues to <bioperl-l@bioperl.org> | ||
| 4 | # | ||
| 5 | # Cared for by Aaron Mackey <amackey@virginia.edu> | ||
| 6 | # | ||
| 7 | # Copyright Aaron Mackey | ||
| 8 | # | ||
| 9 | # You may distribute this module under the same terms as perl itself | ||
| 10 | |||
| 11 | # POD documentation - main docs before the code | ||
| 12 | |||
| 13 | =head1 NAME | ||
| 14 | |||
| 15 | FAST::Bio::SeqIO::ztr - ztr trace sequence input/output stream | ||
| 16 | |||
| 17 | =head1 SYNOPSIS | ||
| 18 | |||
| 19 | Do not use this module directly. Use it via the FAST::Bio::SeqIO class. | ||
| 20 | |||
| 21 | =head1 DESCRIPTION | ||
| 22 | |||
| 23 | This object can transform FAST::Bio::Seq objects to and from ztr trace | ||
| 24 | files. | ||
| 25 | |||
| 26 | =head1 FEEDBACK | ||
| 27 | |||
| 28 | =head2 Mailing Lists | ||
| 29 | |||
| 30 | User feedback is an integral part of the evolution of this and other | ||
| 31 | Bioperl modules. Send your comments and suggestions preferably to one | ||
| 32 | of the Bioperl mailing lists. Your participation is much appreciated. | ||
| 33 | |||
| 34 | bioperl-l@bioperl.org - General discussion | ||
| 35 | http://bioperl.org/wiki/Mailing_lists - About the mailing lists | ||
| 36 | |||
| 37 | =head2 Support | ||
| 38 | |||
| 39 | Please direct usage questions or support issues to the mailing list: | ||
| 40 | |||
| 41 | I<bioperl-l@bioperl.org> | ||
| 42 | |||
| 43 | rather than to the module maintainer directly. Many experienced and | ||
| 44 | reponsive experts will be able look at the problem and quickly | ||
| 45 | address it. Please include a thorough description of the problem | ||
| 46 | with code and data examples if at all possible. | ||
| 47 | |||
| 48 | =head2 Reporting Bugs | ||
| 49 | |||
| 50 | Report bugs to the Bioperl bug tracking system to help us keep track | ||
| 51 | the bugs and their resolution. | ||
| 52 | Bug reports can be submitted via the web: | ||
| 53 | |||
| 54 | https://redmine.open-bio.org/projects/bioperl/ | ||
| 55 | |||
| 56 | =head1 AUTHORS - Aaron Mackey | ||
| 57 | |||
| 58 | Email: amackey@virginia.edu | ||
| 59 | |||
| 60 | =head1 APPENDIX | ||
| 61 | |||
| 62 | The rest of the documentation details each of the object | ||
| 63 | methods. Internal methods are usually preceded with a _ | ||
| 64 | |||
| 65 | =cut | ||
| 66 | |||
| 67 | # Let the code begin... | ||
| 68 | |||
| 69 | package FAST::Bio::SeqIO::ztr; | ||
| 70 | use vars qw(@ISA $READ_AVAIL); | ||
| 71 | use strict; | ||
| 72 | |||
| 73 | use FAST::Bio::SeqIO; | ||
| 74 | use FAST::Bio::Seq::SeqFactory; | ||
| 75 | |||
| 76 | push @ISA, qw( FAST::Bio::SeqIO ); | ||
| 77 | |||
| 78 | sub BEGIN { | ||
| 79 | eval { require FAST::Bio::SeqIO::staden::read; }; | ||
| 80 | if ($@) { | ||
| 81 | $READ_AVAIL = 0; | ||
| 82 | } else { | ||
| 83 | push @ISA, "FAST::Bio::SeqIO::staden::read"; | ||
| 84 | $READ_AVAIL = 1; | ||
| 85 | } | ||
| 86 | } | ||
| 87 | |||
| 88 | sub _initialize { | ||
| 89 | my($self,@args) = @_; | ||
| 90 | $self->SUPER::_initialize(@args); | ||
| 91 | if( ! defined $self->sequence_factory ) { | ||
| 92 | $self->sequence_factory(FAST::Bio::Seq::SeqFactory->new(-verbose => $self->verbose(), -type => 'FAST::Bio::Seq::Quality')); | ||
| 93 | } | ||
| 94 | |||
| 95 | my ($compression) = $self->_rearrange([qw[COMPRESSION]], @args); | ||
| 96 | $compression = 2 unless defined $compression; | ||
| 97 | $self->compression($compression); | ||
| 98 | |||
| 99 | unless ($READ_AVAIL) { | ||
| 100 | FAST::Bio::Root::Root->throw( -class => 'FAST::Bio::Root::SystemException', | ||
| 101 | -text => "FAST::Bio::SeqIO::staden::read is not available; make sure the bioperl-ext package has been installed successfully!" | ||
| 102 | ); | ||
| 103 | } | ||
| 104 | } | ||
| 105 | |||
| 106 | =head2 next_seq | ||
| 107 | |||
| 108 | Title : next_seq | ||
| 109 | Usage : $seq = $stream->next_seq() | ||
| 110 | Function: returns the next sequence in the stream | ||
| 111 | Returns : FAST::Bio::Seq::Quality object | ||
| 112 | Args : NONE | ||
| 113 | |||
| 114 | =cut | ||
| 115 | |||
| 116 | sub next_seq { | ||
| 117 | |||
| 118 | my ($self) = @_; | ||
| 119 | |||
| 120 | my ($seq, $id, $desc, $qual) = $self->read_trace($self->_fh, 'ztr'); | ||
| 121 | |||
| 122 | # create the seq object | ||
| 123 | $seq = $self->sequence_factory->create(-seq => $seq, | ||
| 124 | -id => $id, | ||
| 125 | -primary_id => $id, | ||
| 126 | -desc => $desc, | ||
| 127 | -alphabet => 'DNA', | ||
| 128 | -qual => $qual | ||
| 129 | ); | ||
| 130 | return $seq; | ||
| 131 | } | ||
| 132 | |||
| 133 | =head2 write_seq | ||
| 134 | |||
| 135 | Title : write_seq | ||
| 136 | Usage : $stream->write_seq(@seq) | ||
| 137 | Function: writes the $seq object into the stream | ||
| 138 | Returns : 1 for success and 0 for error | ||
| 139 | Args : FAST::Bio::Seq object | ||
| 140 | |||
| 141 | |||
| 142 | =cut | ||
| 143 | |||
| 144 | sub write_seq { | ||
| 145 | my ($self,@seq) = @_; | ||
| 146 | |||
| 147 | my $fh = $self->_fh; | ||
| 148 | foreach my $seq (@seq) { | ||
| 149 | $self->write_trace($fh, $seq, 'ztr' . $self->compression); | ||
| 150 | } | ||
| 151 | |||
| 152 | $self->flush if $self->_flush_on_write && defined $self->_fh; | ||
| 153 | return 1; | ||
| 154 | } | ||
| 155 | |||
| 156 | =head2 compression | ||
| 157 | |||
| 158 | Title : compression | ||
| 159 | Usage : $stream->compression(3); | ||
| 160 | Function: determines the level of ZTR compression | ||
| 161 | Returns : the current (or newly set) value. | ||
| 162 | Args : 1, 2 or 3 - any other (defined) value will cause the compression | ||
| 163 | to be reset to the default of 2. | ||
| 164 | |||
| 165 | |||
| 166 | =cut | ||
| 167 | |||
| 168 | sub compression { | ||
| 169 | |||
| 170 | my ($self, $val) = @_; | ||
| 171 | |||
| 172 | if (defined $val) { | ||
| 173 | if ($val =~ m/^1|2|3$/o) { | ||
| 174 | $self->{_compression} = $val; | ||
| 175 | } else { | ||
| 176 | $self->{_compression} = 2; | ||
| 177 | } | ||
| 178 | } | ||
| 179 | |||
| 180 | return $self->{_compression}; | ||
| 181 | } | ||
| 182 | |||
| 183 | 1; |