lib/rbbt/tsv/attach.rb in rbbt-util-5.20.9 vs lib/rbbt/tsv/attach.rb in rbbt-util-5.20.10
- old
+ new
@@ -7,11 +7,11 @@
options = Misc.add_defaults options, :sep => "\t"
key_field, fields = Misc.process_options options, :key_field, :fields
sep = options[:sep]
is = case
- when (String === input and not input.index("\n") and input.length < 250 and File.exists?(input))
+ when (String === input and not input.index("\n") and input.length < 250 and File.exist?(input))
CMD.cmd("env LC_ALL=C sort -k1,1 -t'#{sep}' #{ input } | grep -v '^#{sep}' ", :pipe => true)
when (String === input or StringIO === input)
CMD.cmd("env LC_ALL=C sort -k1,1 -t'#{sep}' | grep -v '^#{sep}'", :in => input, :pipe => true)
else
input
@@ -66,11 +66,11 @@
options = Misc.add_defaults options, :sep => "\t"
monitor, key_field, fields = Misc.process_options options, :monitor, :key_field, :fields
sep = options[:sep] || "\t"
case
- when (String === file1 and not file1 =~ /\n/ and file1.length < 250 and File.exists?(file1))
+ when (String === file1 and not file1 =~ /\n/ and file1.length < 250 and File.exist?(file1))
size = CMD.cmd("wc -c '#{file1}'").read.to_f if monitor
file1 = CMD.cmd("env LC_ALL=C sort -k1,1 -t'#{sep}' #{ file1 } | grep -v '^#{sep}' ", :pipe => true)
when (String === file1 or StringIO === file1)
size = file1.length if monitor
file1 = CMD.cmd("env LC_ALL=C sort -k1,1 -t'#{sep}' | grep -v '^#{sep}'", :in => file1, :pipe => true)
@@ -78,11 +78,11 @@
size = file1.size if monitor
file1 = CMD.cmd("env LC_ALL=C sort -k1,1 -t'#{sep}' | grep -v '^#{sep}'", :in => file1.to_s(:sort, true), :pipe => true)
end
case
- when (String === file2 and not file2 =~ /\n/ and file2.length < 250 and File.exists?(file2))
+ when (String === file2 and not file2 =~ /\n/ and file2.length < 250 and File.exist?(file2))
file2 = CMD.cmd("env LC_ALL=C sort -k1,1 -t'#{sep}' #{ file2 } | grep -v '^#{sep}' ", :pipe => true)
when (String === file2 or StringIO === file2)
file2 = CMD.cmd("env LC_ALL=C sort -k1,1 -t'#{sep}' | grep -v '^#{sep}'", :in => file2, :pipe => true)
when TSV === file2
file2 = CMD.cmd("env LC_ALL=C sort -k1,1 -t'#{sep}' | grep -v '^#{sep}'", :in => file2.to_s(:sort, true), :pipe => true)
@@ -172,10 +172,27 @@
# Merge columns from different files
def self.merge_paste(files, delim = "$")
CMD.cmd("paste #{ files.collect{|f| "'#{f}'"} * " "} -d'#{delim}' |sed 's/#{delim}[^\\t]*//g'", :pipe => true)
end
+ def merge_different_fields(other, options = {})
+ TmpFile.with_file do |output|
+ TSV.merge_different_fields(self, other, output, options)
+ tsv = TSV.open output, options
+ tsv.key_field = self.key_field unless self.key_field.nil?
+ tsv.fields = self.fields + other.fields unless self.fields.nil? or other.fields.nil?
+ tsv
+ end
+ end
+
+ def merge_zip(other)
+ other.each do |k,v|
+ self.zip_new k, v
+ end
+ end
+
+
def attach(other, options = {})
options = Misc.add_defaults options, :in_namespace => false, :persist_input => true
fields, one2one, complete = Misc.process_options options, :fields, :one2one, :complete
in_namespace = options[:in_namespace]
@@ -255,22 +272,7 @@
file_fields = file.fields.collect{|field| field.fullname}
detached_fields = []
self.fields.each_with_index{|field,i| detached_fields << i if file_fields.include? field.fullname}
reorder :key, detached_fields
end
-
- def merge_different_fields(other, options = {})
- TmpFile.with_file do |output|
- TSV.merge_different_fields(self, other, output, options)
- tsv = TSV.open output, options
- tsv.key_field = self.key_field unless self.key_field.nil?
- tsv.fields = self.fields + other.fields unless self.fields.nil? or other.fields.nil?
- tsv
- end
- end
-
- def merge_zip(other)
- other.each do |k,v|
- self.zip_new k, v
- end
- end
+
end