| 1 | #! /usr/bin/perl | ||
| 2 | |||
| 3 | package Bio::SeqReader::FastqRecord; | ||
| 4 | |||
| 5 | sub header1; | ||
| 6 | sub header2; | ||
| 7 | sub new; | ||
| 8 | sub quals; | ||
| 9 | sub reset; | ||
| 10 | sub seq; | ||
| 11 | |||
| 12 | =head1 NAME | ||
| 13 | |||
| 14 | Bio::SeqReader::FastqRecord - Class providing methods for representing header, | ||
| 15 | sequence, and quality information in FASTQ records. | ||
| 16 | |||
| 17 | =head1 SYNOPSIS | ||
| 18 | |||
| 19 | use Bio::SeqReader::FastqRecord; | ||
| 20 | |||
| 21 | =head1 EXAMPLES | ||
| 22 | |||
| 23 | my $so = new Bio::SeqReader::FastqRecord(); | ||
| 24 | $so->seq( 'ACGTACGT' ); | ||
| 25 | print $so->seq(); # ACGTACGT | ||
| 26 | |||
| 27 | =head1 DESCRIPTION | ||
| 28 | |||
| 29 | Class representing a sequence in FASTQ format. Headers 1 and 2, sequence text, and quality text | ||
| 30 | are accessed by the object's getter-setter methods. | ||
| 31 | |||
| 32 | =head1 CLASS METHODS | ||
| 33 | |||
| 34 | Bio::SeqReader::FastqRecord provides no class methods. | ||
| 35 | |||
| 36 | =head1 INSTANCE METHODS | ||
| 37 | |||
| 38 | Bio::SeqReader::FastqRecord provides the following instance methods. | ||
| 39 | |||
| 40 | =cut | ||
| 41 | |||
| 42 | use strict; | ||
| 43 | |||
| 44 | =over 12 | ||
| 45 | |||
| 46 | =item B<new()> | ||
| 47 | |||
| 48 | Returns a new Bio::SeqReader::FastqRecord object. | ||
| 49 | |||
| 50 | # Void constructor | ||
| 51 | my $so = new Bio::SeqReader::FastqRecord(); | ||
| 52 | |||
| 53 | # Constructor with initial values | ||
| 54 | my $so = new Bio::SeqReader::FastqRecord( | ||
| 55 | header1 => 'R_12345 read info ...', | ||
| 56 | seqtext => 'ACGTACGT', | ||
| 57 | header2 => '', | ||
| 58 | qualtext => 'A@AA?#??' | ||
| 59 | ); | ||
| 60 | |||
| 61 | =back | ||
| 62 | |||
| 63 | =cut | ||
| 64 | |||
| 65 | sub new { | ||
| 66 | my ( $class, %parms ) = @_; | ||
| 67 | |||
| 68 | my $self = {}; | ||
| 69 | bless( $self, $class ); | ||
| 70 | |||
| 71 | $self->reset(); | ||
| 72 | $self->seq( $parms{ seqtext } ) if exists $parms{ seqtext }; | ||
| 73 | $self->quals( $parms{ qualtext } ) if exists $parms{ qualtext }; | ||
| 74 | $self->header1( $parms{ header1 } ) if exists $parms{ header1 }; | ||
| 75 | $self->header2( $parms{ header2 } ) if exists $parms{ header2 }; | ||
| 76 | |||
| 77 | return $self; | ||
| 78 | } | ||
| 79 | |||
| 80 | =over 12 | ||
| 81 | |||
| 82 | =item B<display_id()> | ||
| 83 | |||
| 84 | Getter for the display id associated with a Bio::SeqReader::FastqRecord object. | ||
| 85 | Makes use of the current contents of header 1. | ||
| 86 | |||
| 87 | print $so->display_id(); # => R_12345 | ||
| 88 | |||
| 89 | =back | ||
| 90 | |||
| 91 | =cut | ||
| 92 | |||
| 93 | sub display_id { | ||
| 94 | my $self = shift; | ||
| 95 | |||
| 96 | my $display_id = $self->{ _HEADER1 }; | ||
| 97 | $display_id =~ s/\s+.*//; | ||
| 98 | |||
| 99 | return $display_id; | ||
| 100 | |||
| 101 | } | ||
| 102 | |||
| 103 | =over 12 | ||
| 104 | |||
| 105 | =item B<header1()> | ||
| 106 | |||
| 107 | Getter-setter for the first header text from a Bio::SeqReader::FastqRecord object. | ||
| 108 | |||
| 109 | $so->header1( 'R_12345 read info ...' ); | ||
| 110 | print $so->header1(); # => R_12345 read info | ||
| 111 | |||
| 112 | =back | ||
| 113 | |||
| 114 | =cut | ||
| 115 | |||
| 116 | sub header1 { | ||
| 117 | my $self = shift; | ||
| 118 | |||
| 119 | if ( @_ ) { | ||
| 120 | $self->{ _HEADER1 } = shift; | ||
| 121 | $self->{ _HEADER1 } =~ s/^\s+//g; | ||
| 122 | $self->{ _HEADER1 } =~ s/\s+$//g; | ||
| 123 | } | ||
| 124 | |||
| 125 | return $self->{ _HEADER1 }; | ||
| 126 | } | ||
| 127 | |||
| 128 | =over 12 | ||
| 129 | |||
| 130 | =item B<header2()> | ||
| 131 | |||
| 132 | Getter-setter for the second header text from a Bio::SeqReader::FastqRecord object. | ||
| 133 | |||
| 134 | $so->header2( 'second header info ...' ); | ||
| 135 | print $so->header2(); # => second header info ... | ||
| 136 | |||
| 137 | =back | ||
| 138 | |||
| 139 | =cut | ||
| 140 | |||
| 141 | sub header2 { | ||
| 142 | my $self = shift; | ||
| 143 | |||
| 144 | if ( @_ ) { | ||
| 145 | $self->{ _HEADER2 } = shift; | ||
| 146 | $self->{ _HEADER2 } =~ s/^\s+//g; | ||
| 147 | $self->{ _HEADER2 } =~ s/\s+$//g; | ||
| 148 | } | ||
| 149 | |||
| 150 | return $self->{ _HEADER2 }; | ||
| 151 | } | ||
| 152 | |||
| 153 | =over 12 | ||
| 154 | |||
| 155 | =item B<quals()> | ||
| 156 | |||
| 157 | Getter-setter for the quality text from a Bio::SeqReader::FastqRecord object. | ||
| 158 | |||
| 159 | $so->quals( 'A@AA?#??' ); | ||
| 160 | print $so->quals(); # => A@AA?#?? | ||
| 161 | |||
| 162 | =back | ||
| 163 | |||
| 164 | =cut | ||
| 165 | |||
| 166 | sub quals { | ||
| 167 | my $self = shift; | ||
| 168 | |||
| 169 | if ( @_ ) { | ||
| 170 | $self->{ _QUALTEXT } = shift; | ||
| 171 | $self->{ _QUALTEXT } =~ s/[\000-\037\s]+//g; | ||
| 172 | } | ||
| 173 | |||
| 174 | return $self->{ _QUALTEXT }; | ||
| 175 | } | ||
| 176 | |||
| 177 | =over 12 | ||
| 178 | |||
| 179 | =item B<reset()> | ||
| 180 | |||
| 181 | Reset a Bio::SeqReader::FastqRecord object. Basically sets all internal | ||
| 182 | data to empty strings. | ||
| 183 | |||
| 184 | =back | ||
| 185 | |||
| 186 | =cut | ||
| 187 | |||
| 188 | sub reset { | ||
| 189 | my $self = shift; | ||
| 190 | |||
| 191 | $self->{ _SEQTEXT } = ''; | ||
| 192 | $self->{ _QUALTEXT } = ''; | ||
| 193 | $self->{ _HEADER1 } = ''; | ||
| 194 | $self->{ _HEADER2 } = ''; | ||
| 195 | } | ||
| 196 | |||
| 197 | =over 12 | ||
| 198 | |||
| 199 | =item B<seq()> | ||
| 200 | |||
| 201 | Getter-setter for the sequence text from a Bio::SeqReader::FastqRecord object. | ||
| 202 | |||
| 203 | $so->seq( 'ACGTACGT' ); | ||
| 204 | print $so->seq(); # => ACGTACGT | ||
| 205 | |||
| 206 | =back | ||
| 207 | |||
| 208 | =cut | ||
| 209 | |||
| 210 | sub seq { | ||
| 211 | my $self = shift; | ||
| 212 | |||
| 213 | if ( @_ ) { | ||
| 214 | $self->{ _SEQTEXT } = shift; | ||
| 215 | $self->{ _SEQTEXT } =~ s/[\000-\037\s]+//g; | ||
| 216 | } | ||
| 217 | |||
| 218 | return $self->{ _SEQTEXT }; | ||
| 219 | } | ||
| 220 | |||
| 221 | 1; | ||
| 222 | |||
| 223 | =head1 EXTERNAL DEPENDENCIES | ||
| 224 | |||
| 225 | Perl core. | ||
| 226 | |||
| 227 | =head1 BUGS | ||
| 228 | |||
| 229 | None reported yet, but let me know. | ||
| 230 | |||
| 231 | =head1 SEE ALSO | ||
| 232 | |||
| 233 | Bio::SeqReader::Fastq, Bio::SeqReader. | ||
| 234 | |||
| 235 | =head1 AUTHOR | ||
| 236 | |||
| 237 | John A. Crow E<lt>jac_at_cpan_dot_orgE<gt> | ||
| 238 | |||
| 239 | =head1 COPYRIGHT AND LICENSE | ||
| 240 | |||
| 241 | This library is free software; you can redistribute it and/or modify | ||
| 242 | it under the same terms as Perl itself, either Perl version 5.10.0 or, | ||
| 243 | at your option, any later version of Perl 5 you may have available. | ||
| 244 | |||
| 245 | Copyright (C) 2012 by John A. Crow | ||
| 246 | Copyright (C) 2012 by National Center for Genome Resources | ||
| 247 | |||
| 248 | |||
| 249 | =cut | ||
| 250 |