Skip to content
Martin Asser Hansen edited this page Oct 1, 2015 · 5 revisions

Biopiece: write_tab

Description

Outputting the data stream as a table can be done with write_tab which will write generate one row per record with the values as columns.

Usage

... | write_tab [[options]]

Options

[-?          | --help]               #  Print full usage description.
[-x          | --no_stream]          #  Do not emit records.
[-o <file>   | --data_out=<file>]    #  Write result to file.
[-c          | --comment]            #  Print comment line  -  Default=no
[-p          | --pretty]             #  Pretty print table.
[-C          | --commify]            #  Commify numbers when pretty printing.
[-d <string> | --delimit=<string>]   #  Changes delimiter   -  Default='\t'
[-k <string> | --keys=<string>]      #  Comma separated list of keys to print in that order.
[-K <string> | --no_keys=<string>]   #  Comma separated list of keys to ignore.
[-I <file!>  | --stream_in=<file!>]  #  Read input from stream file  -  Default=STDIN
[-O <file>   | --stream_out=<file>]  #  Write output to stream file  -  Default=STDOUT
[-Z <string> | --compress=<string>]  #  Compress output using <gzip|bzip2>.
[-v          | --verbose]            #  Verbose output.

Examples

Consider the following records in the stream:

Organism: Human
Count: 23524
Sequence: ATACGTCAG
---
Organism: Dog
Count: 2442
Sequence: AGCATGAC
---
Organism: Mouse
Count: 234
Sequence: GACTG
---
Organism: Cat
Count: 2342
Sequence: AAATGCA
---

To write all records from the stream as a table, do:

... | write_tab -x

Human	23524	ATACGTCAG
Dog	2442	AGCATGAC
Mouse	234	GACTG
Cat	2342	AAATGCA

If you supply the optional -c switch, when the first row in the table will be a 'comment' line prefixed with a '#':

... | write_tab -c -x

#Organism	Count	Sequence
Human	23524	ATACGTCAG
Dog	2442	AGCATGAC
Mouse	234	GACTG
Cat	2342	AAATGCA

You can also change the delimiter from the default (tab) to e.g. ',':

... | write_tab -d ',' -x

Human,23524,ATACGTCAG
Dog,2442,AGCATGAC
Mouse,234,GACTG
Cat,2342,AAATGCA

If you want the values output in a specific order you have to supply a comma separated list using the -k switch that will print only those keys in that order:

... | write_tab -k Sequence,Count -x

ATACGTCAG	23524
AGCATGAC	2442
GACTG	234
AAATGCA	2342

Keys from e.g. read_tab V0, V1, V2 ... Vn, is automagically sorted numerically.

Alternatively, if you have some keys that you don't want in the tabular output, use the -K switch. So to print all keys except SEQ and SEQ_TYPE do:

... | write_tab -K Sequence -x

Human	23524
Dog	2442
Mouse	234
Cat	2342

And if you want a pretty printed table use the -p switch and throw in the -C switch if you want commified numbers.

... | write_tab -cpC -x

+----------+--------+-----------+
| Organism | Count  | Sequence  |
+----------+--------+-----------+
| Human    | 23,524 | ATACGTCAG |
| Dog      |  2,442 | AGCATGAC  |
| Mouse    |    234 | GACTG     |
| Cat      |  2,342 | AAATGCA   |
+----------+--------+-----------+

See also

read_tab

grab

Author

Martin Asser Hansen - Copyright (C) - All rights reserved.

mail@maasha.dk

August 2007

License

GNU General Public License version 2

http://www.gnu.org/copyleft/gpl.html

Help

write_tab is part of the Biopieces framework.

http://www.biopieces.org

Clone this wiki locally