blib/lib/Software/GenoScan/CommandProcessor.pm untested

filter: Statementstmt 0.0% 0 / 131 Branchbran 0.0% 0 / 54 Conditioncond 0.0% 0 / 60 MC/DCmcdc 0.0% 0 / 35 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 289 CC 28 SCAR 56.3
CC
28
Cov
0%
checkManArgMode
420.0
processCmd
90.0
commandHelp
2.0
CRAP 279.3
1 package Software::GenoScan::CommandProcessor;
2  
3 use warnings;
4 use strict;
5  
6 require Exporter;
7  
8 our $VERSION = "v1.0.4";
9 our @ISA = qw(Exporter);
10 our %EXPORT_TAGS = ("all" => [ qw(
11 processCmd
12 ) ] );
13 our @EXPORT_OK = (@{ $EXPORT_TAGS{"all"} });
14  
15 #Description: Processes command line arguments
16 #Parameters: (1) hash containing reference to @ARGV and argument variables
17 #Return value: Commands hash
18 sub processCmd{
19 my %args = @_;
20 my %commands = (
21 "-m" => {"numArgs" => 1, "validArgs" => 'genome|classify|benchmark|retrain', "var" => $args{"MODE"}},
22 "--mode" => {"numArgs" => 1, "validArgs" => 'genome|classify|benchmark|retrain', "var" => $args{"MODE"}},
23 "-d" => {"numArgs" => 1, "validArgs" => '.+', "var" => $args{"INPUT_DIR"}},
24 "--input-dir" => {"numArgs" => 1, "validArgs" => '.+', "var" => $args{"INPUT_DIR"}},
25 "-e" => {"numArgs" => 1, "validArgs" => '.+', "var" => $args{"ANNOT_EXCLUSION_DIR"}},
26 "--exc-filter-dir" => {"numArgs" => 1, "validArgs" => '.+', "var" => $args{"ANNOT_EXCLUSION_DIR"}},
27 "-i" => {"numArgs" => 1, "validArgs" => '.+', "var" => $args{"ANNOT_INCLUSION_FILE"}},
28 "--inc-filter-file" => {"numArgs" => 1, "validArgs" => '.+', "var" => $args{"ANNOT_INCLUSION_FILE"}},
29 "-t" => {"numArgs" => 1, "validArgs" => '^(0(\.[0-9]+)?)|1$', "var" => $args{"PROBABILITY_THRESHOLD"}},
30 "--threshold" => {"numArgs" => 1, "validArgs" => '^(0(\.[0-9]+)?)|1$', "var" => $args{"PROBABILITY_THRESHOLD"}},
31 "-f" => {"numArgs" => 1, "validArgs" => '.+', "var" => $args{"HP_EXTRACTION_FILE"}},
32 "--parameter-file" => {"numArgs" => 1, "validArgs" => '.+', "var" => $args{"HP_EXTRACTION_FILE"}},
33 "-p" => {"numArgs" => 1, "validArgs" => '.+', "var" => $args{"POS_DATASET"}},
34 "--pos-dataset" => {"numArgs" => 1, "validArgs" => '.+', "var" => $args{"POS_DATASET"}},
35 "-n" => {"numArgs" => 1, "validArgs" => '.+', "var" => $args{"NEG_DATASET"}},
36 "--neg-dataset" => {"numArgs" => 1, "validArgs" => '.+', "var" => $args{"NEG_DATASET"}},
37 "-g" => {"numArgs" => 1, "validArgs" => '.+', "var" => $args{"GEN_DATASET"}},
38 "--gen-dataset" => {"numArgs" => 1, "validArgs" => '.+', "var" => $args{"GEN_DATASET"}},
39 "-a" => {"numArgs" => 1, "validArgs" => '.+', "var" => $args{"SCRIPT_PATH"}},
40 "--script-path" => {"numArgs" => 1, "validArgs" => '.+', "var" => $args{"SCRIPT_PATH"}},
41 "-s" => {"numArgs" => 1, "validArgs" => 'hsa', "var" => $args{"SPECIES_CODE"}},
42 "--species" => {"numArgs" => 1, "validArgs" => 'hsa', "var" => $args{"SPECIES_CODE"}},
43 "-l" => {"numArgs" => 1, "validArgs" => '^(0(\.[0-9]+)?)|1$', "var" => $args{"LOW_COMPLEXITY"}},
44 "--low-complexity" => {"numArgs" => 1, "validArgs" => '^(0(\.[0-9]+)?)|1$', "var" => $args{"LOW_COMPLEXITY"}},
45 "-o" => {"numArgs" => 1, "validArgs" => '.+', "var" => $args{"OUTPUT_DIR"}},
46 "--output-dir" => {"numArgs" => 1, "validArgs" => '.+', "var" => $args{"OUTPUT_DIR"}},
47 "-r" => {"numArgs" => 1, "validArgs" => '.+', "var" => $args{"REGRESSION"}},
48 "--regression" => {"numArgs" => 1, "validArgs" => '.+', "var" => $args{"REGRESSION"}},
49 "-c" => {"numArgs" => 1, "validArgs" => '.+', "var" => $args{"CLASSIFY_SET"}},
50 "--classify-set" => {"numArgs" => 1, "validArgs" => '.+', "var" => $args{"CLASSIFY_SET"}},
51 "-v" => {"numArgs" => 0, "var" => $args{"VERBOSE"}, "value" => 1},
52 "--verbose" => {"numArgs" => 0, "var" => $args{"VERBOSE"}, "value" => 1},
53 "-j" => {"numArgs" => 1, "validArgs" => '^[2-5]$', "var" => $args{"JUMP"}},
54 "--jump" => {"numArgs" => 1, "validArgs" => '^[2-5]$', "var" => $args{"JUMP"}},
55 "-h" => {"numArgs" => 0, "sub" => \&commandHelp},
56 "--help" => {"numArgs" => 0, "sub" => \&commandHelp}
57 );
58 my @commandLine = @{$args{"commandline"}};
59 chomp(@commandLine);
60 my @allCommands = @commandLine;
61 if(!@commandLine){
62 commandHelp();
63 }
64 while(@commandLine){
65 my $com = shift(@commandLine);
66 my $arg;
67 if(!$commands{$com}){
68 die "GenoScan error: Unrecognized command '$com'\n";
69 }
70 if($commands{$com}{"numArgs"} == 1){
71 $arg = shift(@commandLine);
72 if($arg =~ /^-/){
73 die "GenoScan error: Missing argument for command '$com'\n";
74 }
75 my $valid = $commands{$com}{"validArgs"};
76 if($arg !~ /$valid/){
77 die "GenoScan error: Invalid argument '$arg' to '$com'\n";
78 }
79 }
80 if($commands{$com}{"var"}){
81 if($commands{$com}{"value"}){
82 ${$commands{$com}{"var"}} = $commands{$com}{"value"};
83 }
84 else{
85 ${$commands{$com}{"var"}} = $arg;
86 }
87 }
88 if($commands{$com}{"sub"}){
89 &{$commands{$com}{"sub"}}($arg, \@allCommands);
90 }
91 }
92 checkManArgMode(${$args{"MODE"}}, \@allCommands);
93 return %commands;
94 }
95  
96 #Description: Checks that mandatory arguments are supplied
97 #Parameters: (1) The -m argument, (2) command line arguments
98 #Return value: None
99 sub checkManArgMode{
100 my ($mode, $comLineRef) = @_;
101 my $commands = join(" ", @{$comLineRef});
102 if($mode eq "genome"){
103 my $foundDJ = 0;
104 my $foundO = 0;
105 if($commands =~ m/-d\s+[^\s]/ || $commands =~ m/--input-dir\s+[^\s]/ || $commands =~ m/-j\s+[3-5]/ || $commands =~ m/--jump\s+[3-5]/){
106 $foundDJ = 1;
107 }
108 if($commands =~ m/-o\s+[^\s]/ || $commands =~ m/--output-dir\s+[^\s]/){
109 $foundO = 1;
110 }
111 if(!$foundDJ || !$foundO){
112 die "GenoScan error: Command line options -d and -o must be given when running in genome mode\n";
113 }
114 }
115 elsif($mode eq "classify"){
116 my $foundO = 0;
117 my $foundC = 0;
118 if($commands =~ m/-o\s+[^\s]/ || $commands =~ m/--output-dir\s+[^\s]/){
119 $foundO = 1;
120 }
121 if($commands =~ m/-c\s+[^\s]/ || $commands =~ m/--classify-set\s+[^\s]/){
122 $foundC = 1;
123 }
124 if(!$foundO || !$foundC){
125 die "GenoScan error: Command line options -o and -c must be given when running in classify mode\n";
126 }
127 }
128 elsif($mode eq "benchmark"){
129 my $foundO = 0;
130 my $foundP = 0;
131 my $foundN = 0;
132 my $foundG = 0;
133 if($commands =~ m/-o\s+[^\s]/ || $commands =~ m/--output-dir\s+[^\s]/){
134 $foundO = 1;
135 }
136 if($commands =~ m/-p\s+[^\s]/ || $commands =~ m/--pos-dataset\s+[^\s]/){
137 $foundP = 1;
138 }
139 if($commands =~ m/-n\s+[^\s]/ || $commands =~ m/--neg-dataset\s+[^\s]/){
140 $foundN = 1;
141 }
142 if($commands =~ m/-g\s+[^\s]/ || $commands =~ m/--gen_dataset\s+[^\s]/){
143 $foundG = 1;
144 }
145 if(!$foundO || !$foundP || !$foundN || !$foundG){
146 die "GenoScan error: Command line options -o, -p, -n and -g must be given when running in classify mode\n";
147 }
148 }
149 elsif($mode eq "retrain"){
150 my $foundO = 0;
151 my $foundP = 0;
152 my $foundN = 0;
153 if($commands =~ m/-o\s+[^\s]/ || $commands =~ m/--output-dir\s+[^\s]/){
154 $foundO = 1;
155 }
156 if($commands =~ m/-p\s+[^\s]/ || $commands =~ m/--pos-dataset\s+[^\s]/){
157 $foundP = 1;
158 }
159 if($commands =~ m/-n\s+[^\s]/ || $commands =~ m/--neg-dataset\s+[^\s]/){
160 $foundN = 1;
161 }
162 if(!$foundO || !$foundP || !$foundN){
163 die "GenoScan error: Command line options -o, -p and -n must be given when running in classify mode\n";
164 }
165 }
166 }
167  
168 #Description: Command line help
169 #Parameters: None
170 #Return value: None
171 sub commandHelp(){
172 my $doc = <<END;
173 Usage
174 perl genoscan.pl [Options]
175  
176 Version $VERSION
177  
178 Options
179 General
180  
181 -m, --mode GenoScan running mode [genome|classify|benchmark|retrain]
182 -t, --threshold Probability threshold for hairpin classification (0 to 1)
183 -r, --regression Name of custom regression model parameter file
184 -o, --output-dir Name of output directory
185 -s, --species Species code [hsa]
186 -l, --low-complexity Percentage threshold for low-complexity filtering (0 to 1)
187 -v, --verbose Report progress during GenoScan run
188 -h, --help Print command line help
189
190 Genome mode only
191
192 -d, --input-dir Directory containing FASTA files to scan for miRNAs
193 -e, --exc-filter-dir Directory containing GBS annotation files
194 -i, --inc-filter-file Name of file containing regions to include in the scan
195 -f, --parameter-file Name of file containing hairpin extraction parameters
196 -j, --jump Start processing on GenoScan step [2-5]
197
198 Classify mode only
199
200 -c, --classify-set FASTA file containing hairpins to classify
201
202 Benchmark and retrain mode only
203
204 -p, --pos-dataset Positive dataset file
205 -n, --neg-dataset Negative dataset file
206 -g, --gen-dataset Genomic dataset file (benchmark only)
207 -a, --script-path Custom path to R-script used for benchmark/retrain
208  
209 Output
210 miRNA_candidates: List of hairpins that pass the probability threshold
211 log: Summary of GenoScan run
212 END
213 die "$doc\n";
214 }
215  
216 return 1;
217