Browse files

Full transformation support

  • Loading branch information...
1 parent 97b80e9 commit 2c4a0b147dd81f3eca06e8a48693d28a4f3cc100 @pjotrp committed Feb 27, 2014
Showing with 25 additions and 2 deletions.
  1. +20 −2
  2. +5 −0 lib/bio-table/rewrite.rb
@@ -87,7 +87,10 @@ When you have a special file format, it is also possible to use a string or rege
bio-table --in-format regex --split-on '\s*,\s*' file
-To filter out rows that contain certain values
+To filter out rows that contain certain values, i.e., filter on the
+third column that have values less than 0.05 (this is actually the 5th
+column in a tabular file, where the fist column is the row name and
+the others count from zero).
bio-table table1.csv --num-filter "values[3] <= 0.05"
@@ -202,6 +205,21 @@ again
where we rewrite the rowname in capitals, and set the second field to
empty if the third field is below 0.25.
+Say we need a log transform, we can also transform and rewrite a full matrix with:
+ bio-table table1.csv --rewrite 'fields = { |f| Math::log(f.to_f) }'
+Note that 'fields' is an alias for 'field', but do not use them in the same expression.
+Another option is to use (lazy) values:
+ bio-table table1.csv --rewrite 'fields = { |v| Math::log(v) }'
+which saves the typing to to_f.
### Statistics
bio-table can handle some column statistics using the Ruby statsample
@@ -268,7 +286,7 @@ to be sorted). For non-matching rownames the fields will be filled
with NA's, unless you add a filter, e.g.
- bio-table --merge table1.csv table2.csv --num-filter "values.compact.size == values.to_a.size"
+ bio-table --merge table1.csv table2.csv --num-filter "values.compact.size == values.size"
5 lib/bio-table/rewrite.rb
@@ -2,14 +2,19 @@ module BioTable
module Rewrite
+ # Rewrite fields. Both field and fields can be used, but not at the same time.
def Rewrite::rewrite code, rowname, field
+ fields = field
+ original = field
+ values =
return rowname,field if not code or code==""
rescue Exception
$stderr.print "Failed to evaluate ",rowname," ",field," with ",code,"\n"
+ field = fields if fields != original
return rowname,field

0 comments on commit 2c4a0b1

Please sign in to comment.