]> git.donarmstrong.com Git - biopieces.git/blob - bp_bin/split_vals
fixed symlink trouble
[biopieces.git] / bp_bin / split_vals
1 #!/usr/bin/env perl -w
2
3 use strict;
4 use Data::Dumper;
5 use Time::HiRes qw( gettimeofday );
6 use Getopt::Long qw( :config bundling );
7 use Maasha::Biopieces;
8
9
10 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
11
12
13 my ( $script, $t0, $t1, %options, $in, $out, $record, @vals, $i );
14
15 $t0 = Time::HiRes::gettimeofday();
16
17 $script = ( split "/", $0 )[ -1 ];
18
19 Maasha::Biopieces::log_biopiece();
20
21 GetOptions(
22     \%options,
23     'key|k=s',
24     'keys|K=s',
25     'delimit|d=s',
26     'stream_in|I=s',
27     'stream_out|O=s',
28     'verbose|v',
29     'help|?'
30 );
31
32 $options{ "keys" }    = [ split ",", $options{ "keys" } ] if defined $options{ "keys" };
33 $options{ "delimit" } = '_' if not defined $options{ "delimit" };
34
35 $in  = Maasha::Biopieces::read_stream( $options{ "stream_in" } );
36 $out = Maasha::Biopieces::write_stream( $options{ "stream_out" } );
37
38 while ( $record = Maasha::Biopieces::get_record( $in ) )
39 {
40     if ( exists $options{ 'key' } and exists $record->{ $options{ 'key' } } )
41     {
42         @vals = split /$options{ 'delimit' }/, $record->{ $options{ 'key' } };
43     
44         for ( $i = 0; $i < @vals; $i++ )
45         {
46             if ( defined $options{ "keys" } and defined $options{ "keys" }->[ $i ] ) {
47                 $record->{ $options{ "keys" }->[ $i ] } = $vals[ $i ];
48             } else {
49                 $record->{ $options{ 'key' } . "_$i" } = $vals[ $i ];
50             }
51         }
52     }
53
54     Maasha::Biopieces::put_record( $record, $out );
55 }
56
57 $t1 = Time::HiRes::gettimeofday();
58
59 print STDERR "Program: $script" . ( " " x ( 25 - length( $script ) ) ) . sprintf( "Run time: %.4f\n", ( $t1 - $t0 ) ) if $options{ 'verbose' };
60
61
62 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
63
64
65 __END__
66