<commit_before># bio-table

[![Build Status](https://secure.travis-ci.org/pjotrp/bioruby-table.png)](http://travis-ci.org/pjotrp/bioruby-table)

Tables of data are often used in bioinformatics. This biogem contains
support for reading tables and manipulation of rows and columns, both
using a command line interface and Ruby library. In time bio-table
should be lazy, be good for big data, and support a functional style
of programming.

Note: this software is under active development!

## Installation

```sh
    gem install bio-table
```

## Usage

```ruby
    require 'bio-table'
```

### Loading a table

Tables are two dimensional matrixes, which can be read from a file

```
    t = BioTable::Table.read_file('test/data/input/test1.csv')
    p t.header              # print the header array
    p t.name[0],t[0]        # print the row name and row fields
    p t[0][0]               # print the top corner field
```

The table reader has quite a few options for defining field separator,
which column to use for names etc. More interestingly you can pass a
function to limit the amount of fields read into memory:

```
    t = BioTable::Table.read_file('test/data/input/test1.csv',
      :by_row => { | fields | fields[0..3] } )
```

will create a table of the column name and 2 table fields. You can use
the same idea to reformat and reorder table columns when reading data
into the table. E.g.

```
    t = BioTable::Table.read_file('test/data/input/test1.csv',
      :by_row => { | fields | [fields[0..3],fields[6].to_i].flatten } )
```

When by_row returns nil, the table row is skipped.

To write a table to file

```
    t.write_file('test1a.csv')
```

again columns can be reordered/transformed using a function. Another
option is by passing in an list of column numbers or header names,
e.g.

```
    t.write_file('test1a.csv', columns: [0,1,2,4,6,8])
    t.write_file('test1b.csv', columns: ["AJ","B6","Axb1","Axb4","AXB13","Axb15","Axb19"] )
```

other options are available for excluding row names, etc.

The API doc is online. For more code examples see the test files in
the source tree.
        
## Project home page

Information on the source tree, documentation, examples, issues and
how to contribute, see

  http://github.com/pjotrp/bioruby-table

The BioRuby community is on IRC server: irc.freenode.org, channel: #bioruby.

## Cite

If you use this software, please cite one of
  
* [BioRuby: bioinformatics software for the Ruby programming language](http://dx.doi.org/10.1093/bioinformatics/btq475)
* [Biogem: an effective tool-based approach for scaling up open source software development in bioinformatics](http://dx.doi.org/10.1093/bioinformatics/bts080)

## Biogems.info

This Biogem is published at [#bio-table](http://biogems.info/index.html)

## Copyright

Copyright (c) 2012 <NAME>. See LICENSE.txt for further details.

<commit_msg>README: API<commit_after># bio-table

[![Build Status](https://secure.travis-ci.org/pjotrp/bioruby-table.png)](http://travis-ci.org/pjotrp/bioruby-table)

Tables of data are often used in bioinformatics. This biogem contains
support for reading tables and manipulation of rows and columns, both
using a command line interface and Ruby library. In time bio-table
should be lazy, be good for big data, and support a functional style
of programming.

Note: this software is under active development!

## Installation

```sh
    gem install bio-table
```

## Usage

```ruby
    require 'bio-table'
    include BioTable
```

### Loading a table

Tables are two dimensional matrixes, which can be read from a file

```
    t = Table.read_file('test/data/input/test1.csv')
    p t.header              # print the header array
    p t.name[0],t[0]        # print the row name and row row
    p t[0][0]               # print the top corner field
```

The table reader has quite a few options for defining field separator,
which column to use for names etc. More interestingly you can pass a
function to limit the amount of row read into memory:

```
    t = Table.read_file('test/data/input/test1.csv',
      :by_row => { | row | row[0..3] } )
```

will create a table of the column name +row[0]+ and 2 table fields. You can use
the same idea to reformat and reorder table columns when reading data
into the table. E.g.

```
    t = Table.read_file('test/data/input/test1.csv',
      :by_row => { | row | [row.rowname, row[0..3], row[6].to_i].flatten } )
```

When a header can not be transformed, it may fail. You can test for
the header with row.header?, but in this case you
can pass in a :by_header, which will have :by_row only call on
actual table rows.

```
    t = Table.read_file('test/data/input/test1.csv',
      :by_header => { | header | ["", header[0..3], header[6]].flatten } )
      :by_row => { | row | [row.rowname, row[0..3], row[6].to_i].flatten } )
```

When by_row returns nil, the table row is skipped. One way to
transform a file, and not loading it in memory, is

```
    f = File.new('test.tab','w')
    t = Table.read_file('test/data/input/test1.csv', 
      :by_row => { | row | 
        TableRow::write(f,[row.rowname,row[0..3],row[6].to_i].flatten, :separator => "\t") 
        nil   # don't create table in memory
      })
```

To write a full table from memory to file use

```
    t.write_file('test1a.csv')
```

again columns can be reordered/transformed using a function. Another
option is by passing in an list of column numbers or header names, so
only those cat written e.g.

```
    t.write_file('test1a.csv', columns: [0,1,2,4,6,8])
    t.write_file('test1b.csv', columns: ["AJ","B6","Axb1","Axb4","AXB13","Axb15","Axb19"] )
```

other options are available for excluding row names (rownames: false), etc.

The API doc is online. For more code examples see the test files in
the source tree.
        
## Project home page

Information on the source tree, documentation, examples, issues and
how to contribute, see

  http://github.com/pjotrp/bioruby-table

The BioRuby community is on IRC server: irc.freenode.org, channel: #bioruby.

## Cite

If you use this software, please cite one of
  
* [BioRuby: bioinformatics software for the Ruby programming language](http://dx.doi.org/10.1093/bioinformatics/btq475)
* [Biogem: an effective tool-based approach for scaling up open source software development in bioinformatics](http://dx.doi.org/10.1093/bioinformatics/bts080)

## Biogems.info

This Biogem is published at [#bio-table](http://biogems.info/index.html)

## Copyright

Copyright (c) 2012 <NAME>. See LICENSE.txt for further details.


{'fraction_non_alphanumeric': 0.11917494270435447, 'fraction_numerical': 0.018029029793735676, 'mean_word_length': 3.5840336134453783, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '551293', 'n_tokens_mistral': 2201, 'n_tokens_neox': 2067, 'n_words': 754}