Fixed $PRIOR support and bugfix in shrinkage results handling
[PsN.git] / bin / cdd
blobfd7cf8d84639fbc50db77dd331d2aca7ad34abe7
1 #!/usr/local/bin/perl
3 use FindBin qw($Bin);
4 use lib "$Bin/../lib";
6 # Don't edit the line below, it must look exactly like this.
7 # Everything above this line will be replaced #
9 use PsN;
10 use model;
11 use tool::cdd;
12 use strict;
13 use debug;
14 use Getopt::Long;
15 use common_options;
17 my $cmd_line = $0 . " " . join( " ", @ARGV );
19 ## Configure the command line parsing
20 Getopt::Long::config("auto_abbrev");
22 my %options;
23 ## Declare the options
25 my %required_options = ( 'case_column:s' => 'column_name|column_number');
26 my %optional_options = ( "bins:i" => '',
27 "xv!" => '',
28 "rplots" => '',
29 "selection_method:s" => '\'random\'|\'consecutive\'',
30 "outside_n_sd_check:f" => '' );
32 my $res = GetOptions( \%options,
33 @common_options::get_opt_strings,
34 keys(%required_options),
35 keys(%optional_options) );
36 exit unless $res;
38 common_options::set_globals( \%options, 'cdd' );
39 common_options::get_defaults( \%options, 'cdd' );
40 common_options::sanity_checks( \%options, 'cdd' );
42 my %help_text;
44 $help_text{Pre_help_message} = <<'EOF';
45 EOF
47 $help_text{Description} = <<'EOF';
48 <h3 class=heading1>Description</h3>
50 The Case Deletion Diagnostics tool is run using the command from the command line
51 with a few mandatory arguments. CDD is run as a diagnostic after
52 a model is regarded finished or at least mature enough to run
53 validation tool on. You need to specify the NONMEM modelfile
54 with a model that have successful termination. You also have to
55 specify the number or name of the datafile column on which to
56 select for deletion. You do so with the case_column option.
57 EOF
59 $help_text{Examples} = <<'EOF';
60 <h3 class=heading1>Examples</h3>
62 cdd -model=run89.mod -case_column=10
64 This will perform a Case Deletion Diagnostic on the model
65 specified in run89.mod based on the factors in column ten. If,
66 for example, column ten holds the ids of the seven centers
67 included in the study, this command will create seven copies of
68 the dataset, each with individuals included in one specific
69 center deleted. Say that the centers are numbered 1 to 7. Then
70 dataset 1 will have individuals from center 1 excluded, dataset
71 2 individuals from center 2 and so on.
72 EOF
74 $help_text{Options} = <<'EOF';
75 <h3 class=heading1>Options</h3>
77 The options are given here in their long form. Any option may be
78 abbreviated to any nonconflicting prefix. The -threads option
79 may be abbreviated to -t(or even -thr) but -debug may not be
80 abbreviated to -d because it conflicts with -debug_packages and
81 -debug_subroutines.
83 The following options are valid:
84 EOF
86 $help_text{-h} = <<'EOF';
87 <p class="option">-h | -?</p>
89 With -h or -? cdd will print a list of options and exit.
90 EOF
92 $help_text{-help} = <<'EOF';
93 <p class="option">-help</p>
95 With -help cdd will print this, longer, help message.
96 EOF
98 $help_text{-bins} = <<'EOF';
99 <p class="option">-bins=$number</p>
101 Sets the number of databins, or cdd datasets, to use. If the
102 number of unique values, or factors, in the based_on column is
103 higher than the number of bins then one or more factors will be
104 deleted in each cdd dataset. Specifying $number as higher than
105 the number of factors will have no effect. The bin number is
106 then set to the number of factors.
107 Default value = Number of unique values in the based_on column.
110 $help_text{-selection_method} = <<'EOF';
111 <p class="option">-selection_method='random' or 'consecutive'</p>
113 Specifies whether the factors selected for exclusion should be
114 drawn randomly or consecutively from the datafile.
115 Default value = 'consecutive'
118 $help_text{-case_column} = <<'EOF';
119 <p class="option">-case_column=column_name|column_number</p>
121 This flag is mandatory. Through this flag you set the column on
122 which the case-deletion is done. You can either use the name of
123 the column as specified in the $INPUT record in the model file
124 or you can use the column number.
128 $help_text{-rplots} = <<'EOF';
129 <p class="option">-rplots</p>
131 Generate R scripts for making various plots of the result.
134 $help_text{-xv} = <<'EOF';
135 <p class="option">-xv|-noxv</p>
137 Turns the cross-validation feature on (-xv) or off (-noxv). The
138 default behavior is to run the cross-validation step.
141 $help_text{Post_help_message} = <<'EOF';
142 Also see 'execute -help' for a description of common options.
145 common_options::online_help( 'cdd', \%options, \%help_text, \%required_options, \%optional_options);
147 ## Check that we do have a model file
148 if ( scalar(@ARGV) < 1 ) {
149 print "A model file must be specified. Use 'cdd -h' for help.\n";
150 exit;
153 if( scalar(@ARGV) > 1 ){
154 print "CDD can only handle one modelfile. Use 'cdd -h' for help.\n";die;
155 exit;
158 unless ( defined $options{'case_column'} ){
159 print "case_column must be given\n" ;
160 exit;
163 my $eval_string = common_options::model_parameters(\%options);
165 my $model = model -> new ( eval( $eval_string ),
166 filename => $ARGV[0],
167 ignore_missing_output_files => 1 );
169 if( $options{'shrinkage'} ) {
170 $model -> shrinkage_stats( enabled => 1 );
173 if( $options{'threads'} ){
174 $options{'threads'} = [1,$options{'threads'}] ;
177 ## Create new Cdd object:
178 my $cdd = tool::cdd ->
179 new ( eval( $common_options::parameters ),
180 models => [ $model ],
181 bins => $options{'bins'},
182 selection_method => $options{'selection_method'},
183 case_columns => $options{'case_column'},
184 outside_n_sd_check => $options{'outside_n_sd_check'},
185 cross_validate => $options{'xv'} );
187 open(CMD, ">", $cdd -> directory . "/command.txt");
188 print CMD $cmd_line, "\n";
189 close(CMD);
191 if ( $options{'summarize'} ) {
192 $cdd -> prepare_results();
193 $cdd -> print_summary;
194 } else {
195 $cdd -> run;
196 $cdd -> prepare_results();
197 $cdd -> print_results;
198 # $cdd -> print_summary;
201 if( $options{'rplots'} ){
202 $cdd -> create_R_scripts();