Egaz/Command/maskfasta.pm

filter: Statementstmt 98.3% 61 / 62 Branchbran 78.5% 11 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 100% 6 / 6 totaltotal 95.7% 89 / 93 CC 12 SCAR 14.5
CC
12
Cov
95%
execute
7.0
validate_args
6.0
BEGIN
1.0
CRAP 4.3
« Egaz/Common.pm ↑ Summary Egaz/Command/partition.pm »
1 package App::Egaz::Command::maskfasta;
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 'soft/hard-masking sequences in a fasta file';
11 }
12  
13 6 ▶sub opt_spec {
Subroutine opt_spec: called CC=1 SCAR=0.0
Pod documented
14 return (
15 6 [ "outfile|o=s", "Output filename. [stdout] for screen", { default => "stdout" }, ],
16 [ 'hard', 'change masked regions to N', ],
17 [ 'len|l=i', 'sequence line length', { default => 80 }, ],
18 { show_defaults => 1, }
19 );
20 }
21  
22 6 ▶sub usage_desc {
Subroutine usage_desc: called CC=1 SCAR=0.0
Pod documented
23 6 return "egaz maskfasta [options] <infile> <runlist.yml>";
24 }
25  
26 1 ▶sub description {
Subroutine description: called CC=1 SCAR=0.0
Pod documented
27 1 my $desc;
28 1 $desc .= ucfirst(abstract) . ".\n";
29  
30 1 return $desc;
31 }
32  
33 5 ▶sub validate_args {
Subroutine validate_args: called CC=6 SCAR=17.9
Pod documented
34 5 my ( $self, $opt, $args ) = @_;
35  
36 5 ▶ if ( @{$args} != 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$args;} != 2) 1 4 5
37 1 my $message = "This command need two input files.\n\tIt found";
38 1 $message .= sprintf " [%s]", $_ for @{$args};
39 1 $message .= ".\n";
40 1 $self->usage_error($message);
41 }
42 4 for ( @{$args} ) {
43 7 ▶ next if lc $_ eq "stdin";
Branch: 1 branch
BranchTrueFalseTotal
if lc $_ eq "stdin" 0 7 7
44 7 ▶ if ( !Path::Tiny::path($_)->is_file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (Path::Tiny::path($_)->is_file) 2 5 7
45 2 $self->usage_error("The input file [$_] doesn't exist.");
46 }
47 }
48  
49 }
50  
51 2 ▶sub execute {
Subroutine execute: called CC=7 SCAR=19.5
Pod documented
52 2 my ( $self, $opt, $args ) = @_;
53  
54 #----------------------------#
55 # load files
56 #----------------------------#
57 2 my $seq_of = App::Fasops::Common::read_fasta( $args->[0] );
58  
59 2 my $set_single
60 = App::RL::Common::runlist2set( YAML::Syck::LoadFile( $args->[1] ) );
61  
62 2 my $out_fh;
63 2 ▶ if ( lc( $opt->{outfile} ) eq "stdout" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $opt->{'outfile'} eq 'stdout') { } 2 0 2
64 2 $out_fh = *STDOUT{IO};
65 }
66 else {
67 0 open $out_fh, ">", $opt->{outfile};
68 }
69  
70 #----------------------------#
71 # processing
72 #----------------------------#
73 2 for my $seq_name ( keys %{$seq_of} ) {
74 2 my $seq = $seq_of->{$seq_name};
75  
76 2 ▶ if ( exists $set_single->{$seq_name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $set_single->{$seq_name}) 2 0 2
77 2 my AlignDB::IntSpan $mask_set = $set_single->{$seq_name};
78  
79 # empty set have no @sets
80 2 my @sets = $mask_set->sets;
81 2 for my AlignDB::IntSpan $set (@sets) {
82 2 my $offset = $set->min - 1;
83 2 my $length = $set->size;
84  
85 2 my $str = substr $seq, $offset, $length;
86 2 ▶ if ( $opt->{hard} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{'hard'}) { } 1 1 2
87 1 my $str_len = length $str;
88 1 $str = 'N' x $str_len;
89 }
90 else {
91 1 $str = lc $str;
92 }
93 2 substr $seq, $offset, $length, $str;
94 }
95 }
96  
97 2 print {$out_fh} ">$seq_name\n";
98 2 ▶ print {$out_fh} substr( $seq, 0, $opt->{len}, '' ) . "\n" while ($seq);
Branch: 1 branch
BranchTrueFalseTotal
$seq and do { print {$out_fh;} substr($seq, 0, $opt->{"len"}, '') . "\n" } 472 2 474
99 }
100  
101 2 close $out_fh;
102 }
103  
104 19 1;
« Egaz/Common.pm ↑ Summary Egaz/Command/partition.pm »