3 # Copyright (C) 2007-2010 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 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
24 # Read 454 entries from fasta and quality file.
26 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
32 use Maasha::Biopieces;
38 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
41 my ( $options, $in, $out, $record, $data_in, $qual_in, $num, $fasta, $qual, @seqs, @scores, $i );
43 $options = Maasha::Biopieces::parse_options(
45 { long => 'data_in', short => 'i', type => 'file!', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef },
46 { long => 'qual_in', short => 'q', type => 'file!', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef },
47 { long => 'num', short => 'n', type => 'uint', mandatory => 'no', default => undef, allowed => undef, disallowed => '0' },
48 { long => 'convert2dec', short => 'c', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
49 { long => 'cutoff', short => 'C', type => 'int', mandatory => 'no', default => 20, allowed => undef, disallowed => undef },
50 { long => 'soft_mask', short => 's', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
51 { long => 'mean', short => 'm', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
55 $in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
56 $out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
58 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
59 Maasha::Biopieces::put_record( $record, $out );
62 if ( $options->{ 'data_in' } )
64 $data_in = Maasha::Filesys::file_read_open( $options->{ 'data_in' } );
65 $qual_in = Maasha::Filesys::file_read_open( $options->{ 'qual_in' } );
69 while ( $fasta = Maasha::Fasta::get_entry( $data_in ) )
71 $qual = get_qual( $qual_in );
73 check_names( $fasta, $qual );
76 SEQ_NAME => $fasta->[ 0 ],
78 SEQ_LEN => length $fasta->[ 1 ],
79 SCORES => $qual->[ 1 ],
82 $record->{ 'SCORES_MEAN' } = sprintf "%.2f", Maasha::Fastq::solexa_str_mean( $qual->[ 1 ] ) if $options->{ 'mean' };
84 Maasha::Fastq::softmask_solexa_str( $record->{ 'SEQ' }, $record->{ 'SCORES' }, $options->{ 'cutoff' } ) if $options->{ 'soft_mask' };
85 $record->{ 'SCORES' } = Maasha::Fastq::solexa_str2dec_str( $record->{ 'SCORES' } ) if $options->{ 'convert2dec' };
87 Maasha::Biopieces::put_record( $record, $out );
89 last if $options->{ "num" } and $num == $options->{ "num" };
98 Maasha::Biopieces::close_stream( $in );
99 Maasha::Biopieces::close_stream( $out );
102 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
107 # Martin A. Hansen, May 2010.
109 # Get the next 454 quality entry from an open file.
111 my ( $fh, # file handle
116 my ( $block, $name, $qual, $scores, $entry );
120 while ( $block = <$fh> )
124 last if $block !~ /^\s+$/;
127 return if not defined $block;
129 $block =~ /^>?(.+)\n/m;
138 $qual =~ tr/ \n\r/;;;/;
141 $scores = Maasha::Fastq::dec_str2solexa_str( $qual );
143 $entry = [ $name, $scores ];
145 return wantarray ? @{ $entry } : $entry;
151 # Martin A. Hansen, May 2010.
153 # Check if the names of the fasta and qual entries match
154 # and raise an error if they don't.
156 my ( $fasta, # fasta entry
162 my ( $f_name, $q_name );
164 if ( $fasta->[ 0 ] =~ /^([^ ]+)/ ) {
168 if ( $qual->[ 0 ] =~ /^([^ ]+)/ ) {
172 Maasha::Common::error( qq(names don't match "$fasta->[ 0 ]" ne "$qual->[ 0 ]") ) if $f_name ne $q_name;
176 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
181 Maasha::Biopieces::status_set();
187 Maasha::Biopieces::status_log();
191 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<