]> git.donarmstrong.com Git - biopieces.git/blob - bp_bin/split_vals
fdb06ced0e89f4100fc2dc94a268b1d10988ff7d
[biopieces.git] / bp_bin / split_vals
1 #!/usr/bin/env perl -w
2
3 use strict;
4 use Maasha::Biopieces;
5
6
7 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
8
9
10 my ( $run_time_beg, $run_time_end, $options, $in, $out, $record, @vals, $i );
11
12 $run_time_beg = Maasha::Biopieces::run_time();
13
14 Maasha::Biopieces::log_biopiece();
15
16 $options = Maasha::Biopieces::parse_options(
17     [
18         { long => 'key',     short => 'k', type => 'string', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef },
19         { long => 'keys',    short => 'K', type => 'list',   mandatory => 'no',  default => undef, allowed => undef, disallowed => undef },
20         { long => 'delimit', short => 'd', type => 'string', mandatory => 'no',  default => '_',   allowed => undef, disallowed => undef },
21     ]   
22 );
23
24 $in  = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
25 $out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
26
27 while ( $record = Maasha::Biopieces::get_record( $in ) )
28 {
29     if ( exists $options->{ 'key' } and exists $record->{ $options->{ 'key' } } )
30     {
31         @vals = split /$options->{ 'delimit' }/, $record->{ $options->{ 'key' } };
32     
33         for ( $i = 0; $i < @vals; $i++ )
34         {
35             if ( defined $options->{ "keys" } and defined $options->{ "keys" }->[ $i ] ) {
36                 $record->{ $options->{ "keys" }->[ $i ] } = $vals[ $i ];
37             } else {
38                 $record->{ $options->{ 'key' } . "_$i" } = $vals[ $i ];
39             }
40         }
41     }
42
43     Maasha::Biopieces::put_record( $record, $out );
44 }
45
46 close $in;
47 close $out;
48
49 $run_time_end = Maasha::Biopieces::run_time();
50
51 Maasha::Biopieces::run_time_print( $run_time_beg, $run_time_end, $options );
52
53
54 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
55
56
57 __END__
58