blib/lib/Algorithm/TrunkClassifier/CommandProcessor.pm untested

filter: Statementstmt 0.0% 0 / 82 Branchbran 0.0% 0 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 118 CC 14 SCAR 44.0
CC
14
Cov
0%
processCmd
132.0
checkTestsetArg
20.0
new
2.0
CRAP 81.1
1 package Algorithm::TrunkClassifier::CommandProcessor;
2  
3 use warnings;
4 use strict;
5  
6 our $VERSION = 'v1.0.1';
7  
8 my %commands;
9  
10 #Description: Command processor constructor
11 #Parameters: (1) TrunkClassifier::CommandProcessor, (2) classification procedure ref, (3), split ref, (4) testset ref,
12 # (5) class name variable ref, (6) output folder variable ref, (7) level variable ref, (8) prospect variable ref,
13 # (9) supplementary file variable ref, (10) verbose variable ref, (11) useall variable ref, (12) input data file variable ref
14 #Return value: TrunkClassifier::CommandProcessor object
15 sub new($ $ $ $ $ $ $ $ $ $ $ $ $){
16 my ($class, $classifyRef, $splitPercentRef, $testsetRef, $classnameRef, $outputRef, $levelRef, $prospectRef, $suppfileRef, $verboseRef, $useallRef, $datafileRef) = @_;
17 %commands = (
18 "-p" => {"numArgs" => 1, "validArgs" => 'loocv|split|dual', "var" => $classifyRef, "sub" => \&checkTestsetArg},
19 "--procedure" => {"numArgs" => 1, "validArgs" => 'loocv|split|dual', "var" => $classifyRef},
20 "-e" => {"numArgs" => 1, "validArgs" => '^[1-9][0-9]?$', "var" => $splitPercentRef},
21 "--split" => {"numArgs" => 1, "validArgs" => '^[1-9][0-9]?$', "var" => $splitPercentRef},
22 "-t" => {"numArgs" => 1, "validArgs" => '.+', "var" => $testsetRef},
23 "--testset" => {"numArgs" => 1, "validArgs" => '.+', "var" => $testsetRef},
24 "-c" => {"numArgs" => 1, "validArgs" => '.+', "var" => $classnameRef},
25 "--classvar" => {"numArgs" => 1, "validArgs" => '.+', "var" => $classnameRef},
26 "-o" => {"numArgs" => 1, "validArgs" => '.+', "var" => $outputRef},
27 "--output" => {"numArgs" => 1, "validArgs" => '.+', "var" => $outputRef},
28 "-l" => {"numArgs" => 1, "validArgs" => '^[1-5]+$', "var" => $levelRef},
29 "--levels" => {"numArgs" => 1, "validArgs" => '^[1-5]+$', "var" => $levelRef},
30 "-i" => {"numArgs" => 1, "validArgs" => '^samples|probes|classes$', "var" => $prospectRef},
31 "--inspect" => {"numArgs" => 1, "validArgs" => '^samples|probes|classes$', "var" => $prospectRef},
32 "-s" => {"numArgs" => 1, "validArgs" => '.+', "var" => $suppfileRef},
33 "--supp" => {"numArgs" => 1, "validArgs" => '.+', "var" => $suppfileRef},
34 "-v" => {"numArgs" => 0, "var" => $verboseRef, "value" => 1},
35 "--verbose" => {"numArgs" => 0, "var" => $verboseRef, "value" => 1},
36 "-u" => {"numArgs" => 0, "var" => $useallRef, "value" => 1},
37 "--useall" => {"numArgs" => 0, "var" => $useallRef, "value" => 1},
38 "-h" => {"numArgs" => 0, "sub" => \&commandHelp},
39 "--help" => {"numArgs" => 0, "sub" => \&commandHelp}
40 );
41 my $self = {"input" => $datafileRef};
42 bless($self, $class);
43 return $self;
44 }
45  
46 #Description: Command processor loop
47 #Parameters: Command line arguments
48 #Return value: None
49 sub processCmd{
50 my $self = shift(@_);
51 my @commandLine = @_;
52 my @allCommands = @_;
53 if(!@commandLine){
54 commandHelp();
55 }
56 while(@commandLine){
57 my $com = shift(@commandLine);
58 my $arg;
59 if(!$commands{$com}){
60 if(scalar(@commandLine) >= 1){
61 die "Error: Unrecognized command '$com'\n";
62 }
63 ${$self->{"input"}} = $com;
64 return;
65 }
66 if($commands{$com}{"numArgs"} == 1){
67 $arg = shift(@commandLine);
68 if($arg =~ /^-/){
69 die "Error: Missing argument for command $com\n";
70 }
71 my $valid = $commands{$com}{"validArgs"};
72 if($arg !~ /$valid/){
73 die "Error: Invalid argument '$arg' to $com\n";
74 }
75 }
76 if($commands{$com}{"var"}){
77 if($commands{$com}{"value"}){
78 ${$commands{$com}{"var"}} = $commands{$com}{"value"};
79 }
80 else{
81 ${$commands{$com}{"var"}} = $arg;
82 }
83 }
84 if($commands{$com}{"sub"}){
85 &{$commands{$com}{"sub"}}($arg, \@allCommands);
86 }
87 }
88 if(!${$self->{"input"}}){
89 die "Error: Input data file not supplied\n";
90 }
91 }
92  
93 #Description: Checks that the -t option is supplied if -c dual is used
94 #Parameters: (1) The -c argument, (2) command line arguments
95 #Return value: None
96 sub checkTestsetArg($ $){
97 my ($argument, $comLineRef) = @_;
98 if($argument eq "dual"){
99 my $foundT = 0;
100 foreach my $arg (@{$comLineRef}){
101 if($arg eq "-t"){
102 $foundT = 1;
103 last;
104 }
105 }
106 if(!$foundT){
107 die "Error: Command line option -t must be given when -c dual is used\n";
108 }
109 }
110 }
111  
112 #Description: Command line help
113 #Parameters: None
114 #Return value: None
115 sub commandHelp(){
116 my $doc = <<END;
117 Usage
118 perl trunk_classifier.pl [Options] [File]
119  
120 Options
121 -p, --procedure Classification procedure to use [loocv|split|dual]
122 -e, --split Percentage of samples to use as test set when using -p split
123 -t, --testset Dataset to classify when using -c dual
124 -c, --classvar Name of the classification variable to use
125 -o, --output Name of the output folder
126 -l, --levels Force classifier to use trunks with X levels for classification
127 -i, --inspect Check data file before running [samples|probes|classes]
128 -s, --supp Supplementary file containing class information
129 -v, --verbose Report progress during classifier run
130 -u, --useall Circumvent level selection and use all trunks for classification
131 -h, --help Print command line help
132  
133 Output
134 performance: Classification accuracy for each LOOCV fold, as well as average accuracy
135 loo_trunks: Structures of leave-one-out decision trunks
136 cts_trunks: Structure of trunks built with compete training set
137 class_report: Classification of all test samples
138 log: Arguments used
139 END
140 die $doc;
141 }
142  
143 return 1;