lib/Bio/App/SELEX/selex_covarianceSearch

filter: Statementstmt 95.2% 100 / 105 Branchbran 58.3% 7 / 12 Conditioncond 37.5% 3 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 92.3% 12 / 13 Podpod n/a totaltotal 85.3% 122 / 143 CC 10 SCAR 15.1
CC
10
Cov
88%
main
10.9
process
3.0
get_full_path_for_executable
2.0
CRAP 4.5
« lib/Bio/App/SELEX/RNAmotifAnalysis.pm ↑ Summary blib/lib/Bio/App/SELEX/selex_stock2fasta.pl »
1 #!/usr/bin/env perl
2  
3 # ABSTRACT:
4  
5 #=============================================================================
6 # STANDARD MODULES AND PRAGMAS
7 1 ▶use 5.008; # Require at least Perl version 5.08
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use strict; # Must declare all variables before using them
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use warnings; # Emit helpful warnings
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use autodie; # Fatal exceptions for common unrecoverable errors (e.g. open)
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Carp qw( croak ); # Throw errors from calling function
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 #=============================================================================
14 # ADDITIONAL MODULES
15 1 ▶use Getopt::Long::Descriptive; # Parse @ARGV as command line flags and arguments
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use lib 'lib';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Bio::App::SELEX::RNAmotifAnalysis;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 #=============================================================================
20 # CONSTANTS
21  
22 1 my $TRUE = 1;
23 1 my $FALSE = 0;
24  
25 1 my $DEFAULT_ITERATIONS = 10;
26 1 my $DEFAULT_CONFIG = 'cluster.cfg';
27 1 my $AWK_CMD = '$1!~/^#/{print $2}';
28  
29 1 my @REQUIRED_FLAGS = qw( cm fasta sto );
30  
31 # CONSTANTS
32 #=============================================================================
33  
34 #=============================================================================
35 # COMMAND LINE
36  
37 # Run as a command-line program if not used as a module
38 1 ▶main(@ARGV) if !caller();
Branch: 1 branch
BranchTrueFalseTotal
unless caller() 1 0 1
39  
40 1 ▶sub main {
Subroutine main: called CC=7 SCAR=23.8
41  
42 #-------------------------------------------------------------------------
43 # COMMAND LINE INTERFACE #
44 # #
45 1 my ( $opt, $usage ) = describe_options(
46 '%c %o <some-arg>',
47 [ 'cm=s', 'file name for the input covariance model (required)', ],
48 [ 'fasta=s', 'file name for the FASTA file (required)', ],
49 [ 'sto=s', 'file name for the Stockholm file (required)', ],
50 [ 'rounds=i', 'Rounds of covariance model searching (default=10)', ],
51 [ 'config=s', 'Configuration file (default="cluster.cfg")', ],
52 [],
53 [ 'help', 'print usage message and exit' ],
54 );
55  
56 0 ▶ my $exit_with_usage = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
57 0 print "\nUSAGE:\n";
58 0 print $usage->text();
59 0 exit();
60 1 };
61  
62 # If requested, give usage information regardless of other options
63 1 ▶ $exit_with_usage->() if $opt->help;
Branch: 1 branch
BranchTrueFalseTotal
if $opt->help 0 1 1
64  
65 # Make some flags required
66 1 my $missing_required = $FALSE;
67 1 for my $flag (@REQUIRED_FLAGS) {
68 3 ▶ if ( !defined $opt->$flag ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opt->$flag) 0 3 3
69 0 print "Missing required option '$flag'\n";
70 0 $missing_required = $TRUE;
71 }
72 }
73  
74 # Exit with usage statement if any required flags are missing
75 1 ▶ $exit_with_usage->() if $missing_required;
Branch: 1 branch
BranchTrueFalseTotal
if $missing_required 0 1 1
76  
77 # #
78 # COMMAND LINE INTERFACE #
79 #-------------------------------------------------------------------------
80  
81 #-------------------------------------------------------------------------
82 # #
83 # #
84  
85 1 ▶ my $config_file = $opt->config || $DEFAULT_CONFIG;
Condition33%1/3
$opt->config || $DEFAULT_CONFIG
l!l&&r!l&&!r
100
MC/DC0%0/2
$opt->config || $DEFAULT_CONFIG
$opt->config $DEFAULT_CONFIG
Truth table33%1/3
A || B
A= $opt->configB= $DEFAULT_CONFIG
ABresult
1X1
011
000
86 1 my $config = Bio::App::SELEX::RNAmotifAnalysis::get_config($config_file);
87  
88 1 ▶ process(
Condition33%1/3
$opt->rounds || $DEFAULT_ITERATIONS
l!l&&r!l&&!r
100
MC/DC0%0/2
$opt->rounds || $DEFAULT_ITERATIONS
$opt->rounds $DEFAULT_ITERATIONS
Truth table33%1/3
A || B
A= $opt->roundsB= $DEFAULT_ITERATIONS
ABresult
1X1
011
000
89 {
90 cm => $opt->cm,
91 fasta => $opt->fasta,
92 sto => $opt->sto,
93 rounds => $opt->rounds || $DEFAULT_ITERATIONS,
94 config => $config,
95 },
96 );
97  
98 1 return;
99  
100 # #
101 # #
102 #-------------------------------------------------------------------------
103 }
104  
105 # COMMAND LINE
106 #=============================================================================
107  
108 #=============================================================================
109 #
110  
111 1 ▶sub process {
Subroutine process: called CC=3 SCAR=11.0
112 1 my ($arg_ref) = @_;
113  
114 1 my $cm = $arg_ref->{cm};
115 1 my $fasta = $arg_ref->{fasta};
116 1 my $sto = $arg_ref->{sto};
117 1 my $config = $arg_ref->{config};
118 1 my $rounds = $arg_ref->{rounds};
119  
120 1 my $cmalign = get_full_path_for_executable('cmalign', $config);
121 1 my $cmbuild = get_full_path_for_executable('cmbuild', $config);
122 1 my $cmcalibrate = get_full_path_for_executable('cmcalibrate',$config);
123 1 my $cmsearch = get_full_path_for_executable('cmsearch', $config);
124  
125 1 my $stock2fasta = $config->{executables}{stock2fasta};
126 1 ▶ die 'stock2fasta executable path not found in the configuration file' if ! defined $stock2fasta;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stock2fasta 0 1 1
127  
128 1 my $round = 1;
129  
130 1 my $basename = $cm;
131  
132 #Strip off extension
133 1 $basename =~ s/\. .* \z//gxms;
134  
135 1 my %file = map { filenames( $basename, $_ ) } ( 1 .. $rounds + 1 );
136  
137 1 print "#round$round\n";
138 1 print "$cmcalibrate $cm\n";
139 1 print "$cmsearch --toponly -E 0.1 --tabfile $file{1}{tab} $cm $fasta\n";
140 1 print "\n";
141 1 print "awk '$AWK_CMD' $file{1}{tab} > $file{1}{found}\n";
142 1 print "\n";
143 1 print "grep -w -f $file{1}{found} $sto > $file{2}{sto}\n";
144 1 print "$stock2fasta $file{2}{sto} > $file{2}{fasta}\n";
145 1 print "\n";
146 1 print "\n";
147  
148 1 ▶ while ( $round < $rounds ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($round < $rounds) 9 1 10
149 9 $round++;
150 9 my $next_round = $round + 1;
151 9 my $current = "${basename}_rnd$round";
152 9 my $current_aln_cm = "${current}_aln.cm";
153 9 my $current_tab = "$current.tab";
154 9 my $current_fasta = "$current.fasta";
155 9 my $current_found = "${current}_clusters_found.txt";
156 9 my $current_cmaligned_sto = "${current}_cmaligned.sto";
157  
158 9 my $next = "${basename}_rnd$next_round";
159 9 my $next_sto = "$next.sto";
160 9 my $next_fasta = "$next.fasta";
161  
162 9 print "#round$round\n";
163 9 print "$cmalign -o $current_cmaligned_sto $cm $current_fasta\n";
164 9 print "$cmbuild $current_aln_cm $current_cmaligned_sto\n";
165 9 print "$cmcalibrate $current_aln_cm\n";
166 9 print "$cmsearch --toponly -E 0.1 --tabfile $current_tab $current_aln_cm $fasta\n";
167 9 print "\n";
168 9 print "awk '$AWK_CMD' $current_tab > $current_found\n";
169 9 print "\n";
170 9 print "grep -w -f $current_found $sto > $next_sto\n";
171 9 print "$stock2fasta $next_sto > $next_fasta\n";
172 9 print "\n";
173 9 print "\n";
174 }
175  
176 1 return;
177 }
178  
179 4 ▶sub get_full_path_for_executable {
Subroutine get_full_path_for_executable: called CC=2 SCAR=7.0
180 4 my $exe = shift;
181 4 my $config = shift;
182 4 ▶ my $full_path = $config->{executables}->{$exe} || die "Path for executable '$exe' not found in configuration file";
Condition50%1/2
$config->{'executables'}{$exe} || die("Path for executable '${exe}' not found in configuration file")
l!l
40
MC/DC0%0/1
$config->{'executables'}{$exe} || die("Path for executable '${exe}' not found in configuration file")
$config->{'executables'}{$exe}
Truth table50%1/2
A
A= $config->{'executables'}{$exe}
Aresult
11
00
183 4 return $full_path;
184 }
185  
186 11 ▶sub filenames {
Subroutine filenames: called CC=1 SCAR=0.0
187 11 my $basename = shift;
188 11 my $round = shift;
189  
190 return (
191 11 $round => {
192 cm => "${basename}_rnd$round.cm",
193 tab => "${basename}_rnd$round.tab",
194 found => "${basename}_rnd${round}_clusters_found.txt",
195 sto => "${basename}_rnd$round.sto",
196 aln => "${basename}_rnd${round}_aln.cm",
197 fasta => "${basename}_rnd${round}.fasta",
198 },
199 );
200 }
201  
202 #
203 #=============================================================================
204  
205 1;
206  
207 #Documentation-----------------------------------------------------------------------------
208  
209 =pod
210  
211 =head1 SYNOPSIS
212  
213 covarianceSearchScripts --cm rna.cm --fasta rna.fasta --sto rna.sto [--rounds 10] [--config cluster.cfg]
214  
215 =head1 DESCRIPTION
216  
217 =head1 SUBROUTINES/METHODS
218  
219 =head1 DIAGNOSTICS
220  
221 =head1 CONFIGURATION AND ENVIRONMENT
222  
223 =head1 DEPENDENCIES
224  
225 =head1 INCOMPATIBILITIES
226  
227 None known
228  
229 =head1 BUGS AND LIMITATIONS
230  
231 There are no known bugs in this module.
232 Please report problems to molecules <at> cpan <dot> org.
233 Patches are welcome.
234  
235 =head1 SEE ALSO
236  
237 =head1 ACKNOWLEDGEMENTS
238  
« lib/Bio/App/SELEX/RNAmotifAnalysis.pm ↑ Summary blib/lib/Bio/App/SELEX/selex_stock2fasta.pl »