# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-require 'biopieces'
-require 'genbank'
+require 'maasha/biopieces'
+require 'maasha/genbank'
casts = []
casts << {:long=>'data_in', :short=>'i', :type=>'files!', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}
casts << {:long=>'features', :short=>'f', :type=>'list', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}
casts << {:long=>'qualifiers', :short=>'q', :type=>'list', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil}
-bp = Biopieces.new
-
-options = bp.parse(ARGV, casts)
+options = Biopieces.options_parse(ARGV, casts)
hash_keys = options[:keys].inject(Hash.new) { |h,k| h[k.upcase.to_sym] = true; h } if options[:keys]
hash_feats = options[:features].inject(Hash.new) { |h,k| h[k.upcase.to_sym] = true; h } if options[:features]
hash_quals = options[:qualifiers].inject(Hash.new) { |h,k| h[k.upcase.to_sym] = true; h } if options[:qualifiers]
-bp.each_record do |record|
- bp.puts record
-end
-num = 0
-last = false
+Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output|
+ input.each_record do |record|
+ output.puts record
+ end
+
+ num = 0
+ last = false
-if options.has_key? :data_in
- options[:data_in].each do |file|
- Genbank.open(file, mode='r') do |gb|
- gb.each(hash_keys, hash_feats, hash_quals) do |entry|
- bp.puts entry
+ if options.has_key? :data_in
+ options[:data_in].each do |file|
+ Genbank.open(file, mode='r') do |gb|
+ gb.each(hash_keys, hash_feats, hash_quals) do |entry|
+ output.puts entry
- num += 1
+ num += 1
- if options.has_key? :num and options[:num] == num
- last = true
- break
+ if options.has_key? :num and options[:num] == num
+ last = true
+ break
+ end
end
end
- end
- break if last
+ break if last
+ end
end
end