Fixed $PRIOR support and bugfix in shrinkage results handling
[PsN.git] / bin / nonpb
blob7ceea964c7e2f26bc917d36aaf5c86f80ca73f77
1 #!/usr/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::nonpb;
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' => '200');
26 #my %optional_options = ( 'alternative_models:s' => 'alt1.mod,alt2.mod,...',
27 # 'ref_ofv:i' => '500',
28 # 'estimate_simulation!' => '1' );
30 my %optional_options = ("etas:i"=>'',
31 "lst:s"=>''
34 my $res = GetOptions( \%options,
35 @common_options::get_opt_strings,
36 keys(%required_options),
37 keys(%optional_options) );
38 exit unless $res;
40 common_options::set_globals( \%options );
41 common_options::get_defaults( \%options, 'nonpb' );
42 common_options::sanity_checks( \%options, 'nonpb' );
44 my %help_text;
46 $help_text{Pre_help_message} = <<'EOF';
47 nonpb
49 Perl script for Non-Parametric Bootstrap.
51 Usage:
52 EOF
54 $help_text{Options} = <<'EOF';
55 Options:
57 The options are given here in their long form. Any option may be
58 abbreviated to any nonconflicting prefix. The -threads option
59 may be abbreviated to -t(or even -thr) but -debug may not be
60 abbreviated to -d because it conflicts with -debug_packages and
61 -debug_subroutines.
63 The following options are valid:
64 EOF
66 $help_text{-h} = <<'EOF';
67 -h | -?
69 With -h or -? nonpb will print a list of options and exit.
70 EOF
72 $help_text{-help} = <<'EOF';
73 -help
75 With -help nonpb will print this, longer, help message.
76 EOF
78 $help_text{-samples} = <<'EOF';
79 -samples=N
81 Required option. The number of samples for the bootstrap.
83 EOF
85 $help_text{-etas} = <<'EOF';
86 -etas=N
88 Optional, the number of ETAs (starting with ETA1) for which the
89 nonp_bootstrap should be run. Default is all ETAs.
91 EOF
93 $help_text{-lst} = <<'EOF';
94 -lst=<filename>
96 Optional, the lst-file from where to read initial parameter estimates.
97 Default is the same name as the model file but with .mod replaced with .lst.
98 EOF
101 $help_text{Post_help_message} = <<'EOF';
102 Also see 'execute -help' for a description of common options.
105 common_options::online_help( 'nonpb', \%options, \%help_text, \%required_options, \%optional_options);
107 ## Check that we do have a model file
108 if ( scalar(@ARGV) < 1 ) {
109 print "A simulation model file must be specified. Use 'nonpb -h' for help.\n";
110 exit;
113 if( scalar(@ARGV) > 1 ){
114 print "NONPB can only handle one modelfile, you listed: ",
115 join(',',@ARGV),". Use 'nonpb -h' for help.\n";die;
116 exit;
119 my $lst_file;
120 if (defined $options{'lst'}){
121 $lst_file=$options{'lst'};
122 } else {
123 #assume modelfile ends with .mod
124 $lst_file = (substr ($ARGV[0],0,-3)).'lst'; #keep from beginning, skip last four characters
125 unless ( -e $lst_file ){
126 print "When option -lst is omitted, the name of the lst-file is assumed to be the same\n".
127 "as the modelfile except that the last three letters are lst. Cannot find file $lst_file\.";
128 exit;
132 #unless ( defined $options{'clean'} ){
133 # Clean may be changed by default
134 # $options{'clean'} = 1;
137 ui -> category( 'nonpb' );
138 ui -> silent(1) if( $options{'silent'} );
140 debug -> level( $options{'debug'} );
141 debug -> package( $options{'debug_package'} );
142 debug -> subroutine( $options{'debug_subroutine'} );
143 debug -> warn_with_trace( $options{'warn_with_trace'} );
145 my $eval_string = common_options::model_parameters(\%options);
147 my $model = model -> new ( eval( $eval_string ),
148 filename => $ARGV[0],
149 ignore_missing_output_files => 1 );
151 my $nonpb = tool::nonpb ->
152 new ( eval( $common_options::parameters ),
153 models => [$model],
154 lst_file => $lst_file,
155 samples => $options{'samples'},
156 etas => $options{'etas'});
159 open(CMD, ">", $nonpb -> directory . "/command.txt");
160 print CMD $cmd_line, "\n";
161 close(CMD);
163 unless( -d $nonpb -> directory . "/intermediate_files" ){
164 mkdir( $nonpb -> directory . "/intermediate_files" );
166 unless( -d $nonpb -> directory . "/result_files" ){
167 mkdir( $nonpb -> directory . "/result_files" );
170 #this is sec 1 and 2 of URS nonp_bootstrap_v2
171 #individual step 1a,1b,2a done by bootstrap tool, can simply collect results
172 #from bootstrap object
174 #1.0
176 ##do the bootstrap in a specific sub-directory of nonpb_dirY : 'bootstrap'
177 #must carry a whole hash of options here, can lump them together according to Pontus, how???.
178 #ask Pontus about not having to list all options
180 chdir( $nonpb -> directory );
181 my $type = defined $options{'bca'} ? 'bca' : undef;
182 my $bs = tool::bootstrap ->
183 new ( eval( $common_options::parameters ),
184 directory => 'bootstrap',
185 models => [ $model ],
186 samples => $options{'samples'}
187 #the hash!!! Ask Pontus....
189 $bs -> run;
190 $bs -> prepare_results();
191 $bs -> print_results();
193 #Does this work? I set model array here and not in 'new' since
194 #must have bootstrap model array first. Want to have
195 #nonpb directory before running bootstrap, therefore do new nonpb before bootstrap
196 #use function here instead of assignment???
197 $nonpb -> {'start_bs_models'} = $bs -> {'prepared_models'}[0]{'own'};
199 $nonpb -> run;
201 #open( TMP, ">", 'ofv.done' );
202 #print TMP "1";
203 #close( TMP );
206 #$nonpb -> prepare_results;
207 #$nonpb -> print_results;