| 1 | package App::Egaz::Command::blastlink; | ||||||||||
| 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 MCE; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 19 | ▶ | use MCE::Flow; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 19 | ▶ | use App::Egaz -command; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 19 | ▶ | use App::Egaz::Common; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 2 | ▶ | sub abstract { | ||||||||
|
Subroutine
abstract: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 13 | 2 | return 'link sequences by blastn'; | |||||||||
| 14 | } | ||||||||||
| 15 | |||||||||||
| 16 | 3 | ▶ | sub opt_spec { | ||||||||
|
Subroutine
opt_spec: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 17 | return ( | ||||||||||
| 18 | 3 | [ "outfile|o=s", "Output filename. [stdout] for screen", { default => "stdout" }, ], | |||||||||
| 19 | [ "coverage|c=f", "coverage of identical matches", { default => 0.9 }, ], | ||||||||||
| 20 | [ "batch=i", "batch size of blast records", { default => 500000 }, ], | ||||||||||
| 21 | [ "parallel|p=i", "number of threads", { default => 2 }, ], | ||||||||||
| 22 | [ "verbose|v", "verbose mode", ], | ||||||||||
| 23 | { show_defaults => 1, } | ||||||||||
| 24 | ); | ||||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | 3 | ▶ | sub usage_desc { | ||||||||
|
Subroutine
usage_desc: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 28 | 3 | return "egaz blastlink [options] <infile>"; | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | 1 | ▶ | sub description { | ||||||||
|
Subroutine
description: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 32 | 1 | my $desc; | |||||||||
| 33 | 1 | $desc .= ucfirst(abstract) . ".\n"; | |||||||||
| 34 | 1 | $desc .= <<'MARKDOWN'; | |||||||||
| 35 | |||||||||||
| 36 | * <infile> is reports produced by `egaz blastn` | ||||||||||
| 37 | * <infile> can't be stdin | ||||||||||
| 38 | |||||||||||
| 39 | MARKDOWN | ||||||||||
| 40 | |||||||||||
| 41 | 1 | return $desc; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 2 | ▶ | sub validate_args { | ||||||||
|
Subroutine
validate_args: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 45 | 2 | my ( $self, $opt, $args ) = @_; | |||||||||
| 46 | |||||||||||
| 47 | 2 | ▶ | if ( @{$args} != 1 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 1 | my $message = "This command need one input file.\n\tIt found"; | |||||||||
| 49 | 1 | $message .= sprintf " [%s]", $_ for @{$args}; | |||||||||
| 50 | 1 | $message .= ".\n"; | |||||||||
| 51 | 1 | $self->usage_error($message); | |||||||||
| 52 | } | ||||||||||
| 53 | 1 | for ( @{$args} ) { | |||||||||
| 54 | 1 | ▶ | if ( !Path::Tiny::path($_)->is_file ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | 1 | $self->usage_error("The input file [$_] doesn't exist."); | |||||||||
| 56 | } | ||||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 0 | ▶ | sub execute { | ||||||||
|
Subroutine
execute: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 62 | 0 | my ( $self, $opt, $args ) = @_; | |||||||||
| 63 | |||||||||||
| 64 | #----------------------------# | ||||||||||
| 65 | # Parse reports | ||||||||||
| 66 | #----------------------------# | ||||||||||
| 67 | 0 | print STDERR "Parse reports\n"; | |||||||||
| 68 | 0 | ▶ | my $worker = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=11 SCAR=48.8
| |||||||||||
| 69 | 0 | my ( $self, $chunk_ref, $chunk_id ) = @_; | |||||||||
| 70 | |||||||||||
| 71 | 0 | my $wid = MCE->wid; | |||||||||
| 72 | 0 | ▶ | print STDERR "* Process task [$chunk_id] by worker #$wid\n" if $opt->{verbose}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | |||||||||||
| 74 | 0 | my @lines = @{$chunk_ref}; | |||||||||
| 75 | 0 | my @links; | |||||||||
| 76 | 0 | for my $line (@lines) { | |||||||||
| 77 | 0 | ▶ | next if $line =~ /^#/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | 0 | chomp $line; | |||||||||
| 79 | |||||||||||
| 80 | # qseqid sseqid qstart qend sstart send qlen slen nident | ||||||||||
| 81 | 0 | my @fields = grep {defined} split /\s+/, $line; | |||||||||
| 82 | 0 | ▶ | if ( @fields != 9 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | 0 | print "Fields error: $line\n"; | |||||||||
| 84 | 0 | next; | |||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | 0 | my $query_name = $fields[0]; | |||||||||
| 88 | 0 | my $hit_name = $fields[1]; | |||||||||
| 89 | 0 | ▶ | next if $query_name eq $hit_name; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 90 | |||||||||||
| 91 | 0 | my $query_length = $fields[6]; | |||||||||
| 92 | 0 | my $hit_length = $fields[7]; | |||||||||
| 93 | 0 | my $max_length = List::Util::max( $query_length, $hit_length ); | |||||||||
| 94 | 0 | ▶ | next if $query_length / $max_length < $opt->{coverage}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 95 | 0 | ▶ | next if $hit_length / $max_length < $opt->{coverage}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 96 | |||||||||||
| 97 | 0 | my $identical_match = $fields[8]; | |||||||||
| 98 | 0 | ▶ | next if $identical_match / $max_length < $opt->{coverage}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 99 | |||||||||||
| 100 | 0 | my ( $h_start, $h_end ) = ( $fields[4], $fields[5] ); | |||||||||
| 101 | 0 | my $strand = "+"; | |||||||||
| 102 | 0 | ▶ | if ( $h_start > $h_end ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 103 | 0 | ( $h_start, $h_end ) = ( $h_end, $h_start ); | |||||||||
| 104 | 0 | $strand = "-"; | |||||||||
| 105 | } | ||||||||||
| 106 | |||||||||||
| 107 | 0 | my $link = join "\t", $query_name, $hit_name, $strand; | |||||||||
| 108 | 0 | push @links, $link; | |||||||||
| 109 | } | ||||||||||
| 110 | |||||||||||
| 111 | 0 | ▶ | printf STDERR "Gather %d links\n", scalar @links if $opt->{verbose}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 112 | 0 | MCE->gather(@links); | |||||||||
| 113 | 0 | }; | |||||||||
| 114 | |||||||||||
| 115 | MCE::Flow::init { | ||||||||||
| 116 | chunk_size => $opt->{batch}, | ||||||||||
| 117 | max_workers => $opt->{parallel}, | ||||||||||
| 118 | 0 | }; | |||||||||
| 119 | 0 | my @all_links = mce_flow_f $worker, $args->[0]; | |||||||||
| 120 | 0 | MCE::Flow::finish; | |||||||||
| 121 | |||||||||||
| 122 | #----------------------------# | ||||||||||
| 123 | # Write outputs | ||||||||||
| 124 | #----------------------------# | ||||||||||
| 125 | 0 | my $out_fh; | |||||||||
| 126 | 0 | ▶ | if ( lc( $opt->{outfile} ) eq "stdout" ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 127 | 0 | $out_fh = *STDOUT{IO}; | |||||||||
| 128 | } | ||||||||||
| 129 | else { | ||||||||||
| 130 | 0 | open $out_fh, ">", $opt->{outfile}; | |||||||||
| 131 | } | ||||||||||
| 132 | |||||||||||
| 133 | 0 | print STDERR "Remove duplicated links\n"; | |||||||||
| 134 | 0 | @all_links = List::MoreUtils::PP::uniq(@all_links); | |||||||||
| 135 | |||||||||||
| 136 | 0 | for my $l (@all_links) { | |||||||||
| 137 | 0 | print {$out_fh} $l . "\n"; | |||||||||
| 138 | } | ||||||||||
| 139 | |||||||||||
| 140 | 0 | close $out_fh; | |||||||||
| 141 | } | ||||||||||
| 142 | |||||||||||
| 143 | 19 | 1; | |||||||||