lib/Bio/RNA/RNAaliSplit/WrapRNAz.pm

filter: Statementstmt 29.1% 30 / 103 Branchbran 0.0% 0 / 56 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 70.0% 7 / 10 Podpod 0.0% 0 / 2 totaltotal 21.6% 37 / 171 CC 31 SCAR 56.6
CC
31
Cov
19%
_parse_rnaz
506.0
BUILD
42.0
run_rnaz
30.0
CRAP 288.5
↑ Summary lib/Bio/RNA/RNAaliSplit/WrapRscape.pm »
1 # -*-CPerl-*-
2 # Last changed Time-stamp: <2019-01-07 00:39:31 mtw>
3  
4 # Bio::RNA::RNAaliSplit::WrapRNAz.pm: A versatile object-oriented
5 # wrapper for RNAz
6 #
7 # Requires RNAz executable available to the Perl interpreter.
8 # This package contains code fragments from the original RNAz Perl module
9  
10 package Bio::RNA::RNAaliSplit::WrapRNAz;
11  
12 1 ▶use version; our $VERSION = qv('0.09');
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use IPC::Cmd qw(can_run run);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use File::Path qw(make_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 #use diagnostics;
20  
21 1 my ($rnaz,$oodir);
22  
23 1 has 'basename' => (
24 is => 'rw',
25 isa => 'Str',
26 predicate => 'has_basename',
27 documentation => q(Set this to override output basename),
28 );
29  
30 1 has 'P' => (
31 is => 'rw',
32 isa => 'Num',
33 init_arg => undef,
34 documentation => q(SVM RNA-class probability),
35 );
36  
37 1 has 'z' => (
38 is => 'rw',
39 isa => 'Num',
40 init_arg => undef,
41 documentation => q(Mean z-score),
42 );
43  
44 1 has 'sci' => (
45 is => 'rw',
46 isa => 'Num',
47 init_arg => undef,
48 documentation => q(Structure conservation index),
49 );
50  
51 1 with 'FileDirUtil';
52 1 with 'Bio::RNA::RNAaliSplit::Roles';
53  
54 sub BUILD {
55 0 ▶ my $self = shift;
Subroutine BUILD: not called CC=6 SCAR=37.4
Pod undocumented
56 0 my $this_function = (caller(0))[3];
57 0 ▶ confess "ERROR [$this_function] \$self->ifile not available"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_ifile 0 0 0
58 unless ($self->has_ifile);
59 0 ▶ $rnaz = can_run('RNAz') or
Branch: 1 branch
BranchTrueFalseTotal
$rnaz = can_run("RNAz") or croak("ERROR [$this_function] RNAz not found") 0 0 0
60 croak "ERROR [$this_function] RNAz not found";
61 0 ▶ unless($self->has_odir){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->has_odir) 0 0 0
62 0 ▶ unless($self->has_dirnam){self->dirnam("as")}
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->has_dirnam) 0 0 0
63 0 $self->odir( [$self->ifile->dir,$self->dirnam] );
64 }
65 0 $oodir = $self->odir->subdir("rnaz");
66 0 my @created = make_path($oodir, {error => \my $err});
67 0 ▶ confess "ERROR [$this_function] could not create output directory $self->oodir"
Branch: 1 branch
BranchTrueFalseTotal
if @$err 0 0 0
68 if (@$err);
69 0 $self->set_ifilebn;
70 0 $self->run_rnaz();
71 }
72  
73 sub run_rnaz {
74 0 ▶ my $self = shift;
Subroutine run_rnaz: not called CC=5 SCAR=34.0
Pod undocumented
75 0 my $this_function = (caller(0))[3];
76 0 my ($rnaz_outfilename,$rnaz_out);
77 0 ▶ if ($self->has_basename){$rnaz_outfilename = $self->basename.".rnaz.out"}
Branch: 2 branches
BranchTrueFalseTotal
if ($self->has_basename) { } 0 0 0
elsif ($self->has_ifilebn) { } 0 0 0
78 0 elsif ($self->has_ifilebn){$rnaz_outfilename = $self->ifilebn.".rnaz.out"}
79 0 else{$rnaz_outfilename = "rnaz.out"}
80 0 $rnaz_out = file($oodir,$rnaz_outfilename);
81 0 open my $fh, ">", $rnaz_out;
82 0 my $rnaz_cmd = $rnaz." -l -d < ".$self->ifile;
83 0 my ( $success, $error_message, $full_buf, $stdout_buf, $stderr_buf ) =
84 run( command => $rnaz_cmd, verbose => 0 );
85 0 ▶ if( !$success ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($success) 0 0 0
86 0 print STDERR "ERROR [$this_function] Call to $rnaz unsuccessful\n";
87 0 print STDERR "ERROR: this is what the command printed:\n";
88 0 print join "", @$full_buf;
89 0 croak $!;
90 }
91 0 my $stdout_buffer = join "", @$stdout_buf;
92 0 my @out = split /\n/, $stdout_buffer;
93 0 foreach my $line( @out){print $fh $line,"\n"}
94 0 close($fh);
95 0 $self->_parse_rnaz($stdout_buffer);
96 }
97  
98 # parse RNAz output
99 sub _parse_rnaz {
100 0 ▶ my ($self,$rnaz) = @_;
Subroutine _parse_rnaz: not called CC=22 SCAR=62.3
101 0 my $this_function = (caller(0))[3];
102 0 my @rnaz=split(/^/, $rnaz);
103 0 my ($N,$identity,$columns,$decValue,$P,$z,$sci,$energy,$strand,
104 $covariance,$combPerPair,$meanMFE,$consensusMFE,$consensusSeq,
105 $consensusFold, $GCcontent, $ShannonEntropy);
106 0 my @aln=();
107  
108 0 foreach my $i (0..$#rnaz){
109 0 my $line=$rnaz[$i];
110 0 ▶ $identity=$1 if ($line=~/Mean pairwise identity:\s*(-?\d+.\d+)/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /Mean pairwise identity:\s*(-?\d+.\d+)/ 0 0 0
111 0 ▶ $N=$1 if ($line=~/Sequences:\s*(\d+)/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /Sequences:\s*(\d+)/ 0 0 0
112 0 ▶ if ($line=~/Reading direction:\s*(forward|reverse)/){
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /Reading direction:\s*(forward|reverse)/) 0 0 0
113 0 ▶ $strand=($1 eq 'forward')?'+':'-';
Branch: 1 branch
BranchTrueFalseTotal
$1 eq 'forward' ? : 0 0 0
114 }
115 0 ▶ $columns=$1 if ($line=~/Columns:\s*(\d+)/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /Columns:\s*(\d+)/ 0 0 0
116 0 ▶ $decValue=$1 if ($line=~/SVM decision value:\s*(-?\d+.\d+)/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /SVM decision value:\s*(-?\d+.\d+)/ 0 0 0
117 0 ▶ $P=$1 if ($line=~/SVM RNA-class probability:\s*(-?\d+.\d+)/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /SVM RNA-class probability:\s*(-?\d+.\d+)/ 0 0 0
118 0 ▶ $z=$1 if ($line=~/Mean z-score:\s*(-?\d+.\d+)/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /Mean z-score:\s*(-?\d+.\d+)/ 0 0 0
119 0 ▶ $sci=$1 if ($line=~/Structure conservation index:\s*(-?\d+.\d+)/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /Structure conservation index:\s*(-?\d+.\d+)/ 0 0 0
120 0 ▶ $energy=$1 if ($line=~/Energy contribution:\s*(-?\d+.\d+)/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /Energy contribution:\s*(-?\d+.\d+)/ 0 0 0
121 0 ▶ $covariance=$1 if ($line=~/Covariance contribution:\s*(-?\d+.\d+)/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /Covariance contribution:\s*(-?\d+.\d+)/ 0 0 0
122 0 ▶ $combPerPair=$1 if ($line=~/Combinations\/Pair:\s*(-?\d+.\d+)/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ m[Combinations/Pair:\s*(-?\d+.\d+)] 0 0 0
123 0 ▶ $consensusMFE=$1 if ($line=~/Consensus MFE:\s*(-?\d+.\d+)/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /Consensus MFE:\s*(-?\d+.\d+)/ 0 0 0
124 0 ▶ $meanMFE=$1 if ($line=~/Mean single sequence MFE:\s*(-?\d+.\d+)/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /Mean single sequence MFE:\s*(-?\d+.\d+)/ 0 0 0
125 0 ▶ $GCcontent=$1 if ($line=~/G\+C content:\s(\d+.\d+)/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /G\+C content:\s(\d+.\d+)/ 0 0 0
126 0 ▶ $ShannonEntropy=$1 if ($line=~/Shannon entropy:\s*(\d+.\d+)/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /Shannon entropy:\s*(\d+.\d+)/ 0 0 0
127  
128 0 ▶ if ($line=~/^>/){
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^>/) 0 0 0
129 0 chomp($rnaz[$i+1]);
130 0 chomp($rnaz[$i+2]);
131 0 ▶ if ($line=~/^>consensus/){
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^>consensus/) { } 0 0 0
132 0 $consensusSeq=$rnaz[$i+1];
133 0 $consensusFold=substr($rnaz[$i+2],0,length($rnaz[$i+1]));
134 0 last;
135 } else {
136 0 ▶ if ($line=~/>(.*?) (\d+) (\d+) (\+|\-) (\d+)/){
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ />(.*?) (\d+) (\d+) (\+|\-) (\d+)/) { } 0 0 0
elsif ($line =~ m[^(.*)/(\d+)-(\d+)$]) { } 0 0 0
137 0 push @aln, {name=>$1,
138 start=>$2,
139 end=>$2+$3,
140 strand=>$4,
141 fullLength=>$5,
142 seq=>$rnaz[$i+1],
143 fold=>substr($rnaz[$i+2],0,length($rnaz[$i+1]))};
144 0 $i+=2;
145 } elsif ($line=~/^(.*)\/(\d+)-(\d+)$/){
146 0 push @aln, {name=>$1,
147 start=>$2,
148 end=>$3,
149 strand=>$strand,
150 fullLength=>'',
151 seq=>$rnaz[$i+1],
152 fold=>substr($rnaz[$i+2],0,length($rnaz[$i+1]))};
153 0 $i+=2;
154 }
155 }
156 }
157 }
158  
159 0 $self->P($P);
160 0 $self->z($z);
161 0 $self->sci($sci);
162 }
163  
164 1 1;
↑ Summary lib/Bio/RNA/RNAaliSplit/WrapRscape.pm »