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.33 share/rbbt_commands/tsv/change_id
rbbt-util-5.14.32 share/rbbt_commands/tsv/change_id
rbbt-util-5.14.31 share/rbbt_commands/tsv/change_id
rbbt-util-5.14.30 share/rbbt_commands/tsv/change_id
rbbt-util-5.14.29 share/rbbt_commands/tsv/change_id
rbbt-util-5.14.28 share/rbbt_commands/tsv/change_id
rbbt-util-5.14.26 share/rbbt_commands/tsv/change_id
rbbt-util-5.14.25 share/rbbt_commands/tsv/change_id
rbbt-util-5.14.24 share/rbbt_commands/tsv/change_id
rbbt-util-5.14.23 share/rbbt_commands/tsv/change_id
rbbt-util-5.14.22 share/rbbt_commands/tsv/change_id
rbbt-util-5.14.21 share/rbbt_commands/tsv/change_id
rbbt-util-5.14.20 share/rbbt_commands/tsv/change_id
rbbt-util-5.14.18 share/rbbt_commands/tsv/change_id
rbbt-util-5.14.17 share/rbbt_commands/tsv/change_id
rbbt-util-5.14.16 share/rbbt_commands/tsv/change_id
rbbt-util-5.14.15 share/rbbt_commands/tsv/change_id
rbbt-util-5.14.14 share/rbbt_commands/tsv/change_id
rbbt-util-5.14.12 share/rbbt_commands/tsv/change_id
rbbt-util-5.14.11 share/rbbt_commands/tsv/change_id