Egaz/Command/repeatmasker.pm

filter: Statementstmt 44.3% 35 / 79 Branchbran 15.0% 3 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.9% 10 / 11 Podpod 100% 6 / 6 totaltotal 46.5% 54 / 116 CC 15 SCAR 40.8
CC
15
Cov
38%
execute
132.0
validate_args
5.0
BEGIN
1.0
CRAP 59.4
« Egaz/Command/raxml.pm ↑ Summary Egaz/Command/fas2vcf.pm »
1 package App::Egaz::Command::repeatmasker;
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 'RepeatMasker wrapper';
11 }
12  
13 4 ▶sub opt_spec {
Subroutine opt_spec: called CC=1 SCAR=0.0
Pod documented
14 return (
15 4 [ "outdir|o=s", "Output directory", { default => "." }, ],
16 [ "species=s", "the species or clade of the input sequence", ],
17 [ "opt=s", "other options be passed to RepeatMasker", ],
18 [ "gff", "create .rm.gff by rmOutToGFF3.pl", ],
19 [ "tmp=s", "user defined tempdir", ],
20 [ "parallel|p=i", "number of threads", { default => 2 }, ],
21 [ "verbose|v", "verbose mode", ],
22 { show_defaults => 1, }
23 );
24 }
25  
26 4 ▶sub usage_desc {
Subroutine usage_desc: called CC=1 SCAR=0.0
Pod documented
27 4 return "egaz repeatmasker [options] <infile> [more infiles]";
28 }
29  
30 1 ▶sub description {
Subroutine description: called CC=1 SCAR=0.0
Pod documented
31 1 my $desc;
32 1 $desc .= ucfirst(abstract) . ".\n";
33 1 $desc .= <<'MARKDOWN';
34  
35 * <infile> should be fasta files (*.fa, *.fasta)
36 * setting --outdir to the same one of infiles will replace original files
37 * `repeatmasker` should be in $PATH
38 * suffix of masked files is .fa, when --outdir is the same as infile:
39 * infile.fa may be replaced
40 * infile.fasta or infile.others will coexist with infile.fa
41  
42 MARKDOWN
43  
44 1 return $desc;
45 }
46  
47 3 ▶sub validate_args {
Subroutine validate_args: called CC=5 SCAR=16.1
Pod documented
48 3 my ( $self, $opt, $args ) = @_;
49  
50 3 ▶ if ( @{$args} < 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$args;} < 1) 1 2 3
51 1 my $message = "This command need one or more input files.\n\tIt found";
52 1 $message .= sprintf " [%s]", $_ for @{$args};
53 1 $message .= ".\n";
54 1 $self->usage_error($message);
55 }
56 2 for ( @{$args} ) {
57 2 ▶ if ( !Path::Tiny::path($_)->is_file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (Path::Tiny::path($_)->is_file) 2 0 2
58 2 $self->usage_error("The input file [$_] doesn't exist.");
59 }
60 }
61  
62 }
63  
64 0 ▶sub execute {
Subroutine execute: not called CC=11 SCAR=48.8
Pod documented
65 0 my ( $self, $opt, $args ) = @_;
66  
67 # absolute pathes as we will chdir to tempdir later
68 0 my @infiles;
69 0 for my $infile ( @{$args} ) {
70 0 push @infiles, Path::Tiny::path($infile)->absolute->stringify;
71 }
72 0 $opt->{outdir} = Path::Tiny::path( $opt->{outdir} )->absolute->stringify;
73  
74 # record cwd, we'll return there
75 0 my $cwd = Path::Tiny->cwd;
76 0 my $tempdir;
77 0 ▶ if ( $opt->{tmp} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{'tmp'}) { } 0 0 0
78 $tempdir = Path::Tiny->tempdir(
79 TEMPLATE => "repeatmasker_XXXXXXXX",
80 DIR => $opt->{tmp},
81 0 );
82 }
83 else {
84 0 $tempdir = Path::Tiny->tempdir("repeatmasker_XXXXXXXX");
85 }
86 0 chdir $tempdir;
87  
88 0 for my $infile (@infiles) {
89 0 my $filename = Path::Tiny::path($infile)->basename();
90 0 my $basename = Path::Tiny::path($infile)->basename(qr/\..+?/);
91  
92 0 my $cmd = "RepeatMasker";
93 0 $cmd .= " $infile";
94 0 $cmd .= " -dir .";
95 0 ▶ $cmd .= " -species $opt->{species}" if $opt->{species};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"species"} 0 0 0
96 0 ▶ $cmd .= " $opt->{opt}" if $opt->{opt};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"opt"} 0 0 0
97 0 $cmd .= " -xsmall --parallel $opt->{parallel}";
98 0 App::Egaz::Common::exec_cmd( $cmd, { verbose => $opt->{verbose}, } );
99 0 ▶ if ( !$tempdir->child("$filename.masked")->is_file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tempdir->child("$filename.masked")->is_file) 0 0 0
100 0 Carp::croak "RepeatMasker on [$infile] failed\n";
101 }
102  
103 0 Path::Tiny::path("$filename.masked")->copy("$opt->{outdir}/$basename.fa");
104 0 Path::Tiny::path("$filename.out")->copy("$opt->{outdir}/$basename.rm.out");
105  
106 0 ▶ if ( $opt->{gff} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"gff"}) 0 0 0
107  
108 # RepeatMasker can be
109 # a symlink
110 # /home/linuxbrew/.linuxbrew/bin/RepeatMasker
111 # or a real executable file
112 # /home/linuxbrew/.linuxbrew/Cellar/repeatmasker/4.0.7_2/bin/RepeatMasker
113 # /home/linuxbrew/.linuxbrew/Cellar/repeatmasker/4.0.7_2/libexec/RepeatMasker
114 #
115 # We want find here
116 # /home/linuxbrew/.linuxbrew/Cellar/repeatmasker/4.0.7_2/libexec/util/rmOutToGFF3.pl
117 0 my $rm_bin = IPC::Cmd::can_run("RepeatMasker");
118 0 my $rm_path = Path::Tiny::path($rm_bin)->realpath;
119  
120 #@type Path::Tiny
121 0 my $rm2gff;
122  
123 0 ▶ if ( $rm_path->parent->child("util")->is_dir ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rm_path->parent->child('util')->is_dir) { } 0 0 0
124 0 $rm2gff = $rm_path->parent()->child("util/rmOutToGFF3.pl");
125 }
126 else {
127 0 $rm2gff = $rm_path->parent(2)->child("libexec/util/rmOutToGFF3.pl");
128 }
129 0 ▶ if ( !$rm2gff->is_file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rm2gff->is_file) 0 0 0
130 0 print STDERR YAML::Syck::Dump(
131 { "rm_bin" => $rm_bin,
132 "rm_path" => $rm_path,
133 "rm2gff" => $rm2gff
134 }
135 );
136 0 Carp::croak "Can't find rmOutToGFF3.pl\n";
137 }
138  
139 0 $cmd = "perl $rm2gff";
140 0 $cmd .= " $filename.out";
141 0 $cmd .= " > $filename.gff";
142 0 App::Egaz::Common::exec_cmd( $cmd, { verbose => $opt->{verbose}, } );
143 0 ▶ if ( !$tempdir->child("$filename.gff")->is_file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tempdir->child("$filename.gff")->is_file) 0 0 0
144 0 Carp::croak "rmOutToGFF3.pl on [$infile] failed\n";
145 }
146  
147 0 Path::Tiny::path("$filename.gff")->copy("$opt->{outdir}/$basename.rm.gff");
148 }
149 }
150  
151 0 chdir $cwd;
152 }
153  
154 19 1;
« Egaz/Command/raxml.pm ↑ Summary Egaz/Command/fas2vcf.pm »