<jupyter_start><jupyter_text>Table of Contents<jupyter_code>import sys
x = 36
pts_l = [x+10, x+20, x+30]
pts_l
?eval
import sys

sys.path.insert(0, '/home/claudius/Downloads/dadi')

import dadi
dadi_model = 'dadi.Demographics1D.bottlegrowth'
f = eval(dadi_model)
%pdoc f
p_init = [0] * len(pts_l)
p_init
for i in range(len(pts_l)):
    p_init[i] = range(pts_l[i], pts_l[i]+10)
p_init
from itertools import product
?product
for i, comb in enumerate(product(*p_init)):
    print comb
    if i > 20: break
print "these are the starting values \'{}\'".format(p_init)
% ll dadiExercises/
path_to_spectrum_file = "dadiExercises/ERY.FOLDED.sfs.dadi_format"
dadi_model = "dadi.Demographics1D.growth"
upper = [1e3, 4]
lower = [1e-3, 0]
p_init = [1, 1]
dadi_opt_func = "dadi.Inference.optimize_log"
cmd = "./run_dadi.py -p {} -m {} -u \'{}\' -l \'{}\' -i \'{}\' -d {}".format(path_to_spectrum_file, dadi_model, upper, lower, p_init, dadi_opt_func)
cmd
import os
os.system(cmd)
import pickle, glob
pickled = glob.glob('OUT_run_dadi/ERY*pickle')
sorted(pickled[:10])
opt_out = []
for filename in glob.iglob('OUT_run_dadi/ERY*pickle'):
    opt_out.append( pickle.load(open(filename, "r")) )
def get_flag_count(out, NM=True):
    """
    out: list of tuples, each containing p_init and popt + additional info, including warnflags
    as produced by run_dadi.py
    """
    from collections import defaultdict
    
    if NM: # if ar from Nelder-Mead
        i = 4 # the warnflag is reported at index position 4 in the output array
    else: # ar from BFGS optimisation
        i = 6
    
    warnflag = defaultdict(int)

    for res in out:
        if res[1][i] == 1: # notice the change in indexing
            warnflag[1] +=1
        elif res[1][i] == 2:
            warnflag[2] += 1
        elif res[1][i] == 0:
            warnflag[0] += 1
        else:
            warnflag[999] +=1
    if NM:
        print "success", warnflag[0]
        print "Maximum number of function evaluations made.", warnflag[1]
        print "Maximum number of iterations reached.", warnflag[2]
        print "unknown flag", warnflag[999]
    else:
        print "success", warnflag[0]
        print "Maximum number of iterations exceeded.", warnflag[1]
        print "Gradient and/or function calls not changing.", warnflag[2]
        print "unknown flag", warnflag[999]
get_flag_count(opt_out, NM=True)<jupyter_output>success 0
Maximum number of function evaluations made. 0
Maximum number of iterations reached. 414
unknown flag 0
{'fraction_non_alphanumeric': 0.12634946021591364, 'fraction_numerical': 0.025189924030387844, 'mean_word_length': 3.3137931034482757, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '303119', 'license': 'MIT', 'n_tokens_mistral': 953, 'n_tokens_neox': 884, 'n_words': 254, 'path': 'Data_analysis/SNP-indel-calling/dadi/test.ipynb', 'repo_name': 'claudiuskerth/PhDthesis', 'size': '2501'}