| 1 | package App::Egaz::Command::partition; | ||||||||||
| 2 | 19 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 19 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 19 | ▶ | use autodie; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 19 | ▶ | use App::Egaz -command; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 19 | ▶ | use App::Egaz::Common; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 2 | ▶ | sub abstract { | ||||||||
|
Subroutine
abstract: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 10 | 2 | return 'partitions fasta files by size'; | |||||||||
| 11 | } | ||||||||||
| 12 | |||||||||||
| 13 | 7 | ▶ | sub opt_spec { | ||||||||
|
Subroutine
opt_spec: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 14 | return ( | ||||||||||
| 15 | 7 | [ 'chunk=i', 'chunk size', { default => 10_010_000 }, ], | |||||||||
| 16 | [ 'overlap=i', 'overlap size', { default => 10_000 }, ], | ||||||||||
| 17 | { show_defaults => 1, } | ||||||||||
| 18 | ); | ||||||||||
| 19 | } | ||||||||||
| 20 | |||||||||||
| 21 | 7 | ▶ | sub usage_desc { | ||||||||
|
Subroutine
usage_desc: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 22 | 7 | return "egaz partition [options] <infile> [more files]"; | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | 1 | ▶ | sub description { | ||||||||
|
Subroutine
description: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 26 | 1 | my $desc; | |||||||||
| 27 | 1 | $desc .= ucfirst(abstract) . ".\n"; | |||||||||
| 28 | 1 | $desc .= <<MARKDOWN; | |||||||||
| 29 | |||||||||||
| 30 | * Start coordinates of output is 1-based | ||||||||||
| 31 | * <infile> can't be stdin | ||||||||||
| 32 | * There is no --output option, outputs must be in the same directory of inputs | ||||||||||
| 33 | * Each fasta files should contain only one sequence. `faops split-name` can be use to do this. | ||||||||||
| 34 | |||||||||||
| 35 | MARKDOWN | ||||||||||
| 36 | |||||||||||
| 37 | 1 | return $desc; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 6 | ▶ | sub validate_args { | ||||||||
|
Subroutine
validate_args: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 41 | 6 | my ( $self, $opt, $args ) = @_; | |||||||||
| 42 | |||||||||||
| 43 | 6 | ▶ | if ( @{$args} < 1 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 1 | my $message = "This command need one or more input files.\n\tIt found"; | |||||||||
| 45 | 1 | $message .= sprintf " [%s]", $_ for @{$args}; | |||||||||
| 46 | 1 | $message .= ".\n"; | |||||||||
| 47 | 1 | $self->usage_error($message); | |||||||||
| 48 | } | ||||||||||
| 49 | 5 | for ( @{$args} ) { | |||||||||
| 50 | 6 | ▶ | if ( !Path::Tiny::path($_)->is_file ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 2 | $self->usage_error("The input file [$_] doesn't exist."); | |||||||||
| 52 | } | ||||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 3 | ▶ | sub execute { | ||||||||
|
Subroutine
execute: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 58 | 3 | my ( $self, $opt, $args ) = @_; | |||||||||
| 59 | |||||||||||
| 60 | 3 | for my $infile ( @{$args} ) { | |||||||||
| 61 | 3 | my $seq_of = App::Fasops::Common::read_fasta($infile); | |||||||||
| 62 | |||||||||||
| 63 | 3 | my @seq_names = keys %{$seq_of}; | |||||||||
| 64 | 3 | ▶ | Carp::croak "More than one sequence in [$infile]\n" if @seq_names > 1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | |||||||||||
| 66 | 2 | my $seq_size = length $seq_of->{ $seq_names[0] }; | |||||||||
| 67 | |||||||||||
| 68 | 2 | ▶ | if ( $seq_size > $opt->{chunk} + $opt->{overlap} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | |||||||||||
| 70 | # break it up | ||||||||||
| 71 | my $ranges | ||||||||||
| 72 | 1 | = App::Egaz::Common::overlap_ranges( 1, $seq_size, $opt->{chunk}, $opt->{overlap} ); | |||||||||
| 73 | 1 | for my $i ( @{$ranges} ) { | |||||||||
| 74 | 4 | my ( $start, $end ) = @{$i}; | |||||||||
| 75 | 4 | Path::Tiny::path( $infile . "[$start,$end]" )->touch; | |||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | } | ||||||||||
| 79 | else { | ||||||||||
| 80 | 1 | Path::Tiny::path( $infile . "[1,$seq_size]" )->touch; | |||||||||
| 81 | } | ||||||||||
| 82 | } | ||||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | 19 | 1; | |||||||||