App-Rangeops
view release on metacpan or search on metacpan
lib/App/Rangeops/Command/create.pm view on Meta::CPAN
package App::Rangeops::Command::create;
use strict;
use warnings;
use autodie;
use App::Rangeops -command;
use App::Rangeops::Common;
sub abstract {
return 'create blocked fasta files from range links';
}
sub opt_spec {
return (
[ "outfile|o=s", "Output filename. [stdout] for screen." ],
[ "genome|g=s", "Reference genome file.", { required => 1 }, ],
[ "name|n=s", "Default name for ranges.", ],
);
}
sub usage_desc {
return "rangeops create [options] <infiles>";
}
sub description {
my $desc;
$desc .= ucfirst(abstract) . ".\n";
return $desc;
}
sub validate_args {
my ( $self, $opt, $args ) = @_;
if ( !@{$args} ) {
$self->usage_error("This command need one or more input files.");
}
for ( @{$args} ) {
next if lc $_ eq "stdin";
if ( !Path::Tiny::path($_)->is_file ) {
$self->usage_error("The input file [$_] doesn't exist.");
}
}
if ( !exists $opt->{outfile} ) {
$opt->{outfile}
= Path::Tiny::path( $args->[0] )->absolute . ".fas";
}
}
sub execute {
my ( $self, $opt, $args ) = @_;
#----------------------------#
# Output
#----------------------------#
my $out_fh;
if ( lc( $opt->{outfile} ) eq "stdout" ) {
$out_fh = \*STDOUT;
}
else {
open $out_fh, ">", $opt->{outfile};
}
#----------------------------#
# Loading
#----------------------------#
my $info_of = {};
for my $file ( @{$args} ) {
for my $line ( App::RL::Common::read_lines($file) ) {
$info_of = App::Rangeops::Common::build_info( [$line], $info_of );
( run in 0.892 second using v1.01-cache-2.11-cpan-39bf76dae61 )