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' },
51 $in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
52 $out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
54 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
55 Maasha::Biopieces::put_record( $record, $out );
58 if ( $options->{ 'data_in' } )
60 $data_in = Maasha::Filesys::file_read_open( $options->{ 'data_in' } );
61 $qual_in = Maasha::Filesys::file_read_open( $options->{ 'qual_in' } );
65 while ( $fasta = Maasha::Fasta::get_entry( $data_in ) )
67 $qual = get_qual( $qual_in );
69 check_names( $fasta, $qual );
70 check_lengths( $fasta, $qual );
73 SEQ_NAME => $fasta->[ 0 ],
75 SEQ_LEN => length $fasta->[ 1 ],
76 SCORES => $qual->[ 1 ],
79 Maasha::Biopieces::put_record( $record, $out );
81 last if $options->{ "num" } and $num == $options->{ "num" };
90 Maasha::Biopieces::close_stream( $in );
91 Maasha::Biopieces::close_stream( $out );
94 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
99 # Martin A. Hansen, May 2010.
101 # Get the next 454 quality entry from an open file.
103 my ( $fh, # file handle
108 my ( $block, $name, $qual, $scores, $entry );
112 while ( $block = <$fh> )
116 last if $block !~ /^\s+$/;
119 return if not defined $block;
121 $block =~ /^>?(.+)\n/m;
130 $qual =~ tr/ \n\r/;;;/;
133 $scores = Maasha::Fastq::dec_str2solexa_str( $qual );
135 $entry = [ $name, $scores ];
137 return wantarray ? @{ $entry } : $entry;
143 # Martin A. Hansen, May 2010.
145 # Check if the names of the fasta and qual entries match
146 # and raise an error if they don't.
148 my ( $fasta, # fasta entry
154 my ( $f_name, $q_name );
156 if ( $fasta->[ 0 ] =~ /^([^ ]+)/ ) {
160 if ( $qual->[ 0 ] =~ /^([^ ]+)/ ) {
164 Maasha::Common::error( qq(names don't match "$fasta->[ 0 ]" ne "$qual->[ 0 ]") ) if $f_name ne $q_name;
170 # Martin A. Hansen, April 2011.
172 # Check if the lengths of the fasta and qual strings are the same
173 # and raise an error if not.
175 my ( $fasta, # fasta entry
181 my ( $f_len, $q_len );
183 $f_len = length $fasta->[ 1 ];
184 $q_len = length $qual->[ 1 ];
186 Maasha::Common::error( qq(lengths don't match "$f_len" != "$q_len") ) if $f_len != $q_len;
190 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
195 Maasha::Biopieces::status_set();
201 Maasha::Biopieces::status_log();
205 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<