App-RL
view release on metacpan or search on metacpan
lib/App/RL/Command/stat2.pm view on Meta::CPAN
package App::RL::Command::stat2;
use strict;
use warnings;
use autodie;
use App::RL -command;
use App::RL::Common;
sub abstract {
return 'coverage statistics on another runlist for runlists';
}
sub opt_spec {
return (
[ "outfile|o=s", "output filename. [stdout] for screen" ],
[ "op=s", "operations: intersect, union, diff or xor", { default => "intersect" } ],
[ "size|s=s", "chr.sizes", { required => 1 } ],
[ "base|b=s", "basename of infile2", ],
[ "remove|r", "remove 'chr0' from chromosome names" ],
[ "mk", "first YAML file contains multiple sets of runlists" ],
[ "all", "only write whole genome stats" ],
{ show_defaults => 1, }
);
}
sub usage_desc {
return "runlist stat2 [options] <infile1> <infile2>";
}
sub description {
my $desc;
$desc .= ucfirst(abstract) . ".\n";
return $desc;
}
sub validate_args {
my ( $self, $opt, $args ) = @_;
if ( @{$args} != 2 ) {
my $message = "This command need two input files.\n\tIt found";
$message .= sprintf " [%s]", $_ for @{$args};
$message .= ".\n";
$self->usage_error($message);
}
for ( @{$args} ) {
next if lc $_ eq "stdin";
if ( !Path::Tiny::path($_)->is_file ) {
$self->usage_error("The input file [$_] doesn't exist.");
}
}
if ( $opt->{op} =~ /^dif/i ) {
$opt->{op} = 'diff';
}
elsif ( $opt->{op} =~ /^uni/i ) {
$opt->{op} = 'union';
}
elsif ( $opt->{op} =~ /^int/i ) {
$opt->{op} = 'intersect';
}
elsif ( $opt->{op} =~ /^xor/i ) {
$opt->{op} = 'xor';
}
else {
Carp::confess "[@{[$opt->{op}]}] invalid\n";
}
if ( !exists $opt->{base} ) {
$opt->{base} = Path::Tiny::path( $args->[1] )->basename( ".yaml", ".yml" );
}
if ( !exists $opt->{outfile} ) {
$opt->{outfile} = Path::Tiny::path( $args->[0] )->absolute . $opt->{op} . ".csv";
}
}
sub execute {
my ( $self, $opt, $args ) = @_;
#----------------------------#
# Loading
#----------------------------#
my $length_of = App::RL::Common::read_sizes( $opt->{size}, $opt->{remove} );
# file1
my $s1_of = {};
my @keys;
if ( $opt->{mk} ) {
my $yml = YAML::Syck::LoadFile( $args->[0] );
@keys = sort keys %{$yml};
for my $key (@keys) {
$s1_of->{$key} = App::RL::Common::runlist2set( $yml->{$key}, $opt->{remove} );
}
}
else {
( run in 1.493 second using v1.01-cache-2.11-cpan-39bf76dae61 )