| 1 | # -*-CPerl-*- | ||||||||||||||
| 2 | # Last changed Time-stamp: <2019-01-07 00:39:21 mtw> | ||||||||||||||
| 3 | |||||||||||||||
| 4 | # Bio::RNA::RNAaliSplit::WrapRNAalifold.pm: A versatile object-oriented | ||||||||||||||
| 5 | # wrapper for RNAalifold | ||||||||||||||
| 6 | # | ||||||||||||||
| 7 | # Requires RNAalifold executable from the ViennaRNA package available | ||||||||||||||
| 8 | # to the Perl interpreter. | ||||||||||||||
| 9 | |||||||||||||||
| 10 | package Bio::RNA::RNAaliSplit::WrapRNAalifold; | ||||||||||||||
| 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 ($rnaalifold,$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 'ribosum' => ( | |||||||||||||
| 31 | is => 'rw', | ||||||||||||||
| 32 | isa => 'Num', | ||||||||||||||
| 33 | predicate => 'has_ribosum', | ||||||||||||||
| 34 | documentation => q(Ribosum scoring), | ||||||||||||||
| 35 | ); | ||||||||||||||
| 36 | |||||||||||||||
| 37 | 1 | has 'SS_cons' => ( | |||||||||||||
| 38 | is => 'rw', | ||||||||||||||
| 39 | isa => 'Num', | ||||||||||||||
| 40 | predicate => 'has_sscons', | ||||||||||||||
| 41 | documentation => q(Use consensus structures from Stockholm file), | ||||||||||||||
| 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 | has 'format' => ( | |||||||||||||
| 52 | is => 'rw', | ||||||||||||||
| 53 | isa => 'Str', | ||||||||||||||
| 54 | default => 'C', | ||||||||||||||
| 55 | predicate => 'has_format', | ||||||||||||||
| 56 | documentation => q(File format of the input multiple sequence alignment (MSA)), | ||||||||||||||
| 57 | ); | ||||||||||||||
| 58 | |||||||||||||||
| 59 | 1 | has 'consensus_struc' => ( | |||||||||||||
| 60 | is => 'rw', | ||||||||||||||
| 61 | isa => 'Str', | ||||||||||||||
| 62 | predicate => 'has_consensus_struc', | ||||||||||||||
| 63 | init_arg => undef, | ||||||||||||||
| 64 | ); | ||||||||||||||
| 65 | |||||||||||||||
| 66 | 1 | has 'consensus_mfe' => ( | |||||||||||||
| 67 | is => 'rw', | ||||||||||||||
| 68 | isa => 'Num', | ||||||||||||||
| 69 | predicate => 'has_consensus_mfe', | ||||||||||||||
| 70 | init_arg => undef, | ||||||||||||||
| 71 | ); | ||||||||||||||
| 72 | |||||||||||||||
| 73 | 1 | has 'consensus_energy' => ( | |||||||||||||
| 74 | is => 'rw', | ||||||||||||||
| 75 | isa => 'Num', | ||||||||||||||
| 76 | predicate => 'has_consensus_energy', | ||||||||||||||
| 77 | init_arg => undef, | ||||||||||||||
| 78 | ); | ||||||||||||||
| 79 | |||||||||||||||
| 80 | 1 | has 'consensus_covar_terms' => ( | |||||||||||||
| 81 | is => 'rw', | ||||||||||||||
| 82 | isa => 'Num', | ||||||||||||||
| 83 | predicate => 'has_consensus_covar_terms', | ||||||||||||||
| 84 | init_arg => undef, | ||||||||||||||
| 85 | ); | ||||||||||||||
| 86 | |||||||||||||||
| 87 | 1 | has 'RNAalifold_version' => ( | |||||||||||||
| 88 | is => 'rw', | ||||||||||||||
| 89 | isa => 'String', | ||||||||||||||
| 90 | init_arg => undef, | ||||||||||||||
| 91 | ); | ||||||||||||||
| 92 | |||||||||||||||
| 93 | 1 | has 'alignment_stk' => ( | |||||||||||||
| 94 | is => 'rw', | ||||||||||||||
| 95 | isa => 'Path::Class::File', | ||||||||||||||
| 96 | predicate => 'has_stk', | ||||||||||||||
| 97 | init_arg => undef, | ||||||||||||||
| 98 | ); | ||||||||||||||
| 99 | |||||||||||||||
| 100 | 1 | with 'FileDirUtil'; | |||||||||||||
| 101 | 1 | with 'Bio::RNA::RNAaliSplit::Roles'; | |||||||||||||
| 102 | |||||||||||||||
| 103 | sub BUILD { | ||||||||||||||
| 104 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
BUILD: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||
| 105 | 0 | my $this_function = (caller(0))[3]; | |||||||||||||
| 106 | 0 | ▶ | confess "ERROR [$this_function] \$self->ifile not available" | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 107 | unless ($self->has_ifile); | ||||||||||||||
| 108 | 0 | ▶ | $rnaalifold = can_run('RNAalifold') or | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 109 | croak "ERROR [$this_function] RNAalifold not found"; | ||||||||||||||
| 110 | 0 | ▶ | unless($self->has_odir){ | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 111 | 0 | ▶ | unless($self->has_dirnam){self->dirnam("as")} | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 112 | 0 | $self->odir( [$self->ifile->dir,$self->dirnam] ); | |||||||||||||
| 113 | } | ||||||||||||||
| 114 | 0 | $oodir = $self->odir->subdir("alifold"); | |||||||||||||
| 115 | 0 | my @created = make_path($oodir, {error => \my $err}); | |||||||||||||
| 116 | 0 | ▶ | confess "ERROR [$this_function] could not create output directory $self->oodir" | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 117 | if (@$err); | ||||||||||||||
| 118 | 0 | $self->set_ifilebn; | |||||||||||||
| 119 | 0 | $self->run_rnaalifold(); | |||||||||||||
| 120 | } | ||||||||||||||
| 121 | |||||||||||||||
| 122 | sub run_rnaalifold { | ||||||||||||||
| 123 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
run_rnaalifold: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||
| 124 | 0 | my $this_function = (caller(0))[3]; | |||||||||||||
| 125 | 0 | my ($out_fn,$out,$alnps_fn,$alnps,$alirnaps_fn,$stk_fn); | |||||||||||||
| 126 | 0 | my ($alirnaps,$alidotps_fn,$alidotps,$alifoldstk); | |||||||||||||
| 127 | 0 | my $tag = ""; | |||||||||||||
| 128 | 0 | ▶ | if ($self->has_ribosum){$tag = ".risobum"} | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 129 | 0 | ▶ | if ($self->has_basename){ | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 130 | 0 | $out_fn = $self->bn.$tag."."."alifold.out"; | |||||||||||||
| 131 | 0 | $alnps_fn = $self->bn.$tag."."."aln.ps"; | |||||||||||||
| 132 | 0 | $alirnaps_fn = $self->bn.$tag."."."alirna.ps"; | |||||||||||||
| 133 | 0 | $alidotps_fn = $self->bn.$tag."."."alidot.ps"; | |||||||||||||
| 134 | 0 | $stk_fn = $self->bn.$tag."."."alifold.stk"; | |||||||||||||
| 135 | } | ||||||||||||||
| 136 | elsif ($self->has_ifilebn){ | ||||||||||||||
| 137 | 0 | $out_fn = $self->ifilebn.$tag."."."alifold.out"; | |||||||||||||
| 138 | 0 | $alnps_fn = $self->ifilebn.$tag."."."aln.ps"; | |||||||||||||
| 139 | 0 | $alirnaps_fn = $self->ifilebn.$tag."."."alirna.ps"; | |||||||||||||
| 140 | 0 | $alidotps_fn = $self->ifilebn.$tag."."."alidot.ps"; | |||||||||||||
| 141 | 0 | $stk_fn = $self->ifilebn.$tag."."."alifold.stk"; | |||||||||||||
| 142 | } | ||||||||||||||
| 143 | else{ | ||||||||||||||
| 144 | 0 | $out_fn = $tag."alifold.out"; | |||||||||||||
| 145 | 0 | $alnps_fn = $tag."aln.ps"; | |||||||||||||
| 146 | 0 | $alirnaps_fn = $tag."alirna.ps"; | |||||||||||||
| 147 | 0 | $alidotps_fn = $tag."alidot.ps"; | |||||||||||||
| 148 | } | ||||||||||||||
| 149 | 0 | $out = file($oodir,$out_fn); # RNAalifold stdout | |||||||||||||
| 150 | 0 | $alnps = file($oodir,$alnps_fn); # RNAalifold aln.ps | |||||||||||||
| 151 | 0 | $alirnaps = file($oodir,$alirnaps_fn); # RNAalifold alirna.ps | |||||||||||||
| 152 | 0 | $alidotps = file($oodir,$alidotps_fn); # RNAalifold alidot.ps | |||||||||||||
| 153 | 0 | $alifoldstk = file($oodir,$stk_fn); # RNAalifold generated Stockholm file with new CS | |||||||||||||
| 154 | |||||||||||||||
| 155 | 0 | open my $fh, ">", $out; | |||||||||||||
| 156 | 0 | my $alifold_options = " --aln --color -p --sci --aln-stk "; | |||||||||||||
| 157 | #$alifold_options .= " --cfactor 0.6 --nfactor 0.5 "; | ||||||||||||||
| 158 | 0 | $alifold_options .= " -f ".$self->format." "; | |||||||||||||
| 159 | 0 | ▶ | if ($self->has_ribosum){$alifold_options.=" -r "} | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 160 | 0 | ▶ | if ($self->has_sscons){$alifold_options.=" --SS_cons "} | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 161 | 0 | my $cmd = $rnaalifold.$alifold_options.$self->ifile; | |||||||||||||
| 162 | 0 | my ( $success, $error_message, $full_buf, $stdout_buf, $stderr_buf ) = | |||||||||||||
| 163 | run( command => $cmd, verbose => 0 ); | ||||||||||||||
| 164 | 0 | ▶ | if( !$success ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 165 | 0 | print STDERR "ERROR [$this_function] Call to $rnaalifold unsuccessful\n"; | |||||||||||||
| 166 | 0 | print STDERR "ERROR: $cmd\n"; | |||||||||||||
| 167 | 0 | print STDERR "ERROR: this is what the command printed:\n"; | |||||||||||||
| 168 | 0 | print join "", @$full_buf; | |||||||||||||
| 169 | 0 | croak $!; | |||||||||||||
| 170 | } | ||||||||||||||
| 171 | 0 | my $stdout_buffer = join "", @$stdout_buf; | |||||||||||||
| 172 | 0 | my @rnaalifoldout = split /\n/, $stdout_buffer; | |||||||||||||
| 173 | 0 | foreach my $line( @rnaalifoldout){ | |||||||||||||
| 174 | 0 | print $fh $line,"\n"; | |||||||||||||
| 175 | } | ||||||||||||||
| 176 | 0 | close($fh); | |||||||||||||
| 177 | |||||||||||||||
| 178 | 0 | $self->_parse_rnaalifold($stdout_buffer); | |||||||||||||
| 179 | 0 | $self->alignment_stk($alifoldstk); | |||||||||||||
| 180 | 0 | rename "aln.ps", $alnps; | |||||||||||||
| 181 | 0 | rename "alirna.ps", $alirnaps; | |||||||||||||
| 182 | 0 | rename "alidot.ps", $alidotps; | |||||||||||||
| 183 | 0 | rename "RNAalifold_results.stk", $alifoldstk; | |||||||||||||
| 184 | 0 | unlink "alifold.out"; | |||||||||||||
| 185 | } | ||||||||||||||
| 186 | |||||||||||||||
| 187 | # parse RNAalifold output | ||||||||||||||
| 188 | sub _parse_rnaalifold { | ||||||||||||||
| 189 | 0 | ▶ | my ($self,$out) = @_; | ||||||||||||
|
Subroutine
_parse_rnaalifold: not called CC=4 SCAR=30.0
| |||||||||||||||
| 190 | 0 | my $this_function = (caller(0))[3]; | |||||||||||||
| 191 | 0 | my @buffer=split(/^/, $out); | |||||||||||||
| 192 | |||||||||||||||
| 193 | 0 | foreach my $i (0..$#buffer){ | |||||||||||||
| 194 | 0 | ▶ | next unless ($i == 1); # just parse consensus structure | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 195 | 0 | ▶ | unless ($buffer[$i] =~ m/([\(\)\.]+)\s+\(\s*(-?\d+\.\d+)\s+=\s+(-?\d+\.\d+)\s+\+\s+(-?\d+\.\d+)\)\s+\[sci\s+=\s+(-?\d+\.\d+)\]/){ | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 196 | 0 | carp "ERROR [$this_function] cannot parse RNAalifold output:"; | |||||||||||||
| 197 | 0 | croak $self->ifile.":\n$buffer[$i]"; | |||||||||||||
| 198 | } | ||||||||||||||
| 199 | 0 | $self->consensus_struc($1); | |||||||||||||
| 200 | 0 | $self->consensus_mfe($2); | |||||||||||||
| 201 | 0 | $self->consensus_energy($3); | |||||||||||||
| 202 | 0 | $self->consensus_covar_terms($4); | |||||||||||||
| 203 | 0 | $self->sci($5); | |||||||||||||
| 204 | 0 | last; | |||||||||||||
| 205 | } | ||||||||||||||
| 206 | } | ||||||||||||||
| 207 | |||||||||||||||
| 208 | 1 | 1; | |||||||||||||