X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=bp_bin%2Fcalc_N50;h=3e56af9a35c184143676034c560d5f4c957801dc;hb=dd12a5077539995f63057a81601380e468922e2d;hp=ed4fd0e6dbf081876f7583132acff70162e9c53c;hpb=270f2807133d6916c484f58b90f83ada885e9b55;p=biopieces.git diff --git a/bp_bin/calc_N50 b/bp_bin/calc_N50 index ed4fd0e..3e56af9 100755 --- a/bp_bin/calc_N50 +++ b/bp_bin/calc_N50 @@ -1,7 +1,5 @@ #!/usr/bin/env ruby -#arg! - # Copyright (C) 2007-2011 Martin A. Hansen. # This program is free software; you can redistribute it and/or @@ -31,42 +29,45 @@ # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -require 'biopieces' -require 'pp' +require 'maasha/biopieces' 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} -bp = Biopieces.new - -options = bp.parse(ARGV, casts) +options = Biopieces.options_parse(ARGV, casts) total = 0 lengths = [] -bp.each_record do |record| - bp.puts record unless options[:no_stream] +Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output| + input.each_record do |record| + output.puts record unless options[:no_stream] - if record.has_key? :SEQ - total += record[:SEQ].length - lengths << record[:SEQ].length + if record.has_key? :SEQ + total += record[:SEQ].length + lengths << record[:SEQ].length + end end end -bp.out = Stream.write(options[:data_out]) - -count = 0 +new_record = {} +count = 0 lengths.sort.reverse.each do |length| count += length if count >= total * 0.50 - bp.puts "N50" => length + new_record["N50"] = length break end end +Biopieces.open(nil, options[:data_out]) do |input, output| + output.puts new_record +end + + # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<