workarround for lsf/nfs bug
[PsN.git] / bin / cdd
blobff14ecb57cbfa5cc82e2c3a1af583226e53893df
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!" => '-xv|-noxv',
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 );
39 common_options::get_defaults( \%options, 'cdd' );
41 my %help_text;
43 $help_text{Pre_help_message} = <<'EOF';
44 cdd
46 Perl script for Case-Deletion Diagnostics of NONMEM runs.
48 Usage:
49 EOF
51 $help_text{Description} = <<'EOF';
52 Description:
54 The Case Deletion Diagnostics tool is run from the command line
55 with a few mandatory arguments. CDD is run as a diagnostic after
56 a model is regarded finished or at least mature enough to run
57 validation tool on. You need to specify the NONMEM modelfile
58 with a model that have successful termination. You also have to
59 specify the number or name of the datafile column on which to
60 select for deletion. You do so with the case_column option.
61 EOF
63 $help_text{Examples} = <<'EOF';
64 Example:
66 cdd -model=run89.mod -case_column=10
68 This will perform a Case Deletion Diagnostic on the model
69 specified in run89.mod based on the factors in column ten. If,
70 for example, column ten holds the ids of the seven centers
71 included in the study, this command will create seven copies of
72 the dataset, each with individuals included in one specific
73 center deleted. Say that the centers are numbered 1 to 7. Then
74 dataset 1 will have individuals from center 1 excluded, dataset
75 2 individuals from center 2 and so on.
76 EOF
78 $help_text{Options} = <<'EOF';
79 Options:
81 The options are given here in their long form. Any option may be
82 abbreviated to any nonconflicting prefix. The -threads option
83 may be abbreviated to -t(or even -thr) but -debug may not be
84 abbreviated to -d because it conflicts with -debug_packages and
85 -debug_subroutines.
87 The following options are valid:
88 EOF
90 $help_text{-h} = <<'EOF';
91 -h | -?
93 With -h or -? cdd will print a list of options and exit.
94 EOF
96 $help_text{-help} = <<'EOF';
97 -help
99 With -help cdd will print this, longer, help message.
102 $help_text{-bins} = <<'EOF';
103 -bins=$number
105 Sets the number of databins, or cdd datasets, to use. If the
106 number of unique values, or factors, in the based_on column is
107 higher than the number of bins then one or more factors will be
108 deleted in each cdd dataset. Specifying $number as higher than
109 the number of factors will have no effect. The bin number is
110 then set to the number of factors.
111 Default value = Number of unique values in the based_on column.
114 $help_text{-selection_method} = <<'EOF';
115 -selection_method='random' or 'consecutive'
117 Specifies whether the factors selected for exclusion should be
118 drawn randomly or consecutively from the datafile.
119 Default value = 'consecutive'
122 $help_text{-case_column} = <<'EOF';
123 -case_column=column_name|column_number
126 $help_text{-rplots} = <<'EOF';
127 <p class="style2">-rplots</p>
129 Generate R scripts for making various plots of the result.
132 $help_text{Post_help_message} = <<'EOF';
133 Also see 'execute -help' for a description of common options.
136 common_options::online_help( 'cdd', \%options, \%help_text, \%required_options, \%optional_options);
138 ## Check that we do have a model file
139 if ( scalar(@ARGV) < 1 ) {
140 print "A model file must be specified. Use 'cdd -h' for help.\n";
141 exit;
144 if( scalar(@ARGV) > 1 ){
145 print "CDD can only handle one modelfile. Use 'cdd -h' for help.\n";die;
146 exit;
149 unless ( defined $options{'case_column'} ){
150 print "case_column must be given\n" ;
151 exit;
154 ui -> category( 'cdd' );
155 ui -> silent(1) if( $options{'silent'} );
157 debug -> level( $options{'debug'} );
158 debug -> package( $options{'debug_package'} );
159 debug -> subroutine( $options{'debug_subroutine'} );
160 debug -> warn_with_trace( $options{'warn_with_trace'} );
162 my $eval_string = common_options::model_parameters(\%options);
164 my $model = model -> new ( eval( $eval_string ),
165 filename => $ARGV[0],
166 ignore_missing_output_files => 1 );
168 if( $options{'shrinkage'} ) {
169 $model -> shrinkage_stats( enabled => 1 );
172 if( $options{'threads'} ){
173 $options{'threads'} = [1,$options{'threads'}] ;
176 ## Create new Cdd object:
177 my $cdd = tool::cdd ->
178 new ( eval( $common_options::parameters ),
179 models => [ $model ],
180 bins => $options{'bins'},
181 selection_method => $options{'selection_method'},
182 case_columns => $options{'case_column'},
183 outside_n_sd_check => $options{'outside_n_sd_check'},
184 cross_validate => $options{'xv'} );
186 open(CMD, ">", $cdd -> directory . "/command.txt");
187 print CMD $cmd_line, "\n";
188 close(CMD);
190 if ( $options{'summarize'} ) {
191 $cdd -> prepare_results();
192 $cdd -> print_summary;
193 } else {
194 $cdd -> run;
195 $cdd -> prepare_results();
196 $cdd -> print_results;
197 # $cdd -> print_summary;
200 if( $options{'rplots'} ){
201 $cdd -> create_R_scripts();