Permalink
Browse files

Add --unshift-headers switch

  • Loading branch information...
1 parent ba084e3 commit da8a003180d3a15fff457a13e8a7045199fd75e0 @pjotrp committed Nov 1, 2012
Showing with 11 additions and 3 deletions.
  1. +6 −2 bin/bio-table
  2. +5 −1 lib/bio-table/table_apply.rb
View
@@ -98,6 +98,10 @@ opts = OptionParser.new do |o|
options[:with_rownames] = true
end
+ o.on('--unshift-headers','Add an extra header element at the front (header contains one fewer field than the number of columns)') do
+ options[:unshift_headers] = true
+ end
+
o.on('--strip-quotes','Strip quotes from table fields') do
options[:strip_quotes] = true
end
@@ -228,7 +232,7 @@ writer =
end
if INPUT_ON_STDIN
- opts = options.dup # so we can modify options
+ opts = options.dup # so we can 'safely' modify options
BioTable::TableLoader.emit(STDIN, opts).each do |row, type|
writer.write(TableRow.new(row[0],row[1..-1]),type)
end
@@ -242,7 +246,7 @@ statistics = if options[:statistics]
end
ARGV.each do | fn |
- opts = options.dup # so we can modify options
+ opts = options.dup # so we can 'safely' modify options
f = File.open(fn,"r")
if not opts[:in_format] and fn =~ /\.csv$/
logger.debug "Autodetected CSV file"
@@ -34,7 +34,11 @@ def initialize options
def parse_header(line, options)
header = LineParser::parse(line, options[:in_format], options[:split_on])
header = Formatter::strip_quotes(header) if @strip_quotes
- return Formatter::transform_header_ids(@transform_ids, header) if @transform_ids
+ # Transform converts the header to upper/lower case
+ header = Formatter::transform_header_ids(@transform_ids, header) if @transform_ids
+ if options[:unshift_headers]
+ header.unshift("ID")
+ end
@logger.info(header) if @logger
header
end

0 comments on commit da8a003

Please sign in to comment.