Sha256: 9321b1e7fa79e9e5ce4620d0165ac41c2bbcbde5240a50dbf1d0edcd26540e79

Contents?: true

Size: 1.17 KB

Versions: 238

Compression:

Stored size: 1.17 KB

Contents

#!/usr/bin/env ruby

require 'rbbt-util'
require 'rbbt/util/simpleopt'

$0 = "rbbt #{$previous_commands*""} #{ File.basename(__FILE__) }" if $previous_commands

options = SOPT.setup <<EOF

Description

$ rbbt tsv attach <file1> <file2> [<file3> ...] [options]

Use - to read from STDIN

-f--fields* Fields to attach (all if not specified)
-i--identifiers* Identifier file
-c--complete Complete TSV with keys new in other files
-h--help Print this help

EOF
if options[:help]
  if defined? rbbt_usage
    rbbt_usage 
  else
    puts SOPT.usage
  end
  exit 0
end

file1, *rest = ARGV
fields = options[:fields]
identifiers = options[:identifiers] 
complete = options[:complete] 

if identifiers.nil?
  require 'rbbt/sources/organism'
  Organism.identifiers(Organism.default_code("Hsa"))
end

fields = fields ? fields.split(/[,|]/).collect{|f| f.strip} : nil

tsv = TSV.open(file1, :unnamed => true)
tsv = tsv.to_double if tsv.type == :flat

rest.each do |file2|
  file_fields = TSV.parse_header(file2).all_fields - tsv.all_fields
  these_fields = fields ? fields & file_fields : nil
  tsv = tsv.attach file2, :fields => these_fields, :identifiers => identifiers, :complete => complete
end

puts tsv.to_s

Version data entries

238 entries across 238 versions & 1 rubygems

Version Path
rbbt-util-5.34.16 share/rbbt_commands/tsv/attach
rbbt-util-5.34.15 share/rbbt_commands/tsv/attach
rbbt-util-5.34.14 share/rbbt_commands/tsv/attach
rbbt-util-5.34.13 share/rbbt_commands/tsv/attach
rbbt-util-5.34.12 share/rbbt_commands/tsv/attach
rbbt-util-5.34.11 share/rbbt_commands/tsv/attach
rbbt-util-5.34.10 share/rbbt_commands/tsv/attach
rbbt-util-5.34.9 share/rbbt_commands/tsv/attach
rbbt-util-5.34.8 share/rbbt_commands/tsv/attach
rbbt-util-5.34.7 share/rbbt_commands/tsv/attach
rbbt-util-5.34.5 share/rbbt_commands/tsv/attach
rbbt-util-5.34.4 share/rbbt_commands/tsv/attach
rbbt-util-5.34.3 share/rbbt_commands/tsv/attach
rbbt-util-5.34.2 share/rbbt_commands/tsv/attach
rbbt-util-5.34.1 share/rbbt_commands/tsv/attach
rbbt-util-5.34.0 share/rbbt_commands/tsv/attach
rbbt-util-5.33.21 share/rbbt_commands/tsv/attach
rbbt-util-5.33.20 share/rbbt_commands/tsv/attach
rbbt-util-5.33.19 share/rbbt_commands/tsv/attach
rbbt-util-5.33.18 share/rbbt_commands/tsv/attach