Skip to content
Martin Asser Hansen edited this page Oct 2, 2015 · 4 revisions

Biopiece: bioscript

Description

bioscript allows a Perl one-liner to be eval'ed. From the Maaaha::Biopieces module the two subroutines get_record() and put_record() are available which are the record parser and emitter, respectively.

And also available are the two variables $in and $out that are filehandles to the stream in and out, respectively.

get_record() takes a single argument $in, where put_record takes one or two arguments, namely the Biopiece record (that we typically denote $r) and the optional filehandle to the output stream $out.

See also:

http://code.google.com/p/biopieces/wiki/HowTo#Howto_to_use_complex_Biopiece_records

Usage

... | bioscript [options] -e <string>

Options

[-?          | --help]               #  Print full usage description.
[-e <string> | --eval=<string>]      #  Key with value to split.
[-I <file!>  | --stream_in=<file!>]  #  Read input from stream file    -  Default=STDIN
[-O <file>   | --stream_out=<file>]  #  Write output to stream file    -  Default=STDOUT
[-v          | --verbose]            #  Verbose output.

Examples

The most simple bioscript that reads all records from the stream and emits these to the stream looks like this:

... | bioscript -e 'while( $r = get_record( $in ) ){ put_record( $r ) }'

In the above example the records are output to STDOUT, so if you want to use the -O switch to save the stream to a output file you need to use the second argument to the put_record() subroutine:

... | bioscript -e 'while( $r = get_record( $in ) ){ put_record( $r, $out ) }' -O test.stream

Now you can manipulate the records easily. Here we add an index to the record. Note that bareword keys are allowed, and there is no need for quoting the keys:

... | bioscript -e '$i=0; while( $r=get_record( $in ) ){ $r->{ INDEX }=$i++; put_record( $r ) }'

Note that Perl's Data::Dumper is enabled in bioscript which allows for easy testing and debugging:

bioscript -I test.stream -e '$r = get_record( $in ); print Dumper( $r )'

$VAR1 = {
          'SEQ' => 'ACATAGACAGCACGTAC--GACGACGACG',
          'SEQ_NAME' => 'test2'
        };

See also

Author

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

[email protected]

June 2009

License

GNU General Public License version 2

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

Help

bioscript is part of the Biopieces framework.

http://www.biopieces.org

Clone this wiki locally