changed input options to allow list of alternative models, or none. Removed inapplica...
[PsN.git] / bin / mcs
blobc9d5db42e85cd3a9b39fea5b487a45889191bde4
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::mc;
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 = ( 'samples:i' => '100');
26 my %optional_options = ( 'alternative_model:s' => 'alt1.mod,alt2.mod,...',
27 "bins:i" => '',
28 "selection_method:s" => '\'random\'|\'consecutive\'' );
30 my $res = GetOptions( \%options,
31 @common_options::get_opt_strings,
32 keys(%required_options),
33 keys(%optional_options) );
34 exit unless $res;
36 my %help_text;
38 $help_text{Pre_help_message} = <<'EOF';
41 Perl script for Monte-Carlo Simulation of NONMEM runs.
43 Usage:
44 EOF
46 $help_text{Options} = <<'EOF';
47 Options:
49 The options are given here in their long form. Any option may be
50 abbreviated to any nonconflicting prefix. The -threads option
51 may be abbreviated to -t(or even -thr) but -debug may not be
52 abbreviated to -d because it conflicts with -debug_packages and
53 -debug_subroutines.
55 The following options are valid:
56 EOF
58 $help_text{-h} = <<'EOF';
59 -h | -?
61 With -h or -? mc will print a list of options and exit.
62 EOF
64 $help_text{-help} = <<'EOF';
65 -help
67 With -help mc will print this, longer, help message.
68 EOF
70 $help_text{-alternative_model} = <<'EOF';
71 -alternative_model=alt1.mod,alt2.mod,...
73 List of one or more alternative models to use for estimation
74 with simulated datasets. The filenames must be comma-separated,
75 no spaces.
76 EOF
78 $help_text{-bins} = <<'EOF';
79 -bins=$number
81 Sets the number of databins, or mc datasets, to use. If the
82 number of unique values, or factors, in the based_on column is
83 higher than the number of bins then one or more factors will be
84 deleted in each mc dataset. Specifying $number as higher than
85 the number of factors will have no effect. The bin number is
86 then set to the number of factors.
87 Default value = Number of unique values in the based_on column.
88 EOF
90 $help_text{-selection_method} = <<'EOF';
91 -selection_method='random' or 'consecutive'
93 Specifies whether the factors selected for exclusion should be
94 drawn randomly or consecutively from the datafile.
95 Default value = 'consecutive'
96 EOF
99 $help_text{Post_help_message} = <<'EOF';
100 Also see 'execute -help' for a description of common options.
103 common_options::online_help( 'mc', \%options, \%help_text, \%required_options, \%optional_options);
105 ## Check that we do have a model file
106 if ( scalar(@ARGV) < 1 ) {
107 print "A model file must be specified. Use 'mc -h' for help.\n";
108 exit;
111 if( scalar(@ARGV) > 1 ){
112 print "MC can only handle one modelfile. Use 'mc -h' for help.\n";die;
113 exit;
116 unless ( defined $options{'samples'} ){
117 print "samples must be given\n" ;
118 exit;
121 ui -> category( 'mc' );
122 ui -> silent(1) if( $options{'silent'} );
124 debug -> level( $options{'debug'} );
125 debug -> package( $options{'debug_package'} );
126 debug -> subroutine( $options{'debug_subroutine'} );
127 debug -> warn_with_trace( $options{'warn_with_trace'} );
129 my $eval_string = common_options::model_parameters(\%options);
131 my $model = model -> new ( eval( $eval_string ),
132 filename => $ARGV[0],
133 ignore_missing_output_files => 1 );
136 my @alternatives=();
138 if ( defined $options{'alternative_model'} ){
139 #split string, assume comma separated
140 foreach my $altfile (split(/,/,$options{'alternative_model'})){
141 if (length($altfile)>0){
142 my $alternative_model = model ->
143 new ( eval( $eval_string ),filename => $altfile,ignore_missing_output_files => 1 );
144 push(@alternatives,$alternative_model);
147 if (scalar(@alternatives)<1){
148 die "Error: Option alternative_model used, but list of filenames could not be parsed.\n";
150 }else{
151 print "No alternative model given, will only estimate original model.\n" ;
155 my $mc = tool::mc ->
156 new ( eval( $common_options::parameters ),
157 models => [ $model ],
158 alternative_models => \@alternatives,
159 samples => $options{'samples'} );
160 open(CMD, ">", $mc -> directory . "/command.txt");
161 print CMD $cmd_line, "\n";
162 close(CMD);
164 $mc -> run;
165 $mc -> print_results;