Sha256: 8bac85f20bef04a70ece677e0b597cf6b0aabea7edf6ffbe9ab7c3357e70033c

Contents?: true

Size: 1.07 KB

Versions: 110

Compression:

Stored size: 1.07 KB

Contents

#!/usr/bin/env ruby

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

options = SOPT.setup <<EOF

Change the ID format of a column in a tsv file

$ rbbt command command [options] -f file

Use - to read from STDIN. The `field` is the tsv column to change.
the `target` is the target format, as appearing in the `identifiers`
file or in `Organism.identifiers("Hsa")`.

-f--file* File to process
-f--field* Field to change
-t--target* Target format
-i--identifiers* Identifier file to use
-h--help Help

EOF
rbbt_usage and exit 0 if options[:help]

SOPT.require options, :file, :field, :target

require 'rbbt/sources/organism'

identifiers = options[:identifiers] || Organism.identifiers("Hsa").find

begin
  index = TSV.index(identifiers, :persist => true, :target => target, :merge => true)
rescue
  raise ParameterException, "Could not build index for '#{target}': #{ identifiers }"
end

tsv = TSV.open file

tsv.process field do |value|
  if Array === value
    index.values_at *value
  else
    index[value]
  end
end

tsv.fields = tsv.fields.collect{|f| f == field ? target : f}

puts tsv

Version data entries

110 entries across 110 versions & 1 rubygems

Version Path
rbbt-util-5.14.10 share/rbbt_commands/tsv/change_id
rbbt-util-5.14.9 share/rbbt_commands/tsv/change_id
rbbt-util-5.14.8 share/rbbt_commands/tsv/change_id
rbbt-util-5.14.7 share/rbbt_commands/tsv/change_id
rbbt-util-5.14.6 share/rbbt_commands/tsv/change_id
rbbt-util-5.14.5 share/rbbt_commands/tsv/change_id
rbbt-util-5.14.4 share/rbbt_commands/tsv/change_id
rbbt-util-5.14.3 share/rbbt_commands/tsv/change_id
rbbt-util-5.14.2 share/rbbt_commands/tsv/change_id
rbbt-util-5.14.1 share/rbbt_commands/tsv/change_id
rbbt-util-5.14.0 share/rbbt_commands/tsv/change_id
rbbt-util-5.13.37 share/rbbt_commands/tsv/change_id
rbbt-util-5.13.36 share/rbbt_commands/tsv/change_id
rbbt-util-5.13.35 share/rbbt_commands/tsv/change_id
rbbt-util-5.13.34 share/rbbt_commands/tsv/change_id
rbbt-util-5.13.33 share/rbbt_commands/tsv/change_id
rbbt-util-5.13.32 share/rbbt_commands/tsv/change_id
rbbt-util-5.13.31 share/rbbt_commands/tsv/change_id
rbbt-util-5.13.30 share/rbbt_commands/tsv/change_id
rbbt-util-5.13.29 share/rbbt_commands/tsv/change_id