X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=bp_bin%2Freplace_vals;h=860b913156962b29c581141442e244ca9982b05d;hb=48bea5c28b89dc5586d0bddb338ccd6ba23aa1f9;hp=356a6335a15fbade75213b71775abb5cdbec8af3;hpb=ed64328c7cb91daf65273e91be4bb373122798c4;p=biopieces.git diff --git a/bp_bin/replace_vals b/bp_bin/replace_vals index 356a633..860b913 100755 --- a/bp_bin/replace_vals +++ b/bp_bin/replace_vals @@ -57,7 +57,12 @@ if options[:file] ios.each_line do |line| unless line[0] == '#' fields = line.chomp.split(delimiter) - replace_hash[fields[options[:search_col] - 1]] = fields[options[:replace_col] - 1] + k = fields[options[:search_col] - 1] + v = fields[options[:replace_col] - 1] + + raise RuntimeError, "duplicate key: #{k} found in file" if replace_hash[k] + + replace_hash[k] = v end end end @@ -65,8 +70,8 @@ end Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output| input.each_record do |record| - if record.has_key? key - if replace_hash.has_key? record[key] + if record[key] + if replace_hash[record[key]] record[key] = replace_hash[record[key]] end end