def load_parameters_from_python_file(filename, as_module=False): if not as_module: f = support.check_file_existence(filename) try: module = imp.load_source('module', f) except Exceprint, e: support.error('File ' + filename + " is not valid python file.", error_instance=e)
def main(): parser = argparse.ArgumentParser( 'GADMA module for runs of local search on bootstrapped data. Is needed for calculating confidence intervals.' ) parser.add_argument('-b', '--boots', metavar="<dir>", required=True, help='Directory where bootstrapped data is located.') parser.add_argument( '-d', '--dem_model', metavar="<filename>", required=True, help= 'File with demographic model. Should contain `model_func` or `generated_model` function. One can put there several extra parameters and they will be taken automatically, otherwise one will need to enter them manually. Such parameters are:\n\t1) p0 (or popt) - initial parameters values\n\t2) lower_bound - list of lower bounds for parameters values\n\t4) upper_bound - list of upper bounds for parameters values\n\t5) par_labels/param_labels - list of string names for parameters 6) pts - pts for dadi (if there is no pts then moments will be run automatically).' ) parser.add_argument('-o', '--output', metavar="<dir>", required=True, help='Output directory.') parser.add_argument('-j', '--jobs', metavar="N", type=int, default=1, help='Number of threads for parallel run.') parser.add_argument( '--opt', metavar="log/powell", type=str, default='log', help= 'Local search algorithm, by now it can be:\n\t1) `log` - Inference.optimize_log\n\t2) `powell` - Inference.optimize_powell.' ) parser.add_argument( '-p', '--params', metavar="<filename>", type=str, default=None, help= 'Filename with parameters, should be valid python file. Parameters are presented in -d/--dem_model option description upper.' ) args = parser.parse_args() output = support.ensure_dir_existence(args.output, False) all_boot = gadma.Inference.load_bootstrap_data_from_dir( args.boots, return_filenames=True) print(str(len(all_boot)) + ' bootstrapped data found.') #extract model_func, we cannot put it to function as multiprocessing need pickleable functions args.dem_model = support.check_file_existence(args.dem_model) try: file_with_model_func = imp.load_source('module', args.dem_model) except Exception, e: support.error('File ' + args.dem_model + " is not valid python file.", error_instance=e)
def main(): parser = argparse.ArgumentParser( 'GADMA module for calculating confidence intervals from the result table of local search runs on bootstrapped data.' ) parser.add_argument( 'input_filename', metavar='<filename>', help= 'Filename (.csv or .pkl) with result from local search runs on bootstrapped data. Output of gadma-run_ls_on_boot_data.' ) parser.add_argument( '--log', required=False, action='store_true', help= 'If log then logarithm will be used to calculate confidence intervals.' ) parser.add_argument('--tex', required=False, action='store_true', help='Tex output.') parser.add_argument('--acc', required=False, metavar='N', type=int, default=5, help='Accuracy of output (dafault: 5).') args = parser.parse_args() filename = support.check_file_existence(args.input_filename) ext = filename.split('.')[-1] if ext == 'csv': df = pd.read_csv(filename, index_col=0) elif ext == 'pkl': df = pd.read_pickle(filename) a = df.values if args.log: a = np.log(a) means = np.mean(a, axis=0) stds = np.std(a, axis=0) for m, s, x, par_name in zip(means, stds, a.T, df.columns): l = m - 1.96 * s u = m + 1.96 * s if args.log: l = np.exp(l) u = np.exp(u) k2, p = stats.normaltest(x) if p < 0.05: normtest_str = 'data looks ' if args.log: normtest_str += 'log-normal (fail to reject H0)' else: normtest_str += 'normal (fail to reject H0)' else: normtest_str = 'data does not look ' if args.log: normtest_str += 'log-normal (reject H0)' else: normtest_str += 'normal (reject H0)' normtest_str += ' p-value=%.2e' % p if args.tex: format_string = '%s:\t$[%.' + str(args.acc) + 'f - %.' + str( args.acc) + 'f]$\t%s' else: format_string = '%s:\t%.' + str(args.acc) + 'f\t%.' + str( args.acc) + 'f\t%s' print(format_string % (par_name.strip(), l, u, normtest_str))