-#!/usr/bin/env perl
+#!/usr/bin/env ruby
-# Copyright (C) 2007-2009 Martin A. Hansen.
+# Copyright (C) 2007-2012 Martin A. Hansen.
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# http://www.gnu.org/copyleft/gpl.html
-
-# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-
-# Write sequences from stream in FASTQ format.
-
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+# This program is part of the Biopieces framework (www.biopieces.org).
-use warnings;
-use strict;
-use Maasha::Fastq;
-use Maasha::Biopieces;
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+# Write sequences from stream in FASTQ format.
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+require 'maasha/biopieces'
+require 'maasha/fastq'
-my ( $options, $in, $out, $record, $data_out, $entry );
+allowed_enc = 'base_33,base_64'
-$options = Maasha::Biopieces::parse_options(
- [
- { long => 'no_stream', short => 'x', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
- { long => 'data_out', short => 'o', type => 'file', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
- { long => 'compress', short => 'Z', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef },
- ]
-);
+casts = []
+casts << {:long=>'no_stream', :short=>'x', :type=>'flag', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}
+casts << {:long=>'data_out', :short=>'o', :type=>'file', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}
+casts << {:long=>'encoding', :short=>'e', :type=>'string', :mandatory=>false, :default=>'base_33', :allowed=>allowed_enc, :disallowed=>nil}
+casts << {:long=>'compress', :short=>'Z', :type=>'flag', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}
-$in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
-$out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
+options = Biopieces.options_parse(ARGV, casts)
-$data_out = Maasha::Biopieces::write_stream( $options->{ "data_out" }, $options->{ "compress" } );
+encoding = options[:encoding].to_sym
-while ( $record = Maasha::Biopieces::get_record( $in ) )
-{
- if ( $entry = Maasha::Fastq::biopiece2fastq( $record ) ) {
- Maasha::Fastq::put_entry( $entry, $data_out, $options->{ "wrap" } );
- }
-
- Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
-}
-
-close $data_out;
-
-Maasha::Biopieces::close_stream( $in );
-Maasha::Biopieces::close_stream( $out );
-
-
-# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output|
+ if options[:data_out]
+ if options[:compress]
+ io_out = Zlib::GzipWriter.open(options[:data_out])
+ else
+ io_out = Fastq.open(options[:data_out], 'w')
+ end
+ else
+ io_out = $stdout
+ end
+ input.each do |record|
+ if record[:SEQ_NAME] and record[:SEQ] and record[:SCORES]
+ entry = Seq.new_bp(record)
+ entry.qual_convert!(:base_33, encoding)
-BEGIN
-{
- Maasha::Biopieces::status_set();
-}
+ io_out.puts entry.to_fastq
+ end
+ output.puts record unless options[:no_stream]
+ end
-END
-{
- Maasha::Biopieces::status_log();
-}
+ io_out.close
+end
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<