X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=bp_bin%2Fwrite_fasta;h=f44d6f4fb64d2188b83cda14d2da7e29e68c2cbe;hb=48bea5c28b89dc5586d0bddb338ccd6ba23aa1f9;hp=b6dd3440b469d659ca847f570f2610cf1267383b;hpb=5aed4676ad1bf35abbade6215ac90ee591e6d8fe;p=biopieces.git diff --git a/bp_bin/write_fasta b/bp_bin/write_fasta index b6dd344..f44d6f4 100755 --- a/bp_bin/write_fasta +++ b/bp_bin/write_fasta @@ -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,46 @@ # http://www.gnu.org/copyleft/gpl.html - -# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - -# Write sequences from stream in FASTA format. - # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< +# This program is part of the Biopieces framework (www.biopieces.org). -use strict; -use Maasha::Fasta; -use Maasha::Biopieces; +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< +# Write sequences from stream in FASTA format. # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< +require 'maasha/biopieces' +require 'maasha/fasta' -my ( $options, $in, $out, $record, $data_out, $entry ); +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: 'wrap', short: 'w', type: 'uint', mandatory: false, default: nil, allowed: nil, disallowed: "0"} +casts << {long: 'compress', short: 'Z', type: 'string', mandatory: false, default: nil, allowed: "gzip,bzip,bzip2", disallowed: nil} -$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 => 'wrap', short => 'w', type => 'uint', mandatory => 'no', default => undef, allowed => undef, disallowed => '0' }, - { long => 'compress', short => 'Z', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, - ] -); +options = Biopieces.options_parse(ARGV, casts) -$in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } ); -$out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } ); +compress = options[:compress] ? options[:compress].to_sym : nil -$data_out = Maasha::Biopieces::write_stream( $options->{ "data_out" }, $options->{ "compress" } ); +raise "--data_out is mandatory for compressed output" if compress and not options[:data_out] -while ( $record = Maasha::Biopieces::get_record( $in ) ) -{ - if ( $entry = Maasha::Fasta::biopiece2fasta( $record ) ) { - Maasha::Fasta::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| + fasta_out = options[:data_out] ? Fasta.open(options[:data_out], 'w', compress: compress) : STDOUT + input.each do |record| + if record[:SEQ_NAME] and record[:SEQ] + entry = Seq.new_bp(record) -BEGIN -{ - Maasha::Biopieces::status_set(); -} + fasta_out.puts entry.to_fasta(options[:wrap]) + end + output.puts record unless options[:no_stream] + end -END -{ - Maasha::Biopieces::status_log(); -} + fasta_out.close +end # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<