3 # Copyright (C) 2006-2009 Martin A. Hansen.
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 # http://www.gnu.org/copyleft/gpl.html
22 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
25 # Routines for manipulation of FASTQ files and FASTQ entries.
27 # http://maq.sourceforge.net/fastq.shtml
30 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
37 use vars qw( @ISA @EXPORT );
39 @ISA = qw( Exporter );
48 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
53 # Martin A. Hansen, July 2009.
55 # Gets the next FASTQ entry from a given filehandle.
57 my ( $fh, # filehandle
62 my ( $seq, $seq_name, $qual, $qual_name );
78 return wantarray ? ( $seq_name, $seq, $qual ) : [ $seq_name, $seq, $qual ];
84 # Martin A. Hansen, July 2009.
86 # Output a FASTQ entry to STDOUT or a filehandle.
88 my ( $entry, # FASTQ entry
89 $fh, # filehandle - OPTIONAL
96 print $fh "@" . $entry->[ SEQ_NAME ] . "\n";
97 print $fh $entry->[ SEQ ] . "\n";
99 print $fh $entry->[ SCORES ] . "\n";
105 # Martin A. Hansen, July 2009.
107 # Converts a FASTQ entry to a Biopiece record, where
108 # the FASTQ quality scores are converted to numerics.
110 my ( $entry, # FASTQ entry,
117 $record->{ 'SEQ' } = $entry->[ SEQ ];
118 $record->{ 'SEQ_NAME' } = $entry->[ SEQ_NAME ];
119 $record->{ 'SCORES' } = $entry->[ SCORES ];
121 $record->{ 'SCORES' } =~ s/(.)/ord( $1 ) - 33 . ";"/ge; # http://maq.sourceforge.net/fastq.shtml
122 $record->{ 'SCORE_MEAN' } = sprintf( "%.2f", Maasha::Calc::mean( [ split /;/, $record->{ 'SCORES' } ] ) );
124 return wantarray ? %{ $record } : $record;
130 # Martin A. Hansen, July 2009.
132 # Converts a Biopiece record to a FASTQ entry.
134 my ( $record, # Biopiece record
141 if ( exists $record->{ 'SEQ' } and exists $record->{ 'SEQ_NAME' } and exists $record->{ 'SCORES' } )
143 $list->[ SEQ_NAME ] = $record->{ 'SEQ_NAME' };
144 $list->[ SEQ ] = $record->{ 'SEQ' };
145 $list->[ SCORES ] = $record->{ 'SCORES' };
147 $list->[ SCORES ] =~ s/(\d+);/chr( ( $1 <= 93 ? $1 : 93 ) + 33 )/ge;
149 return wantarray ? @{ $list } : $list;
156 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<