X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=bp_bin%2Fwrite_fastq;h=f6050f38555071932cab4ad91eaba821c8d84a83;hb=9b109416b6dcbf422ad38d45d134c59f78221198;hp=5f81de231d3a80ff203e905facbaf9286303218c;hpb=862e5199fc285d72f68c494ed59ca12bfadf039a;p=biopieces.git diff --git a/bp_bin/write_fastq b/bp_bin/write_fastq index 5f81de2..f6050f3 100755 --- a/bp_bin/write_fastq +++ b/bp_bin/write_fastq @@ -1,6 +1,6 @@ -#!/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 @@ -18,66 +18,55 @@ # 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 = 'sanger,solexa,illumina1.3,illumina1.5,illumina1.8' -$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=>'illumina1.3', :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].downcase.delete('.') -while ( $record = Maasha::Biopieces::get_record( $in ) ) -{ - if ( $entry = Maasha::Fastq::biopiece2fastq( $record ) ) { - Maasha::Fastq::put_entry( $entry, $data_out ); - } - - 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.convert_scores!('illumina13', encoding) -BEGIN -{ - Maasha::Biopieces::status_set(); -} + io_out.puts entry.to_fastq + end + output.puts record unless options.has_key? :no_stream + end -END -{ - Maasha::Biopieces::status_log(); -} + io_out.close +end # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<