# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-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[: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
+
+
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<