| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::RL::Command::convert; | 
| 2 | 15 |  |  | 15 |  | 16192 | use strict; | 
|  | 15 |  |  |  |  | 45 |  | 
|  | 15 |  |  |  |  | 632 |  | 
| 3 | 15 |  |  | 15 |  | 105 | use warnings; | 
|  | 15 |  |  |  |  | 43 |  | 
|  | 15 |  |  |  |  | 924 |  | 
| 4 | 15 |  |  | 15 |  | 116 | use autodie; | 
|  | 15 |  |  |  |  | 43 |  | 
|  | 15 |  |  |  |  | 144 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 15 |  |  | 15 |  | 101193 | use App::RL -command; | 
|  | 15 |  |  |  |  | 43 |  | 
|  | 15 |  |  |  |  | 271 |  | 
| 7 | 15 |  |  | 15 |  | 8038 | use App::RL::Common; | 
|  | 15 |  |  |  |  | 50 |  | 
|  | 15 |  |  |  |  | 14228 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | sub abstract { | 
| 10 | 2 |  |  | 2 | 1 | 97 | return 'convert runlist file to position file'; | 
| 11 |  |  |  |  |  |  | } | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | sub opt_spec { | 
| 14 |  |  |  |  |  |  | return ( | 
| 15 | 4 |  |  | 4 | 1 | 49 | [ "outfile|o=s", "output filename. [stdout] for screen" ], | 
| 16 |  |  |  |  |  |  | [ "remove|r",    "remove 'chr0' from chromosome names" ], | 
| 17 |  |  |  |  |  |  | { show_defaults => 1, } | 
| 18 |  |  |  |  |  |  | ); | 
| 19 |  |  |  |  |  |  | } | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | sub usage_desc { | 
| 22 | 4 |  |  | 4 | 1 | 80323 | return "runlist convert [options] "; | 
| 23 |  |  |  |  |  |  | } | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | sub description { | 
| 26 | 1 |  |  | 1 | 1 | 1377 | my $desc; | 
| 27 | 1 |  |  |  |  | 7 | $desc .= ucfirst(abstract) . ".\n"; | 
| 28 | 1 |  |  |  |  | 6 | return $desc; | 
| 29 |  |  |  |  |  |  | } | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | sub validate_args { | 
| 32 | 3 |  |  | 3 | 1 | 4661 | my ( $self, $opt, $args ) = @_; | 
| 33 |  |  |  |  |  |  |  | 
| 34 | 3 | 100 |  |  |  | 11 | if ( @{$args} != 1 ) { | 
|  | 3 |  |  |  |  | 26 |  | 
| 35 | 1 |  |  |  |  | 5 | my $message = "This command need one input file.\n\tIt found"; | 
| 36 | 1 |  |  |  |  | 3 | $message .= sprintf " [%s]", $_ for @{$args}; | 
|  | 1 |  |  |  |  | 9 |  | 
| 37 | 1 |  |  |  |  | 5 | $message .= ".\n"; | 
| 38 | 1 |  |  |  |  | 23 | $self->usage_error($message); | 
| 39 |  |  |  |  |  |  | } | 
| 40 | 2 |  |  |  |  | 9 | for ( @{$args} ) { | 
|  | 2 |  |  |  |  | 11 |  | 
| 41 | 2 | 50 |  |  |  | 16 | next if lc $_ eq "stdin"; | 
| 42 | 2 | 100 |  |  |  | 20 | if ( !Path::Tiny::path($_)->is_file ) { | 
| 43 | 1 |  |  |  |  | 202 | $self->usage_error("The input file [$_] doesn't exist."); | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  | } | 
| 46 |  |  |  |  |  |  |  | 
| 47 | 1 | 50 |  |  |  | 154 | if ( !exists $opt->{outfile} ) { | 
| 48 | 0 |  |  |  |  | 0 | $opt->{outfile} = Path::Tiny::path( $args->[0] )->absolute . ".pos.txt"; | 
| 49 |  |  |  |  |  |  | } | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | sub execute { | 
| 53 | 1 |  |  | 1 | 1 | 13 | my ( $self, $opt, $args ) = @_; | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | #----------------------------# | 
| 56 |  |  |  |  |  |  | # Loading | 
| 57 |  |  |  |  |  |  | #----------------------------# | 
| 58 | 1 |  |  |  |  | 6 | my $infile;    # YAML::Syck::LoadFile handles IO::* | 
| 59 | 1 | 50 |  |  |  | 9 | if ( lc $args->[0] eq 'stdin' ) { | 
| 60 | 0 |  |  |  |  | 0 | $infile = *STDIN; | 
| 61 |  |  |  |  |  |  | } | 
| 62 |  |  |  |  |  |  | else { | 
| 63 | 1 |  |  |  |  | 5 | $infile = $args->[0]; | 
| 64 |  |  |  |  |  |  | } | 
| 65 | 1 |  |  |  |  | 10 | my $r_of = App::RL::Common::runlist2set( YAML::Syck::LoadFile($infile), $opt->{remove} ); | 
| 66 |  |  |  |  |  |  |  | 
| 67 | 1 |  |  |  |  | 15 | my $out_fh; | 
| 68 | 1 | 50 |  |  |  | 11 | if ( lc( $opt->{outfile} ) eq "stdout" ) { | 
| 69 | 1 |  |  |  |  | 9 | $out_fh = *STDOUT; | 
| 70 |  |  |  |  |  |  | } | 
| 71 |  |  |  |  |  |  | else { | 
| 72 | 0 |  |  |  |  | 0 | open $out_fh, ">", $opt->{outfile}; | 
| 73 |  |  |  |  |  |  | } | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | #----------------------------# | 
| 76 |  |  |  |  |  |  | # Operating | 
| 77 |  |  |  |  |  |  | #----------------------------# | 
| 78 | 1 |  |  |  |  | 6 | for my $key ( sort keys %{$r_of} ) { | 
|  | 1 |  |  |  |  | 18 |  | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | #@type AlignDB::IntSpan | 
| 81 | 16 |  |  |  |  | 504 | my $set = $r_of->{$key}; | 
| 82 | 16 | 100 |  |  |  | 70 | next if $set->is_empty; | 
| 83 | 11 |  |  |  |  | 284 | for my $span ( $set->runlists ) { | 
| 84 | 28 |  |  |  |  | 1432 | printf {$out_fh} "%s:%s\n", $key, $span; | 
|  | 28 |  |  |  |  | 186 |  | 
| 85 |  |  |  |  |  |  | } | 
| 86 |  |  |  |  |  |  | } | 
| 87 |  |  |  |  |  |  |  | 
| 88 | 1 |  |  |  |  | 43 | close $out_fh; | 
| 89 |  |  |  |  |  |  | } | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | 1; |