script/eval_alignment.pl untested

filter: Statementstmt 0.0% 0 / 102 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 16 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 147 CC 2 SCAR 9.0
CC
2
Cov
0%
remove_gaponly
6.0
set_logfile
2.0
BEGIN
2.0
CRAP 2.5
1 #!/usr/bin/env perl
2 # Last changed Time-stamp: <2019-04-23 22:33:47 mtw>
3 # -*-CPerl-*-
4 #
5 # A structural alignment evaluator
6 #
7 # usage: eval_alignment.pl -a myaln.stk --statistics RAFS
8 #
9  
10 use version; our $VERSION = qv('0.11');
11 use strict;
12 use warnings;
13 use File::Basename;
14 use Bio::AlignIO;
15 use Bio::RNA::RNAaliSplit::WrapRscape;
16 use Bio::RNA::RNAaliSplit::WrapRNAz;
17 use Getopt::Long qw( :config posix_default bundling no_ignore_case );
18 use Data::Dumper;
19 use Pod::Usage;
20 use Path::Class;
21 use Carp;
22 use Cwd;
23  
24 #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^#
25 #^^^^^^^^^^ Variables ^^^^^^^^^^^#
26 #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^#
27  
28 my $show_version = 0;
29 my ($id,$stkfile,$alnfile,$logfile,$in,$out,$cwd,$bn);
30 my @odir = ();
31 my $handle=undef;
32 my $nofigures = 0;
33 my $outdir = "eval_result";
34 my $stat = "GTp";
35 my $have_logfile=0;
36 use diagnostics;
37  
38 Getopt::Long::config('no_ignore_case');
39 pod2usage(-verbose => 1) unless
40 GetOptions("a|aln=s" => \$stkfile,
41 "s|statistic=s" => \$stat,
42 "o|out=s" => \$outdir,
43 "l|log=s" => \&set_logfile,
44 "n|nofigures" => sub{$nofigures = 1},
45 "version" => sub{$show_version = 1},
46 "man" => sub{pod2usage(-verbose => 2)},
47 "help|h" => sub{pod2usage(1)}
48 );
49  
50 if ($show_version == 1){
51 print "eval_alignment.pl $VERSION\n";
52 exit(0);
53 }
54  
55  
56 if ($have_logfile == 1){
57 open($handle, ">", $logfile)
58 || die "$0: can't open $logfile for appending: $!";
59 }
60 else{
61 open($handle, ">&", STDOUT)
62 || die "$0: can't open handle for STDOUT: $!";
63 }
64  
65 @odir = split /\//, $outdir;
66 $cwd = getcwd();
67 unless (-f $stkfile){
68 warn "Could not find input file provided via -a|-aln option";
69 pod2usage(-verbose => 0);
70 }
71 $bn = basename($stkfile, ".stk");
72 $alnfile = file($cwd,$bn.".aln");
73 # convert Stockholm -> Clustal for RNAz
74 $in = Bio::AlignIO->new(-file => $stkfile ,
75 -format => "Stockholm");
76  
77 $out = Bio::AlignIO->new(-file => ">$alnfile" ,
78 -format => "ClustalW");
79  
80 while ( my $aln = $in->next_aln ) {
81 my $clean = remove_gaponly($aln);
82 $out->write_aln($clean);
83 }
84  
85 my $r = Bio::RNA::RNAaliSplit::WrapRscape->new(ifile => $stkfile,
86 statistic => $stat,
87 nofigures => $nofigures,
88 odir => \@odir,
89 );
90 #print Dumper($r);
91  
92 my $z = Bio::RNA::RNAaliSplit::WrapRNAz->new(ifile => $alnfile,
93 odir => \@odir);
94 #print Dumper($z);
95  
96 if ($r->cseq <= 1){ # stk file had only one sequence
97 print $handle join("\t","-",$stkfile,"n/a"),"\n";
98 }
99 else{ # normal stk file
100 my $hint = "-";
101 my $prob=sprintf("%6.4f",$z->P);
102 my $str;
103 if ($r->status == 0){ # R-scape went through and gave results
104 ($prob>0.9 && $r->TP>1) ? ($hint = "*") : ($hint = "-");
105 $str = join("\t",$hint,$stkfile,$prob,$r->statistic,$r->TP,$r->alen,$r->nbpairs,$r->nseq)."\n";
106 }
107 else{
108 $str = join("\t",$hint,$stkfile,$prob,"nodata")."\n";
109 }
110 print $handle $str;
111 }
112  
113  
114 sub set_logfile {
115 $logfile=$_[1];
116 $have_logfile=1;
117 }
118  
119 sub remove_gaponly {
120 my $a = shift;
121 $a->set_displayname_flat();
122 my $l = $a->length;
123 my $dim = $a->num_sequences;
124 #print "+++ $dim sequences with length $l in alignment +++\n";
125 my $gapstring = ("-"x$l);
126 #print "gapstring\n$gapstring\n\n\n";
127 my @keep = ();
128  
129 foreach my $i (1..$dim){
130 my $alnT = $a->get_seq_by_pos($i);
131 my $seq = $alnT->seq();
132 # check if we have a gap-only substring of length $l
133 index($seq,$gapstring) == 0 ? next : 1;
134 push @keep, $i;
135 #print "keep $seq\n";
136 }
137 return ( $a->select_noncont(@keep) );
138 }
139  
140  
141 __END__